Skip to content

Instantly share code, notes, and snippets.

@otakustay
Last active March 14, 2024 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otakustay/6dcb163053b51b95e0dff4ec6d52acad to your computer and use it in GitHub Desktop.
Save otakustay/6dcb163053b51b95e0dff4ec6d52acad to your computer and use it in GitHub Desktop.
Watch file
import fs from 'node:fs/promises';
import chokidar form 'chokidar';
const watchState = {
running: false,
};
export class MySkillProvider extends SkillProvider {
constructor(init: ProviderInit) {
super(init);
// 其它初始化代码
if (!watchState.running) {
// https://github.com/paulmillr/chokidar
const watcher = chokidar.watch(['.'], {cwd});
watcher.on(
'ready',
() => {
const scan = (file: string) => this.scanForFile(file);
watcher.on('add', scan).on('change', scan);
}
);
watchState.running = true;
}
}
async scanForFile(file: string) {
// 实际扫描逻辑
const content = await fs.readFile(file);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment