Own task runner

This commit is contained in:
Thibault “Adædra” Hamel 2024-06-27 04:10:50 +02:00
parent 4bfecd462e
commit 334a0dd68d
3 changed files with 41 additions and 7 deletions

View File

@ -1,3 +1,36 @@
import { articles } from "../lib/tasks/articles.js";
import { css } from "../lib/tasks.js";
import { fonts } from "../lib/tasks.js";
import { images } from "../lib/tasks.js";
import { svg } from "../lib/tasks.js";
(async () => await articles())();
import { argv, exit } from "node:process";
const wrapTask = (name: string, task: () => Promise<void>) => async () => {
console.log("[start]", name);
await task();
console.log("[end]", name);
};
const TASKS = {
all: wrapTask("all", () => fonts().then(images).then(svg).then(css).then(articles)),
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) => {
if (!TASKS.hasOwnProperty(task)) {
console.error("Unknown task", task);
exit(1);
}
return TASKS[task];
})
.reduce((prev, cur) => prev.then(cur), Promise.resolve());

View File

@ -18,7 +18,7 @@ import { renderToStaticMarkup } from "preact-render-to-string";
import { SITE_TITLE, SITE_DESCRIPTION } from "../constants.js";
import { JSX } from "preact/jsx-runtime";
import { reloadAssets } from "../assets.js";
import { mergeMap, Observable, Subscriber } from "rxjs";
import { lastValueFrom, mergeMap, Observable, Subscriber } from "rxjs";
import { dest, fromGlob, onComplete } from "../rx-utils.js";
const Asciidoctor = asciidoctor();
@ -119,8 +119,8 @@ export const articles = () => {
reloadAssets();
const articles = [];
return fromGlob("articles/**/*.asciidoc")
.pipe(
return lastValueFrom(
fromGlob("articles/**/*.asciidoc").pipe(
mergeMap(
(file) =>
new Observable<File>((subscriber) => {
@ -131,6 +131,7 @@ export const articles = () => {
}),
),
onComplete(finalizeArticles(articles)),
)
.forEach(dest("dist"));
mergeMap(dest("dist")),
),
).then(() => {});
};

View File

@ -23,4 +23,4 @@ export const css = () =>
hashPaths("css.manifest"),
mergeMap(dest("dist/_assets")),
),
);
).then(() => {});