npm scripts

Decision

We write scripts into the scripts section of package.json files and add custom TypeScript scripts to a scripts folder that we directly call from the scripts block of package.json where necessary.

Problems

The packages and applications we write need scripts to be tested, built, deployed, and for other tasks that might need to be run from time to time.

Scripts need to integrate with external tools that provide shell-scripts.

Context

At the moment, we use a combination of bash scripts, Rush, npm scripts, gulp, grunt, and JavaScript to run scripts. Understanding a single deployment script might take you through 11 different files ind 4 different formats.

Options

  • Bash scripts
  • JavaScript script files
  • TypeScript script files
  • npm scripts
  • Gulp
  • Grunt

Reasoning

Most scripts we have can be simplified to one line of npm script. The tooling we use is advanced enough so no major coordination via gulp or grunt is needed. Using TypeScript script files instead of bash scripts or JavaScript files allows to more easily use code from the actual package or application in scripts.

Consequences

For packages and applications with many or complicated scripts, the package.json might get complicated. Additional work might be needed to extract scripts into TypeScript files.