51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
import chokidar from "chokidar";
|
|
import { execSync } from "child_process";
|
|
|
|
const [ , , clientName, appName, variantName ] = process.argv;
|
|
|
|
if (!clientName || !appName || !variantName) {
|
|
console.error("❌ Usage: node watch.js <client> <application> <variant>");
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log("👀 Watch mode");
|
|
console.log(` Client : ${clientName}`);
|
|
console.log(` Application : ${appName}`);
|
|
console.log(` Variant : ${variantName}`);
|
|
|
|
const WATCH_PATHS = [
|
|
"2-tokens",
|
|
"3-styles",
|
|
`4-clients/${clientName}`
|
|
];
|
|
|
|
let timeout = null;
|
|
|
|
function rebuild() {
|
|
console.log("\n🔄 Change detected");
|
|
|
|
try {
|
|
execSync(
|
|
`node 5-build/build-css.js ${clientName} ${variantName}`,
|
|
{ stdio: "inherit" }
|
|
);
|
|
|
|
execSync(
|
|
`node 5-build/deploy.js ${clientName} ${appName} ${variantName}`,
|
|
{ stdio: "inherit" }
|
|
);
|
|
|
|
console.log("✅ Rebuild + deploy done");
|
|
} catch (err) {
|
|
console.error("❌ Error during rebuild/deploy");
|
|
}
|
|
}
|
|
|
|
const watcher = chokidar.watch(WATCH_PATHS, {
|
|
ignoreInitial: true
|
|
});
|
|
|
|
watcher.on("all", () => {
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(rebuild, 100);
|
|
});
|