1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-23 17:19:37 +01:00
deka-dom-el/bs/docs.js

52 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-11-22 11:02:01 +01:00
#!/usr/bin/env -S npx nodejsscript
2023-09-26 16:02:10 +02:00
/* jshint esversion: 11,-W097, -W040, module: true, node: true, expr: true, undef: true *//* global echo, $, pipe, s, fetch, cyclicLoop */
2023-11-07 15:10:55 +01:00
echo("Building static documentation files…");
echo("Preparing…");
2024-11-22 11:00:15 +01:00
import { path_target, pages as pages_registered, styles, dispatchEvent, t } from "../docs/ssr.js";
2023-09-26 16:02:10 +02:00
import { createHTMl } from "./docs/jsdom.js";
import { register } from "../jsdom.js";
const pkg= s.cat("package.json").xargs(JSON.parse);
2023-11-07 15:10:55 +01:00
if(s.test("-d", path_target.root)){
echo("Removing old files…");
s.rm("-rf", path_target.root+"*");
} else {
echo("Creating directory…");
s.mkdir("-p", path_target.root);
}
echo("Collecting list of pages…");
2024-11-22 11:00:15 +01:00
const pages= s.ls($.xdg.main`../docs/*.html.js`).map(addPage);
for(const { id, info } of pages){
2023-11-07 15:10:55 +01:00
echo(`Generating ${id}.html…`);
2023-11-30 17:05:19 +01:00
const serverDOM= createHTMl("");
serverDOM.registerGlobally(
"HTMLScriptElement"
);
const { el }= await register(serverDOM.dom);
2024-11-22 11:00:15 +01:00
const { page }= await import(`../docs/${id}.html.js`);
2023-11-30 17:05:19 +01:00
serverDOM.document.body.append(
2023-11-10 17:15:59 +01:00
el(page, { pkg, info }),
2023-11-07 15:10:55 +01:00
);
echo.use("-R", `Writing ${id}.html…`);
2023-11-10 17:15:59 +01:00
dispatchEvent("oneachrender", document);
2023-11-30 17:05:19 +01:00
s.echo(serverDOM.serialize()).to(path_target.root+id+".html");
2023-11-07 15:10:55 +01:00
}
2023-11-10 17:15:59 +01:00
s.echo(styles.content).to(path_target.css+styles.name);
dispatchEvent("onssrend");
2023-11-07 15:10:55 +01:00
echo("Done");
/** @param {`${string}/${string}.html.js`} path */
function addPage(path){
const id= idFromPath(path);
const [ info_pre ]= s.cat(path).match(/(?<=\s*export\s+const\s+info\s*=\s*)\{(.|\s)*?\}(?=;)/gm);
const info= { id, href: id, ...eval(`(${info_pre})`) };
pages_registered.push(info);
return { id, info };
}
/** @param {`${string}/${string}.html.js`} path */
function idFromPath(path){
const file_start= path.lastIndexOf("/");
return path.slice(file_start+1, path.indexOf(".", file_start));
}