Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using package.json script to run another package.json script

I have a package.json script for example npm run script1 and I have also private npm package which is added as a dependency in my project and this package has also scripts in package.json and this script name script2. I want that when I run npm run script1 then run automatically start script2. Is that possible?

Thank you.

like image 837
Onur Sabit Salman Avatar asked Jan 02 '23 09:01

Onur Sabit Salman


2 Answers

Package.json

"scripts": {
  "runbothscripts": "npm run script1 && npm run script2"
}

Should run both scripts for you if you execute it by doing npm run runbothscripts.

If script2 would be in a different folders package.json you also first navigate to that folder by doing cd ./otherfolder && npm run script2

like image 116
Jelle Avatar answered Jan 05 '23 15:01

Jelle


Use npm explore command. For example, to run a test script from lodash after running eslint, add this script in your package.json file:

"scripts": {
    "script1": "eslint . && npm explore lodash -- npm run test"
}

Then run it as:

npm run script1
like image 31
harsh989 Avatar answered Jan 05 '23 16:01

harsh989