35 lines
1012 B
JavaScript
35 lines
1012 B
JavaScript
const { Webview } = require("webview-nodejs");
|
||
const { spawn } = require("child_process");
|
||
const PORT = 5173;
|
||
|
||
/**
|
||
* I don’t see an alternative: “DeprecationWarning: Passing args to a child process with shell option true …”
|
||
* https://github.com/nodejs/help/issues/5063
|
||
*/
|
||
const p = spawn("pnpm", ["vitepress", "dev", "--port", String(PORT), "docs"], {
|
||
shell: true,
|
||
stdio: "inherit",
|
||
});
|
||
|
||
const w = new Webview();
|
||
w.title(require("./package.json").name);
|
||
w.size(1920, 1280);
|
||
w.init(/* js */ `
|
||
document.addEventListener('click', (ev) => {
|
||
if (ev.target.matches('a')) {
|
||
const href = ev.target.href || '';
|
||
if (href.startsWith('https://resources.allsetlearning.com/chinese/')) ev.preventDefault();
|
||
}
|
||
})
|
||
`);
|
||
w.navigate(`http://localhost:${PORT}`);
|
||
w.show();
|
||
|
||
console.log(p.kill("SIGINT"));
|
||
|
||
/**
|
||
* node:child_process#spawn doesn't fire close event if app exits immediately after spawned app exits
|
||
* ??? https://github.com/oven-sh/bun/issues/3083
|
||
*/
|
||
require("kill-port")(PORT);
|