@@ -51,14 +51,56 @@ _We highly recommend to use Yarn when you think to contribute to this project._
51
51
$ yarn add {%= name %}
52
52
```
53
53
54
+ ## Monorepo support
55
+
56
+ For making it work on monorepo setups, you should pass ` options.packages ` - an array
57
+ of package names that are changes and a ` options.cwd ` - the root of the monorepo.
58
+ Usually this can be extracted from commit message or the response of ` lerna changed ` .
59
+
60
+ ``` js
61
+ import detectNextVersion from ' detect-next-version' ;
62
+
63
+ async function main () {
64
+ // e.g. /home/charlike/develop/some-monorepo
65
+ const cwd = process .cwd ();
66
+
67
+ // try using `git-commits-since` for getting all commits
68
+ // it returns an object with `rawCommits` property
69
+ const commits = [' feat: foo bar' , ' chore(ok): qux okey' ];
70
+ const packages = [' @tunnckocore/qq5' , ' foo-bar-baz-qux' ];
71
+
72
+ const results = await detectNextVersion (commits, { packages, cwd });
73
+ console .log (results);
74
+
75
+ const [itemOne , itemTwo ] = results;
76
+ console .log (itemOne .name ); // => '@tunnckocore/qq5'
77
+ console .log (itemOne .path ); // => '@tunnckocore/qq5'
78
+ console .log (itemOne .increment ); // => 'minor'
79
+ console .log (itemOne .lastVersion ); // => '0.1.0'
80
+ console .log (itemOne .nextVersion ); // => '0.2.0'
81
+ console .log (itemOne .cwd ); // => /home/charlike/develop/some-monorepo
82
+
83
+ console .log (itemTwo .name ); // => 'foo-bar-baz-qux'
84
+ console .log (itemTwo .path ); // => 'packages/foo-bar-baz-qux'
85
+ console .log (itemTwo .increment ); // => 'minor'
86
+ console .log (itemTwo .lastVersion ); // => '1.0.4'
87
+ console .log (itemTwo .nextVersion ); // => '1.1.0'
88
+ console .log (itemTwo .cwd ); // => /home/charlike/develop/some-monorepo
89
+ }
90
+
91
+ main ().catch (console .error );
92
+ ```
93
+
54
94
## API
55
95
56
96
<!-- docks-start -->
97
+
57
98
_ Generated using [ docks] ( http://npm.im/docks ) ._
58
99
59
100
### [ src/index.js] ( /src/index.js )
60
101
61
- #### [ detectNextVersion] ( /src/index.js#L72 )
102
+ #### [ detectNextVersion] ( /src/index.js#L75 )
103
+
62
104
Calculates next version of given package with ` name ` ,
63
105
based given ` commitMessages ` which should follow
64
106
the [ Conventional Commits Specification] ( https://www.conventionalcommits.org/ ) .
@@ -73,16 +115,18 @@ returned result won't have `nextVersion` and `increment` will be `false`.
73
115
ProTip: See [ parse-commit-message types] ( https://github.com/tunnckoCoreLabs/parse-commit-message#type-definitions ) documentation!
74
116
75
117
** Params**
76
- - ` name ` ** {string} ** a package name which you looking to update
118
+
77
119
- ` commits ` ** {string|}** directly passed to [ recommended-bump] [ ]
78
- May be one of ` string ` , ` Array<string> ` or ` Array<Commit> `
120
+ May be one of ` string ` , ` Array<string> ` or ` Array<Commit> `
79
121
- ` [options] ` ** {object}** optional, passed to above mentioned packages.
80
122
81
123
** Returns**
82
- - ` object ` an object which is basically the return of [ recommended-bump] [ ]
83
- plus ` { pkg, lastVersion, nextVersion? } ` .
124
+
125
+ - ` Array<object> ` an array of objects where each is basically the return of [ recommended-bump] [ ]
126
+ plus ` { pkg, name, cwd, path, lastVersion, nextVersion? } ` .
84
127
85
128
** Examples**
129
+
86
130
``` ts
87
131
type Commit = {
88
132
header: Header ;
@@ -93,14 +137,15 @@ type Commit = {
93
137
mentions? : Array <Mention >;
94
138
};
95
139
```
140
+
96
141
``` javascript
97
142
import detector from ' detect-next-version' ;
98
143
99
144
async function main () {
100
145
const commits = [' chore(ci): some build tweaks' , ' fix(cli): foo bar' ];
101
146
102
147
// consider `my-npm-package` is version 0.1.0
103
- const result = await detector (' my-npm-package' , commits );
148
+ const [ result ] = await detector (commits, { name : ' my-npm-package' } );
104
149
console .log (result .increment ); // => 'patch'
105
150
console .log (result .pkg ); // => package's latest package.json metadata
106
151
console .log (result .lastVersion ); // => '0.1.0'
@@ -113,6 +158,7 @@ async function main() {
113
158
114
159
main ().catch (console .error );
115
160
```
161
+
116
162
``` javascript
117
163
import { parse } from ' parse-commit-message' ;
118
164
import detector from ' detect-next-version' ;
@@ -121,7 +167,11 @@ async function main() {
121
167
const commitOne = parse (' fix: foo bar' );
122
168
const commitTwo = parse (' feat: some feature subject' );
123
169
124
- const result = await detector (' @my-org/my-awesomepkg' , [commitOne, commitTwo]);
170
+ // always an array, but we can destruct it here,
171
+ // because we know that it has only one item
172
+ const [result ] = await detector ([commitOne, commitTwo], {
173
+ name: ' @my-org/my-awesomepkg' ,
174
+ });
125
175
console .log (result .increment ); // => 'minor'
126
176
}
127
177
@@ -198,24 +248,20 @@ Released under the [Apache-2.0 License][license-url].
198
248
199
249
[ ghrelease-url ] : https://github.com/tunnckoCoreLabs/detect-next-version/releases/latest
200
250
[ ghrelease-img ] : https://badgen.net/github/release/tunnckoCoreLabs/detect-next-version?icon=github
201
-
202
251
[ license-url ] : https://github.com/tunnckoCoreLabs/detect-next-version/blob/master/LICENSE
252
+
203
253
[ license-img] : https://badgen.net/npm/license/{%= name %}
204
254
205
255
<!-- Front line badges -->
206
256
207
257
[ codestyle-url ] : https://github.com/airbnb/javascript
208
258
[ codestyle-img ] : https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb
209
-
210
259
[ linuxbuild-url ] : https://circleci.com/gh/tunnckoCoreLabs/detect-next-version/tree/master
211
260
[ linuxbuild-img ] : https://badgen.net/circleci/github/tunnckoCoreLabs/detect-next-version/master?label=build&icon=circleci
212
-
213
261
[ codecoverage-url ] : https://codecov.io/gh/tunnckoCoreLabs/detect-next-version
214
262
[ codecoverage-img ] : https://badgen.net/codecov/c/github/tunnckoCoreLabs/detect-next-version?icon=codecov
215
-
216
263
[ dependencies-url ] : https://david-dm.org/tunnckoCoreLabs/detect-next-version
217
264
[ dependencies-img ] : https://badgen.net/david/dep/tunnckoCoreLabs/detect-next-version?label=deps
218
-
219
265
[ ccommits-url ] : https://conventionalcommits.org/
220
266
[ ccommits-img ] : https://badgen.net/badge/conventional%20commits/v1.0.0/dfb317
221
267
[ new-release-url ] : https://ghub.io/new-release
@@ -234,7 +280,6 @@ Released under the [Apache-2.0 License][license-url].
234
280
[ patreon-url ] : https://www.patreon.com/bePatron?u=5579781
235
281
[ patreon-img ] : https://badgen.net/badge/patreon/tunnckoCore/F96854?icon=patreon
236
282
[ patreon-sponsor-img ] : https://badgen.net/badge/become/a%20sponsor/F96854?icon=patreon
237
-
238
283
[ shareu ] : https://twitter.com/intent/tweet?text=https://github.com/tunnckoCoreLabs/detect-next-version&via=tunnckoCore
239
284
[ shareb ] : https://badgen.net/badge/twitter/share/1da1f2?icon=twitter
240
285
[ open-issue-url ] : https://github.com/tunnckoCoreLabs/detect-next-version/issues/new
0 commit comments