-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.mjs
37 lines (34 loc) · 1.08 KB
/
watch.mjs
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
import { readFileSync } from 'fs';
import { join } from 'path';
import { spawn } from 'node:child_process';
const tsc = spawn('./node_modules/.bin/tsc', [
'--build',
'--watch',
'--preserveWatchOutput',
'--pretty',
'--assumeChangesOnlyAffectDirectDependencies',
]);
tsc.stdout.on('data', data => {
const str = data.toString().trim();
// We know, tsc...
if (
str.includes('Starting incremental compilation...') ||
str.includes('Starting compilation in watch mode...')
) return;
console.log(`[tsc] ${str}`);
});
tsc.stderr.on('data', data => console.error(`[tsc] ${data.toString().trim()}`));
function readPackageJson(p) {
return JSON.parse(readFileSync(join(p, 'package.json'), 'utf8'));
}
const { workspaces } = readPackageJson('.');
workspaces
.filter(w => {
const p = readPackageJson(w);
return p.scripts && p.scripts.watch;
})
.forEach(w => {
const watcher = spawn('npm', ['run', '-w', w, 'watch']);
watcher.stdout.on('data', data => console.log(`[${w}] ${data.toString().trim()}`));
watcher.stderr.on('data', data => console.error(`[${w}] ${data.toString().trim()}`));
});