From 334a0dd68d1a37e86eb499c08dcba1724c8d16e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20=E2=80=9CAd=C3=A6dra=E2=80=9D=20Hamel?= Date: Thu, 27 Jun 2024 04:10:50 +0200 Subject: [PATCH] Own task runner --- bin/build.ts | 35 ++++++++++++++++++++++++++++++++++- lib/tasks/articles.ts | 11 ++++++----- lib/tasks/css.ts | 2 +- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/bin/build.ts b/bin/build.ts index 88f7a28..ddcc9e5 100644 --- a/bin/build.ts +++ b/bin/build.ts @@ -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) => 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()); diff --git a/lib/tasks/articles.ts b/lib/tasks/articles.ts index 71da2bf..e272bd1 100644 --- a/lib/tasks/articles.ts +++ b/lib/tasks/articles.ts @@ -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((subscriber) => { @@ -131,6 +131,7 @@ export const articles = () => { }), ), onComplete(finalizeArticles(articles)), - ) - .forEach(dest("dist")); + mergeMap(dest("dist")), + ), + ).then(() => {}); }; diff --git a/lib/tasks/css.ts b/lib/tasks/css.ts index 87d0ed7..8b46dbf 100644 --- a/lib/tasks/css.ts +++ b/lib/tasks/css.ts @@ -23,4 +23,4 @@ export const css = () => hashPaths("css.manifest"), mergeMap(dest("dist/_assets")), ), - ); + ).then(() => {});