Skip to content

Commit

Permalink
refactor(maker): replace zip-folder with cross-zip
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #322
  • Loading branch information
malept committed Sep 18, 2017
1 parent fcdc0a0 commit a9b3986
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 37 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"bluebird": "^3.4.6",
"colors": "^1.1.2",
"commander": "^2.9.0",
"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 @@ -132,8 +133,7 @@
"sudo-prompt": "^7.0.0",
"tabtab": "^2.2.1",
"username": "^3.0.0",
"yarn-or-npm": "^2.0.2",
"zip-folder": "^1.0.0"
"yarn-or-npm": "^2.0.2"
},
"config": {
"commitizen": {
Expand Down
40 changes: 5 additions & 35 deletions src/makers/generic/zip.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,17 @@
import { spawn } from 'child_process';
import path from 'path';
import pify from 'pify';
import { zip } from 'cross-zip';

import { ensureFile } from '../../util/ensure-output';

export const isSupportedOnCurrentPlatform = async () => true;

const zipPromise = (from, to) =>
new Promise((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, exitted with code: ${code}`));
});
});

export default async ({ dir, appName, targetPlatform, packageJSON }) => {
const zipFolder = require('zip-folder');

const zipDir = targetPlatform === 'darwin' ? path.resolve(dir, `${appName}.app`) : dir;
const zipPath = path.resolve(dir, '../make', `${path.basename(dir)}-${packageJSON.version}.zip`);

await ensureFile(zipPath);
switch (targetPlatform) {
// This case is tested but not on the coverage reporting platform
/* istanbul ignore next */
case 'win32':
await pify(zipFolder)(dir, zipPath);
break;
case 'darwin':
await zipPromise(path.resolve(dir, `${appName}.app`), zipPath);
break;
// This case is tested but not on the coverage reporting platform
/* istanbul ignore next */
case 'linux':
await zipPromise(dir, zipPath);
break;
default:
throw new Error('Unrecognized platform');
}
await pify(zip)(zipDir, zipPath);

return [zipPath];
};

0 comments on commit a9b3986

Please sign in to comment.