All files / makers/generic zip.js

87.5% Statements 14/16
50% Branches 2/4
83.33% Functions 5/6
86.67% Lines 13/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45              1x 1x 1x       1x 1x   1x 1x           1x 1x 1x             1x 1x                 1x    
import { spawn } from 'child_process';
import path from 'path';
import pify from 'pify';
import zipFolder from 'zip-folder';
 
import { ensureFile } from '../../util/ensure-output';
 
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) => {
      Eif (code === 0) return resolve();
      reject(new Error(`Failed to zip, exitted with code: ${code}`));
    });
  });
 
export default async (dir, appName, targetArch, forgeConfig, packageJSON) => { // eslint-disable-line
  const zipPath = path.resolve(dir, '../make', `${path.basename(dir)}.zip`);
  await ensureFile(zipPath);
  switch (process.platform) {
    // 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');
  }
  return [zipPath];
};