27 lines
1.2 KiB
JavaScript
27 lines
1.2 KiB
JavaScript
// Erzeugt dist/w.js und dist/h.js: core.js + Einstieg als IIFE, ohne import/export (kein Build-Tool).
|
|
// Aufruf: node client/build.js
|
|
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
import { dirname, join } from 'node:path';
|
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
|
|
const DIR = dirname(fileURLToPath(import.meta.url));
|
|
const read = (f) => readFileSync(join(DIR, f), 'utf8');
|
|
|
|
function wrap(name, entry) {
|
|
const core = read('core.js').replace(/^export\s+/gm, '');
|
|
const body = read(entry).replace(/^import\s[^\n]*\n/gm, '');
|
|
return `/* WEBklar Analyse ${name} - generiert aus client/core.js + client/${entry} (node client/build.js), nicht von Hand aendern */\n(function () {\n'use strict';\n${core}\n${body}\n})();\n`;
|
|
}
|
|
|
|
export function buildAll() {
|
|
return { w: wrap('w.js', 'w.js'), h: wrap('h.js', 'h.js') };
|
|
}
|
|
|
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
const b = buildAll();
|
|
mkdirSync(join(DIR, 'dist'), { recursive: true });
|
|
writeFileSync(join(DIR, 'dist', 'w.js'), b.w);
|
|
writeFileSync(join(DIR, 'dist', 'h.js'), b.h);
|
|
console.log('dist/w.js', b.w.length, 'Bytes; dist/h.js', b.h.length, 'Bytes');
|
|
}
|