├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .npmrc ├── README.md ├── __snapshots__ └── bin-spec.js ├── bin └── npm-quick-run.js ├── package-lock.json ├── package.json └── src ├── bin-spec.js ├── quick-run-spec.js ├── quick-run.js └── run.js /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | on: push 3 | jobs: 4 | test: 5 | runs-on: ubuntu-20.04 6 | steps: 7 | - name: Checkout 🛎 8 | uses: actions/checkout@v2 9 | 10 | - name: Install NPM dependencies 📦 11 | uses: bahmutov/npm-install@v1 12 | 13 | - name: Run tests 🧪 14 | run: npm test 15 | 16 | - name: Run examples 📊 17 | env: 18 | DEBUG: quick 19 | run: | 20 | npm run example 21 | node bin/npm-quick-run.js test-foo 'foo bar' 22 | node bin/npm-quick-run.js echo 23 | # use prefix search by word 24 | node bin/npm-quick-run.js t-f 'foo bar' 25 | node bin/npm-quick-run.js t:f 'foo bar' 26 | # with stopper . at the end 27 | # https://github.com/bahmutov/npm-quick-run/issues/35 28 | node bin/npm-quick-run.js t-f. 'foo bar' 29 | # should find single "size" script 30 | node bin/npm-quick-run.js s. 31 | 32 | - name: Semantic Release 🚀 33 | uses: cycjimmy/semantic-release-action@v2 34 | env: 35 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 36 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .DS_Store 3 | npm-debug.log 4 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | registry=http://registry.npmjs.org/ 2 | save-exact=true 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # npm-quick-run 2 | 3 | > Quickly run NPM script by prefix without typing the full name 4 | 5 | [![NPM][npm-quick-run-icon] ][npm-quick-run-url] 6 | 7 | [![ci status][ci image]][ci url] 8 | [![semantic-release][semantic-image] ][semantic-url] 9 | [![manpm](https://img.shields.io/badge/manpm-%E2%9C%93-3399ff.svg)](https://github.com/bahmutov/manpm) 10 | [![standard](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) 11 | 12 | ## Install 13 | 14 | Install as a global tool `npm install -g npm-quick-run`. This creates two aliases `nrun` and `nr` 15 | 16 | ## Use example 17 | 18 | $ nr t # runs script starting with "t" 19 | $ nr m -w # runs a script starting with "m", probably "npm run mocha -- -w" 20 | $ nr -i # runs npm-quick-run in interactive mode 21 | $ nr c-r # find script that has two+ words 22 | # first starts with "c", second with "r" 23 | $ nr c-r. # find script with exactly two words 24 | # first starts with "c", second with "r" 25 | 26 | ## Demo 27 | 28 | Watch the video [NPM Quick Run](https://youtu.be/f2uXdCOkJb0) 29 | 30 | Watch this screencast to see `npm-quick-run` in action. I am using `nr` alias 31 | 32 | [![demo](https://asciinema.org/a/31015.png)](https://asciinema.org/a/31015) 33 | 34 | ### Interactive Mode 35 | 36 | ![Demo: Interactive Mode](https://cloud.githubusercontent.com/assets/87983/24231500/f791fb04-0fbf-11e7-9fa0-1d0f48efd72f.gif) 37 | 38 | ## Details 39 | 40 | Take a look at the scripts inside your `package.json`. You probably have something like 41 | this 42 | 43 | ```json 44 | "scripts": { 45 | "test": "...", 46 | "lint": "..." 47 | } 48 | ``` 49 | 50 | You can quickly run tests using `nr t` and run the linter using `nr l`, assuming there are 51 | no other script names starting with `t` or `l`. If there are, just be more specific and provide 52 | more unique prefix. 53 | 54 | ## Separate words 55 | 56 | If your scripts have separate words, you can specify prefix for each one. For example, the `package.json` file below has 3 scripts 57 | 58 | ```json 59 | { 60 | "scripts": { 61 | "cypress:open": "cypress open", 62 | "cypress:run": "cypress run", 63 | "cypress:run:record": "cypress run --record" 64 | } 65 | } 66 | ``` 67 | 68 | You can quickly open Cypress using 69 | 70 | ``` 71 | nr c:o 72 | # same as 73 | nr c-o 74 | # same as 75 | nr cy-open 76 | ``` 77 | 78 | Characters `:` and `-` are interchangeable and can be used in the prefix or in the script names. 79 | 80 | In the above situation 81 | 82 | ``` 83 | nr c-r 84 | # returns both "cypress:run" and "cypress:run:record" 85 | nr c-r-r 86 | # executes "cypress:run:record" 87 | ``` 88 | 89 | ### Separate words with count 90 | 91 | Sometimes you want to match a script with one word, but there are multiple two and three word scripts matching the prefix. 92 | 93 | ```json 94 | { 95 | "scripts": { 96 | "cypress": "cypress -help", 97 | "cypress:open": "cypress open", 98 | "cypress:run": "cypress run", 99 | "cypress:run:record": "cypress run --record" 100 | } 101 | } 102 | ``` 103 | 104 | In order to run "cypress" script use prefix with "." at the end: 105 | 106 | ``` 107 | # same as "npm run cypress" 108 | $ nr c. # only finds single word starting with "c" 109 | 110 | # same as "npm run cypress:open" 111 | $ nr c-o. 112 | 113 | # same as "npm run cypress:run" 114 | $ nr c-r. 115 | ``` 116 | 117 | ## Extra arguments 118 | 119 | You can pass extra arguments right after the prefix string 120 | 121 | nr t --watch 122 | 123 | would be the same as 124 | 125 | npm run test -- --watch 126 | 127 | which can run Mocha unit tests in the watching mode for example. 128 | 129 | ## Error handling 130 | 131 | If there are no scripts starting with the given prefix, an error message will be shown. 132 | If there are multiple scripts, they will be printed to the console and an error will be shown. 133 | 134 | ## Similar projects 135 | 136 | * [as-a](https://github.com/bahmutov/as-a) adds env variables before running a command 137 | * [json-package](https://github.com/bahmutov/json-package) quickly shows value from `package.json` 138 | by property name prefix 139 | * [npm-run](https://www.npmjs.com/package/npm-run) run locally-installed executables to avoid 140 | using long string `node node_modules/.bin/some-alias ...` 141 | * [nrun](https://github.com/2do2go/nrun) is very similar to this project, but the script name 142 | completion is done via shell script, see [the relevant issue](https://github.com/2do2go/nrun/issues/3) 143 | 144 | ### Benefits compared to similar projects 145 | 146 | * `npm-quick-run` is cross platform - the command completion is done in JS 147 | * Boilerplate NPM error output is filtered out automatically 148 | * Most commands require typing only 3 characters - 2 for the tool itself "nr" and 1 character for the 149 | the script label 150 | 151 | ## Debug 152 | 153 | If something is not working as expected, you can see the verbose debug messages 154 | by running 155 | 156 | DEBUG=quick nr ... 157 | 158 | ### Small print 159 | 160 | Author: Gleb Bahmutov © 2015 161 | 162 | * [@bahmutov](https://twitter.com/bahmutov) 163 | * [glebbahmutov.com](https://glebbahmutov.com) 164 | * [blog](https://glebbahmutov.com/blog/) 165 | 166 | License: MIT - do anything with the code, but don't blame me if it does not work. 167 | 168 | Spread the word: tweet, star on github, etc. 169 | 170 | Support: if you find any problems with this module, email / tweet / 171 | [open issue](https://github.com/bahmutov/npm-quick-run/issues) on Github 172 | 173 | ## MIT License 174 | 175 | Copyright (c) 2015 Gleb Bahmutov 176 | 177 | Permission is hereby granted, free of charge, to any person 178 | obtaining a copy of this software and associated documentation 179 | files (the "Software"), to deal in the Software without 180 | restriction, including without limitation the rights to use, 181 | copy, modify, merge, publish, distribute, sublicense, and/or sell 182 | copies of the Software, and to permit persons to whom the 183 | Software is furnished to do so, subject to the following 184 | conditions: 185 | 186 | The above copyright notice and this permission notice shall be 187 | included in all copies or substantial portions of the Software. 188 | 189 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 190 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 191 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 192 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 193 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 194 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 195 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 196 | OTHER DEALINGS IN THE SOFTWARE. 197 | 198 | [npm-quick-run-icon]: https://nodei.co/npm/npm-quick-run.svg?downloads=true 199 | [npm-quick-run-url]: https://npmjs.org/package/npm-quick-run 200 | [ci image]: https://github.com/bahmutov/npm-quick-run/workflows/ci/badge.svg?branch=master 201 | [ci url]: https://github.com/bahmutov/npm-quick-run/actions 202 | [semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg 203 | [semantic-url]: https://github.com/semantic-release/semantic-release 204 | -------------------------------------------------------------------------------- /__snapshots__/bin-spec.js: -------------------------------------------------------------------------------- 1 | exports['quick run bin shows available scripts with prefix 1'] = ` 2 | stdout: 3 | ------- 4 | running command with prefix "t" 5 | ------- 6 | stderr: 7 | ------- 8 | Several scripts start with "t" test, test-foo 9 | ------- 10 | 11 | ` 12 | 13 | exports['quick run bin runs by prefix 1'] = ` 14 | stdout: 15 | ------- 16 | running command with prefix "ech" 17 | 18 | > echo hello 19 | 20 | hello 21 | ------- 22 | 23 | ` 24 | -------------------------------------------------------------------------------- /bin/npm-quick-run.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict' 4 | 5 | const debug = require('debug')('quick') 6 | const quickRun = require('..') 7 | const join = require('path').join 8 | 9 | const help = [ 10 | 'USE: nrun [arguments]