ember-cli-eyeglass
Version:
Use eyeglass and node-sass to compile Sass files.
83 lines • 3.03 kB
JavaScript
;
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const BroccoliPlugin = require("broccoli-plugin");
const path = require("path");
const fs = __importStar(require("fs-extra"));
const tmp = require("tmp");
/* eslint-disable-next-line @typescript-eslint/no-var-requires */
const ensureSymlink = require("ensure-symlink");
/**
* Creates symlinks to the source files specified.
*
* BroccoliSymbolicLinker
*/
class BroccoliSymbolicLinker extends BroccoliPlugin {
constructor(fileMap, options = {}) {
let pluginOpts = { needsCache: false };
Object.assign(pluginOpts, options);
super([], pluginOpts);
this.files = Object.assign({}, fileMap);
}
reset(fileMap) {
this.files = Object.assign({}, fileMap);
}
/**
* Record that a symlink should be created from src to dest.
*
* This can be called many times before the build method is invoked.
* Calling it after will not have an effect until the next time build() is
* invoked.
*
* @param src The file that should be symlinked into the tree.
* @param dest the relative path from the tree's root to the location of the
* symlink. the filename does not have to be the same.
* @returns the absolute path to the location where the symlink will be created.
*/
// eslint-disable-next-line @typescript-eslint/camelcase
ln_s(src, dest) {
// console.log(`will link ${src} to ${dest}`);
this.files[dest] = src;
let tartgetDir = this.outputPath;
if (!tartgetDir) {
this.fakeOutputPath = this.fakeOutputPath || tmp.dirSync().name;
tartgetDir = this.fakeOutputPath;
}
return path.join(tartgetDir, dest);
}
/**
* Returns the number of symlinks that will be created.
*/
numberOfFiles() {
return Object.keys(this.files).length;
}
/**
* Create the symlinks. Directories to them will be created as necessary.
*/
build() {
// eslint-disable-next-line no-console
// console.log(`Building ${this.numberOfFiles()} symlinks for ${this["_annotation"]}.`);
for (let dest of Object.keys(this.files)) {
let src = this.files[dest];
// console.log(`linking ${src} to ${dest}`);
dest = path.join(this.outputPath, dest);
let dir = path.dirname(dest);
fs.mkdirpSync(dir);
ensureSymlink(src, dest);
}
}
/**
* Output the symlinks that will be created for debugging.
*/
debug() {
return Object.keys(this.files).join("\n");
}
}
exports.BroccoliSymbolicLinker = BroccoliSymbolicLinker;
//# sourceMappingURL=broccoli-ln-s.js.map