Add preversion, version, and postversion scripts
Closed this issue · 1 comments
dan-f commented
npm has some nifty script hooks for automating our versioning flow. See the documentation from npm help version
:
If preversion, version, or postversion are in the scripts property of the package.json,
they will be executed as part of running npm version.
The exact order of execution is as follows:
1. Check to make sure the git working directory is clean before we get started. Your
scripts may add files to the commit in future steps. This step is skipped if the
--force flag is set.
2. Run the preversion script. These scripts have access to the old version in package.json.
A typical use would be running your full test suite before deploying. Any files you
want added to the commit should be explicitly added using git add.
3. Bump version in package.json as requested (patch, minor, major, etc).
4. Run the version script. These scripts have access to the new version in package.json (so
they can incorporate it into file headers in generated files for example). Again,
scripts should explicitly add generated files to the commit using git add.
5. Commit and tag.
6. Run the postversion script. Use it to clean up the file system or automatically push the
commit and/or tag.
Take the following example:
"scripts": {
"preversion": "npm test",
"version": "npm run build && git add -A dist",
"postversion": "git push && git push --tags && rm -rf build/temp"
}
This runs all your tests, and proceeds only if they pass. Then runs your build script, and
adds everything in the dist directory to the commit. After the commit, it pushes the new
commit and tag up to the server, and deletes the build/temp directory.
Since we're already handling building during publish, I think we should add something like assuming we want to publish every time we bump the version (maybe we don't?):
"preversion": "npm test",
"postversion": "git push --follow-tags && npm publish"
We can also automate releasing to GH Pages as part of this.
dmitrizagidulin commented
Implemented, closing.