-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathwatcher.mjs
More file actions
48 lines (42 loc) · 1.14 KB
/
watcher.mjs
File metadata and controls
48 lines (42 loc) · 1.14 KB
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 chokidar from "chokidar";
import chalk from "chalk";
import { exec } from "child_process";
import path from "path";
const log = console.log.bind(console);
const ignorePackages = [];
const watcher = chokidar.watch(
[
"packages/**/*.ts",
"packages/**/*.tsx",
"packages/**/*.css",
"packages/markdown/assets/**/*",
"platforms/**/*.ts",
"platforms/**/*.css",
"platforms/**/*.tsx",
],
{
ignored: ["packages/**/dist/**"],
depth: 6,
followSymlinks: false,
persistent: true,
usePolling: true,
interval: 500,
},
);
log(chalk.yellow.bold("Watching all files... 👀"));
watcher.on("change", async (filePath) => {
const splitPath = filePath.split(path.sep);
const location = `${splitPath[0]}${path.sep}${splitPath[1]}${path.sep}`;
const fileName = splitPath[1];
if (ignorePackages.includes(fileName)) {
return;
}
log(chalk.yellow(`Changes detected in ${fileName}`));
exec(`pnpm build`, { cwd: location }, (err, stdout, stderr) => {
if (!err || err === null) {
log(`build ${chalk.green("success")} - ${splitPath[1]}`);
} else {
log(err, stdout, stderr);
}
});
});