-
Notifications
You must be signed in to change notification settings - Fork 404
/
Copy pathwatch.ts
48 lines (40 loc) · 1.3 KB
/
watch.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import path from 'path';
import ParcelWatcher from '@parcel/watcher';
import { copy } from 'fs-extra';
import glob from 'glob';
import { run } from './fn/shell';
let handler: ParcelWatcher.AsyncSubscription;
(async () => {
// await run('npm run clean');
const filePattern = '*/src/**/!(*.ts|*.tsx)';
console.log(`[COPY]: ${filePattern}`);
const cwd = path.join(__dirname, '../packages');
const files = glob.sync(filePattern, { cwd, nodir: true });
const fileSet = new Set();
for (const file of files) {
await copyOneFile(file, cwd);
fileSet.add(path.join(cwd, file));
}
handler = await ParcelWatcher.subscribe(cwd, (err, e) => {
e.forEach((e) => {
if (e.type === 'create' || e.type === 'update' || e.type === 'delete') {
const filePath = e.path;
if (fileSet.has(filePath)) {
console.log('non-ts change detected:', filePath);
copyOneFile(path.relative(cwd, filePath), cwd);
}
}
});
});
// build webview resources
await run('npx tsc --build configs/ts/tsconfig.build.json -w');
})().catch((e) => {
console.trace(e);
handler.unsubscribe();
process.exit(128);
});
async function copyOneFile(file, cwd) {
const from = path.join(cwd, file);
const to = path.join(cwd, file.replace(/\/src\//, '/lib/'));
await copy(from, to);
}