Files
claw-code/packages/gpt-runner-cli/src/watcher.ts
2023-05-14 16:07:06 +08:00

23 lines
603 B
TypeScript

import type { FSWatcher } from 'chokidar'
import type { CliOptions } from './types'
let watcher: FSWatcher
export async function getWatcher(options?: CliOptions) {
// test case entry without options
if (watcher && !options)
return watcher
const { watch } = await import('chokidar')
const ignored = ['**/{.git,node_modules}/**']
// cli may create multiple watchers
const newWatcher = watch(options?.patterns as string[], {
ignoreInitial: true,
ignorePermissionErrors: true,
ignored,
cwd: options?.cwd || process.cwd(),
})
watcher = newWatcher
return newWatcher
}