添加deps目录软链

This commit is contained in:
whyour
2021-11-27 16:20:24 +08:00
parent 3206ff6a1e
commit 32f0774df2
4 changed files with 36 additions and 1 deletions
+30
View File
@@ -0,0 +1,30 @@
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));
};