Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
build() {
let tree = this.toTree();
if (!fs.existsSync('tmp')) {
fs.mkdirSync('tmp');
}
let builder = new broccoli.Builder(tree, { tmpdir: './tmp' });
if (this.watch) {
let watcher = new broccoli.Watcher(builder);
watcher.on('change', () => {
try {
let duration = Math.round(builder.outputNodeWrapper.buildState.totalTime) + 'ms';
if (duration > 1000) {
duration = chalk.yellow(duration);
}
log('info', `${ this.firstBuild ? 'Build' : 'Rebuild' } complete (${ duration })`);
this.afterBuild(builder.outputPath);
this.firstBuild = false;
if (duration > 1000) {
printSlowNodes(builder.outputNodeWrapper);
}
} catch (err) {
console.log('Error while attempting to restart the server:\n', err.stack || err);
}
});
function getBroccoliWatcher(outputDir, builder, ui) {
return new broccoli.Watcher(
builder,
builder.watchedSourceNodeWrappers,
buildWatcherOptions(ui),
);
}
constructBroccoliWatcher(options) {
const { Watcher } = require('broccoli');
const { watchedSourceNodeWrappers } = this.builder.builder;
let watcher = new Watcher(this.builder, watchedSourceNodeWrappers, { saneOptions: options });
watcher.start();
return watcher;
}