From b4cb27b77d9bad701187e1d4f8e75dcf1234f5a0 Mon Sep 17 00:00:00 2001 From: Chris Brody Date: Wed, 1 Apr 2020 22:01:47 -0400 Subject: [PATCH] quick commander@5 update (#297) * quick commander@5 update * cleanup: rename internal action function & drop argument not needed --- lib/cli-command.js | 2 +- lib/cli-program.js | 4 ++-- package.json | 2 +- .../cli/help/__snapshots__/cli-help.test.js.snap | 2 +- .../cli/noargs/__snapshots__/cli-noargs.test.js.snap | 2 +- .../lib-cli-command-object-text.test.js.snap | 2 +- .../cli-command-with-bogus-platforms-name.test.js | 4 ++-- .../cli-command-with-empty-platforms-string.test.js | 4 ++-- .../cli-command-with-logging-with-error.test.js | 6 ++---- .../with-options/cli-command-func-with-options.test.js | 6 ++---- .../cli-program-with-defaults-for-android.test.js | 2 +- yarn.lock | 8 ++++---- 12 files changed, 20 insertions(+), 24 deletions(-) diff --git a/lib/cli-command.js b/lib/cli-command.js index b33ed0f9..5a831c23 100644 --- a/lib/cli-command.js +++ b/lib/cli-command.js @@ -40,7 +40,7 @@ module.exports = { name: 'create-library', description: 'creates a React Native library module for one or more platforms', usage: '[options] ', - func: (args, config, options) => { + action: (args, options) => { const name = args[0]; const beforeCreation = Date.now(); diff --git a/lib/cli-program.js b/lib/cli-program.js index 012e8511..dd4ea78d 100644 --- a/lib/cli-program.js +++ b/lib/cli-program.js @@ -13,8 +13,8 @@ program .version(pkg.version) .usage(command.usage) .description(command.description) - .action(function runAction () { - command.func(arguments, {}, this.opts()); + .action(function programAction (_, args) { + command.action(args, this.opts()); }); (command.options || []) diff --git a/package.json b/package.json index db2a7480..79644050 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ }, "homepage": "https://github.com/brodybits/create-react-native-module#readme", "dependencies": { - "commander": "^3.0.1", + "commander": "^5.0.0", "execa": "^3.3.0", "fs-extra": "^8.1.0", "jsonfile": "^6.0.0", diff --git a/tests/integration/cli/help/__snapshots__/cli-help.test.js.snap b/tests/integration/cli/help/__snapshots__/cli-help.test.js.snap index c0dd5052..c8164644 100644 --- a/tests/integration/cli/help/__snapshots__/cli-help.test.js.snap +++ b/tests/integration/cli/help/__snapshots__/cli-help.test.js.snap @@ -24,5 +24,5 @@ Options: --example-name [exampleName] Name for the example project (default: \\"example\\") --example-react-native-version [exampleReactNativeVersion] React Native version for the generated example project (default: \\"react-native@latest\\") --write-example-podfile [iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: write (or overwrite) example ios/Podfile - -h, --help output usage information" + -h, --help display help for command" `; diff --git a/tests/integration/cli/noargs/__snapshots__/cli-noargs.test.js.snap b/tests/integration/cli/noargs/__snapshots__/cli-noargs.test.js.snap index 0e45c018..618c4d4a 100644 --- a/tests/integration/cli/noargs/__snapshots__/cli-noargs.test.js.snap +++ b/tests/integration/cli/noargs/__snapshots__/cli-noargs.test.js.snap @@ -24,5 +24,5 @@ Options: --example-name [exampleName] Name for the example project (default: \\"example\\") --example-react-native-version [exampleReactNativeVersion] React Native version for the generated example project (default: \\"react-native@latest\\") --write-example-podfile [iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: write (or overwrite) example ios/Podfile - -h, --help output usage information" + -h, --help display help for command" `; diff --git a/tests/with-injection/cli/command/object/__snapshots__/lib-cli-command-object-text.test.js.snap b/tests/with-injection/cli/command/object/__snapshots__/lib-cli-command-object-text.test.js.snap index d5f7459f..e38a366d 100644 --- a/tests/with-injection/cli/command/object/__snapshots__/lib-cli-command-object-text.test.js.snap +++ b/tests/with-injection/cli/command/object/__snapshots__/lib-cli-command-object-text.test.js.snap @@ -2,8 +2,8 @@ exports[`cli-command object 1`] = ` Object { + "action": [Function], "description": "creates a React Native library module for one or more platforms", - "func": [Function], "name": "create-library", "options": Array [ Object { diff --git a/tests/with-mocks/cli/command/func/with-logging/with-bogus-platforms/bogus-name/cli-command-with-bogus-platforms-name.test.js b/tests/with-mocks/cli/command/func/with-logging/with-bogus-platforms/bogus-name/cli-command-with-bogus-platforms-name.test.js index ebd0631e..c701094c 100644 --- a/tests/with-mocks/cli/command/func/with-logging/with-bogus-platforms/bogus-name/cli-command-with-bogus-platforms-name.test.js +++ b/tests/with-mocks/cli/command/func/with-logging/with-bogus-platforms/bogus-name/cli-command-with-bogus-platforms-name.test.js @@ -1,4 +1,4 @@ -const func = require('../../../../../../../../lib/cli-command.js').func; +const action = require('../../../../../../../../lib/cli-command.js').action; // special compact mocks for this test: const mysnap = []; @@ -38,7 +38,7 @@ test(`create alice-bobbi module with logging, with platforms: 'bogus'`, async () const options = { platforms: 'bogus' }; - await func(args, null, options); + await action(args, options); expect(mysnap).toMatchSnapshot(); }); diff --git a/tests/with-mocks/cli/command/func/with-logging/with-bogus-platforms/empty-string/cli-command-with-empty-platforms-string.test.js b/tests/with-mocks/cli/command/func/with-logging/with-bogus-platforms/empty-string/cli-command-with-empty-platforms-string.test.js index 2089fe3a..06f49369 100644 --- a/tests/with-mocks/cli/command/func/with-logging/with-bogus-platforms/empty-string/cli-command-with-empty-platforms-string.test.js +++ b/tests/with-mocks/cli/command/func/with-logging/with-bogus-platforms/empty-string/cli-command-with-empty-platforms-string.test.js @@ -1,4 +1,4 @@ -const func = require('../../../../../../../../lib/cli-command.js').func; +const action = require('../../../../../../../../lib/cli-command.js').action; // special compact mocks for this test: const mysnap = []; @@ -38,7 +38,7 @@ test(`create alice-bobbi module with logging, with platforms: ''`, async () => { const options = { platforms: '' }; - await func(args, null, options); + await action(args, options); expect(mysnap).toMatchSnapshot(); }); diff --git a/tests/with-mocks/cli/command/func/with-logging/with-error/cli-command-with-logging-with-error.test.js b/tests/with-mocks/cli/command/func/with-logging/with-error/cli-command-with-logging-with-error.test.js index 955072ad..8f263ec1 100644 --- a/tests/with-mocks/cli/command/func/with-logging/with-error/cli-command-with-logging-with-error.test.js +++ b/tests/with-mocks/cli/command/func/with-logging/with-error/cli-command-with-logging-with-error.test.js @@ -1,4 +1,4 @@ -const func = require('../../../../../../../lib/cli-command.js').func; +const action = require('../../../../../../../lib/cli-command.js').action; // special compact mocks for this test: const mysnap = []; @@ -61,9 +61,7 @@ global.console = { test('create alice-bobbi module with logging, with fs error (with defaults for Android & iOS)', async () => { const args = ['alice-bobbi']; - const config = 'bogus'; - - await func(args, config, {}); + await action(args, {}); expect(mysnap).toMatchSnapshot(); }); diff --git a/tests/with-mocks/cli/command/func/with-options/cli-command-func-with-options.test.js b/tests/with-mocks/cli/command/func/with-options/cli-command-func-with-options.test.js index ea46564e..5e15eac9 100644 --- a/tests/with-mocks/cli/command/func/with-options/cli-command-func-with-options.test.js +++ b/tests/with-mocks/cli/command/func/with-options/cli-command-func-with-options.test.js @@ -1,4 +1,4 @@ -const func = require('../../../../../../lib/cli-command.js').func; +const action = require('../../../../../../lib/cli-command.js').action; // special compact mocks for this test: const mysnap = []; @@ -20,8 +20,6 @@ jest.mock('fs-extra', () => ({ test('create alice-bobbi module with explicit config options for Android & iOS', () => { const args = ['alice-bobbi']; - const config = 'bogus'; - const options = { platforms: 'android,ios', tvosEnabled: true, @@ -31,6 +29,6 @@ test('create alice-bobbi module with explicit config options for Android & iOS', license: 'ISC', }; - return func(args, config, options) + return action(args, options) .then(() => { expect(mysnap).toMatchSnapshot(); }); }); diff --git a/tests/with-mocks/cli/program/with-defaults/for-android/cli-program-with-defaults-for-android.test.js b/tests/with-mocks/cli/program/with-defaults/for-android/cli-program-with-defaults-for-android.test.js index 6bea9997..3850cf68 100644 --- a/tests/with-mocks/cli/program/with-defaults/for-android/cli-program-with-defaults-for-android.test.js +++ b/tests/with-mocks/cli/program/with-defaults/for-android/cli-program-with-defaults-for-android.test.js @@ -56,7 +56,7 @@ const mockCommander = { mockpushit({ parse: { argv } }); mockCommanderState.actionFunction.apply( { opts: () => ({ platforms: 'android' }) }, - ['test-package']); + [{ bogus: {} }, ['test-package']]); }, help: () => { throw new Error('help call not expected in this test'); diff --git a/yarn.lock b/yarn.lock index cdca1e42..076d252a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1073,10 +1073,10 @@ combined-stream@^1.0.6, combined-stream@~1.0.6: dependencies: delayed-stream "~1.0.0" -commander@^3.0.1: - version "3.0.2" - resolved "https://registry.yarnpkg.com/commander/-/commander-3.0.2.tgz#6837c3fb677ad9933d1cfba42dd14d5117d6b39e" - integrity sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow== +commander@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-5.0.0.tgz#dbf1909b49e5044f8fdaf0adc809f0c0722bdfd0" + integrity sha512-JrDGPAKjMGSP1G0DUoaceEJ3DZgAfr/q6X7FVk4+U5KxUSKviYGM2k6zWkfyyBHy5rAtzgYJFa1ro2O9PtoxwQ== commander@~4.1.0: version "4.1.1"