blog/bin/build.ts

37 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-06-27 04:22:58 +00:00
import { articles } from "../lib/tasks/articles.ts";
import { css } from "../lib/tasks/css.ts";
import { fonts } from "../lib/tasks/fonts.ts";
import { images } from "../lib/tasks/images.ts";
import { svg } from "../lib/tasks/svg.ts";
2024-06-26 02:21:31 +00:00
2024-06-27 02:10:50 +00:00
import { argv, exit } from "node:process";
const wrapTask = (name: string, task: () => Promise<void>) => async () => {
console.log("[start]", name);
await task();
console.log("[end]", name);
};
2024-06-27 04:22:58 +00:00
const TASKS: { [task: string]: () => Promise<void> } = {
2024-06-27 02:10:50 +00:00
articles: wrapTask("articles", articles),
css: wrapTask("css", css),
fonts: wrapTask("fonts", fonts),
images: wrapTask("images", images),
svg: wrapTask("svg", svg),
};
const ALL_TASKS = ["fonts", "images", "svg", "css", "articles"];
const args = argv.slice(2);
2024-06-27 04:22:58 +00:00
console.log("args", args);
(args.length ? args : ALL_TASKS)
.map((task: string) => {
2024-06-27 02:10:50 +00:00
if (!TASKS.hasOwnProperty(task)) {
console.error("Unknown task", task);
exit(1);
}
return TASKS[task];
})
2024-06-27 04:22:58 +00:00
.reduce((prev: Promise<void>, cur: () => Promise<void>) => prev.then(cur), Promise.resolve());