Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call one command from another in package.json?

Tags:

suppose if i have some script in package.json like this

 "scripts": {     "a1": "first command",     "a2": "second command",     "a3": "third command",          } 

and if i want to run script a1 and a2 in the script a3 how can i do this? can this be possible? I am using

node version : v6.9.4

npm version : 4.3.0

i want to achieve something like this

"scripts": {     "a1": "first command",     "a2": "second command",     "a3": "third command && a1 && a2",          } 
like image 723
Lijin Durairaj Avatar asked Mar 23 '17 14:03

Lijin Durairaj


People also ask

How do I run a command in a package json script?

json file: To execute your Script, use the 'npm run <NAME-OF-YOUR-SCRIPT>' command. Some predefined aliases convert to npm run, like npm test or npm start, you can use them interchangeably.

How do I run two commands in npm?

Approach 1(npm-run all package): We can use the” npm-run all” package to run different scripts at the same time. First, we have to install the package itself by using the command. After installation of the package we have to navigate to the package.

How can I run multiple npm scripts in parallel?

A quick way of doing it is npm run start-watch & npm run wp-server . This will run the first command as a background thread. This works really well when one of the commands is not long running and does not need to be manually exited later.


1 Answers

Use npm run inside the script. E.g.

"scripts": {   "a1": "first command",   "a2": "second command",   "a3": "third command && npm run a1 && npm run a2", } 

Running $ npm run a3 via the CLI will run the third command (whatever that is), followed by a1, then a2.

However, if running $npm run a3 via the CLI is to only run a1 followed by a2 then:

"scripts": {   "a1": "first command",   "a2": "second command",   "a3": "npm run a1 && npm run a2", } 
like image 153
RobC Avatar answered Oct 09 '22 08:10

RobC