Bump and Release
Bump and Release is a tiny command line helper to bump and release packages.
Installation
> cd your-project
> npm install --save-dev bump-and-release
Configuration
Update your package.json
file with the following scripts calls:
"scripts": {
"bump": "bump-and-release -t bump",
"release": "bump-and-release-t release"
}
If you are using a configuration file, you can pass it via the parameter -c
:
"scripts": {
"bump": "bump-and-release -t bump -c ./config/app-config.js",
"release": "bump-and-release-t release -c ./config/app-config.js"
}
Or if you name it .bump-and-release.config.js
and put it in the same location as your package.json
file, it will be taken into account automatically.
This:
"bump": "bump-and-release -t bump -c .bump-and-release.config.js"
is equivalent to:
"bump": "bump-and-release -t bump"
if the file .bump-and-release.config.js
can be found next to your package.json
.
Bump
By default, the "bump" command will:
- Run the following preflight validations
- check if the current branch name is
master
- check if the current branch has a tracking remote
- check if that remote is either
github/master
or origin/master
- check if your repo has uncommitted files
- Prompt the user to choose from a list of possible "new versions"
- Update your
package.json
file with the new version - Update your
package-lock.json
file with the new version - Stage and commit those files
- Push to the tracking remote
If any of those tasks fail, the process stops.
Bump example
Release
By default, the "release" command will:
- Run the following preflight validations
- check if the current branch name is
master
- check if the current branch has a tracking remote
- check if that remote is
github/master
or origin/master
- check if your repo has uncommitted files
- Stage and commit any modified files
- Tag the version with the following template:
vCurrentVersion
- Push code and tags to the tracking remote
If any of those tasks fail, the process stops.
Release example
Custom configuration
While the defaults are pretty straight forward, it is possible to override them with a configuration file.
Example
module.exports = {
disallowedBranches: [],
allowedBranches: ["master", "main"],
allowedRemotes: ["github/master", "upstream/main"],
bump: {
lerna: true,
local: true,
commitMessage: (version) =>
`chore: bumping version for next release: ${version}`,
nextPossible: [
{
pos: 0,
type: "prepatch",
identifier: "beta",
enabled: true,
default: true,
prompt: (type, version) =>
`[${type}] ... bump to next ${type} (${version})`,
},
{
type: "patch",
prompt: (type, version) =>
`[${type}] ... bump to next ${type} (${version})`,
},
{
type: "minor",
prompt: (type, version) =>
`[${type}] ... bump to next ${type} (${version})`,
},
{
type: "major",
prompt: (type, version) =>
`[${type}] ... bump to next ${type} (${version})`,
},
{
type: "separator",
},
{
type: "custom",
prompt: (type) => `[${type}] ... enter a custom version`,
},
],
prebump: [
{
name: "run tests",
command: "npm run test",
verbose: true,
},
{
name: "lint the files",
command: "npm run lint",
},
],
},
release: {
local: true,
commitMessage: (version) => `chore: tagging release ${version}`,
tag: {
enabled: true,
prefix: "v",
},
prerelease: [
{
name: "run tests",
command: "npm run test",
verbose: true,
},
{
name: "generate changelog",
command: "npm run changelog",
},
],
},
};
Next Available Versions
The possible "next" versions to be offered to the user at the prompt are the same that are accepted from method inc()
of the node-semver library.
Here are possible values, assuming the current version of a package is 1.0.0.
type | current version | new version |
---|
prepatch | 1.0.0 | 1.0.1-beta.0 |
patch | 1.0.0 | 1.0.1 |
preminor | 1.0.0 | 1.1.0-beta.0 |
minor | 1.0.0 | 1.1.0 |
premajor | 1.0.0 | 2.0.0-beta.0 |
major | 1.0.0 | 2.0.0 |
NOTE: the "beta" identifier can be customized by providing the key "identifier".
License
MIT © Arno Versini