Skip to content

Commit

Permalink
Added flat bundle option
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Oct 15, 2023
1 parent 6c794d2 commit 7363e50
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 18 deletions.
37 changes: 36 additions & 1 deletion src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
chmod,
lstat,
mkdir,
readdir,
readlink,
stat,
symlink,
Expand Down Expand Up @@ -83,6 +84,11 @@ export abstract class Bundle {
*/
public readonly path: string;

/**
* Flat bundle.
*/
public readonly flat: boolean;

/**
* Projector instance.
*/
Expand All @@ -102,9 +108,11 @@ export abstract class Bundle {
* Bundle constructor.
*
* @param path Output path for the main executable.
* @param flat Flat bundle.
*/
constructor(path: string) {
constructor(path: string, flat = false) {
this.path = path;
this.flat = flat;
}

/**
Expand Down Expand Up @@ -447,6 +455,17 @@ export abstract class Bundle {
* Check that output path is valid, else throws.
*/
protected async _checkOutput() {
if (this.flat) {
const p = dirname(this.path);
if (await fsLstatExists(p)) {
for (const n of await readdir(p)) {
if (!this.isExcludedFile(n)) {
throw new Error(`Output path not empty: ${p}`);
}
}
}
return;
}
await Promise.all(
[this.path, this.resourcePath('')].map(async p => {
if (await fsLstatExists(p)) {
Expand Down Expand Up @@ -596,6 +615,22 @@ export abstract class Bundle {
return dest;
}

/**
* Get the projector path.
*
* @returns This path or the nested path.
*/
protected _getProjectorPath() {
return this.flat ? this.path : this._getProjectorPathNested();
}

/**
* Get nested projector path.
*
* @returns Output path.
*/
protected abstract _getProjectorPathNested(): string;

/**
* Create projector instance for the bundle.
*
Expand Down
12 changes: 8 additions & 4 deletions src/bundle/otto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export async function cleanBundlesDir(...path: string[]) {
export class BundleOttoDummy extends BundleOtto {
public readonly projector: ProjectorOttoDummy;

constructor(path: string) {
super(path);
constructor(path: string, flat = false) {
super(path, flat);

this.projector = this._createProjector();
}
Expand All @@ -28,13 +28,17 @@ export class BundleOttoDummy extends BundleOtto {
return '.exe';
}

protected _createProjector() {
protected _getProjectorPathNested(): string {
const {path, extension} = this;
const directory = trimExtension(path, extension, true);
if (directory === path) {
throw new Error(`Output path must end with: ${extension}`);
}
return new ProjectorOttoDummy(pathJoin(directory, basename(path)));
return pathJoin(directory, basename(path));
}

protected _createProjector() {
return new ProjectorOttoDummy(this._getProjectorPath());
}

protected async _writeLauncher() {
Expand Down
12 changes: 12 additions & 0 deletions src/bundle/otto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,17 @@ void describe('bundle/otto', () => {
strictEqual((await st('d/a.txt')).isFile(), true);
strictEqual((await st('d/b.txt')).isFile(), true);
});

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

const b = new BundleOttoDummy(dest, true);
b.projector.skeleton = fixtureFile('dummy.zip');
b.projector.configFile = fixtureFile('config.ini.crlf.bin');
await b.write(async p => {
await p.createResourceFile('resource.txt', 'testing123');
});
});
});
});
9 changes: 6 additions & 3 deletions src/bundle/otto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ export abstract class BundleOtto extends Bundle {
* ProjectorOtto constructor.
*
* @param path Output path.
* @param flat Flat bundle.
*/
constructor(path: string) {
super(path);
constructor(path: string, flat = false) {
super(path, flat);
}

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

Expand Down
15 changes: 15 additions & 0 deletions src/bundle/otto/mac.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ void describe('bundle/otto/mac', () => {
);
});
});

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

const b = new BundleOttoMac(dest, true);
b.projector.skeleton = await getSkeleton();
b.projector.configFile = fixtureFile('config.ini.lf.bin');
await b.write(async b => {
await b.copyResource(
'movie.dir',
fixtureFile('dir7.dir')
);
});
});
});
}
});
Expand Down
17 changes: 12 additions & 5 deletions src/bundle/otto/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export class BundleOttoMac extends BundleOtto {
* BundleOttoMac constructor.
*
* @param path Output path for the main application.
* @param flat Flat bundle.
*/
constructor(path: string) {
super(path);
constructor(path: string, flat = false) {
super(path, flat);

this.projector = this._createProjector();
}
Expand All @@ -45,13 +46,19 @@ export class BundleOttoMac extends BundleOtto {
return trimExtension(basename(this.path), this.extension, true);
}

/**
*@inheritdoc
*/
protected _getProjectorPathNested(): string {
const projName = `${this._getLauncherName()}${this.extension}`;
return pathJoin(this.path, 'Contents', 'Resources', projName);
}

/**
* @inheritdoc
*/
protected _createProjector() {
const projName = `${this._getLauncherName()}${this.extension}`;
const projPath = pathJoin(this.path, 'Contents', 'Resources', projName);
return new ProjectorOttoMac(projPath);
return new ProjectorOttoMac(this._getProjectorPath());
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/bundle/otto/windows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ void describe('bundle/otto/windows', () => {
);
});
});

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

const b = new BundleOttoWindows(dest, true);
b.projector.skeleton = await getSkeleton();
b.projector.configFile = fixtureFile('config.ini.crlf.bin');
await b.write(async b => {
await b.copyResource(
'movie.dir',
fixtureFile('dir7.dir')
);
});
});
});
}
});
Expand Down
18 changes: 13 additions & 5 deletions src/bundle/otto/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ export class BundleOttoWindows extends BundleOtto {
* BundleOttoWindows constructor.
*
* @param path Output path for the main application.
* @param flat Flat bundle.
*/
constructor(path: string) {
super(path);
constructor(path: string, flat = false) {
super(path, flat);

this.projector = this._createProjector();
}
Expand All @@ -34,15 +35,22 @@ export class BundleOttoWindows extends BundleOtto {
}

/**
* @inheritdoc
*@inheritdoc
*/
protected _createProjector() {
protected _getProjectorPathNested(): string {
const {path, extension} = this;
const directory = trimExtension(path, extension, true);
if (directory === path) {
throw new Error(`Output path must end with: ${extension}`);
}
return new ProjectorOttoWindows(pathJoin(directory, basename(path)));
return pathJoin(directory, basename(path));
}

/**
* @inheritdoc
*/
protected _createProjector() {
return new ProjectorOttoWindows(this._getProjectorPath());
}

/**
Expand Down

0 comments on commit 7363e50

Please sign in to comment.