Skip to content

Commit

Permalink
refactor(maker): replace zip-folder with cross-zip (#325)
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #322
  • Loading branch information
malept authored and MarshallOfSound committed May 3, 2018
1 parent 77077ce commit e06aa0b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 35 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"commander": "^2.9.0",
"cross-spawn": "^6.0.4",
"cross-spawn-promise": "^0.10.1",
"cross-zip": "^2.1.5",
"debug": "^3.0.0",
"electron-forge-template-angular2": "^1.0.3",
"electron-forge-template-react": "^1.0.2",
Expand Down Expand Up @@ -70,8 +71,7 @@
"source-map-support": "^0.5.4",
"sudo-prompt": "^8.0.0",
"username": "^3.0.0",
"yarn-or-npm": "^2.0.2",
"zip-folder": "^1.0.0"
"yarn-or-npm": "^2.0.2"
},
"devDependencies": {
"@babel/cli": "^7.0.0-beta.44",
Expand Down
4 changes: 2 additions & 2 deletions packages/maker/zip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"dependencies": {
"@electron-forge/maker-base": "6.0.0-beta.5",
"@electron-forge/shared-types": "6.0.0-beta.5",
"cross-zip": "^2.1.5",
"fs-extra": "^5.0.0",
"pify": "^3.0.0",
"zip-folder": "^1.0.0"
"pify": "^3.0.0"
}
}
37 changes: 6 additions & 31 deletions packages/maker/zip/src/MakerZIP.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import MakerBase, { MakerOptions } from '@electron-forge/maker-base';
import { ForgePlatform } from '@electron-forge/shared-types';

import { spawn } from 'child_process';
import path from 'path';
import pify from 'pify';

Expand All @@ -22,39 +21,15 @@ export default class MakerZIP extends MakerBase<MakerZIPConfig> {
packageJSON,
targetPlatform,
}: MakerOptions) {
const zipFolder = require('zip-folder');
const zip = require('cross-zip');

const zipDir = ['darwin', 'mas'].includes(targetPlatform) ? path.resolve(dir, `${appName}.app`) : dir;

const zipPath = path.resolve(makeDir, `${path.basename(dir)}-${packageJSON.version}.zip`);

await this.ensureFile(zipPath);
switch (targetPlatform) {
case 'win32':
await pify(zipFolder)(dir, zipPath);
break;
case 'mas':
case 'darwin':
await this.zipPromise(path.resolve(dir, `${appName}.app`), zipPath);
break;
case 'linux':
await this.zipPromise(dir, zipPath);
break;
default:
throw `Unrecognized platform: ${process.platform}`;
}
await pify(zip)(zipDir, zipPath);

return [zipPath];
}

private zipPromise = (from: string, to: string) =>
new Promise<void>((resolve, reject) => {
const child = spawn('zip', ['-r', '-y', to, path.basename(from)], {
cwd: path.dirname(from),
});

child.stdout.on('data', () => {});
child.stderr.on('data', () => {});

child.on('close', (code) => {
if (code === 0) return resolve();
reject(new Error(`Failed to zip, exited with code: ${code}`));
});
});
}

0 comments on commit e06aa0b

Please sign in to comment.