-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
cli-version-commands.ts
318 lines (304 loc) · 11.3 KB
/
cli-version-commands.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import { VersionCommandOption } from '@lerna-lite/core';
import log from 'npmlog';
/**
* @see https://github.com/yargs/yargs/blob/master/docs/advanced.md#providing-a-command-module
*/
const addBumpPositionalFn = function (yargs: any, additionalKeywords: string[] = []) {
const semverKeywords = ['major', 'minor', 'patch', 'premajor', 'preminor', 'prepatch', 'prerelease'].concat(additionalKeywords);
const bumpOptionList = `'${semverKeywords.slice(0, -1).join(`', '`)}', or '${semverKeywords[semverKeywords.length - 1]}'.`;
yargs.positional('bump', {
describe: `Increment version(s) by explicit version _or_ semver keyword,\n${bumpOptionList}`,
type: 'string',
});
};
let addBumpPositional = addBumpPositionalFn;
export default {
command: 'version [bump]',
describe: 'Bump version of packages changed since the last release.',
builder: (yargs: any, composed?: string) => {
const opts = {
'allow-branch': {
describe: 'Specify which branches to allow versioning from.',
type: 'array',
},
amend: {
describe: 'Amend the existing commit, instead of generating a new one.',
type: 'boolean',
},
'build-metadata': {
describe: 'Apply build metadata to the release, compatible with SemVer.',
requiresArg: true,
type: 'string',
},
'conventional-bump-prerelease': {
describe: 'Bumps prerelease versions if conventional commits requires it.',
type: 'boolean',
},
'conventional-commits': {
describe: 'Use conventional-changelog to determine version bump and generate CHANGELOG.',
type: 'boolean',
},
'conventional-graduate': {
describe: 'Version currently prereleased packages to a non-prerelease version.',
// type must remain ambiguous because it is overloaded (boolean _or_ string _or_ array)
},
'conventional-prerelease': {
describe: 'Version changed packages as prereleases when using --conventional-commits.',
// type must remain ambiguous because it is overloaded (boolean _or_ string _or_ array)
},
'changelog-header-message': {
describe:
'Add a custom message at the top of all "changelog.md" files. This option is only available when using --conventional-commits with changelogs.',
group: 'Version Command Options:',
requiresArg: true,
type: 'string',
},
'changelog-include-commits-git-author': {
describe:
"Specify if we want to include the commit git author's name, this option is only available when using --conventional-commits with changelogs. We can also optionally provide a custom message or else a default format will be used.",
group: 'Version Command Options:',
requiresArg: false,
type: 'string',
},
'changelog-include-commits-client-login': {
describe:
'Specify if we want to include the commit remote client login name (ie GitHub username), this option is only available when using --conventional-commits with changelogs. We can also optionally provide a custom message or else a default format will be used.',
group: 'Version Command Options:',
requiresArg: false,
type: 'string',
},
'changelog-preset': {
describe: 'Custom conventional-changelog preset.',
type: 'string',
requiresArg: true,
defaultDescription: 'angular',
},
'dry-run': {
describe: 'Displays the process command that would be performed without executing it.',
group: 'Version Command Options:',
type: 'boolean',
},
exact: {
describe: 'Specify cross-dependency version numbers exactly rather than with a caret (^).',
type: 'boolean',
},
'exclude-dependents': {
describe: `Exclude all transitive dependents when running a command with --since, overriding the default 'changed' algorithm.`,
type: 'boolean',
},
'independent-subpackages': {
describe: 'Exclude sub-packages when versioning',
type: 'boolean',
},
'force-publish': {
describe: 'Always include targeted packages in versioning operations, skipping default logic.',
// type must remain ambiguous because it is overloaded (boolean _or_ string _or_ array)
},
'git-remote': {
describe: 'Push git changes to the specified remote.',
type: 'string',
requiresArg: true,
defaultDescription: 'origin',
},
'create-release': {
describe: 'Create an official GitHub or GitLab release for every version.',
type: 'string',
choices: ['gitlab', 'github'],
},
'ignore-changes': {
describe: [
'Ignore changes in files matched by glob(s) when detecting changed packages.',
'Pass --no-ignore-changes to completely disable.',
].join('\n'),
type: 'array',
},
'ignore-scripts': {
describe: 'Disable all lifecycle scripts',
type: 'boolean',
},
'include-merged-tags': {
describe: 'Include tags from merged branches when detecting changed packages.',
type: 'boolean',
},
m: {
describe: 'Use a custom commit message when creating the version commit.',
alias: 'message',
type: 'string',
requiresArg: true,
},
'no-changelog': {
describe: 'Do not generate CHANGELOG.md files when using --conventional-commits.',
type: 'boolean',
},
changelog: {
// proxy for --no-changelog
hidden: true,
type: 'boolean',
},
'no-commit-hooks': {
describe: 'Do not run git commit hooks when committing version changes.',
type: 'boolean',
},
'commit-hooks': {
// proxy for --no-commit-hooks
hidden: true,
type: 'boolean',
},
'git-tag-command': {
describe:
'Allows users to specify a custom command to be used when applying git tags. For example, this may be useful for providing a wrapper command in CI/CD pipelines that have no direct write access.',
type: 'string',
},
'no-git-tag-version': {
describe: 'Do not commit or tag version changes.',
type: 'boolean',
},
'git-tag-version': {
// proxy for --no-git-tag-version
hidden: true,
type: 'boolean',
},
// TODO: (major) make --no-granular-pathspec the default
'no-granular-pathspec': {
describe: 'Do not stage changes file-by-file, but globally.',
type: 'boolean',
},
'granular-pathspec': {
// proxy for --no-granular-pathspec
hidden: true,
// describe: 'Stage changes file-by-file, not globally.',
type: 'boolean',
},
// TODO: (major) make --no-private the default
'no-private': {
describe: 'Do not version private packages.',
type: 'boolean',
},
private: {
// proxy for --no-private
hidden: true,
type: 'boolean',
},
'no-push': {
describe: 'Do not push tagged commit to git remote.',
type: 'boolean',
},
push: {
// proxy for --no-push
hidden: true,
type: 'boolean',
},
// preid is copied into ../publish/command because a whitelist for one option isn't worth it
preid: {
describe: 'Specify the prerelease identifier when versioning a prerelease',
type: 'string',
requiresArg: true,
defaultDescription: 'alpha',
},
'remote-client': {
describe:
'Remote git client, which client is used when reading commits from remote which is useful when associating client login for each changelog entry.',
type: 'string',
choices: ['gitlab', 'github'],
},
'sign-git-commit': {
describe: 'Pass the `--gpg-sign` flag to `git commit`.',
type: 'boolean',
},
'signoff-git-commit': {
describe: 'Pass the `--signoff` flag to `git commit`.',
type: 'boolean',
},
'sign-git-tag': {
describe: 'Pass the `--sign` flag to `git tag`.',
type: 'boolean',
},
'force-git-tag': {
describe: 'Pass the `--force` flag to `git tag`.',
type: 'boolean',
},
'tag-version-prefix': {
describe: 'Customize the tag prefix. To remove entirely, pass an empty string.',
type: 'string',
requiresArg: true,
defaultDescription: 'v',
},
'no-manually-update-root-lockfile': {
describe: 'Do not manually update (read/write back to the lock file) the project root lock file.',
type: 'boolean',
},
'manually-update-root-lockfile': {
// proxy for --no-manually-update-root-lockfile
hidden: true,
type: 'boolean',
},
'npm-client-args': {
describe: "Additional arguments to pass to the npm client when performing 'npm install'.",
type: 'array',
},
'no-sync-workspace-lock': {
describe:
'Do not run `npm install --package-lock-only` or equivalent depending on the package manager defined in `npmClient`.',
type: 'boolean',
},
'sync-workspace-lock': {
describe: 'Runs `npm install --package-lock-only` or equivalent depending on the package manager defined in `npmClient`.',
type: 'boolean',
},
'skip-bump-only-release': {
describe: 'do we want to skip creating a release (github/gitlab) when the version is a "version bump only"?',
type: 'boolean',
},
'workspace-strict-match': {
describe:
'Strict match transform version numbers to an exact range (like "1.2.3") rather than with a caret (like ^1.2.3) when using `workspace:*`.',
type: 'boolean',
},
y: {
describe: 'Skip all confirmation prompts.',
alias: 'yes',
type: 'boolean',
},
};
if (composed) {
// hide options from composed command's help output
Object.keys(opts).forEach((key) => {
opts[key].hidden = true;
});
// set argv.composed for wrapped execution logic
yargs.default('composed', composed).hide('composed');
} else {
addBumpPositional = addBumpPositionalFn(yargs) as any;
}
yargs.options(opts);
// workaround yargs bug that re-interprets unknown arguments in argv._
yargs.parserConfiguration({
'populate--': true,
});
if (!composed) {
// hide options from composed command's help output
yargs.group(Object.keys(opts), 'Command Options:');
}
return yargs.check((argv) => {
if (argv['--']) {
log.warn('EDOUBLEDASH', 'Arguments after -- are no longer passed to subprocess executions.');
log.warn('EDOUBLEDASH', 'This will cause an error in a future major version.');
}
return argv;
});
},
handler: async (argv: VersionCommandOption) => {
try {
// @ts-ignore
// eslint-disable-next-line
const { VersionCommand } = await import('@lerna-lite/version');
new VersionCommand(argv);
} catch (err: unknown) {
console.error(
`"@lerna-lite/version" is optional and was not found. Please install it with "npm install @lerna-lite/version -D -W".`,
err
);
}
},
};
export { addBumpPositional };