From 67dbed7e72a152122c45663b69231e78b32490e8 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Thu, 9 Feb 2017 14:30:44 -0700 Subject: [PATCH] fix(cli): improve handling of forwarding args/flags **What**: This migrates us from `commander` and `omelette` to `yargs` and in the process changes how we handle forwarding of arguments and flags. We no longer just arbitrarily forward arguments to every script. Also instead of comma separated scripts, they're simply separated by a space. If you want to pass args/flags to a script, then you put it in quotes. **Why**: Makes this more predicatble. Also `yargs` is more powerful in general anyway. **How**: Magic... Will comment inline... --- .all-contributorsrc | 9 + README.md | 79 +++---- cli-test/__snapshots__/cli.test.js.snap | 41 ++-- cli-test/cli.test.js | 10 +- cli-test/fixtures/package-scripts.js | 2 + cli-test/run-nps.js | 4 +- other/ERRORS_AND_WARNINGS.md | 10 +- other/EXAMPLES.md | 1 - package-scripts.js | 21 +- package.json | 8 +- src/__mocks__/console.js | 7 + src/__mocks__/find-up.js | 8 + src/__mocks__/get-logger.js | 16 ++ src/__mocks__/readline-sync.js | 8 + src/bin-utils/autocomplete-get-scripts.js | 42 ++++ .../autocomplete-get-scripts.test.js | 77 +++++++ src/bin-utils/autocomplete/index.js | 37 ---- src/bin-utils/autocomplete/index.test.js | 67 ------ src/bin-utils/index.js | 33 +-- src/bin-utils/index.test.js | 37 +--- src/bin-utils/parser.js | 197 ++++++++++++++++++ src/bin-utils/parser.test.js | 186 +++++++++++++++++ src/bin/nps.js | 135 ++---------- src/get-logger.js | 18 +- src/get-logger.test.js | 71 ++++--- src/index.js | 37 ++-- src/index.test.js | 22 +- test/jest.src.config.json | 1 + yarn.lock | 44 ++-- 29 files changed, 752 insertions(+), 476 deletions(-) create mode 100644 src/__mocks__/console.js create mode 100644 src/__mocks__/find-up.js create mode 100644 src/__mocks__/get-logger.js create mode 100644 src/__mocks__/readline-sync.js create mode 100644 src/bin-utils/autocomplete-get-scripts.js create mode 100644 src/bin-utils/autocomplete-get-scripts.test.js delete mode 100644 src/bin-utils/autocomplete/index.js delete mode 100644 src/bin-utils/autocomplete/index.test.js create mode 100644 src/bin-utils/parser.js create mode 100644 src/bin-utils/parser.test.js mode change 100644 => 100755 src/bin/nps.js diff --git a/.all-contributorsrc b/.all-contributorsrc index 65d0870..470df5b 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -228,6 +228,15 @@ "contributions": [ "bug" ] + }, + { + "login": "addityasingh", + "name": "Aditya Pratap Singh", + "avatar_url": "https://avatars.githubusercontent.com/u/5351262?v=3", + "profile": "http://blog.adityapsingh.com", + "contributions": [ + "review" + ] } ] } diff --git a/README.md b/README.md index 489d3db..1b46890 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ All the benefits of npm scripts without the cost of a bloated package.json and l [![downloads][downloads-badge]][npm-stat] [![MIT License][license-badge]][LICENSE] -[![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-23-orange.svg?style=flat-square)](#contributors) [![PRs Welcome][prs-badge]][prs] [![Donate][donate-badge]][donate] [![Code of Conduct][coc-badge]][coc] @@ -58,6 +58,7 @@ module.exports = { }, // learn more about concurrently here: https://npm.im/concurrently validate: 'concurrently "nps lint" "nps test" "nps build"', + // concurrently script too verbose for your liking? Check out other/EXAMPLES.md! }, } ``` @@ -81,27 +82,41 @@ scripts: ``` To use `p-s`, it's recommended that you either install it globally (`npm i -g p-s`) or add `./node_modules/bin` to your -`$PATH` (be careful that you know what you're doing when doing this). +`$PATH` (be careful that you know what you're doing when doing this, find out how [here](https://youtu.be/2WZ5iS_3Jgs)). Then you can run: ```console -nps --help +nps help ``` Which will output: ```console - Usage: nps [options] - - Options: - - -h, --help output usage information - -V, --version output the version number - -s, --silent Silent nps output - -c, --config Config file to use (defaults to nearest package-scripts.yml or package-scripts.js) - -l, --log-level The log level to use (error, warn, info [default]) - -r, --require Module to preload +Usage: nps [options]