diff --git a/app.js b/app.js index 54b8d3f4..0bcf5072 100644 --- a/app.js +++ b/app.js @@ -37,6 +37,7 @@ let util; let dir; let log; let pre; +let alt; const EventEmitter = require('events'); class AppEmitter extends EventEmitter {} @@ -64,6 +65,7 @@ function init(mod) { startTime = time(); lastmod = mod.util.lastmod; logger = mod.log; + alt = ENV.alt; pre = ENV.pre || mod.meta.pre; debug = ENV.debug || mod.meta.debug; oversion = ENV.over || mod.meta.over; @@ -191,6 +193,14 @@ function init(mod) { append[key] = minify(append[key]); } } + + if (alt) { + for (let [ key, val ] of Object.entries(append)) { + fs.mkdirSync(`alt/main`, { recursive: true }); + let body = fs.readFileSync(`src/main/${key}.js`); + fs.writeFileSync(`alt/main/${key}.js`, body + val); + } + } }; // either add module assets to path or require(init.js) @@ -288,14 +298,14 @@ function initModule(mod, file, dir) { const path = mod.dir + '/' + dir + '/' + file; try { const body = fs.readFileSync(path); - // console.log({ inject: code, file, opt }); + logger.log({ inject: code, file, opt }); if (opt.first) { append[code] = body.toString() + '\n' + append[code]; } else { append[code] += body.toString() + '\n'; } } catch (e) { - console.log({ missing_file: path, dir, mod }); + logger.log({ missing_file: path, dir, mod }); } }, onload(fn) { @@ -430,6 +440,10 @@ function generateDevices() { let dstr = JSON.stringify(devs); util.mkdir(PATH.join(dir,"src","pack")); fs.writeFileSync(PATH.join(dir,"src","pack","kiri-devs.js"), `export const devices = ${dstr};`); + if (alt) { + fs.mkdirSync('alt/pack', { recursive: true }); + fs.writeFileSync(PATH.join(dir,"alt","pack","kiri-devs.js"), `export const devices = ${dstr};`); + } } function minify(code) { diff --git a/bin/bundle.config.json b/bin/bundle.config.json index 93994e27..e7bd3566 100644 --- a/bin/bundle.config.json +++ b/bin/bundle.config.json @@ -5,7 +5,8 @@ }, "inputs": [ { "root": "web", "prefix": "" }, - { "root": "src", "prefix": "lib" }, + { "root": "alt", "prefix": "lib"}, + { "root": "src", "prefix": "lib"}, { "root": "src/wasm", "prefix": "wasm" }, { "root": "src/wasm", "prefix": "lib/kiri/wasm" } ], diff --git a/bin/bundler.mjs b/bin/bundler.mjs index 3a96efb4..36d66e9e 100644 --- a/bin/bundler.mjs +++ b/bin/bundler.mjs @@ -32,13 +32,19 @@ function* walk(dir, seen = new Set()) { // --- collect all files according to config --- let entries = []; +let virtMap = new Set(); for (const input of inputs) { const root = input.root; const prefix = input.prefix || ''; for (const file of walk(root)) { const rel = path.relative(root, file).replace(/\\/g, '/'); const virt = prefix ? `${prefix}/${rel}` : rel; - entries.push({ file, virt }); + if (virtMap.has(virt)) { + console.log('pre-existing', virt, rel, root); + } else { + entries.push({ file, virt }); + virtMap.add(virt); + } } }