From c340b5e7761a9b98554f76824c816a89ef4b4621 Mon Sep 17 00:00:00 2001 From: JrMasterModelBuilder Date: Fri, 27 Oct 2023 01:02:33 -0400 Subject: [PATCH] Use the HTML bundle, some cleanup --- make.mjs | 138 +++++++++++++++++++++-------------------- src/browser/index.html | 66 -------------------- util/dist.mjs | 7 +-- util/fs.mjs | 46 -------------- 4 files changed, 74 insertions(+), 183 deletions(-) delete mode 100644 src/browser/index.html delete mode 100644 util/fs.mjs diff --git a/make.mjs b/make.mjs index 02f2021..2bc676f 100644 --- a/make.mjs +++ b/make.mjs @@ -1,4 +1,4 @@ -import {readFile} from 'fs/promises'; +import {readFile, readdir, rm} from 'node:fs/promises'; import {Manager} from '@shockpkg/core'; import { @@ -8,6 +8,7 @@ import { ValueBoolean } from '@shockpkg/plist-dom'; import { + BundleHtml, BundleSaWindows, BundleSaMac, BundleSaLinux, @@ -28,31 +29,27 @@ import { import {docs} from './util/doc.mjs'; import {isMac, codesign} from './util/mac.mjs'; import {makeZip, makeTgz, makeExe, makeDmg} from './util/dist.mjs'; -import {copyFile, files, outputFile, remove} from './util/fs.mjs'; import {flash4FpsCap, setFps} from './util/fps.mjs'; async function * resources() { - for await (const [a, r, f] of files('mod/files', false)) { - if (/\.swf$/.test(f)) { - const d = await readFile(a); - setFps(d, flash4FpsCap); - yield [r, d]; - } - } - const txtDir = 'original/files/eng/bionicle/recentupdates'; - for await (const [a, r, f] of files(txtDir, false)) { - if (/\.txt$/i.test(f)) { - yield [r, await readFile(a)]; - } - } - for await (const [a, r, f] of files('src/shared', false)) { - if (/\.swf$/i.test(f)) { - yield [r, await readFile(a)]; + for (const [dir, reg, cap] of [ + ['mod/files', /[^.].*\.swf$/i, true], + ['original/files/eng/bionicle/recentupdates', /[^.].*\.txt$/i, false], + ['src/shared', /[^.].*\.swf$/i, false] + ]) { + for (const f of (await readdir(dir)).sort()) { + if (reg.test(f)) { + const d = await readFile(`${dir}/${f}`); + if (cap) { + setFps(d, flash4FpsCap); + } + yield [f, d]; + } } } } -function movie(delay) { +function projected(delay) { const swfv = 5; const [w, h] = [770, 425]; const fps = 18; @@ -61,50 +58,47 @@ function movie(delay) { return loader(swfv, w, h, fps, bg, url, delay ? Math.round(fps / 2) : 0); } -async function bundler(b) { - for await (const [file, data] of resources()) { - await b.createResourceFile(file, data); - } -} - -async function browser(dest) { - for await (const [file, data] of resources()) { - await outputFile(`${dest}/${file}`, data); - } - await copyFile('src/browser/index.html', `${dest}/index.html`); -} - const task = {'': _ => Object.keys(task).map(t => t && console.error(t)) && 1}; task['clean'] = async () => { - await remove('build', 'dist'); -}; - -task['build:pages'] = async () => { - const build = 'build/pages'; - await remove(build); - await browser(build); - await docs('docs', build); + await rm('dist', {force: true, recursive: true}); + await rm('build', {force: true, recursive: true}); }; -task['build:browser'] = async () => { - const build = 'build/browser'; - await remove(build); - await browser(`${build}/data`); - await outputFile( - `${build}/${appFile}.html`, - '\n' - ); - await docs('docs', build); -}; - -task['dist:browser:zip'] = async () => { - await makeZip(`dist/${distName}-Browser.zip`, 'build/browser'); -}; +for (const [type, flat] of Object.entries({ + 'pages': true, + 'browser': false +})) { + const build = `build/${type}`; + task[`build:${type}`] = async () => { + await rm(build, {force: true, recursive: true}); + const file = flat ? 'index.html' : `${appFile}.html`; + const b = new BundleHtml(`${build}/${file}`, flat); + b.projector.lang = 'en-US'; + b.projector.title = appName; + b.projector.background = '#000000'; + b.projector.color = '#999999'; + b.projector.src = 'bohrokanimations.swf'; + b.projector.width = 770; + b.projector.height = 425; + b.projector.bgcolor = '#000000'; + await b.write(async b => { + for await (const [file, data] of resources()) { + await b.createResourceFile(file, data); + } + }); + await docs('docs', build); + }; +} -task['dist:browser:tgz'] = async () => { - await makeTgz(`dist/${distName}-Browser.tgz`, 'build/browser'); -}; +for (const [type, make] of Object.entries({ + 'zip': makeZip, + 'tgz': makeTgz +})) { + task[`dist:browser:${type}`] = async () => { + await make(`dist/${distName}-Browser.${type}`, 'build/browser'); + }; +} for (const [type, pkg] of Object.entries({ 'i386': 'flash-player-35.0.0.204-windows-i386-sa-2022-08-13', @@ -113,11 +107,11 @@ for (const [type, pkg] of Object.entries({ })) { const build = `build/windows-${type}`; task[`build:windows-${type}`] = async () => { - await remove(build); + await rm(build, {force: true, recursive: true}); const file = `${appFile}.exe`; const b = new BundleSaWindows(`${build}/${file}`); b.projector.player = await new Manager().file(pkg); - b.projector.movieData = movie(false); + b.projector.movieData = projected(false); b.projector.versionStrings = { FileVersion: version, ProductVersion: versionShort, @@ -134,7 +128,11 @@ for (const [type, pkg] of Object.entries({ b.projector.patchWindowTitle = appName; b.projector.patchOutOfDateDisable = true; b.projector.removeCodeSignature = true; - await b.write(bundler); + await b.write(async b => { + for await (const [file, data] of resources()) { + await b.createResourceFile(file, data); + } + }); await docs('docs', build); }; task[`dist:windows-${type}:zip`] = async () => { @@ -170,11 +168,11 @@ for (const [type, pkg] of Object.entries({ })) { const build = `build/mac-${type}`; task[`build:mac-${type}`] = async () => { - await remove(build); + await rm(build, {force: true, recursive: true}); const pkgInfo = 'APPL????'; const b = new BundleSaMac(`${build}/${appFile}.app`); b.projector.player = await new Manager().file(pkg); - b.projector.movieData = movie(false); + b.projector.movieData = projected(false); b.projector.binaryName = appFile; b.projector.pkgInfoData = pkgInfo; b.projector.infoPlistData = (new Plist(new ValueDict(new Map([ @@ -206,7 +204,11 @@ for (const [type, pkg] of Object.entries({ b.projector.patchWindowTitle = appName; b.projector.removeInfoPlistStrings = true; b.projector.removeCodeSignature = true; - await b.write(bundler); + await b.write(async b => { + for await (const [file, data] of resources()) { + await b.createResourceFile(file, data); + } + }); if (isMac) { await codesign(b.projector.path); await codesign(b.path); @@ -242,14 +244,18 @@ for (const [type, pkg] of Object.entries({ })) { const build = `build/linux-${type}`; task[`build:linux-${type}`] = async () => { - await remove(build); + await rm(build, {force: true, recursive: true}); const b = new BundleSaLinux(`${build}/${appFile}`); b.projector.player = await new Manager().file(pkg); - b.projector.movieData = movie(true); + b.projector.movieData = projected(true); b.projector.patchProjectorOffset = /x86_64/.test(type); b.projector.patchProjectorPath = true; b.projector.patchWindowTitle = appName; - await b.write(bundler); + await b.write(async b => { + for await (const [file, data] of resources()) { + await b.createResourceFile(file, data); + } + }); await docs('docs', build); }; task[`dist:linux-${type}:tgz`] = async () => { diff --git a/src/browser/index.html b/src/browser/index.html deleted file mode 100644 index f72ae9a..0000000 --- a/src/browser/index.html +++ /dev/null @@ -1,66 +0,0 @@ - - - - - Bohrok Animations - - - - -
-
- - - - -
-
- - diff --git a/util/dist.mjs b/util/dist.mjs index 2f892a8..0ac4978 100644 --- a/util/dist.mjs +++ b/util/dist.mjs @@ -2,15 +2,12 @@ import {createRequire} from 'node:module'; import {createWriteStream} from 'node:fs'; import {readdir, mkdir, rm} from 'node:fs/promises'; import {basename, dirname} from 'node:path'; -import {promisify} from 'node:util'; -import {pipeline} from 'node:stream'; +import {pipeline} from 'node:stream/promises'; import {spawn} from 'node:child_process'; import archiver from 'archiver'; import tar from 'tar'; -const pipe = promisify(pipeline); - export async function makeZip(target, source) { await rm(target, {force: true}); await mkdir(dirname(target), {recursive: true}); @@ -22,7 +19,7 @@ export async function makeZip(target, source) { archive.on('warning', err => { archive.emit('error', err); }); - const done = pipe(archive, createWriteStream(target)); + const done = pipeline(archive, createWriteStream(target)); archive.directory(source, false); await Promise.all([archive.finalize(), done]); } diff --git a/util/fs.mjs b/util/fs.mjs deleted file mode 100644 index a774008..0000000 --- a/util/fs.mjs +++ /dev/null @@ -1,46 +0,0 @@ -import {copyFile as cf, mkdir, readdir, rm, writeFile} from 'node:fs/promises'; -import {dirname} from 'node:path'; - -export async function copyFile(src, dst) { - await mkdir(dirname(dst), {recursive: true}); - await cf(src, dst); -} - -export async function outputFile(file, data) { - await mkdir(dirname(file), {recursive: true}); - await writeFile(file, data); -} - -export async function remove(...paths) { - await Promise.all(paths.map(p => rm(p, {recursive: true, force: true}))); -} - -export async function * files(dir, recurse = true, dots = false) { - const o = { - withFileTypes: true - }; - const q = ['']; - while (q.length) { - const d = q.shift(); - const dirs = []; - const files = []; - for (const e of await readdir(`${dir}/${d}`, o)) { - if (!dots && e.name[0] === '.') { - continue; - } - if (e.isFile()) { - files.push(e.name); - } - else if (recurse && e.isDirectory()) { - dirs.push(d ? `${d}/${e.name}` : e.name); - } - } - for (const f of files.sort()) { - const rel = d ? `${d}/${f}` : f; - yield [`${dir}/${rel}`, rel, f]; - } - for (const d of dirs.sort()) { - q.push(d); - } - } -}