From 2670cf2c0b4afe39ac4a7733c00cd3cb9429ccce Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Wed, 20 Apr 2016 08:34:44 -0700 Subject: [PATCH 1/2] Move CLI code to the common module This allows the CLI argument parsing code to be unit tested. Add unit tests for most of the argument corner cases. --- cli.js | 37 ++----------------------------------- common.js | 43 +++++++++++++++++++++++++++++++++++++++++++ test/basic.js | 24 ++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 35 deletions(-) diff --git a/cli.js b/cli.js index c6ba1e4c..aac84617 100755 --- a/cli.js +++ b/cli.js @@ -1,50 +1,17 @@ #!/usr/bin/env node +var common = require('./common') var fs = require('fs') -var args = require('minimist')(process.argv.slice(2), { - boolean: [ - 'prune', - 'asar', - 'all', - 'overwrite', - 'strict-ssl', - 'download.strictSSL' - ], - default: { - 'strict-ssl': true, - 'download.strictSSL': true - } -}) var packager = require('./') var path = require('path') var usage = fs.readFileSync(path.join(__dirname, 'usage.txt')).toString() -args.dir = args._[0] -args.name = args._[1] - -var protocolSchemes = [].concat(args.protocol || []) -var protocolNames = [].concat(args['protocol-name'] || []) - -if (protocolSchemes && protocolNames && protocolNames.length === protocolSchemes.length) { - args.protocols = protocolSchemes.map(function (scheme, i) { - return {schemes: [scheme], name: protocolNames[i]} - }) -} +var args = common.parseCLIArgs(process.argv.slice(2)) if (!args.dir || (!args.all && (!args.platform || !args.arch))) { console.error(usage) process.exit(1) } -// minimist doesn't support multiple types for a single argument (in this case, `String` or `false`) -if (args.tmpdir === 'false') { - args.tmpdir = false -} - -// (in this case, `Object` or `true`) -if (args['osx-sign'] === 'true') { - args['osx-sign'] = true -} - packager(args, function done (err, appPaths) { if (err) { if (err.message) console.error(err.message) diff --git a/common.js b/common.js index 92236748..5e740e91 100644 --- a/common.js +++ b/common.js @@ -1,6 +1,7 @@ var asar = require('asar') var child = require('child_process') var fs = require('fs-extra') +var minimist = require('minimist') var os = require('os') var path = require('path') var series = require('run-series') @@ -8,6 +9,46 @@ var series = require('run-series') var archs = ['ia32', 'x64'] var platforms = ['darwin', 'linux', 'mas', 'win32'] +function parseCLIArgs (argv) { + var args = minimist(argv, { + boolean: [ + 'prune', + 'asar', + 'all', + 'overwrite', + 'download.strictSSL' + ], + default: { + 'strict-ssl': true, + 'download.strictSSL': true + } + }) + + args.dir = args._[0] + args.name = args._[1] + + var protocolSchemes = [].concat(args.protocol || []) + var protocolNames = [].concat(args['protocol-name'] || []) + + if (protocolSchemes && protocolNames && protocolNames.length === protocolSchemes.length) { + args.protocols = protocolSchemes.map(function (scheme, i) { + return {schemes: [scheme], name: protocolNames[i]} + }) + } + + // minimist doesn't support multiple types for a single argument (in this case, `String` or `false`) + if (args.tmpdir === 'false') { + args.tmpdir = false + } + + // (in this case, `Object` or `true`) + if (args['osx-sign'] === 'true') { + args['osx-sign'] = true + } + + return args +} + function asarApp (appPath, asarOptions, cb) { var src = path.join(appPath) var dest = path.join(appPath, '..', 'app.asar') @@ -87,6 +128,8 @@ module.exports = { archs: archs, platforms: platforms, + parseCLIArgs: parseCLIArgs, + isPlatformMac: function isPlatformMac (platform) { return platform === 'darwin' || platform === 'mas' }, diff --git a/test/basic.js b/test/basic.js index 8002dd9e..a977d93a 100644 --- a/test/basic.js +++ b/test/basic.js @@ -515,6 +515,30 @@ test('download argument test: download.{arch,platform,version} does not overwrit t.end() }) +test('CLI argument test: --strict-ssl default', function (t) { + var args = common.parseCLIArgs([]) + t.true(args['strict-ssl'], 'default for --strict-ssl is true') + t.end() +}) + +test('CLI argument test: --download.strictSSL default', function (t) { + var args = common.parseCLIArgs([]) + t.true(args.download.strictSSL, 'default for --download.strictSSL is true') + t.end() +}) + +test('CLI argument test: --tmpdir=false', function (t) { + var args = common.parseCLIArgs(['--tmpdir=false']) + t.equal(args.tmpdir, false) + t.end() +}) + +test('CLI argument test: --osx-sign=true', function (t) { + var args = common.parseCLIArgs(['--osx-sign=true']) + t.equal(args['osx-sign'], true) + t.end() +}) + util.testSinglePlatform('infer test', createInferTest) util.testSinglePlatform('defaults test', createDefaultsTest) util.testSinglePlatform('default_app.asar removal test', createDefaultAppAsarTest) From 52294127eb22f0d42075680ba225a05e0cd38207 Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Wed, 20 Apr 2016 08:35:26 -0700 Subject: [PATCH 2/2] Use an alias for the deprecated --strict-ssl flag This should remove the consistent deprecation message. --- NEWS.md | 8 ++++++++ common.js | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index ffadbac2..c6854397 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,13 @@ ## Unreleased + +## [7.0.1] - 2016-04-20 + +### Fixed + +* Not specifying `strict-ssl` CLI parameter no longer triggers a deprecation warning (#335) + ## [7.0.0] - 2016-04-17 ### Added @@ -121,6 +128,7 @@ For versions prior to 5.2.0, please see `git log`. +[7.0.1]: https://github.com/electron-userland/electron-packager/compare/v7.0.0...v7.0.1 [7.0.0]: https://github.com/electron-userland/electron-packager/compare/v6.0.2...v7.0.0 [6.0.2]: https://github.com/electron-userland/electron-packager/compare/v6.0.1...v6.0.2 [6.0.1]: https://github.com/electron-userland/electron-packager/compare/v6.0.0...v6.0.1 diff --git a/common.js b/common.js index 5e740e91..e1df292f 100644 --- a/common.js +++ b/common.js @@ -18,8 +18,10 @@ function parseCLIArgs (argv) { 'overwrite', 'download.strictSSL' ], + alias: { + 'download.strictSSL': 'strict-ssl' + }, default: { - 'strict-ssl': true, 'download.strictSSL': true } })