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 Apr 16, 2018
1 parent 1d976bb commit 6c82a0b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ config object:

| Target Name | Available Platforms | Description | Configurable Options | Default? | Requirements |
|-------------|---------------------|-------------|----------------------|----------|--------------|
| `zip` | All | Zips your packaged application | None | Yes | `zip` on Darwin/Linux |
| `zip` | All | Zips your packaged application | None | Yes | `zip` on Darwin/Linux, [Windows requirements](https://github.com/feross/cross-zip#windows-users) |
| `squirrel` | Windows | Generates an installer and `.nupkg` files for Squirrel.Windows | [`electronWinstallerConfig`](https://github.com/electron/windows-installer#usage) | Yes | |
| `appx` | Windows | Generates a Windows Store package | [`windowsStoreConfig`](https://github.com/felixrieseberg/electron-windows-store#programmatic-usage) | No | |
| `wix` | Windows | Generates a traditional MSI file | [`electronWixMSIConfig`](https://github.com/felixrieseberg/electron-wix-msi#configuration) | No | [Wix Toolit](https://github.com/felixrieseberg/electron-wix-msi#prerequisites) |
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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 @@ -64,8 +65,7 @@
"semver": "^5.3.0",
"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.40",
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 @@ -18,8 +18,8 @@
},
"dependencies": {
"@electron-forge/maker-base": "6.0.0-beta.2",
"cross-zip": "^2.1.5",
"fs-extra": "^5.0.0",
"pify": "^3.0.0",
"zip-folder": "^1.0.0"
"pify": "^3.0.0"
}
}
36 changes: 5 additions & 31 deletions packages/maker/zip/src/MakerZIP.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import MakerBase from '@electron-forge/maker-base';

import { spawn } from 'child_process';
import path from 'path';
import pify from 'pify';
import { zip } from 'cross-zip';

export default class MakerZIP extends MakerBase {
name = 'zip';
Expand All @@ -18,39 +18,13 @@ export default class MakerZIP extends MakerBase {
packageJSON,
targetPlatform,
}) {
const zipFolder = require('zip-folder');
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];
}

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}`));
});
});
}

0 comments on commit 6c82a0b

Please sign in to comment.