mirror of
https://github.com/jaandrle/deka-dom-el
synced 2025-07-01 12:22:15 +02:00
✨ Add docs page
This commit is contained in:
24
bs/docs.js
Executable file
24
bs/docs.js
Executable file
@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env nodejsscript
|
||||
/* jshint esversion: 11,-W097, -W040, module: true, node: true, expr: true, undef: true *//* global echo, $, pipe, s, fetch, cyclicLoop */
|
||||
const path_target= {
|
||||
root: "docs/",
|
||||
html: "docs/index.html",
|
||||
css: "docs/"
|
||||
};
|
||||
import { createHTMl } from "./docs/jsdom.js";
|
||||
const ssr= createHTMl("");
|
||||
import { register } from "../jsdom.js";
|
||||
const { el }= await register(ssr.dom);
|
||||
|
||||
echo("Loading components…");
|
||||
const pkg= s.cat("package.json").xargs(JSON.parse);
|
||||
import { head, body, css } from "../docs_src/index.html.js";
|
||||
document.head.append(head(pkg, path_target));
|
||||
document.body.append(body(pkg));
|
||||
document.body.append(
|
||||
el("script", { src: "https://cdn.jsdelivr.net/npm/shiki" }),
|
||||
el("script", { src: "index.js", type: "module" })
|
||||
);
|
||||
|
||||
s.echo(ssr.serialize()).to(path_target.html);
|
||||
s.echo(css.content).to(path_target.css+"index.css");
|
34
bs/docs/jsdom.js
Normal file
34
bs/docs/jsdom.js
Normal file
@ -0,0 +1,34 @@
|
||||
import { JSDOM } from "jsdom";
|
||||
const html_default= "<!doctype html><html><head><meta charset=\"utf-8\"></head><body></body></html>";
|
||||
let keys= [];
|
||||
let dom= null;
|
||||
import { relative } from 'node:path';
|
||||
import { writeFileSync } from 'node:fs';
|
||||
export function createHTMl(html, options= {}){
|
||||
if(!html) html= html_default;
|
||||
if(dom) cleanHTML();
|
||||
// set a default url if we don't get one - otherwise things explode when we copy localstorage keys
|
||||
if (!('url' in options)) { Object.assign(options, { url: 'http://localhost:3000' }) }
|
||||
|
||||
dom= new JSDOM(html, options);
|
||||
const window= dom.window;
|
||||
if(!keys.length)
|
||||
keys= Object.getOwnPropertyNames(window).filter((k) => !k.startsWith('_') && !(k in globalThis));
|
||||
keys.forEach(key=> globalThis[key]= window[key]);
|
||||
globalThis.document= window.document
|
||||
globalThis.window= window
|
||||
window.console= globalThis.console
|
||||
return {
|
||||
dom,
|
||||
writeToFS({ html, css }){
|
||||
if(css) this.style.writeToFile(css, relative(html, css).slice(1));
|
||||
if(html) writeFileSync(html, dom.serialize());
|
||||
},
|
||||
serialize(){ return dom.serialize(); }
|
||||
};
|
||||
}
|
||||
export function cleanHTML(){
|
||||
if(!dom) return;
|
||||
keys.forEach(key=> delete globalThis[key]);
|
||||
dom= false;
|
||||
}
|
Reference in New Issue
Block a user