Skip to content

Commit

Permalink
Moved skeleton to property
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Oct 11, 2023
1 parent f1eed5e commit c3a964a
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 154 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import {ProjectorWindows} from '@shockpkg/dir-projector';

const projector = new ProjectorWindows('projector-windows/application.exe');

// Required skeleton.
projector.skeleton = 'skeleton.zip';

// Optional custom icon.
projector.iconFile = 'icon.ico';

Expand Down Expand Up @@ -70,7 +73,7 @@ projector.nestXtrasConfiguration = true;
// Optionally fix Shockwave 3D Xtra InstalledDisplayDrivers reading.
projector.patchShockwave3dInstalledDisplayDriversSize = true;

await projector.withFile('skeleton.zip', 'config.ini');
await projector.withFile('config.ini');
```

### Mac App
Expand All @@ -80,6 +83,9 @@ import {ProjectorMacApp} from '@shockpkg/dir-projector';

const projector = new ProjectorMacApp('projector-macapp/application.app');

// Required skeleton.
projector.skeleton = 'skeleton.zip';

// Optional custom icon.
projector.iconFile = 'icon.icns';

Expand Down Expand Up @@ -118,7 +124,7 @@ projector.nestXtrasContents = true;
// Optionally use Intel-only skeleton.
// projector.intel = true;

await projector.withFile('skeleton.dmg', 'config.ini');
await projector.withFile('config.ini');
```

## Bundle
Expand All @@ -131,11 +137,9 @@ import {BundleWindows} from '@shockpkg/dir-projector';
const bundle = new BundleWindows('bundle-windows/application.exe');

// Use projector property to set options.
bundle.projector.includeXtras = {
'': null
};
bundle.projector.skeleton = 'skeleton.zip';

await bundle.withFile('skeleton.zip', 'config.ini', async b => {
await bundle.withFile('config.ini', async b => {
// Add resources in callback.
await b.copyResource('movie.dir', 'movie.dir');
});
Expand All @@ -149,11 +153,9 @@ import {BundleMacApp} from '@shockpkg/dir-projector';
const bundle = new BundleMacApp('bundle-macapp/application.app');

// Use projector property to set options.
bundle.projector.includeXtras = {
'': null
};
bundle.projector.skeleton = 'skeleton.zip';

await bundle.withFile('skeleton.dmg', 'config.ini', async b => {
await bundle.withFile('config.ini', async b => {
// Add resources in callback.
await b.copyResource('movie.dir', 'movie.dir');
});
Expand Down
88 changes: 40 additions & 48 deletions src/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ void describe('bundle', () => {
const dir = await getDir('simple');
const dest = pathJoin(dir, 'application.exe');

const p = new BundleDummy(dest);
await p.withFile(
fixtureFile('dummy.exe'),
fixtureFile('config.ini.crlf.bin')
);
const b = new BundleDummy(dest);
b.projector.skeleton = fixtureFile('dummy.zip');
await b.withFile(fixtureFile('config.ini.crlf.bin'));
});

void it('resources', async () => {
Expand Down Expand Up @@ -109,48 +107,45 @@ void describe('bundle', () => {

await utimes(resources, dateA, dateA);

const p = new BundleDummy(dest);
await p.withFile(
fixtureFile('dummy.exe'),
fixtureFile('config.ini.crlf.bin'),
async p => {
await p.copyResource('resources0', resources);

await p.copyResource('resources1', resources, {
atimeCopy: true,
mtimeCopy: true,
executableCopy: true
});

await p.copyResource('resources2/a.txt', resourcesA, {
const b = new BundleDummy(dest);
b.projector.skeleton = fixtureFile('dummy.zip');
await b.withFile(fixtureFile('config.ini.crlf.bin'), async p => {
await p.copyResource('resources0', resources);

await p.copyResource('resources1', resources, {
atimeCopy: true,
mtimeCopy: true,
executableCopy: true
});

await p.copyResource('resources2/a.txt', resourcesA, {
atime: dateB,
mtime: dateB,
executable: true
});
await p.copyResource('resources2/d/b.txt', resourcesB, {
atime: dateB,
mtime: dateB,
executable: false
});

if (supportsSymlinks) {
await p.copyResource('resources2/l1.txt', resourcesL1, {
atime: dateB,
mtime: dateB,
executable: true
});
await p.copyResource('resources2/d/b.txt', resourcesB, {
await p.copyResource('resources2/l2.txt', resourcesL2, {
atime: dateB,
mtime: dateB,
executable: false
});

if (supportsSymlinks) {
await p.copyResource('resources2/l1.txt', resourcesL1, {
atime: dateB,
mtime: dateB,
executable: true
});
await p.copyResource('resources2/l2.txt', resourcesL2, {
atime: dateB,
mtime: dateB,
executable: false
});
}
}
);
});

await rm(resources, {recursive: true, force: true});

const st = async (path: string) => lstat(p.resourcePath(path));
const st = async (path: string) => lstat(b.resourcePath(path));

const res0 = await st('resources0');
notEqual(res0.atime.getFullYear(), 2001);
Expand Down Expand Up @@ -255,23 +250,20 @@ void describe('bundle', () => {
await mkdir(dirname(resourcesA), {recursive: true});
await writeFile(resourcesA, 'alpha');

const p = new BundleDummy(dest);
await p.withFile(
fixtureFile('dummy.exe'),
fixtureFile('config.ini.crlf.bin'),
async p => {
await p.createResourceFile('d/b.txt', 'beta');
const b = new BundleDummy(dest);
b.projector.skeleton = fixtureFile('dummy.zip');
await b.withFile(fixtureFile('config.ini.crlf.bin'), async p => {
await p.createResourceFile('d/b.txt', 'beta');

// Merge contents at root of resources.
await p.copyResource('.', resources, {
merge: true
});
}
);
// Merge contents at root of resources.
await p.copyResource('.', resources, {
merge: true
});
});

await rm(resources, {recursive: true, force: true});

const st = async (path: string) => lstat(p.resourcePath(path));
const st = async (path: string) => lstat(b.resourcePath(path));

strictEqual((await st('d/a.txt')).isFile(), true);
strictEqual((await st('d/b.txt')).isFile(), true);
Expand Down
26 changes: 8 additions & 18 deletions src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,26 @@ export abstract class Bundle {
/**
* Open output with file.
*
* @param player Player path.
* @param configFile Config file.
*/
public async openFile(player: string, configFile: string | null) {
public async openFile(configFile: string | null) {
const configData = configFile ? await readFile(configFile) : null;
await this.openData(player, configData);
await this.openData(configData);
}

/**
* Open output with data.
*
* @param player Player path.
* @param configData Config data.
*/
public async openData(player: string, configData: Readonly<Buffer> | null) {
public async openData(configData: Readonly<Buffer> | null) {
if (this._isOpen) {
throw new Error('Already open');
}
await this._checkOutput();

this._closeQueue.clear();
await this._openData(player, configData);
await this._openData(configData);

this._isOpen = true;
}
Expand All @@ -180,35 +178,31 @@ export abstract class Bundle {
* Write out projector with player and file.
* Has a callback to write out the resources.
*
* @param player Player path.
* @param configFile Config file.
* @param func Async function.
* @returns Return value of the async function.
*/
public async withFile<T>(
player: string,
configFile: string | null,
func: ((self: this) => Promise<T>) | null = null
) {
const configData = configFile ? await readFile(configFile) : null;
return this.withData(player, configData, func);
return this.withData(configData, func);
}

/**
* Write out projector with player and data.
* Has a callback to write out the resources.
*
* @param player Player path.
* @param configData Config data.
* @param func Async function.
* @returns Return value of the async function.
*/
public async withData<T>(
player: string,
configData: Readonly<Buffer> | null,
func: ((self: this) => Promise<T>) | null = null
) {
await this.openData(player, configData);
await this.openData(configData);
try {
return func ? await func.call(this, this) : null;
} finally {
Expand Down Expand Up @@ -588,14 +582,10 @@ export abstract class Bundle {
/**
* Open output with data.
*
* @param player Player path.
* @param configData Config data.
*/
protected async _openData(
player: string,
configData: Readonly<Buffer> | null
) {
await this.projector.withData(player, configData);
protected async _openData(configData: Readonly<Buffer> | null) {
await this.projector.withData(configData);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/mac/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ void describe('bundle/mac/app', () => {
const dest = pathJoin(dir, 'application.app');

const b = new BundleMacApp(dest);
b.projector.skeleton = await getSkeleton();
await b.withFile(
await getSkeleton(),
fixtureFile('config.ini.lf.bin'),
async b => {
await b.copyResource(
Expand All @@ -44,6 +44,7 @@ void describe('bundle/mac/app', () => {

const b = new BundleMacApp(dest);
const p = b.projector;
p.skeleton = await getSkeleton();
p.lingoFile = fixtureFile('lingo.ini.lf.bin');
p.splashImageFile = fixtureFile('splash.pict');
p.iconFile = fixtureFile('icon.icns');
Expand All @@ -57,7 +58,6 @@ void describe('bundle/mac/app', () => {
'': null
};
await b.withFile(
await getSkeleton(),
fixtureFile('config.ini.lf.bin'),
async b => {
await b.copyResource(
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/windows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ void describe('bundle/windows', () => {
const dest = pathJoin(dir, 'application.exe');

const b = new BundleWindows(dest);
b.projector.skeleton = await getSkeleton();
await b.withFile(
await getSkeleton(),
fixtureFile('config.ini.crlf.bin'),
async b => {
await b.copyResource(
Expand All @@ -48,6 +48,7 @@ void describe('bundle/windows', () => {

const b = new BundleWindows(dest);
const p = b.projector;
p.skeleton = await getSkeleton();
p.lingoFile = fixtureFile('lingo.ini.crlf.bin');
p.splashImageFile = fixtureFile('splash.bmp');
p.nestXtrasConfiguration = true;
Expand All @@ -60,7 +61,6 @@ void describe('bundle/windows', () => {
p.iconFile = fixtureFile('icon.ico');
p.versionStrings = versionStrings;
await b.withFile(
await getSkeleton(),
fixtureFile('config.ini.crlf.bin'),
async b => {
await b.copyResource(
Expand Down
12 changes: 8 additions & 4 deletions src/projector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ void describe('projector', () => {
const dest = pathJoin(dir, 'application.exe');

const p = new ProjectorDummy(dest);
await p.withFile('dummy', fixtureFile('config.ini.crlf.bin'));
p.skeleton = 'dummy';
await p.withFile(fixtureFile('config.ini.crlf.bin'));

await copyFile(fixtureFile('dir7.dir'), pathJoin(dir, 'movie.dir'));
});
Expand All @@ -24,8 +25,9 @@ void describe('projector', () => {
const dest = pathJoin(dir, 'application.exe');

const p = new ProjectorDummy(dest);
p.skeleton = 'dummy';
p.lingoFile = fixtureFile('lingo.ini.crlf.bin');
await p.withFile('dummy', fixtureFile('config.ini.crlf.bin'));
await p.withFile(fixtureFile('config.ini.crlf.bin'));

await copyFile(fixtureFile('dir7.dir'), pathJoin(dir, 'movie.dir'));
});
Expand All @@ -35,8 +37,9 @@ void describe('projector', () => {
const dest = pathJoin(dir, 'application.exe');

const p = new ProjectorDummy(dest);
p.skeleton = 'dummy';
p.splashImageFile = fixtureFile('splash.bmp');
await p.withFile('dummy', fixtureFile('config.ini.crlf.bin'));
await p.withFile(fixtureFile('config.ini.crlf.bin'));

await copyFile(fixtureFile('dir7.dir'), pathJoin(dir, 'movie.dir'));
});
Expand All @@ -46,9 +49,10 @@ void describe('projector', () => {
const dest = pathJoin(dir, 'application.exe');

const p = new ProjectorDummy(dest);
p.skeleton = 'dummy';
p.lingoFile = fixtureFile('lingo.ini.crlf.bin');
p.splashImageFile = fixtureFile('splash.bmp');
await p.withFile('dummy', fixtureFile('config.ini.crlf.bin'));
await p.withFile(fixtureFile('config.ini.crlf.bin'));

await copyFile(fixtureFile('dir7.dir'), pathJoin(dir, 'movie.dir'));
});
Expand Down
Loading

0 comments on commit c3a964a

Please sign in to comment.