UNPKG

10.5 kBMarkdownView Raw
1# Standard Version
2
3[![Join the chat at https://gitter.im/conventional-changelog/standard-version](https://badges.gitter.im/conventional-changelog/standard-version.svg)](https://gitter.im/conventional-changelog/standard-version?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
5[![Build Status](https://travis-ci.org/conventional-changelog/standard-version.svg?branch=master)](https://travis-ci.org/conventional-changelog/standard-version)
6[![NPM version](https://img.shields.io/npm/v/standard-version.svg)](https://www.npmjs.com/package/standard-version)
7[![Coverage Status](https://coveralls.io/repos/conventional-changelog/standard-version/badge.svg?branch=)](https://coveralls.io/r/conventional-changelog/standard-version?branch=master)
8[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
9
10> stop using `npm version`, use `standard-version` it rocks!
11
12Automatic versioning and CHANGELOG generation, using GitHub's squash button and
13[conventional commit messages](https://conventionalcommits.org).
14
15_how it works:_
16
171. when you land commits on your `master` branch, select the _Squash and Merge_ option.
182. add a title and body that follows the [Conventional Commits Specification](https://conventionalcommits.org).
193. when you're ready to release to npm:
20 1. `git checkout master; git pull origin master`
21 2. run `standard-version`
22 3. `git push --follow-tags origin master; npm publish`
23
24`standard-version` does the following:
25
261. bumps the version in _package.json/bower.json_ (based on your commit history)
272. uses [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) to update _CHANGELOG.md_
283. commits _package.json (et al.)_ and _CHANGELOG.md_
294. tags a new release
30
31## Installation
32
33### As `npm run` script
34
35Install and add to `devDependencies`:
36
37```
38npm i --save-dev standard-version
39```
40
41Add an [`npm run` script](https://docs.npmjs.com/cli/run-script) to your _package.json_:
42
43```json
44{
45 "scripts": {
46 "release": "standard-version"
47 }
48}
49```
50
51Now you can use `npm run release` in place of `npm version`.
52
53This has the benefit of making your repo/package more portable, so that other developers can cut releases without having to globally install `standard-version` on their machine.
54
55### As global bin
56
57Install globally (add to your `PATH`):
58
59```
60npm i -g standard-version
61```
62
63Now you can use `standard-version` in place of `npm version`.
64
65This has the benefit of allowing you to use `standard-version` on any repo/package without adding a dev dependency to each one.
66
67## CLI Usage
68
69### First Release
70
71To generate your changelog for your first release, simply do:
72
73```sh
74# npm run script
75npm run release -- --first-release
76# or global bin
77standard-version --first-release
78```
79
80This will tag a release **without bumping the version in package.json (_et al._)**.
81
82When ready, push the git tag and `npm publish` your first release. \o/
83
84### Cut a Release
85
86If you typically use `npm version` to cut a new release, do this instead:
87
88```sh
89# npm run script
90npm run release
91# or global bin
92standard-version
93```
94
95As long as your git commit messages are conventional and accurate, you no longer need to specify the semver type - and you get CHANGELOG generation for free! \o/
96
97After you cut a release, you can push the new git tag and `npm publish` (or `npm publish --tag next`) when you're ready.
98
99### Release as a pre-release
100
101Use the flag `--prerelease` to generate pre-releases:
102
103Suppose the last version of your code is `1.0.0`, and your code to be committed has patched changes. Run:
104
105```bash
106# npm run script
107npm run release -- --prerelease
108```
109you will get version `1.0.1-0`.
110
111If you want to name the pre-release, you specify the name via `--prerelease <name>`.
112
113For example, suppose your pre-release should contain the `alpha` prefix:
114
115```bash
116# npm run script
117npm run release -- --prerelease alpha
118```
119
120this will tag the version `1.0.1-alpha.0`
121
122### Release as a target type imperatively like `npm version`
123
124To forgo the automated version bump use `--release-as` with the argument `major`, `minor` or `patch`:
125
126Suppose the last version of your code is `1.0.0`, you've only landed `fix:` commits, but
127you would like your next release to be a `minor`. Simply do:
128
129```bash
130# npm run script
131npm run release -- --release-as minor
132# Or
133npm run release -- --release-as 1.1.0
134```
135
136you will get version `1.1.0` rather than the auto generated version `1.0.1`.
137
138> **NOTE:** you can combine `--release-as` and `--prerelease` to generate a release. This is useful when publishing experimental feature(s).
139
140### Prevent Git Hooks
141
142If you use git hooks, like pre-commit, to test your code before committing, you can prevent hooks from being verified during the commit step by passing the `--no-verify` option:
143
144```sh
145# npm run script
146npm run release -- --no-verify
147# or global bin
148standard-version --no-verify
149```
150
151### Signing commits and tags
152
153If you have your GPG key set up, add the `--sign` or `-s` flag to your `standard-version` command.
154
155### Lifecycle scripts
156
157`standard-version` supports lifecycle scripts. These allow you to execute your
158own supplementary commands during the release. The following
159hooks are available and execute in the order documented:
160
161* `prebump`/`postbump`: executed before and after the version is bumped. If the `prebump`
162 script returns a version #, it will be used rather than
163 the version calculated by `standard-version`.
164* `prechangelog`/`postchangelog`: executes before and after the CHANGELOG is generated.
165* `precommit`/`postcommit`: called before and after the commit step.
166* `pretag`/`posttag`: called before and after the tagging step.
167
168Simply add the following to your package.json to configure lifecycle scripts:
169
170```json
171{
172 "standard-version": {
173 "scripts": {
174 "prebump": "echo 9.9.9"
175 }
176 }
177}
178```
179
180### Skipping lifecycle steps
181
182You can skip any of the lifecycle steps (`bump`, `changelog`, `commit`, `tag`),
183by adding the following to your package.json:
184
185```json
186{
187 "standard-version": {
188 "skip": {
189 "changelog": true
190 }
191 }
192}
193```
194
195### Committing generated artifacts in the release commit
196
197If you want to commit generated artifacts in the release commit (e.g. [#96](https://github.com/conventional-changelog/standard-version/issues/96)), you can use the `--commit-all` or `-a` flag. You will need to stage the artifacts you want to commit, so your `release` command could look like this:
198
199```json
200"prerelease": "webpack -p --bail",
201"release": "git add <file(s) to commit> && standard-version -a"
202```
203
204### Dry run mode
205
206running `standard-version` with the flag `--dry-run` allows you to see what
207commands would be run, without committing to git or updating files.
208
209```sh
210# npm run script
211npm run release -- --dry-run
212# or global bin
213standard-version --dry-run
214```
215
216### CLI Help
217
218```sh
219# npm run script
220npm run release -- --help
221# or global bin
222standard-version --help
223```
224
225## Code usage
226
227Use the `silent` option to stop `standard-version` from printing anything
228to the console.
229
230```js
231var standardVersion = require('standard-version')
232
233// Options are the same as command line, except camelCase
234standardVersion({
235 noVerify: true,
236 infile: 'docs/CHANGELOG.md',
237 silent: true
238}, function (err) {
239 if (err) {
240 console.error(`standard-version failed with message: ${err.message}`)
241 }
242 // standard-version is done
243})
244```
245
246## Commit Message Convention, at a Glance
247
248_patches:_
249
250```sh
251git commit -a -m "fix(parsing): fixed a bug in our parser"
252```
253
254_features:_
255
256```sh
257git commit -a -m "feat(parser): we now have a parser \o/"
258```
259
260_breaking changes:_
261
262```sh
263git commit -a -m "feat(new-parser): introduces a new parsing library
264BREAKING CHANGE: new library does not support foo-construct"
265```
266
267_other changes:_
268
269You decide, e.g., docs, chore, etc.
270
271```sh
272git commit -a -m "docs: fixed up the docs a bit"
273```
274
275_but wait, there's more!_
276
277Github usernames (`@bcoe`) and issue references (#133) will be swapped out for the
278appropriate URLs in your CHANGELOG.
279
280## Badges!
281
282Tell your users that you adhere to the Conventional Commits specification:
283
284```markdown
285[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
286```
287
288## FAQ
289
290### How is `standard-version` different from `semantic-release`?
291
292[`semantic-release`](https://github.com/semantic-release/semantic-release) is a fully automated library/system for versioning, changelog generation, git tagging, and publishing to the npm registry.
293
294`standard-version` is different because it handles the versioning, changelog generation, and git tagging for you **without** automatic pushing (to GitHub) or publishing (to an npm registry). Use of `standard-version` only affects your local git repo - it doesn't affect remote resources at all. After you run `standard-version`, you still have to ability to review things and correct mistakes if you want to.
295
296They are both based on the same foundation of structured commit messages (using [Angular format](https://github.com/bcoe/conventional-changelog-standard/blob/master/convention.md)), but `standard-version` is a good choice for folks who are not yet comfortable letting publishes go out automatically. In this way, you can view `standard-version` as an incremental step to adopting `semantic-release`.
297
298We think they are both fantastic tools, and we encourage folks to use `semantic-release` instead of `standard-version` if it makes sense for them.
299
300### Should I always squash commits when merging PRs?
301
302The instructions to squash commits when merging pull requests assumes that **one PR equals, at most, one feature or fix**.
303
304If you have multiple features or fixes landing in a single PR and each commit uses a structured message, then you can do a standard merge when accepting the PR. This will preserve the commit history from your branch after the merge.
305
306Although this will allow each commit to be included as separate entries in your CHANGELOG, the entries will **not** be able to reference the PR that pulled the changes in because the preserved commit messages do not include the PR number.
307
308For this reason, we recommend keeping the scope of each PR to one general feature or fix. In practice, this allows you to use unstructured commit messages when committing each little change and then squash them into a single commit with a structured message (referencing the PR number) once they have been reviewed and accepted.
309
310## License
311
312ISC