Skip to content

Commit

Permalink
Created Otto class of projector, making room for other classes
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Oct 13, 2023
1 parent 404f44f commit 15fd988
Show file tree
Hide file tree
Showing 23 changed files with 677 additions and 625 deletions.
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ Currently only flat projectors are supported, not the kind that Director makes w

## Projector

### Windows
### Otto

#### Windows

```js
import {ProjectorWindows} from '@shockpkg/dir-projector';
import {ProjectorOttoWindows} from '@shockpkg/dir-projector';

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

// Required skeleton.
projector.skeleton = 'skeleton.zip';
Expand Down Expand Up @@ -79,12 +81,12 @@ projector.patchShockwave3dInstalledDisplayDriversSize = true;
await projector.write();
```

### Mac
#### Mac

```js
import {ProjectorMac} from '@shockpkg/dir-projector';
import {ProjectorOttoMac} from '@shockpkg/dir-projector';

const projector = new ProjectorMac('projector-mac/application.app');
const projector = new ProjectorOttoMac('projector-mac/application.app');

// Required skeleton.
projector.skeleton = 'skeleton.zip';
Expand Down Expand Up @@ -135,12 +137,14 @@ await projector.write();

## Bundle

### Windows
### Otto

#### Windows

```js
import {BundleWindows} from '@shockpkg/dir-projector';
import {BundleOttoWindows} from '@shockpkg/dir-projector';

const bundle = new BundleWindows('bundle-windows/application.exe');
const bundle = new BundleOttoWindows('bundle-windows/application.exe');

// Use projector property to set options.
bundle.projector.skeleton = 'skeleton.zip';
Expand All @@ -154,12 +158,12 @@ await bundle.write(async b => {
});
```

### Mac
#### Mac

```js
import {BundleMac} from '@shockpkg/dir-projector';
import {BundleOttoMac} from '@shockpkg/dir-projector';

const bundle = new BundleMac('bundle-mac/application.app');
const bundle = new BundleOttoMac('bundle-mac/application.app');

// Use projector property to set options.
bundle.projector.skeleton = 'skeleton.zip';
Expand Down
13 changes: 0 additions & 13 deletions src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ export abstract class Bundle {
* Close output.
*/
protected async _close() {
await this._writeLauncher();
await this._closeQueue.run();
}

Expand Down Expand Up @@ -589,22 +588,10 @@ export abstract class Bundle {
return dest;
}

/**
* Main application file extension.
*
* @returns File extension.
*/
public abstract get extension(): string;

/**
* Create projector instance for the bundle.
*
* @returns Projector instance.
*/
protected abstract _createProjector(): Projector;

/**
* Write the launcher file.
*/
protected abstract _writeLauncher(): Promise<void>;
}
4 changes: 2 additions & 2 deletions src/bundle/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './windows';
export * from './mac';
export * from './otto';
export * from './otto/';
File renamed without changes.
37 changes: 22 additions & 15 deletions src/bundle.test.ts → src/bundle/otto.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {describe, it} from 'node:test';
import {notEqual, strictEqual} from 'node:assert';
import {notEqual, ok, strictEqual} from 'node:assert';
import {
chmod,
lstat,
Expand All @@ -13,13 +13,15 @@ import {join as pathJoin, basename, dirname} from 'node:path';

import {fsLchmod, fsLutimes} from '@shockpkg/archive-files';

import {trimExtension} from './util';
import {fixtureFile} from './util.spec';
import {ProjectorDummy} from './projector.spec';
import {Bundle} from './bundle';
import {cleanBundlesDir} from './bundle.spec';
import {trimExtension} from '../util';
import {fixtureFile} from '../util.spec';
import {Bundle} from '../bundle';
import {ProjectorOttoDummy} from '../projector/otto.spec';

const getDir = async (d: string) => cleanBundlesDir('dummy', d);
import {cleanBundlesDir} from './otto.spec';
import {BundleOtto} from './otto';

const getDir = async (d: string) => cleanBundlesDir('otto', 'dummy', d);

const supportsExecutable = !process.platform.startsWith('win');
const supportsSymlinks = !process.platform.startsWith('win');
Expand All @@ -28,8 +30,8 @@ const supportsSymlinkAttrs = process.platform.startsWith('darwin');
// eslint-disable-next-line no-bitwise
const isUserExec = (mode: number) => !!(mode & 0b001000000);

class BundleDummy extends Bundle {
public readonly projector: ProjectorDummy;
class BundleOttoDummy extends BundleOtto {
public readonly projector: ProjectorOttoDummy;

constructor(path: string) {
super(path);
Expand All @@ -47,7 +49,7 @@ class BundleDummy extends Bundle {
if (directory === path) {
throw new Error(`Output path must end with: ${extension}`);
}
return new ProjectorDummy(pathJoin(directory, basename(path)));
return new ProjectorOttoDummy(pathJoin(directory, basename(path)));
}

protected async _writeLauncher() {
Expand All @@ -56,13 +58,18 @@ class BundleDummy extends Bundle {
}
}

void describe('bundle', () => {
void describe('BundleDummy', () => {
void describe('bundle/otto', () => {
void describe('BundleOttoDummy', () => {
void it('instanceof', () => {
ok(BundleOttoDummy.prototype instanceof BundleOtto);
ok(BundleOttoDummy.prototype instanceof Bundle);
});

void it('simple', async () => {
const dir = await getDir('simple');
const dest = pathJoin(dir, 'application.exe');

const b = new BundleDummy(dest);
const b = new BundleOttoDummy(dest);
b.projector.skeleton = fixtureFile('dummy.zip');
b.projector.configFile = fixtureFile('config.ini.crlf.bin');
await b.write();
Expand Down Expand Up @@ -108,7 +115,7 @@ void describe('bundle', () => {

await utimes(resources, dateA, dateA);

const b = new BundleDummy(dest);
const b = new BundleOttoDummy(dest);
b.projector.skeleton = fixtureFile('dummy.zip');
b.projector.configFile = fixtureFile('config.ini.crlf.bin');
await b.write(async p => {
Expand Down Expand Up @@ -252,7 +259,7 @@ void describe('bundle', () => {
await mkdir(dirname(resourcesA), {recursive: true});
await writeFile(resourcesA, 'alpha');

const b = new BundleDummy(dest);
const b = new BundleOttoDummy(dest);
b.projector.skeleton = fixtureFile('dummy.zip');
b.projector.configFile = fixtureFile('config.ini.crlf.bin');
await b.write(async p => {
Expand Down
48 changes: 48 additions & 0 deletions src/bundle/otto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {ProjectorOtto} from '../projector/otto';
import {Bundle} from '../bundle';

/**
* BundleOtto object.
*/
export abstract class BundleOtto extends Bundle {
/**
* ProjectorOtto instance.
*/
public abstract readonly projector: ProjectorOtto;

/**
* ProjectorOtto constructor.
*
* @param path Output path.
*/
constructor(path: string) {
super(path);
}

/**
* @inheritdoc
*/
protected async _close(): Promise<void> {
await this._writeLauncher();
await super._close();
}

/**
* Main application file extension.
*
* @returns File extension.
*/
public abstract get extension(): string;

/**
* Create projector instance for the bundle.
*
* @returns Projector instance.
*/
protected abstract _createProjector(): ProjectorOtto;

/**
* Write the launcher file.
*/
protected abstract _writeLauncher(): Promise<void>;
}
2 changes: 2 additions & 0 deletions src/bundle/otto/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './windows';
export * from './mac';
25 changes: 13 additions & 12 deletions src/bundle/mac.test.ts → src/bundle/otto/mac.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@ import {describe, it} from 'node:test';
import {ok} from 'node:assert';
import {join as pathJoin} from 'node:path';

import {listSamples} from '../projector/mac.spec';
import {cleanBundlesDir} from '../bundle.spec';
import {fixtureFile, getPackageFile} from '../util.spec';
import {Bundle} from '../bundle';
import {listSamples} from '../../projector/otto/mac.spec';
import {cleanBundlesDir} from '../otto.spec';
import {fixtureFile, getPackageFile} from '../../util.spec';
import {BundleOtto} from '../otto';

import {BundleMac} from './mac';
import {BundleOttoMac} from './mac';

void describe('bundle/mac', () => {
void describe('BundleMac', () => {
void it('instanceof Bundle', () => {
ok(BundleMac.prototype instanceof Bundle);
void describe('bundle/otto/mac', () => {
void describe('BundleOttoMac', () => {
void it('instanceof', () => {
ok(BundleOttoMac.prototype instanceof BundleOtto);
});

for (const {name} of listSamples()) {
const getDir = async (d: string) => cleanBundlesDir('mac', name, d);
const getDir = async (d: string) =>
cleanBundlesDir('otto', 'mac', name, d);
const getSkeleton = async () => getPackageFile(name);

void describe(name, () => {
void it('simple', async () => {
const dir = await getDir('simple');
const dest = pathJoin(dir, 'application.app');

const b = new BundleMac(dest);
const b = new BundleOttoMac(dest);
b.projector.skeleton = await getSkeleton();
b.projector.configFile = fixtureFile('config.ini.lf.bin');
await b.write(async b => {
Expand All @@ -39,7 +40,7 @@ void describe('bundle/mac', () => {
const dir = await getDir('complex');
const dest = pathJoin(dir, 'application.app');

const b = new BundleMac(dest);
const b = new BundleOttoMac(dest);
const p = b.projector;
p.skeleton = await getSkeleton();
p.configFile = fixtureFile('config.ini.lf.bin');
Expand Down
30 changes: 13 additions & 17 deletions src/bundle/mac.ts → src/bundle/otto/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import {join as pathJoin, basename, dirname} from 'node:path';
import {fsLstatExists} from '@shockpkg/archive-files';
import {Plist, ValueDict, ValueString} from '@shockpkg/plist-dom';

import {trimExtension} from '../util';
import {machoTypesFile, machoAppLauncher} from '../util/mac';
import {ProjectorMac} from '../projector/mac';
import {Bundle} from '../bundle';
import {trimExtension} from '../../util';
import {machoTypesFile, machoAppLauncher} from '../../util/mac';
import {ProjectorOttoMac} from '../../projector/otto/mac';
import {BundleOtto} from '../otto';

/**
* BundleMac object.
* BundleOttoMac object.
*/
export class BundleMac extends Bundle {
export class BundleOttoMac extends BundleOtto {
/**
* ProjectorMac instance.
* ProjectorOttoMac instance.
*/
public readonly projector: ProjectorMac;
public readonly projector: ProjectorOttoMac;

/**
* BundleMac constructor.
* BundleOttoMac constructor.
*
* @param path Output path for the main application.
*/
Expand All @@ -30,9 +30,7 @@ export class BundleMac extends Bundle {
}

/**
* Main application file extension.
*
* @returns File extension.
* @inheritdoc
*/
public get extension() {
return '.app';
Expand All @@ -48,18 +46,16 @@ export class BundleMac extends Bundle {
}

/**
* Create projector instance for the bundle.
*
* @returns Projector instance.
* @inheritdoc
*/
protected _createProjector() {
const projName = `${this._getLauncherName()}${this.extension}`;
const projPath = pathJoin(this.path, 'Contents', 'Resources', projName);
return new ProjectorMac(projPath);
return new ProjectorOttoMac(projPath);
}

/**
* Write the launcher file.
* @inheritdoc
*/
protected async _writeLauncher() {
const {path, projector} = this;
Expand Down
Loading

0 comments on commit 15fd988

Please sign in to comment.