Last active
March 14, 2024 09:08
-
-
Save otakustay/6dcb163053b51b95e0dff4ec6d52acad to your computer and use it in GitHub Desktop.
Watch file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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