mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-06 05:48:00 +03:00
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
import { copyFileSync, existsSync, mkdirSync, watch, writeFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import sass from "node-sass";
|
|
|
|
const sourceDirectory = resolve(".", "src");
|
|
const outDirectory = resolve(".", "dist");
|
|
|
|
const styleSheetInput = resolve(sourceDirectory, "style.scss");
|
|
const htmlInput = resolve(sourceDirectory, "index.html");
|
|
|
|
const styleSheetOutput = resolve(outDirectory, "style.css");
|
|
const htmlOutput = resolve(outDirectory, "index.html");
|
|
|
|
const compile = () => {
|
|
console.time("Compiled site");
|
|
if (!existsSync(outDirectory)) {
|
|
mkdirSync(outDirectory);
|
|
}
|
|
|
|
const result = sass.renderSync({
|
|
file: styleSheetInput,
|
|
});
|
|
writeFileSync(styleSheetOutput, result.css);
|
|
|
|
copyFileSync(htmlInput, htmlOutput);
|
|
|
|
console.timeEnd("Compiled site");
|
|
};
|
|
|
|
const debounce = 100; // Watch debounce time in MS
|
|
let lastCompileTime = Date.now();
|
|
(() => {
|
|
if (process.argv.includes("--watch")) {
|
|
console.info("Enabling Watcher...");
|
|
|
|
watch(sourceDirectory, (event, filename) => {
|
|
if (event === "change" && Date.now() - lastCompileTime > debounce) {
|
|
console.info(`${filename} ${event}`);
|
|
|
|
compile();
|
|
lastCompileTime = Date.now();
|
|
}
|
|
});
|
|
}
|
|
|
|
compile();
|
|
})();
|