本文整理汇总了TypeScript中chokidar.watch函数的典型用法代码示例。如果您正苦于以下问题:TypeScript watch函数的具体用法?TypeScript watch怎么用?TypeScript watch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了watch函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: startWatch
/* 监听模式 */
startWatch(): void {
let config = this.config;
let watchFile: Array<string> = [];
if (config.file || config.file.length) {
for(let file of config.file) {
file = file.replace(/\\/g, '/');
watchFile.push(path.resolve(this.basePath, file));
}
if (this.configFile) {
// 命令行模式没有配置文件
watchFile.push(this.configFile);
}
if (config.browserSync) {
if (!this.browserSync) {
this.browserSync = browserSync.create();
}
if (config.browserSync.init) {
this.browserSync.init(config.browserSync.init);
}
else {
this.browserSync.init();
}
this.watcher = this.browserSync.watch(watchFile).on('change', this.compileCallback.bind(this));
}
else {
console.log('watch model,files:\n'+watchFile.join('\n'));
this.watcher = chokidar.watch(watchFile).on('change', this.compileCallback.bind(this));
}
}
}
示例2: processFile
.then(() => {
if (program['watch']) {
let watcher = chokidar.watch('*', { cwd: workingDirectory });
watcher
.on('add', path => {
if (match.test(path)) {
processFile(pathUtils.join(workingDirectory, path));
}
})
.on('change', path => {
if (match.test(path)) {
processFile(pathUtils.join(workingDirectory, path));
}
})
.on('unlink', path => {
if (match.test(path)) {
let destFileName = getDestFileName(pathUtils.join(workingDirectory, path));
if (fs.existsSync(destFileName)) {
fs.unlinkSync(destFileName)
}
}
});
let watched = watcher.getWatched();
}
});
示例3: eventChannel
chan = yield eventChannel((emit) => {
const watcher = chokidar.watch(allUris);
watcher.on("ready", () => {
const emitChange = (path) => {
const mtime = fs.lstatSync(path).mtime;
const fileCacheItem = initialFileCache.find((item) => item.filePath === path);
if (fileCacheItem && fileCacheItem.mtime === mtime) {
return;
}
const newContent = fs.readFileSync(path, "utf8");
const publicPath = getPublicFilePath(path, state);
// for internal -- do not want this being sent over the network since it is slow
emit(fileContentChanged(path, publicPath, newContent, mtime));
}
watcher.on("add", emitChange);
watcher.on("change", emitChange);
watcher.on("unlink", (path) => {
emit(fileRemoved(path, getPublicFilePath(path, state)));
});
});
return () => {
watcher.close();
};
});
示例4: watchFiles
private watchFiles(watchPaths: string[])
{
this.clearModifyTimeout();
if (watchPaths.length > 0)
{
let theThis = this;
this.fileWatcher = fs_watcher.watch(watchPaths);
this.fileWatcher.on('change',
function (path, stats)
{
theThis.clearModifyTimeout();
theThis.reloadTimer = setTimeout(
function ()
{
theThis.reloadActiveModel();
theThis.notifyModelUpdate();
theThis.reloadTimer = undefined;
},
400);
});
}
}
示例5: createFsWatcher
export function createFsWatcher(events: d.BuildEvents, paths: string, opts: any) {
const chokidar = require('chokidar');
const watcher = chokidar.watch(paths, opts);
watcher
.on('change', (path: string) => {
events.emit('fileUpdate', path);
})
.on('add', (path: string) => {
events.emit('fileAdd', path);
})
.on('unlink', (path: string) => {
events.emit('fileDelete', path);
})
.on('addDir', (path: string) => {
events.emit('dirAdd', path);
})
.on('unlinkDir', (path: string) => {
events.emit('dirDelete', path);
})
.on('error', (err: any) => {
console.error(err);
});
return watcher;
}
示例6: reportDiagnostics
onFileChange: (options, listener, ready: () => void) => {
if (!options.basePath) {
reportDiagnostics([{
category: ts.DiagnosticCategory.Error,
messageText: 'Invalid configuration option. baseDir not specified',
source: api.SOURCE,
code: api.DEFAULT_ERROR_CODE
}]);
return {close: () => {}};
}
const watcher = chokidar.watch(options.basePath, {
// ignore .dotfiles, .js and .map files.
// can't ignore other files as we e.g. want to recompile if an `.html` file changes as well.
ignored: /((^[\/\\])\..)|(\.js$)|(\.map$)|(\.metadata\.json)/,
ignoreInitial: true,
persistent: true,
});
watcher.on('all', (event: string, path: string) => {
switch (event) {
case 'change':
listener(FileChangeEvent.Change, path);
break;
case 'unlink':
case 'add':
listener(FileChangeEvent.CreateDelete, path);
break;
case 'unlinkDir':
case 'addDir':
listener(FileChangeEvent.CreateDeleteDir, path);
break;
}
});
watcher.on('ready', ready);
return {close: () => watcher.close(), ready};
},
示例7: fileReload
export function fileReload(path: string, callback: ContentReadyCallback) {
const watcher: fs.FSWatcher = watch(path);
watcher.on('add', file=>readContent(file, callback));
watcher.on('change', file=>readContent(file, callback));
watcher.on('error', error=>console.log(`Watcher error: ${error}`));
}
示例8: constructor
constructor(path: string, handleUpdate: any) {
this.currentPath = path
this.handleUpdate = handleUpdate
this.watcher = chokidar.watch(this.currentPath)
this.watcher.on('add', this.onUpdate.bind(this))
this.watcher.on('change', this.onUpdate.bind(this))
}
示例9: watch
export function watch(watchDirectory: FilePath, sourcePath: FilePath, outputFolder: FilePath) {
let watcher = chokidar.watch([watchDirectory + globSuffix])
.on('add', () => build(sourcePath, outputFolder))
.on('change', () => build(sourcePath, outputFolder));
return watcher;
}
示例10: watchConfigFiles
private watchConfigFiles() {
const watcher = chokidar.watch([configFile, secretsFile, webpackFile], {
cwd: this.appDir,
ignoreInitial: true
})
watcher.on("add", this.onConfigFileUpdate.bind(this, "add"))
watcher.on("change", this.onConfigFileUpdate.bind(this, "change"))
}