user5049061
user5049061

Reputation:

Writing a script to automate npm command

I am working on an angular js project and I would like to automate The following two commands.

./node_modules/protractor/bin/webdriver-manager update
./node_modules/protractor/bin/webdriver-manager start

The issue is that I am working on a small angular project on github. I added all dependencies required to my package.json, However when my friend pulled it from git he was able to install protractor but he could not get webdriver to start unless he ran the above two commands. So i wanted to write some script to automate it and better yet even add protractor ./conf.js to it.

So I did research and I am aware that I can write a npm script but I was not able to find a proper document that showed where to write the script and how to execute it. I would appreciate all suggestions.

Upvotes: 2

Views: 683

Answers (2)

Josh
Josh

Reputation: 694

You can add a scripts property to your package.json with the command you wish you run.

"scripts": {
  "prostart": "./node_modules/protractor/bin/webdriver-manager start",
  "proupdate": "./node_modules/protractor/bin/webdriver-manager update"
}

you would then run these by typing npm run prostart or npm run proupdate which would look for those commands in your package.json.

Upvotes: 4

Joseph Furlott
Joseph Furlott

Reputation: 136

In addition to Josh's answer, the script start could be run as npm start as start is a special keyword, but update should be run as npm run update because npm update is another npm command entirely.

For any other command besides start and test (I think), you have to preface it with npm run ...

Upvotes: 1

Related Questions