Own task runner
This commit is contained in:
parent
4bfecd462e
commit
334a0dd68d
35
bin/build.ts
35
bin/build.ts
|
@ -1,3 +1,36 @@
|
||||||
import { articles } from "../lib/tasks/articles.js";
|
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());
|
||||||
|
|
|
@ -18,7 +18,7 @@ import { renderToStaticMarkup } from "preact-render-to-string";
|
||||||
import { SITE_TITLE, SITE_DESCRIPTION } from "../constants.js";
|
import { SITE_TITLE, SITE_DESCRIPTION } from "../constants.js";
|
||||||
import { JSX } from "preact/jsx-runtime";
|
import { JSX } from "preact/jsx-runtime";
|
||||||
import { reloadAssets } from "../assets.js";
|
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";
|
import { dest, fromGlob, onComplete } from "../rx-utils.js";
|
||||||
|
|
||||||
const Asciidoctor = asciidoctor();
|
const Asciidoctor = asciidoctor();
|
||||||
|
@ -119,8 +119,8 @@ export const articles = () => {
|
||||||
reloadAssets();
|
reloadAssets();
|
||||||
const articles = [];
|
const articles = [];
|
||||||
|
|
||||||
return fromGlob("articles/**/*.asciidoc")
|
return lastValueFrom(
|
||||||
.pipe(
|
fromGlob("articles/**/*.asciidoc").pipe(
|
||||||
mergeMap(
|
mergeMap(
|
||||||
(file) =>
|
(file) =>
|
||||||
new Observable<File>((subscriber) => {
|
new Observable<File>((subscriber) => {
|
||||||
|
@ -131,6 +131,7 @@ export const articles = () => {
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
onComplete(finalizeArticles(articles)),
|
onComplete(finalizeArticles(articles)),
|
||||||
)
|
mergeMap(dest("dist")),
|
||||||
.forEach(dest("dist"));
|
),
|
||||||
|
).then(() => {});
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,4 +23,4 @@ export const css = () =>
|
||||||
hashPaths("css.manifest"),
|
hashPaths("css.manifest"),
|
||||||
mergeMap(dest("dist/_assets")),
|
mergeMap(dest("dist/_assets")),
|
||||||
),
|
),
|
||||||
);
|
).then(() => {});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user