Merge branch 'rel-4.3' of github.com:GridSpace/grid-apps into rel-4.3

This commit is contained in:
Stewart Allen 2025-10-13 11:45:40 -04:00
commit 122588e633
2 changed files with 24 additions and 11 deletions

View file

@ -1,11 +1,16 @@
{ {
"compress": false,
"outputs": { "outputs": {
"bundle": "./web/boot/bundle.bin" "bundle": "./web/boot/bundle.bin"
}, },
"inputs": [ "inputs": [
{ "root": "./web", "prefix": "" }, { "root": "web", "prefix": "" },
{ "root": "./src", "prefix": "lib" }, { "root": "src", "prefix": "lib" },
{ "root": "./src/wasm", "prefix": "wasm" }, { "root": "src/wasm", "prefix": "wasm" },
{ "root": "./src/wasm", "prefix": "lib/kiri/wasm" } { "root": "src/wasm", "prefix": "lib/kiri/wasm" }
],
"excludes": [
"src/pack",
"web/boot/bundle.bin"
] ]
} }

View file

@ -4,10 +4,17 @@ import uglify from 'uglify-js';
import { Buffer } from 'buffer'; import { Buffer } from 'buffer';
const cfg = JSON.parse(fs.readFileSync(process.argv[2] || './bin/bundle.config.json', 'utf8')); const cfg = JSON.parse(fs.readFileSync(process.argv[2] || './bin/bundle.config.json', 'utf8'));
const compress = process.env.UGLIFY ? true : false const { inputs, outputs, excludes, compress } = cfg;
const envcomp = process.env.COMPRESS ? JSON.parse(process.env.COMPRESS) : undefined;
const debug = process.env.DEBUG;
// --- recursive directory walker (follows symlinks safely) --- // --- recursive directory walker (follows symlinks safely) ---
function* walk(dir, seen = new Set()) { function* walk(dir, seen = new Set()) {
dir = path.normalize(dir);
if (excludes.indexOf(dir) >= 0) {
return;
}
const real = fs.realpathSync(dir); const real = fs.realpathSync(dir);
if (seen.has(real)) { if (seen.has(real)) {
return; return;
@ -25,7 +32,7 @@ function* walk(dir, seen = new Set()) {
// --- collect all files according to config --- // --- collect all files according to config ---
let entries = []; let entries = [];
for (const input of cfg.inputs) { for (const input of inputs) {
const root = input.root; const root = input.root;
const prefix = input.prefix || ''; const prefix = input.prefix || '';
for (const file of walk(root)) { for (const file of walk(root)) {
@ -42,16 +49,17 @@ let offset = 0;
let cache = new Map(); let cache = new Map();
for (const { file, virt } of entries) { for (const { file, virt } of entries) {
if (file.endsWith('/bundle.bin')) { if (excludes.indexOf(file) >= 0) {
continue; continue;
} }
let record = cache.get(file); let record = cache.get(file);
if (record) { if (record) {
// console.log({ dup: file }); if (debug) console.log({ alias: virt, from: file });
entryMeta.push({ ...record, virt }); entryMeta.push({ ...record, virt });
} else { } else {
if (debug) console.log({ write: virt, from: file });
let data = fs.readFileSync(file); let data = fs.readFileSync(file);
if (compress && file.endsWith("js")) { if ((envcomp ?? compress) && file.endsWith("js")) {
console.log('compress', file); console.log('compress', file);
data = uglify.minify(data.toString(), { data = uglify.minify(data.toString(), {
compress: { compress: {
@ -61,7 +69,7 @@ for (const { file, virt } of entries) {
}); });
// console.log({ to: typeof(data), data }); // console.log({ to: typeof(data), data });
if (!data.code) { if (!data.code) {
console.log({ skip: file }); if (debug) console.log({ skip: file });
continue; continue;
} }
data = Buffer.from(data.code); data = Buffer.from(data.code);
@ -102,7 +110,7 @@ const header = Buffer.concat([count, ...headerParts]);
const full = Buffer.concat([header, ...dataParts]); const full = Buffer.concat([header, ...dataParts]);
// --- write final bundle --- // --- write final bundle ---
const outPath = cfg.outputs.bundle || './bundle.bin'; const outPath = outputs.bundle || './bundle.bin';
fs.mkdirSync(path.dirname(outPath), { recursive: true }); fs.mkdirSync(path.dirname(outPath), { recursive: true });
fs.writeFileSync(outPath, full); // ⚡ write raw binary fs.writeFileSync(outPath, full); // ⚡ write raw binary