Home

Awesome

npm-quick-run

Quickly run NPM script by prefix without typing the full name

NPM

ci status semantic-release manpm standard

Install

Install as a global tool npm install -g npm-quick-run. This creates two aliases nrun and nr

Use example

$ nr t      # runs script starting with "t"
$ nr m -w   # runs a script starting with "m", probably "npm run mocha -- -w"
$ nr -i     # runs npm-quick-run in interactive mode
$ nr c-r    # find script that has two+ words
            # first starts with "c", second with "r"
$ nr c-r.   # find script with exactly two words
            # first starts with "c", second with "r"

Demo

Watch the video NPM Quick Run

Watch this screencast to see npm-quick-run in action. I am using nr alias

demo

Interactive Mode

Demo: Interactive Mode

Details

Take a look at the scripts inside your package.json. You probably have something like this

"scripts": {
  "test": "...",
  "lint": "..."
}

You can quickly run tests using nr t and run the linter using nr l, assuming there are no other script names starting with t or l. If there are, just be more specific and provide more unique prefix.

Separate words

If your scripts have separate words, you can specify prefix for each one. For example, the package.json file below has 3 scripts

{
  "scripts": {
    "cypress:open": "cypress open",
    "cypress:run": "cypress run",
    "cypress:run:record": "cypress run --record"
  }
}

You can quickly open Cypress using

nr c:o
# same as
nr c-o
# same as
nr cy-open

Characters : and - are interchangeable and can be used in the prefix or in the script names.

In the above situation

nr c-r
# returns both "cypress:run" and "cypress:run:record"
nr c-r-r
# executes "cypress:run:record"

Separate words with count

Sometimes you want to match a script with one word, but there are multiple two and three word scripts matching the prefix.

{
  "scripts": {
    "cypress": "cypress -help",
    "cypress:open": "cypress open",
    "cypress:run": "cypress run",
    "cypress:run:record": "cypress run --record"
  }
}

In order to run "cypress" script use prefix with "." at the end:

# same as "npm run cypress"
$ nr c. # only finds single word starting with "c"

# same as "npm run cypress:open"
$ nr c-o.

# same as "npm run cypress:run"
$ nr c-r.

Extra arguments

You can pass extra arguments right after the prefix string

nr t --watch

would be the same as

npm run test -- --watch

which can run Mocha unit tests in the watching mode for example.

Error handling

If there are no scripts starting with the given prefix, an error message will be shown. If there are multiple scripts, they will be printed to the console and an error will be shown.

Similar projects

Benefits compared to similar projects

Debug

If something is not working as expected, you can see the verbose debug messages by running

DEBUG=quick nr ...

Small print

Author: Gleb Bahmutov © 2015

License: MIT - do anything with the code, but don't blame me if it does not work.

Spread the word: tweet, star on github, etc.

Support: if you find any problems with this module, email / tweet / open issue on Github

MIT License

Copyright (c) 2015 Gleb Bahmutov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.