2024-03-01 09:23:35 -05:00
|
|
|
import proc from "node:child_process";
|
|
|
|
import fs from "node:fs/promises";
|
|
|
|
import ph from "node:path";
|
|
|
|
|
|
|
|
import log from "fancy-log";
|
|
|
|
import * as h from "./_helpers.js";
|
|
|
|
import ppt from "pretty-time";
|
|
|
|
|
|
|
|
const worker = h.startWorker();
|
|
|
|
let sass = null;
|
|
|
|
|
|
|
|
async function compileSassAll() {
|
|
|
|
const start = process.hrtime();
|
2024-07-01 03:28:40 -05:00
|
|
|
log.info("init: compile styles");
|
2024-03-01 09:23:35 -05:00
|
|
|
|
|
|
|
sass = await h.compileSassAll(worker);
|
|
|
|
let output = await h.concatSass(sass);
|
|
|
|
await fs.writeFile("./resources/public/css/main.css", output);
|
|
|
|
|
|
|
|
const end = process.hrtime(start);
|
|
|
|
log.info("done: compile styles", `(${ppt(end)})`);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function compileSass(path) {
|
|
|
|
const start = process.hrtime();
|
|
|
|
log.info("changed:", path);
|
|
|
|
|
2024-11-25 06:44:10 -05:00
|
|
|
try {
|
|
|
|
const result = await h.compileSass(worker, path, { modules: true });
|
|
|
|
sass.index[result.outputPath] = result.css;
|
2024-03-01 09:23:35 -05:00
|
|
|
|
2024-11-25 06:44:10 -05:00
|
|
|
const output = h.concatSass(sass);
|
2024-03-01 09:23:35 -05:00
|
|
|
|
2024-11-25 06:44:10 -05:00
|
|
|
await fs.writeFile("./resources/public/css/main.css", output);
|
|
|
|
|
|
|
|
const end = process.hrtime(start);
|
|
|
|
log.info("done:", `(${ppt(end)})`);
|
|
|
|
} catch (cause) {
|
|
|
|
console.error(cause);
|
|
|
|
const end = process.hrtime(start);
|
|
|
|
log.error("error:", `(${ppt(end)})`);
|
|
|
|
}
|
2024-03-01 09:23:35 -05:00
|
|
|
}
|
|
|
|
|
2024-06-18 06:59:57 -05:00
|
|
|
await fs.mkdir("./resources/public/css/", { recursive: true });
|
2024-03-01 09:23:35 -05:00
|
|
|
await compileSassAll();
|
2024-07-01 03:28:40 -05:00
|
|
|
await h.copyAssets();
|
|
|
|
await h.compileSvgSprites();
|
2024-03-01 09:23:35 -05:00
|
|
|
await h.compileTemplates();
|
|
|
|
await h.compilePolyfills();
|
|
|
|
|
2024-07-01 03:28:40 -05:00
|
|
|
log.info("watch: scss src (~)");
|
2024-03-01 09:23:35 -05:00
|
|
|
|
|
|
|
h.watch("src", h.isSassFile, async function (path) {
|
|
|
|
if (path.includes("common")) {
|
|
|
|
await compileSassAll(path);
|
|
|
|
} else {
|
|
|
|
await compileSass(path);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-07-01 03:28:40 -05:00
|
|
|
log.info("watch: scss: resources (~)");
|
2024-03-01 09:23:35 -05:00
|
|
|
h.watch("resources/styles", h.isSassFile, async function (path) {
|
|
|
|
log.info("changed:", path);
|
2024-07-01 03:28:40 -05:00
|
|
|
await compileSassAll();
|
2024-03-01 09:23:35 -05:00
|
|
|
});
|
|
|
|
|
2024-07-01 03:28:40 -05:00
|
|
|
log.info("watch: templates (~)");
|
2024-03-01 09:23:35 -05:00
|
|
|
h.watch("resources/templates", null, async function (path) {
|
|
|
|
log.info("changed:", path);
|
|
|
|
await h.compileTemplates();
|
|
|
|
});
|
|
|
|
|
2024-07-01 03:28:40 -05:00
|
|
|
log.info("watch: translations (~)");
|
2024-06-13 04:41:12 -05:00
|
|
|
h.watch("translations", null, async function (path) {
|
|
|
|
log.info("changed:", path);
|
|
|
|
await h.compileTemplates();
|
|
|
|
});
|
|
|
|
|
2024-07-01 03:28:40 -05:00
|
|
|
log.info("watch: assets (~)");
|
|
|
|
h.watch(
|
|
|
|
["resources/images", "resources/fonts", "resources/plugins-runtime"],
|
|
|
|
null,
|
|
|
|
async function (path) {
|
|
|
|
log.info("changed:", path);
|
|
|
|
await h.compileSvgSprites();
|
|
|
|
await h.copyAssets();
|
|
|
|
await h.compileTemplates();
|
|
|
|
},
|
|
|
|
);
|
2024-03-01 09:23:35 -05:00
|
|
|
|
|
|
|
worker.terminate();
|