Minor adjustments

This commit is contained in:
Thibault “Adædra” Hamel 2024-06-27 08:51:56 +02:00
parent cacfdd3bfd
commit 0b373fc57e
2 changed files with 18 additions and 15 deletions

View File

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

View File

@ -4,7 +4,7 @@ import { execFile } from "node:child_process";
import { readFileSync, unlinkSync } from "node:fs";
import hashPaths from "../hash.ts";
import { dest, fromGlob } from "../rx-utils.ts";
import { mergeMap } from "rxjs";
import { lastValueFrom, mergeMap } from "rxjs";
const FONT_PRESETS: { [variant: string]: { ranges: string[] } } = {
mono: { ranges: ["20-7F", "2205", "2E22-2E25", "2713", "2717"] },
@ -16,13 +16,13 @@ function compileFont(font: File): Promise<File> {
const tmpOutput = tmp.fileSync({ discardDescriptor: true });
const unicodes = FONT_PRESETS[variant.toLowerCase()].ranges;
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
execFile("pyftsubset", [
font.path,
`--unicodes=${unicodes.join(",")}`,
`--output-file=${tmpOutput.name}`,
"--flavor=woff2",
]).once("exit", () => {
]).on("error", (e) => reject(e)).once("exit", () => {
font.path = `iosevka-adaedra-${variant.toLowerCase()}-${weight.toLowerCase()}.woff2`;
font.contents = readFileSync(tmpOutput.name);
(font as any).base = null;
@ -33,7 +33,9 @@ function compileFont(font: File): Promise<File> {
});
}
export const fonts = () =>
export const fonts = async () => {
await lastValueFrom(
fromGlob("vendor/*.ttf")
.pipe(mergeMap(compileFont), hashPaths("fonts.manifest"))
.forEach(dest("dist/_assets"));
.pipe(mergeMap(compileFont), hashPaths("fonts.manifest"), mergeMap(dest("dist/_assets"))),
);
};