Skip to content
Permalink
Browse files

refactor(maker): replace zip-folder with cross-zip (#325)

ISSUES CLOSED: #322
  • Loading branch information
malept authored and MarshallOfSound committed May 3, 2018
1 parent 77077ce commit e06aa0b7a7210c735e10c965c34d642493a6e4f3
Showing with 10 additions and 35 deletions.
  1. +2 −2 package.json
  2. +2 −2 packages/maker/zip/package.json
  3. +6 −31 packages/maker/zip/src/MakerZIP.ts
@@ -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",
@@ -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",
@@ -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"
}
}
@@ -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';

@@ -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.
You can’t perform that action at this time.