46 lines
2.0 KiB
TypeScript
Executable File
46 lines
2.0 KiB
TypeScript
Executable File
#!/usr/bin/env -S bun run
|
|
import { $ } from "bun";
|
|
import { readdir } from "node:fs/promises";
|
|
function info(message: any) { console.log(`\x1b[1;44;97m INFO \x1b[0m ${message}`) }
|
|
function err(message: any) { console.log(`\x1b[1;41;97m ERROR \x1b[0m ${message}`) }
|
|
info("Annwan’s wiki build script v3");
|
|
info("Collecting pages...");
|
|
let page_files = await readdir("./pages", {withFileTypes: true, recursive: true});
|
|
let page_list = [];
|
|
for(let f of page_files) {
|
|
if (f.isFile() && f.name.endsWith(".typ")) {
|
|
page_list.push((f.parentPath + "/" + f.name).slice(6, -4));
|
|
}
|
|
}
|
|
info(`Found ${page_list.length} pages.`)
|
|
let pages = `pages=${JSON.stringify(page_list)}`
|
|
info("Collecting assets...");
|
|
let static_files = await readdir("static", {withFileTypes: true, recursive: true});
|
|
let static_list = [];
|
|
for(let f of static_files) {
|
|
if (f.isFile()) { static_list.push((f.parentPath + "/" + f.name).slice(7)); }
|
|
}
|
|
info(`Found ${static_list.length} static assets.`)
|
|
let assets = `static=${JSON.stringify(static_list)}`
|
|
info("Collecting data files...")
|
|
let data_files = await readdir("./data", {withFileTypes: true, recursive: true});
|
|
let data_list = [];
|
|
for (let f of data_files) {
|
|
if (f.isFile() && f.name.endsWith(".toml")) {
|
|
data_list.push(f.parentPath + "/" + f.name.slice(0, -5));
|
|
}
|
|
}
|
|
info(`Found ${data_list.length} data files.`);
|
|
let data = `data=${JSON.stringify(data_list)}`;
|
|
info("Generating watch script...");
|
|
await $`mkdir -p .cache`;
|
|
let cmd = `#!/bin/sh\ntypst --color always w --features html,bundle --format bundle --root . root.typ public_html --input '${pages}' --input '${assets}' --input '${data}' --port 8080`;
|
|
await $`echo ${cmd} > .cache/watch.sh`;
|
|
await $`chmod +x .cache/watch.sh`;
|
|
info("Done.");
|
|
info("Compiling typst bundle...");
|
|
try {
|
|
await $`typst --color always c --features html,bundle --format bundle --root . root.typ public_html --input ${pages} --input ${assets} --input ${data}`;
|
|
} catch { err("something went wrong, see typst log above"); process.exit(); }
|
|
info("Done.");
|