Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function watch() {
console.log(` watching source folder...`);
watcher.unwatchTree(from);
watcher.watchTree(from, { interval: 0.5 }, function (f, curr, prev) {
console.log(' building...');
if (typeof f == "object" && prev === null && curr === null) {
// 首次扫描
main();
} else {
main(true);
}
});
}
async function taskWatch() {
const watchDir = path.join(projectRoot, config.watch);
const watchName = path.relative(process.cwd(), watchDir);
watch.unwatchTree(watchDir);
watch.watchTree(watchDir, { interval: 0.5 }, function (p, curr, prev) {
if (typeof p == "object" && prev === null && curr === null)
return log.start(`watching "${watchName}"`); //First time scan
const file = String(p);
const fileName = path.relative(process.cwd(), file);
log.info(`"${fileName}" is modified`);
if (assetEntrypoints.has(file))
return taskCopyAssets(file).catch(onFatal);
if (file.endsWith('.css') || file.endsWith('.scss') || file.endsWith('.sass'))
return taskBuildStylesheets(stylesheetEntrypoints.has(file) ? file : '').catch(onFatal);
});
}
} // end of main function
FileWatcher.prototype.stop = function() {
if (this.filePath) {
watch.unwatchTree(this.filePath);
this.filePath = null;
this._isRunning = false;
}
};
global.watchesTree.map( function ( el ) {
watch.unwatchTree( el );
} );
unwatchDir() {
if (this.watchingDirectory) {
watch.unwatchTree(this.watchingDirectory);
}
}
}
FileTree.prototype.pauseWatch = function() {
watch.unwatchTree(this.path);
this.watching = false;
};