Skip to content

Commit

Permalink
Use the HTML bundle, some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Oct 27, 2023
1 parent 77d0693 commit c340b5e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 183 deletions.
138 changes: 72 additions & 66 deletions make.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {readFile} from 'fs/promises';
import {readFile, readdir, rm} from 'node:fs/promises';

import {Manager} from '@shockpkg/core';
import {
Expand All @@ -8,6 +8,7 @@ import {
ValueBoolean
} from '@shockpkg/plist-dom';
import {
BundleHtml,
BundleSaWindows,
BundleSaMac,
BundleSaLinux,
Expand All @@ -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;
Expand All @@ -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`,
'<meta http-equiv="refresh" content="0;url=data/index.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',
Expand All @@ -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,
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 () => {
Expand Down
66 changes: 0 additions & 66 deletions src/browser/index.html

This file was deleted.

7 changes: 2 additions & 5 deletions util/dist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand All @@ -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]);
}
Expand Down
46 changes: 0 additions & 46 deletions util/fs.mjs

This file was deleted.

0 comments on commit c340b5e

Please sign in to comment.