diff --git a/common.js b/common.js index e5ea6a96..fc593f98 100644 --- a/common.js +++ b/common.js @@ -3,6 +3,7 @@ const asar = require('asar') const child = require('child_process') const debug = require('debug')('electron-packager') +const download = require('electron-download') const fs = require('fs-extra') const ignore = require('./ignore') const minimist = require('minimist') @@ -81,6 +82,10 @@ function asarApp (appPath, asarOptions, cb) { }) } +function isPlatformMac (platform) { + return platform === 'darwin' || platform === 'mas' +} + function sanitizeAppName (name) { return sanitize(name, {replacement: '-'}) } @@ -116,28 +121,45 @@ function createAsarOpts (opts) { return asarOptions } +function createDownloadOpts (opts, platform, arch) { + let downloadOpts = opts.download || {} + + subOptionWarning(downloadOpts, 'download', 'platform', platform) + subOptionWarning(downloadOpts, 'download', 'arch', arch) + subOptionWarning(downloadOpts, 'download', 'version', opts.version) + + return downloadOpts +} + module.exports = { archs: archs, platforms: platforms, parseCLIArgs: parseCLIArgs, - isPlatformMac: function isPlatformMac (platform) { - return platform === 'darwin' || platform === 'mas' - }, + isPlatformMac: isPlatformMac, subOptionWarning: subOptionWarning, createAsarOpts: createAsarOpts, + createDownloadOpts: createDownloadOpts, + createDownloadCombos: function createDownloadCombos (opts, selectedPlatforms, selectedArchs, ignoreFunc) { + let combinations = [] + for (let arch of selectedArchs) { + for (let platform of selectedPlatforms) { + // Electron does not have 32-bit releases for Mac OS X, so skip that combination + if (isPlatformMac(platform) && arch === 'ia32') continue + if (typeof ignoreFunc === 'function' && ignoreFunc(platform, arch)) continue + combinations.push(createDownloadOpts(opts, platform, arch)) + } + } - createDownloadOpts: function createDownloadOpts (opts, platform, arch) { - let downloadOpts = opts.download || {} - - subOptionWarning(downloadOpts, 'download', 'platform', platform) - subOptionWarning(downloadOpts, 'download', 'arch', arch) - subOptionWarning(downloadOpts, 'download', 'version', opts.version) + return combinations + }, - return downloadOpts + downloadElectronZip: function downloadElectronZip (downloadOpts, cb) { + debug(`Downloading Electron with options ${JSON.stringify(downloadOpts)}`) + download(downloadOpts, cb) }, generateFinalBasename: generateFinalBasename, diff --git a/index.js b/index.js index c91f3bea..25d9c82c 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,6 @@ const common = require('./common') const debug = require('debug')('electron-packager') -const download = require('electron-download') const extract = require('extract-zip') const fs = require('fs-extra') const getPackageInfo = require('get-package-info') @@ -92,15 +91,6 @@ function createSeries (opts, archs, platforms) { }) } - var combinations = [] - archs.forEach(function (arch) { - platforms.forEach(function (platform) { - // Electron does not have 32-bit releases for Mac OS X, so skip that combination - if (common.isPlatformMac(platform) && arch === 'ia32') return - combinations.push(common.createDownloadOpts(opts, platform, arch)) - }) - }) - var tasks = [] var useTempDir = opts.tmpdir !== false if (useTempDir) { @@ -108,14 +98,13 @@ function createSeries (opts, archs, platforms) { fs.remove(tempBase, cb) }) } - return tasks.concat(combinations.map(function (combination) { + return tasks.concat(common.createDownloadCombos(opts, platforms, archs).map(combination => { var arch = combination.arch var platform = combination.platform var version = combination.version - return function (callback) { - debug(`Downloading Electron with options ${JSON.stringify(combination)}`) - download(combination, function (err, zipPath) { + return (callback) => { + common.downloadElectronZip(combination, (err, zipPath) => { if (err) return callback(err) function createApp (comboOpts) { diff --git a/test/util.js b/test/util.js index a63dfff5..14c0a40d 100644 --- a/test/util.js +++ b/test/util.js @@ -3,7 +3,6 @@ const bufferEqual = require('buffer-equal') const common = require('../common') const config = require('./config.json') -const download = require('electron-download') const fs = require('fs-extra') const path = require('path') const series = require('run-series') @@ -13,22 +12,6 @@ const test = require('tape') const ORIGINAL_CWD = process.cwd() const WORK_CWD = path.join(__dirname, 'work') -var combinations = [] -common.archs.forEach(function (arch) { - common.platforms.forEach(function (platform) { - // Electron does not have 32-bit releases for Mac OS X, so skip that combination - // Also skip testing darwin/mas target on Windows since electron-packager itself skips it - // (see https://github.com/electron-userland/electron-packager/issues/71) - if (common.isPlatformMac(platform) && (arch === 'ia32' || require('os').platform() === 'win32')) return - - combinations.push({ - arch: arch, - platform: platform, - version: config.version - }) - }) -}) - exports.areFilesEqual = function areFilesEqual (file1, file2, callback) { series([ function (cb) { @@ -43,11 +26,17 @@ exports.areFilesEqual = function areFilesEqual (file1, file2, callback) { } exports.downloadAll = function downloadAll (version, callback) { - series(combinations.map(function (combination) { - return function (cb) { + let combinations = common.createDownloadCombos({version: config.version}, common.platforms, common.archs, (platform, arch) => { + // Skip testing darwin/mas target on Windows since electron-packager itself skips it + // (see https://github.com/electron-userland/electron-packager/issues/71) + return common.isPlatformMac(platform) && process.platform === 'win32' + }) + + series(combinations.map(combination => { + return (cb) => { var downloadOpts = Object.assign({}, combination) downloadOpts.version = version - download(downloadOpts, cb) + common.downloadElectronZip(downloadOpts, cb) } }), callback) }