Files
Senbei/web/tools/stage.mjs
T
Momoko-Ayase 21236e8b98 feat(web): bring the Senbei workbench to the browser
Add folder scanning, Android library and package recovery, and the localized desktop-style workbench. Keep browser-refused outputs in a fallback ZIP and include logs with folder and ZIP exports.

Align the desktop and web modal transitions and polish the desktop About and legal dialogs.
2026-11-18 17:10:12 +08:00

47 lines
1.6 KiB
JavaScript

// Stage the static site: the files the page loads, and nothing else.
//
// node web/tools/stage.mjs <dist>
//
// Run after `wasm-pack build --target web --out-dir ../web/pkg`. The CI
// artifact and the release deployment are both made from this directory, so
// the list of what ships is here once.
import { cpSync, existsSync, mkdirSync, readdirSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
const web = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
/** Paths under `web/` that make up the site. */
export function siteFiles() {
const top = readdirSync(web).filter(
(name) => name.endsWith('.js') || ['index.html', 'style.css', 'LICENSE'].includes(name),
);
const catalogs = readdirSync(path.join(web, 'i18n'))
.filter((name) => name.endsWith('.js'))
.map((name) => `i18n/${name}`);
const assets = readdirSync(path.join(web, 'assets')).map((name) => `assets/${name}`);
const engine = ['pkg/senbei_wasm.js', 'pkg/senbei_wasm_bg.wasm'];
return [...top, ...catalogs, ...assets, ...engine].sort();
}
function main() {
const dist = process.argv[2];
if (!dist) {
console.error('usage: stage.mjs <dist>');
process.exit(2);
}
for (const file of siteFiles()) {
const from = path.join(web, file);
if (!existsSync(from)) {
console.error(`${file} is missing; build senbei-wasm into web/pkg first`);
process.exit(1);
}
const to = path.join(dist, file);
mkdirSync(path.dirname(to), { recursive: true });
cpSync(from, to);
}
}
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main();