Introduce fromGlob
helper
This commit is contained in:
parent
500361c023
commit
4bfecd462e
|
@ -1,9 +1,10 @@
|
||||||
import { Observable, Subscriber } from "rxjs";
|
import { Observable, Subscriber, from, mergeMap } from "rxjs";
|
||||||
import File from "vinyl";
|
import File from "vinyl";
|
||||||
import { readFile } from "node:fs/promises";
|
import { readFile } from "node:fs/promises";
|
||||||
import { join, dirname } from "node:path";
|
import { join, dirname } from "node:path";
|
||||||
import { existsSync } from "node:fs";
|
import { existsSync } from "node:fs";
|
||||||
import { writeFile, mkdir } from "node:fs/promises";
|
import { writeFile, mkdir } from "node:fs/promises";
|
||||||
|
import { Glob } from "glob";
|
||||||
|
|
||||||
export function dest(prefix: string) {
|
export function dest(prefix: string) {
|
||||||
return async (file: File) => {
|
return async (file: File) => {
|
||||||
|
@ -18,9 +19,6 @@ export function dest(prefix: string) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadFile = async (path: string): Promise<File> =>
|
|
||||||
new File({ path, contents: await readFile(path) });
|
|
||||||
|
|
||||||
export function onComplete<T>(f: (sink: Subscriber<T>) => Promise<void>) {
|
export function onComplete<T>(f: (sink: Subscriber<T>) => Promise<void>) {
|
||||||
return (observable: Observable<T>) =>
|
return (observable: Observable<T>) =>
|
||||||
new Observable<T>((subscriber) =>
|
new Observable<T>((subscriber) =>
|
||||||
|
@ -38,3 +36,9 @@ export function onComplete<T>(f: (sink: Subscriber<T>) => Promise<void>) {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const loadFile = async (path: string): Promise<File> =>
|
||||||
|
new File({ path, contents: await readFile(path) });
|
||||||
|
|
||||||
|
export const fromGlob = (paths: string | string[]): Observable<File> =>
|
||||||
|
from(new Glob(paths, {})).pipe(mergeMap(loadFile));
|
||||||
|
|
|
@ -18,9 +18,8 @@ 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 { from, mergeMap, Observable, Subscriber } from "rxjs";
|
import { mergeMap, Observable, Subscriber } from "rxjs";
|
||||||
import { dest, loadFile, onComplete } from "../rx-utils.js";
|
import { dest, fromGlob, onComplete } from "../rx-utils.js";
|
||||||
import { Glob } from "glob";
|
|
||||||
|
|
||||||
const Asciidoctor = asciidoctor();
|
const Asciidoctor = asciidoctor();
|
||||||
const EXTENSION_REGISTRY = Asciidoctor.Extensions.create();
|
const EXTENSION_REGISTRY = Asciidoctor.Extensions.create();
|
||||||
|
@ -120,9 +119,8 @@ export const articles = () => {
|
||||||
reloadAssets();
|
reloadAssets();
|
||||||
const articles = [];
|
const articles = [];
|
||||||
|
|
||||||
return from(new Glob("articles/**/*.asciidoc", {}))
|
return fromGlob("articles/**/*.asciidoc")
|
||||||
.pipe(
|
.pipe(
|
||||||
mergeMap(loadFile),
|
|
||||||
mergeMap(
|
mergeMap(
|
||||||
(file) =>
|
(file) =>
|
||||||
new Observable<File>((subscriber) => {
|
new Observable<File>((subscriber) => {
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
import postcss, { Result } from "postcss";
|
import postcss, { Result } from "postcss";
|
||||||
import config from "../../postcss.config.js";
|
import config from "../../postcss.config.js";
|
||||||
import { dest, loadFile } from "../rx-utils.js";
|
import { dest, fromGlob } from "../rx-utils.js";
|
||||||
import { from, lastValueFrom, mergeMap } from "rxjs";
|
import { lastValueFrom, mergeMap } from "rxjs";
|
||||||
import hashPaths from "../hash.js";
|
import hashPaths from "../hash.js";
|
||||||
import { Glob } from "glob";
|
|
||||||
|
|
||||||
export const css = () =>
|
export const css = () =>
|
||||||
lastValueFrom(
|
lastValueFrom(
|
||||||
from(new Glob("src/index.css", {})).pipe(
|
fromGlob("src/index.css").pipe(
|
||||||
mergeMap(loadFile),
|
|
||||||
mergeMap(
|
mergeMap(
|
||||||
(file) =>
|
(file) =>
|
||||||
new Promise((resolve) =>
|
new Promise((resolve) =>
|
||||||
|
|
|
@ -3,9 +3,8 @@ import tmp from "tmp";
|
||||||
import { execFile } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
import { readFileSync, unlinkSync } from "node:fs";
|
import { readFileSync, unlinkSync } from "node:fs";
|
||||||
import hashPaths from "../hash.js";
|
import hashPaths from "../hash.js";
|
||||||
import { dest, loadFile } from "../rx-utils.js";
|
import { dest, fromGlob } from "../rx-utils.js";
|
||||||
import { from, mergeMap } from "rxjs";
|
import { mergeMap } from "rxjs";
|
||||||
import { Glob } from "glob";
|
|
||||||
|
|
||||||
const FONT_PRESETS = {
|
const FONT_PRESETS = {
|
||||||
mono: { ranges: ["20-7F", "2205", "2E22-2E25", "2713", "2717"] },
|
mono: { ranges: ["20-7F", "2205", "2E22-2E25", "2713", "2717"] },
|
||||||
|
@ -35,6 +34,6 @@ function compileFont(font: File): Promise<File> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fonts = () =>
|
export const fonts = () =>
|
||||||
from(new Glob("vendor/*.ttf", {}))
|
fromGlob("vendor/*.ttf")
|
||||||
.pipe(mergeMap(loadFile), mergeMap(compileFont), hashPaths("fonts.manifest"))
|
.pipe(mergeMap(compileFont), hashPaths("fonts.manifest"))
|
||||||
.forEach(dest("dist/_assets"));
|
.forEach(dest("dist/_assets"));
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
import { Glob } from "glob";
|
|
||||||
import hashPaths from "../hash.js";
|
import hashPaths from "../hash.js";
|
||||||
import { dest, loadFile } from "../rx-utils.js";
|
import { dest, fromGlob } from "../rx-utils.js";
|
||||||
import { from, mergeMap, tap } from "rxjs";
|
import { mergeMap, tap } from "rxjs";
|
||||||
|
|
||||||
export const images = () =>
|
export const images = () =>
|
||||||
from(new Glob("src/*.avif", {}))
|
fromGlob("src/*.avif")
|
||||||
.pipe(
|
.pipe(
|
||||||
mergeMap(loadFile),
|
|
||||||
tap((f) => (f.path = f.path.substring(4))),
|
tap((f) => (f.path = f.path.substring(4))),
|
||||||
hashPaths("images.manifest"),
|
hashPaths("images.manifest"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
import { Glob } from "glob";
|
import { tap } from "rxjs";
|
||||||
import { from, mergeMap, tap } from "rxjs";
|
import { dest, fromGlob } from "../rx-utils.js";
|
||||||
import { dest, loadFile } from "../rx-utils.js";
|
|
||||||
|
|
||||||
// SVG `use` has no way of allowing cross-origin, so we need to keep them with the HTML files.
|
// SVG `use` has no way of allowing cross-origin, so we need to keep them with the HTML files.
|
||||||
export const svg = () =>
|
export const svg = () =>
|
||||||
from(new Glob("src/*.svg", {}))
|
fromGlob("src/*.svg")
|
||||||
.pipe(
|
.pipe(tap((f) => (f.path = f.path.substring(4))))
|
||||||
mergeMap(loadFile),
|
|
||||||
tap((f) => (f.path = f.path.substring(4))),
|
|
||||||
)
|
|
||||||
.forEach(dest("dist"));
|
.forEach(dest("dist"));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user