-
Copy the aliases to
.profile/.bashrc/ wherever you like -
Use
npmruninstead ofnpm run, enjoy
$ npmrun[TAB]
run-debug run-prod tdd test-bar test-foo
$ npmrun te[TAB]
test-bar test-foo
$ npmrun test-bar
On big projects, there are usually many technologies and tools used - for running builds, partial builds, tests, partial tests, etc. Often you have helper scripts to run those tools.
The common problems of all those little tools are the following:
- they might be spread over the repo in the subfolders (to not pollute the root folder with lots of random scripts)
- they might be run in a different way (sometimes as a shell scripts written in bash / nodejs / python etc., sometimes through third party runner like
grunt/gulp) - your
Gruntfilemight have many subtasks embedded, you commonly use many of them, not only the default one - in each of your repos, those helper scripts / grunt task are named differently, located in different place etc.
- you don't get autocompletion in console for grunt tasks names, parameter names etc.
Hence, it's helpful to list all your scripts in one place. A good place for this is package.json:
{
"name": "foo",
"scripts": {
"run-debug": "bash scripts/run-debug.sh",
"run-prod": "bash scripts/run-prod.sh",
"test-foo": "grunt test:foo",
"test-bar": "grunt test:bar",
"tdd": "grunt tdd"
}
}
and now you can npm run [scriptname] (npm run is a shortcut for npm run-script).
But the problem of autocompletion is still unsolved.
There comes npmrun which is just an alias to npm run, but we additionally establish bash autocompletion for it by reading package.json contents and running bash machinery (complete bash builtin) that will enable the completion.
yo!
File
https://gist.githubusercontent.com/jakub-g/d350f1153ab01b0cd370/raw/f589567993a9027bbfb21ad2b94882c5de0bc774/%2520npmrun
has a %20 at the beginning of the file