mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
31 lines
757 B
TypeScript
31 lines
757 B
TypeScript
import path from 'path';
|
|
import fs from 'fs';
|
|
import chokidar from 'chokidar';
|
|
|
|
function linkToNodeModule(src: string, dst?: string) {
|
|
const target = path.join(__dirname, 'node_modules', dst || src);
|
|
const source = path.join(__dirname, src);
|
|
|
|
fs.lstat(target, (err, stat) => {
|
|
if (!stat) {
|
|
fs.symlink(source, target, 'dir', (err) => {
|
|
if (err) throw err;
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
export default async (src: string = 'deps') => {
|
|
linkToNodeModule(src);
|
|
|
|
const source = path.join(__dirname, src);
|
|
const watcher = chokidar.watch(source, {
|
|
ignored: /(^|[\/\\])\../, // ignore dotfiles
|
|
persistent: true,
|
|
});
|
|
|
|
watcher
|
|
.on('add', (path) => linkToNodeModule(src))
|
|
.on('change', (path) => linkToNodeModule(src));
|
|
};
|