Tuesday 6 June 2017

NPM run script using cocurrently but conditioned by succesfull build

prestart Scenario.

Node.js application
This is the "scripts" section in package.json:

  "scripts": {    
    "build": "tsc -p app/",
    "build:watch": "tsc -p app/ --watch",
    "start_server": "lite-server -c=bs-config.json",
    "prestart": "npm run build",
    "start_dev": "concurrently \"npm run build:watch\" \"npm run start_server\""
  }

To start the development server I run: npm run start_dev.

Thew problem is the fact that in this way if the build fails (= tsc -p app/ return some error) I can't see it because the server is started anyway and the "watch" fill the console with continuous output.

I found many errors when I deployed the code in production and the "buil" script failed returning me the errors predsent in the code.

I want something like:

"start_dev": "\"npm run prestart\" THEN concurrently \"npm run build:watch\" \"npm run start_server\""

so the npm run start_server is called only if the build command exit with "0" (no error).

Suggestion to achieve this result? How can I run the "start_dev" "conditionally" to the "prestart" script?

Thanks,

Alex



via Alex 75

No comments:

Post a Comment