forked from cloudflare/cloudflare-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.js
39 lines (35 loc) · 906 Bytes
/
watch.js
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
const chokidar = require("chokidar");
const fs = require("fs");
const args = process.argv.slice(2);
const product = args[0];
if (!product) {
console.error(
"You must provide a directory to watch. Run the develop script with yarn develop -- $product."
);
process.exit(1);
}
console.log(`Watching: products/${product}`);
const copyFile = (path) => {
const newPath = path.substring(path.indexOf(`products/${product}/`));
console.log(`${path} changed. Updating: .docs/${newPath}`);
fs.copyFile(
`products/${product}/${path}`,
`products/${product}/.docs/${newPath}`,
() => {
console.log("File updated.");
}
);
};
chokidar
.watch(`.`, {
persistent: true,
cwd: `products/${product}/`,
ignored: [".docs", "node_modules"],
ignoreInitial: true,
})
.on("add", (path) => {
copyFile(path);
})
.on("change", (path) => {
copyFile(path);
});