-
-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(maker): replace zip-folder with cross-zip
ISSUES CLOSED: #322
- Loading branch information
Showing
2 changed files
with
7 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
}; |