本文整理汇总了TypeScript中chokidar.FSWatcher类的典型用法代码示例。如果您正苦于以下问题:TypeScript FSWatcher类的具体用法?TypeScript FSWatcher怎么用?TypeScript FSWatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FSWatcher类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: init
public async init(): Promise<FSWatcher> {
try {
logger.info('Starting watcher');
return this.fswatcher.on('add', this.onAdd.bind(this));
} catch (err) {
logger.error(err);
throw err;
}
}
示例2: constructor
public constructor(
private serializer: Serializer,
private path: string,
private extension: string,
watcher?: FSWatcher
) {
super();
if (watcher) {
watcher
.on('add', filePath => this.onFileUpdated(filePath))
.on('change', filePath => this.onFileUpdated(filePath))
.on('unlink', filePath => this.onFileRemoved(filePath))
.add(path);
}
}
示例3: it
it('watch()', () => {
let watcher: FSWatcher;
return fs.watch(tmpDir).then(watcher_ => {
watcher = watcher_;
return new Promise((resolve, reject) => {
const path = join(tmpDir, 'test.txt');
watcher.on('add', (path_) => {
path_.should.eql(path);
resolve();
});
fs.writeFile(path, 'test').catch(reject);
});
}).finally(() => {
if (watcher) watcher.close();
});
});
示例4: constructor
public constructor(watcher: FSWatcher) {
watcher
.on('add', path => log(chalk.cyan('ADD ') + path))
.on('change', path => log(chalk.cyan('CHG ') + path))
.on('unlink', path => log(chalk.cyan('REM ') + path));
}
示例5: Promise
return new Promise((resolve, reject) => {
const path = join(tmpDir, 'test.txt');
watcher.on('add', (path_) => {
path_.should.eql(path);
resolve();
});
fs.writeFile(path, 'test').catch(reject);
});
示例6:
}).finally(() => {
if (watcher) watcher.close();
});