Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(Builder): fix stripping for packed apps
Browse files Browse the repository at this point in the history
  • Loading branch information
evshiron committed May 6, 2017
1 parent 2a6a153 commit bc5f68e
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/lib/Builder.ts
Expand Up @@ -136,6 +136,20 @@ export class Builder {
return ((Date.now() - started) / 1000).toFixed(2);
}

protected async writeStrippedManifest(path: string, pkg: any, config: BuildConfig) {

const json: any = {};

for(const key in pkg) {
if(pkg.hasOwnProperty(key) && config.strippedProperties.indexOf(key) === -1) {
json[key] = pkg[key];
}
}

await writeFile(path, JSON.stringify(json));

}

protected combineExecutable(executable: string, nwFile: string) {
return new Promise((resolve, reject) => {

Expand Down Expand Up @@ -343,13 +357,23 @@ export class Builder {
case 'win32':
case 'win':
case 'linux':

const nwFile = await tmpName({
postfix: '.zip',
});

await compress(this.dir, files, 'zip', nwFile);

const { path: tempDir } = await tmpDir();
await this.writeStrippedManifest(resolve(tempDir, 'package.json'), pkg, config);
await compress(tempDir, [ './package.json' ], 'zip', nwFile);
await remove(tempDir);

const executable = await findExecutable(platform, targetDir);
await this.combineExecutable(executable, nwFile);

await remove(nwFile);

break;
case 'darwin':
case 'osx':
Expand All @@ -369,23 +393,9 @@ export class Builder {
await copyFileAsync(resolve(this.dir, file), resolve(appRoot, file));
}

}

// Here we overwrite `package.json` with a stripped one.

await writeFile(resolve(appRoot, 'package.json'), (() => {

const json: any = {};

for(const key in pkg) {
if(pkg.hasOwnProperty(key) && config.strippedProperties.indexOf(key) == -1) {
json[key] = pkg[key];
}
}

return JSON.stringify(json);
await this.writeStrippedManifest(resolve(appRoot, 'package.json'), pkg, config);

})());
}

}

Expand Down

0 comments on commit bc5f68e

Please sign in to comment.