Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
watcher.on('all', (event, path) => {
if (event === 'change' || event === 'add') {
try {
// 当监听的可能是多个配置文件时,需要清理掉更新文件以及入口文件的缓存,重新获取
cleanCache(path);
watchFiles.forEach(file => cleanCache(file));
mocker = getConfig();
console.log(`${color.green_b.black(' Done: ')} Hot Mocker ${color.green(path.replace(process.cwd(), ''))} file replacement success!`);
} catch (ex) {
console.error(`${color.red_b.black(' Failed: ')} Hot Mocker ${color.red(path.replace(process.cwd(), ''))} file replacement failed!!`);
}
}
})
// 监听文件修改重新加载代码