Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is colon : in npm script names?

Trying to figure out what putting : in an npm script name does. For example:

package.json

"test:ci": "rest of script" 

what would :ci do? running npm run test:ci fails

I can't find anything bash syntax really.

like image 357
PositiveGuy Avatar asked Dec 02 '17 08:12

PositiveGuy


People also ask

What are scripts in npm?

An npm script is a convenient way to bundle common shell commands for your project. They are typically commands, or a string of commands, which would normally be entered at the command line in order to do something with your application. Scripts are stored in a project's package.

How do I list npm scripts?

Listing the scripts available in a package. json file is easy: just go to the root directory of your project and type npm run in the terminal. Then run the ntl command in the project folder. You'll get a list of available scripts, with the option of selecting one of them to run.


2 Answers

I believe it's just a naming convention to group a set of related tasks. For example you might have

"test:ci": ... "test:units": .... "test:integration"... 

In this case it is grouping a related set of test tasks.

It would be down to the package author to specify. You can split tasks out like described in the answer above and then have a 'global' test command which combines each of them e.g. test:ci && test:unit && test:integration enabling you to run them all at once or when individually when needed.

You can use npm-run-all (link) and use the command npm-run-all test:*, which would then find all scripts starting with the test: group.

like image 59
brrwdl Avatar answered Sep 27 '22 23:09

brrwdl


I solved this by running - "npm run <scriptName>"

Within my package.json file, I had two "start scripts"

start: nodemon server.js

start:elasticsearch: docker run elasticsearch..

Solved with npm run start:elasticsearch

like image 33
Guy Rawsthorn Avatar answered Sep 28 '22 01:09

Guy Rawsthorn