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"; import { argv, exit } from "node:process"; type Task = () => Promise; const wrapTask = (name: string, task: Task) => async () => { console.log("[start]", name); await task(); console.log("[end]", name); }; const TASKS = new Map(Object.entries({ 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); await (args.length ? args : ALL_TASKS) .map((task: string) => { if (!TASKS.has(task)) { console.error("Unknown task", task); exit(1); } return TASKS.get(task)!; }) .reduce((prev: Promise, cur: Task) => prev.then(cur), Promise.resolve());