/ script / lib / compress-artifacts.js
compress-artifacts.js
 1  'use strict';
 2  
 3  const fs = require('fs-extra');
 4  const path = require('path');
 5  const spawnSync = require('./spawn-sync');
 6  const { path7za } = require('7zip-bin');
 7  
 8  const CONFIG = require('../config');
 9  
10  module.exports = function(packagedAppPath) {
11    const appArchivePath = path.join(CONFIG.buildOutputPath, getArchiveName());
12    compress(packagedAppPath, appArchivePath);
13  
14    if (process.platform === 'darwin') {
15      const symbolsArchivePath = path.join(
16        CONFIG.buildOutputPath,
17        'atom-mac-symbols.zip'
18      );
19      compress(CONFIG.symbolsPath, symbolsArchivePath);
20    }
21  };
22  
23  function getArchiveName() {
24    switch (process.platform) {
25      case 'darwin':
26        return 'atom-mac.zip';
27      case 'win32':
28        return `atom-${process.arch === 'x64' ? 'x64-' : ''}windows.zip`;
29      default:
30        return `atom-${getLinuxArchiveArch()}.tar.gz`;
31    }
32  }
33  
34  function getLinuxArchiveArch() {
35    switch (process.arch) {
36      case 'ia32':
37        return 'i386';
38      case 'x64':
39        return 'amd64';
40      default:
41        return process.arch;
42    }
43  }
44  
45  function compress(inputDirPath, outputArchivePath) {
46    if (fs.existsSync(outputArchivePath)) {
47      console.log(`Deleting "${outputArchivePath}"`);
48      fs.removeSync(outputArchivePath);
49    }
50  
51    console.log(`Compressing "${inputDirPath}" to "${outputArchivePath}"`);
52    let compressCommand, compressArguments;
53    if (process.platform === 'darwin') {
54      compressCommand = 'zip';
55      compressArguments = ['-r', '--symlinks'];
56    } else if (process.platform === 'win32') {
57      compressCommand = path7za;
58      compressArguments = ['a', '-r'];
59    } else {
60      compressCommand = 'tar';
61      compressArguments = ['caf'];
62    }
63    compressArguments.push(outputArchivePath, path.basename(inputDirPath));
64    spawnSync(compressCommand, compressArguments, {
65      cwd: path.dirname(inputDirPath)
66    });
67  }