55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import { mkdir, writeFile } from "node:fs/promises";
|
|
import { watch } from "node:fs";
|
|
import { dirname, join } from "node:path";
|
|
import { transform } from "lightningcss";
|
|
import { stylesheet } from "../styles/index";
|
|
|
|
const root = process.cwd();
|
|
const minify = process.argv.includes("--minify");
|
|
const watchMode = process.argv.includes("--watch");
|
|
const outputs = [
|
|
join(root, "dist", "theme-gitea-auto.css"),
|
|
join(root, ".gitea", "custom", "public", "assets", "css", "theme-gitea-auto.css"),
|
|
];
|
|
|
|
async function build() {
|
|
const result = transform({
|
|
filename: "theme-gitea-auto.css",
|
|
code: Buffer.from(stylesheet),
|
|
minify,
|
|
targets: {
|
|
chrome: 108 << 16,
|
|
firefox: 108 << 16,
|
|
safari: 16 << 16,
|
|
},
|
|
});
|
|
|
|
await Promise.all(
|
|
outputs.map(async (output) => {
|
|
await mkdir(dirname(output), { recursive: true });
|
|
await writeFile(output, result.code);
|
|
}),
|
|
);
|
|
|
|
console.log(`built ${outputs.length} css outputs`);
|
|
}
|
|
|
|
await build();
|
|
|
|
if (watchMode) {
|
|
console.log("watching styles, themes, and src");
|
|
const watchedDirs = [join(root, "styles"), join(root, "themes"), join(root, "src")];
|
|
const watchers = watchedDirs.map((dir) =>
|
|
watch(dir, { recursive: true }, async (_eventType, filename) => {
|
|
if (filename?.endsWith(".ts")) {
|
|
await build();
|
|
}
|
|
}),
|
|
);
|
|
|
|
process.on("SIGINT", () => {
|
|
watchers.forEach((watcher) => watcher.close());
|
|
process.exit(0);
|
|
});
|
|
}
|