Option 3: NPM-Run-All Moving on, this package is another popular option from NPM, called NPM-Run-All. The NPM page proclaims npm-run-all “A CLI tool to run multiple npm-scripts in parallel or sequential.”
Concurrently is an npm package that allows you to run multiple commands concurrently.
Invoke these scripts via npm run and chain them with double ampersand &&:
npm run pre-build && npm run build_logic && npm run post_build && npm run exit
Explanation:
&& (double ampersand) for sequential execution.& (single ampersand) for parallel execution.Following @Mobiletainment's great answer, you can also use npm-run-all to make the command much shorter and much more readable. In your case:
"scripts": {
    ...
    "build": "run-s pre-build build_logic post_build exit"
}
run-s is a shortcut npm-run-all provides, that runs all the given npm-scripts sequentially, hence the -s (run-s is a shorter version of npm-run-all -s).
You can prefix your scripts pre and post so they will execute automatically:
"scripts": {
  "prebuild": "echo \"Welcome\" && exit 1",
  "build": "start cmd.exe @cmd /k \"yo esri-appbuilder-js:widget && exit 1\"",
  "postbuild":  "start C:\\WebAppBuilderForArcGIS\\startupShortcut",
  "exit" : "start cmd.exe @cmd /k \"echo \"goodbye\" && exit 1\""
}
then run npm run build
You could just string them into another script. "start": "pre-build && build_logic && post_build && exit"
You can use npm-run-all to combine multiple commands in a lot of different ways
For example, if you had the following scripts in your package.json:
"scripts": {
    "clean": "rimraf dist",
    "lint":  "eslint src",
    "build": "babel src -o lib"
}
You could run them all sequentially like this:
$ npm-run-all clean lint build
See this question for how to run multiple npm commands in parallel
you can try:
"scripts": {
  "clean-dist": "rm -f ./dist/*.js && rm -f ./dist/*.map",
  "build": "npm run clean-dist && parcel build ./packages/index.html"
},
    
                If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With