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 |
|
12 | Automatic versioning and CHANGELOG generation, using GitHub's squash button and
|
13 | [conventional commit messages](https://conventionalcommits.org).
|
14 |
|
15 | _how it works:_
|
16 |
|
17 | 1. when you land commits on your `master` branch, select the _Squash and Merge_ option.
|
18 | 2. add a title and body that follows the [Conventional Commits Specification](https://conventionalcommits.org).
|
19 | 3. 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 |
|
26 | 1. bumps the version in _package.json/bower.json_ (based on your commit history)
|
27 | 2. uses [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) to update _CHANGELOG.md_
|
28 | 3. commits _package.json (et al.)_ and _CHANGELOG.md_
|
29 | 4. tags a new release
|
30 |
|
31 | ## Installation
|
32 |
|
33 | ### As `npm run` script
|
34 |
|
35 | Install and add to `devDependencies`:
|
36 |
|
37 | ```
|
38 | npm i --save-dev standard-version
|
39 | ```
|
40 |
|
41 | Add 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 |
|
51 | Now you can use `npm run release` in place of `npm version`.
|
52 |
|
53 | This 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 |
|
57 | Install globally (add to your `PATH`):
|
58 |
|
59 | ```
|
60 | npm i -g standard-version
|
61 | ```
|
62 |
|
63 | Now you can use `standard-version` in place of `npm version`.
|
64 |
|
65 | This 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 |
|
71 | To generate your changelog for your first release, simply do:
|
72 |
|
73 | ```sh
|
74 | # npm run script
|
75 | npm run release -- --first-release
|
76 | # or global bin
|
77 | standard-version --first-release
|
78 | ```
|
79 |
|
80 | This will tag a release **without bumping the version in package.json (_et al._)**.
|
81 |
|
82 | When ready, push the git tag and `npm publish` your first release. \o/
|
83 |
|
84 | ### Cut a Release
|
85 |
|
86 | If you typically use `npm version` to cut a new release, do this instead:
|
87 |
|
88 | ```sh
|
89 | # npm run script
|
90 | npm run release
|
91 | # or global bin
|
92 | standard-version
|
93 | ```
|
94 |
|
95 | As 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 |
|
97 | After 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 |
|
101 | Use the flag `--prerelease` to generate pre-releases:
|
102 |
|
103 | Suppose 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
|
107 | npm run release -- --prerelease
|
108 | ```
|
109 | you will get version `1.0.1-0`.
|
110 |
|
111 | If you want to name the pre-release, you specify the name via `--prerelease <name>`.
|
112 |
|
113 | For example, suppose your pre-release should contain the `alpha` prefix:
|
114 |
|
115 | ```bash
|
116 | # npm run script
|
117 | npm run release -- --prerelease alpha
|
118 | ```
|
119 |
|
120 | this will tag the version `1.0.1-alpha.0`
|
121 |
|
122 | ### Release as a target type imperatively like `npm version`
|
123 |
|
124 | To forgo the automated version bump use `--release-as` with the argument `major`, `minor` or `patch`:
|
125 |
|
126 | Suppose the last version of your code is `1.0.0`, you've only landed `fix:` commits, but
|
127 | you would like your next release to be a `minor`. Simply do:
|
128 |
|
129 | ```bash
|
130 | # npm run script
|
131 | npm run release -- --release-as minor
|
132 | # Or
|
133 | npm run release -- --release-as 1.1.0
|
134 | ```
|
135 |
|
136 | you 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 |
|
142 | If 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
|
146 | npm run release -- --no-verify
|
147 | # or global bin
|
148 | standard-version --no-verify
|
149 | ```
|
150 |
|
151 | ### Signing commits and tags
|
152 |
|
153 | If 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
|
158 | own supplementary commands during the release. The following
|
159 | hooks 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 |
|
168 | Simply 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 |
|
182 | You can skip any of the lifecycle steps (`bump`, `changelog`, `commit`, `tag`),
|
183 | by 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 |
|
197 | If 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 |
|
206 | running `standard-version` with the flag `--dry-run` allows you to see what
|
207 | commands would be run, without committing to git or updating files.
|
208 |
|
209 | ```sh
|
210 | # npm run script
|
211 | npm run release -- --dry-run
|
212 | # or global bin
|
213 | standard-version --dry-run
|
214 | ```
|
215 |
|
216 | ### CLI Help
|
217 |
|
218 | ```sh
|
219 | # npm run script
|
220 | npm run release -- --help
|
221 | # or global bin
|
222 | standard-version --help
|
223 | ```
|
224 |
|
225 | ## Code usage
|
226 |
|
227 | Use the `silent` option to stop `standard-version` from printing anything
|
228 | to the console.
|
229 |
|
230 | ```js
|
231 | var standardVersion = require('standard-version')
|
232 |
|
233 | // Options are the same as command line, except camelCase
|
234 | standardVersion({
|
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
|
251 | git commit -a -m "fix(parsing): fixed a bug in our parser"
|
252 | ```
|
253 |
|
254 | _features:_
|
255 |
|
256 | ```sh
|
257 | git commit -a -m "feat(parser): we now have a parser \o/"
|
258 | ```
|
259 |
|
260 | _breaking changes:_
|
261 |
|
262 | ```sh
|
263 | git commit -a -m "feat(new-parser): introduces a new parsing library
|
264 | BREAKING CHANGE: new library does not support foo-construct"
|
265 | ```
|
266 |
|
267 | _other changes:_
|
268 |
|
269 | You decide, e.g., docs, chore, etc.
|
270 |
|
271 | ```sh
|
272 | git commit -a -m "docs: fixed up the docs a bit"
|
273 | ```
|
274 |
|
275 | _but wait, there's more!_
|
276 |
|
277 | Github usernames (`@bcoe`) and issue references (#133) will be swapped out for the
|
278 | appropriate URLs in your CHANGELOG.
|
279 |
|
280 | ## Badges!
|
281 |
|
282 | Tell 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 |
|
296 | They 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 |
|
298 | We 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 |
|
302 | The instructions to squash commits when merging pull requests assumes that **one PR equals, at most, one feature or fix**.
|
303 |
|
304 | If 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 |
|
306 | Although 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 |
|
308 | For 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 |
|
312 | ISC
|