@leverege/build-tools 2.96.7 → 2.96.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,681 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable security/detect-unsafe-regex */
3
+ /* eslint-disable no-console */
4
+ /* eslint-disable max-len */
5
+ "use strict";
6
+
7
+ var _nodePath = _interopRequireDefault(require("node:path"));
8
+ var _commandLineArgs = _interopRequireDefault(require("command-line-args"));
9
+ var _commandLineUsage = _interopRequireDefault(require("command-line-usage"));
10
+ var _zx = require("zx");
11
+ var _enquirer = _interopRequireDefault(require("enquirer"));
12
+ var _ansiColors = _interopRequireDefault(require("ansi-colors"));
13
+ var _readPkg = require("read-pkg");
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ const {
16
+ prompt
17
+ } = _enquirer.default;
18
+ const NPMJS_TAGS = {
19
+ ALPHA: 'alpha',
20
+ BETA: 'beta',
21
+ LATEST: 'latest'
22
+ };
23
+ const DEFAULT_PACKAGES_PATH = './packages/*';
24
+
25
+ /**
26
+ * Functions
27
+ */
28
+
29
+ const validateVersionArg = ({
30
+ args
31
+ }) => {
32
+ if (!args.version) {
33
+ return;
34
+ }
35
+ const isValid = /^\d+\.\d+\.\d+(-[a-zA-Z]+\.\d+)?$/.test(args.version);
36
+ if (!isValid) {
37
+ console.log(`
38
+ ${_ansiColors.default.bold.red('ERROR:')} Invalid version arg: ${_ansiColors.default.bold.yellow(args.version)}.
39
+ Use SemVer specs (e.g: ${_ansiColors.default.bold.yellow('2.25.5-beta.1')}).
40
+ `);
41
+ process.exit(1);
42
+ }
43
+ };
44
+ const validateNpmjsTag = ({
45
+ args,
46
+ config
47
+ }) => {
48
+ const npmjsTags = Object.values(NPMJS_TAGS);
49
+ if (args['npmjs-tag'] && !npmjsTags.includes(args['npmjs-tag'])) {
50
+ console.log(`
51
+ ${_ansiColors.default.bold.red('ERROR:')} Invalid npmjs tag: ${_ansiColors.default.bold.yellow(args['npmjs-tag'])}.
52
+ Possible values: ${_ansiColors.default.bold.yellow(npmjsTags.join(', '))}.
53
+ `);
54
+ process.exit(1);
55
+ }
56
+ if ((config?.isBetaRelease === true || args?.version?.includes('-beta.')) && args['npmjs-tag'] === NPMJS_TAGS.LATEST) {
57
+ console.log(`
58
+ ${_ansiColors.default.bold.red('ERROR:')} It's not possible to publish a beta release to npmjs with tag ${_ansiColors.default.bold.yellow('latest')}.
59
+ `);
60
+ process.exit(1);
61
+ }
62
+ };
63
+ const validateArgs = args => {
64
+ validateVersionArg({
65
+ args
66
+ });
67
+ validateNpmjsTag({
68
+ args
69
+ });
70
+ };
71
+ const getCurrentBranch = async () => {
72
+ const {
73
+ stdout
74
+ } = await (0, _zx.$)`git branch --show-current`.nothrow().quiet();
75
+ return stdout.split('\n')[0];
76
+ };
77
+ const getLatestBranches = async ({
78
+ n = 10,
79
+ branchFilter
80
+ }) => {
81
+ const grepFilter = branchFilter || '';
82
+ const {
83
+ stdout
84
+ } = await (0, _zx.$)`git branch -r --sort=-committerdate --format "%(refname:lstrip=3)" | grep "${grepFilter}"`.nothrow().quiet();
85
+ const branches = stdout.split('\n').slice(0, -1).filter(branch => branch !== 'HEAD');
86
+ return branches.slice(0, n);
87
+ };
88
+ const promptForBranch = async (latestBranches, currentBranch) => {
89
+ if (latestBranches.length === 0) {
90
+ console.log(`
91
+ ${_ansiColors.default.bold.red('ERROR:')} Could not find git branches.
92
+ `);
93
+ process.exit(1);
94
+ }
95
+ const {
96
+ branch
97
+ } = await prompt({
98
+ type: 'select',
99
+ name: 'branch',
100
+ message: 'Which branch would you like to release?',
101
+ choices: latestBranches.map(option => ({
102
+ value: option
103
+ })),
104
+ initial: currentBranch
105
+ });
106
+ return branch;
107
+ };
108
+ const getBranch = async branchFilter => {
109
+ const currentBranch = await getCurrentBranch();
110
+ const latestBranches = await getLatestBranches(branchFilter);
111
+ return promptForBranch(latestBranches, currentBranch);
112
+ };
113
+ const getGitRootDirectory = async () => {
114
+ const {
115
+ stdout
116
+ } = await (0, _zx.$)`git rev-parse --show-toplevel`.quiet();
117
+ return stdout.split('\n')[0];
118
+ };
119
+ const getSubDirectories = async (repositoryRoot, directory) => {
120
+ const absolutePathDirectory = _nodePath.default.join(repositoryRoot, directory);
121
+ const relativeDirectory = _nodePath.default.relative(repositoryRoot, absolutePathDirectory);
122
+ try {
123
+ const entries = await _zx.fs.promises.readdir(absolutePathDirectory, {
124
+ withFileTypes: true
125
+ });
126
+ const subDirectories = entries.filter(entry => entry.isDirectory());
127
+ return subDirectories.map(entry => _nodePath.default.join(relativeDirectory, entry.name));
128
+ } catch (err) {
129
+ return [];
130
+ }
131
+ };
132
+ const fileExists = async filePath => {
133
+ try {
134
+ await _zx.fs.promises.access(filePath);
135
+ return true;
136
+ } catch (err) {
137
+ return false;
138
+ }
139
+ };
140
+ const findPackagesInDirectories = async (repositoryRoot, directories) => {
141
+ return directories.reduce(async (accPromise, directory) => {
142
+ const acc = await accPromise;
143
+ const hasWildcard = directory.endsWith('*');
144
+ const basePath = hasWildcard ? directory.slice(0, -1) : directory;
145
+ const directoriesToSearch = hasWildcard ? await getSubDirectories(repositoryRoot, basePath) : [basePath];
146
+ for (let i = 0; i < directoriesToSearch.length; i++) {
147
+ const currentDirectory = directoriesToSearch[i];
148
+ const pkgPath = _nodePath.default.join(directoriesToSearch[i], 'package.json');
149
+ const pkgExists = await fileExists(_nodePath.default.join(repositoryRoot, pkgPath)); // eslint-disable-line no-await-in-loop
150
+ if (pkgExists) {
151
+ acc.push(currentDirectory);
152
+ }
153
+ }
154
+ return acc;
155
+ }, Promise.resolve([]));
156
+ };
157
+ const getMonorepoPackagePaths = async (repositoryRoot, packagesPath) => {
158
+ let pkg;
159
+ try {
160
+ pkg = await (0, _readPkg.readPackage)({
161
+ cwd: repositoryRoot
162
+ });
163
+ } catch (err) {}
164
+ return findPackagesInDirectories(repositoryRoot, pkg?.workspaces || [packagesPath]);
165
+ };
166
+ const selectPackageToUpdate = async (repositoryRoot, packagePaths) => {
167
+ const currentPath = process.cwd();
168
+ const currentPackageRelativePath = _nodePath.default.relative(repositoryRoot, currentPath);
169
+ const {
170
+ packageName
171
+ } = await prompt({
172
+ type: 'select',
173
+ name: 'packageName',
174
+ message: 'What package are you releasing?',
175
+ choices: packagePaths,
176
+ initial: currentPackageRelativePath
177
+ });
178
+ return _nodePath.default.join(repositoryRoot, packageName);
179
+ };
180
+ const getPackagePath = async ({
181
+ repositoryRoot,
182
+ packagesPath = DEFAULT_PACKAGES_PATH
183
+ }) => {
184
+ const packagePaths = await getMonorepoPackagePaths(repositoryRoot, packagesPath);
185
+ if (packagePaths.length > 0) {
186
+ return selectPackageToUpdate(repositoryRoot, packagePaths);
187
+ }
188
+ return repositoryRoot;
189
+ };
190
+ const checkoutToBranch = async ({
191
+ branch
192
+ }) => {
193
+ try {
194
+ await (0, _zx.$)`git checkout ${branch}`;
195
+ } catch (err) {
196
+ console.log(err.stderr || err);
197
+ process.exit(1);
198
+ }
199
+ };
200
+ const getPackageJsonVersion = async packagePath => {
201
+ if (!packagePath) {
202
+ console.log(`
203
+ ${_ansiColors.default.bold.red('ERROR:')} Could not find a package.json file.
204
+ The tag-release script must run from a npm project.
205
+ `);
206
+ return process.exit(1);
207
+ }
208
+ const packageJson = await (0, _readPkg.readPackage)({
209
+ cwd: packagePath
210
+ });
211
+ return packageJson.version;
212
+ };
213
+ const getNextVersions = currentVersion => {
214
+ const regex = /^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-(\w+)\.(\d+))?$/i;
215
+ const [, dirtyMajor, dirtyMinor, dirtyPatch, testTag, dirtyTestVersion] = currentVersion.match(regex);
216
+ const major = parseInt(dirtyMajor);
217
+ const minor = parseInt(dirtyMinor) || 0;
218
+ const patch = parseInt(dirtyPatch) || 0;
219
+ const testVersion = parseInt(dirtyTestVersion) || 0;
220
+ const nextMajor = `${major + 1}.0.0`;
221
+ const nextMinor = `${major}.${minor + 1}.0`;
222
+ const nextPatch = `${major}.${minor}.${patch + 1}`;
223
+ const nextAlpha = testTag === 'alpha' ? `${major}.${minor}.${patch}-alpha.${testVersion + 1}` : `${major}.${minor}.${patch + 1}-alpha.1`;
224
+ const nextBeta = testTag === 'beta' ? `${major}.${minor}.${patch}-beta.${testVersion + 1}` : `${major}.${minor}.${patch + 1}-beta.1`;
225
+ const nextTestTag = testTag && !['alpha', 'beta'].includes(testTag) ? `${major}.${minor}.${patch}-${testTag}.${testVersion + 1}` : null;
226
+ return {
227
+ nextMajor,
228
+ nextMinor,
229
+ nextPatch,
230
+ nextAlpha,
231
+ nextBeta,
232
+ nextTestTag,
233
+ testTag
234
+ };
235
+ };
236
+ const promptForVersion = async currentVersion => {
237
+ const {
238
+ nextMajor,
239
+ nextMinor,
240
+ nextPatch,
241
+ nextAlpha,
242
+ nextBeta,
243
+ nextTestTag,
244
+ testTag
245
+ } = getNextVersions(currentVersion);
246
+ const choices = [{
247
+ hint: '(major release)',
248
+ value: nextMajor
249
+ }, {
250
+ hint: '(minor release)',
251
+ value: nextMinor
252
+ }, {
253
+ hint: '(patch release)',
254
+ value: nextPatch
255
+ }, {
256
+ hint: '(alpha release)',
257
+ value: nextAlpha
258
+ }, {
259
+ hint: '(beta release)',
260
+ value: nextBeta
261
+ }, ...(nextTestTag ? [{
262
+ hint: `(${testTag} release)`,
263
+ value: nextTestTag
264
+ }] : []), {
265
+ hint: '(current version)',
266
+ value: currentVersion
267
+ }, {
268
+ value: 'custom'
269
+ }];
270
+ const {
271
+ version
272
+ } = await prompt({
273
+ type: 'select',
274
+ name: 'version',
275
+ message: `What version are you releasing (current version is ${currentVersion})?`,
276
+ choices
277
+ });
278
+ if (version === 'custom') {
279
+ const {
280
+ customVersion
281
+ } = await prompt({
282
+ type: 'input',
283
+ name: 'customVersion',
284
+ message: `What custom version are you releasing (current version is ${currentVersion})?`,
285
+ initial: currentVersion
286
+ });
287
+ return customVersion;
288
+ }
289
+ return version;
290
+ };
291
+ const getVersion = async ({
292
+ branch,
293
+ packagePath
294
+ }) => {
295
+ const currentVersion = await getPackageJsonVersion(packagePath);
296
+ return promptForVersion(currentVersion);
297
+ };
298
+ const getPackageName = async ({
299
+ packagePath
300
+ }) => {
301
+ const noTrailingSlashPath = packagePath.slice(-1) === '/' ? packagePath.substr(0, packagePath.length - 1) : packagePath;
302
+ return noTrailingSlashPath.split('/').slice(-1)[0];
303
+ };
304
+ const getBuildMessage = ({
305
+ isPackageInRepositoryRoot,
306
+ packageName,
307
+ version
308
+ }) => {
309
+ if (isPackageInRepositoryRoot) {
310
+ return `BUILD v${version}`;
311
+ }
312
+ return `BUILD ${packageName}/v${version}`;
313
+ };
314
+ const getGitTagSuffix = async () => {
315
+ const {
316
+ tagSuffix
317
+ } = await prompt({
318
+ type: 'input',
319
+ name: 'tagSuffix',
320
+ message: 'What suffix you like to add to the tag name for git? (e.g: "-RC.1" for v1.2.3-RC.1)'
321
+ });
322
+ return tagSuffix;
323
+ };
324
+ const getGitAnnotationMessage = async ({
325
+ tagName
326
+ }) => {
327
+ const {
328
+ annotationMessage
329
+ } = await prompt({
330
+ type: 'input',
331
+ name: 'annotationMessage',
332
+ message: 'What annotation message would you like to add to git tag?',
333
+ initial: tagName
334
+ });
335
+ return annotationMessage;
336
+ };
337
+ const confirmPushCommit = async buildMessage => {
338
+ const {
339
+ confirm
340
+ } = await prompt([{
341
+ type: 'confirm',
342
+ name: 'confirm',
343
+ message: `${_ansiColors.default.bold.red('[Warning]')} Commit and push ${_ansiColors.default.bold.yellow(buildMessage)} to git remote?`
344
+ }]);
345
+ return confirm;
346
+ };
347
+ const isPackageInRepositoryRoot = async ({
348
+ repositoryRoot,
349
+ packagePath
350
+ }) => {
351
+ return repositoryRoot === packagePath;
352
+ };
353
+ const promptForNpmjsTag = async ({
354
+ isBetaRelease
355
+ }) => {
356
+ const choices = Object.values(NPMJS_TAGS).map(option => ({
357
+ value: option,
358
+ ...(isBetaRelease && option === NPMJS_TAGS.LATEST && {
359
+ disabled: '(not available for beta releases)'
360
+ })
361
+ }));
362
+ const {
363
+ npmjsTag
364
+ } = await prompt({
365
+ type: 'select',
366
+ name: 'npmjsTag',
367
+ message: 'Which npmjs tag would you like to use when publishing?',
368
+ choices,
369
+ initial: isBetaRelease ? NPMJS_TAGS.BETA : NPMJS_TAGS.LATEST
370
+ });
371
+ return npmjsTag;
372
+ };
373
+ const confirmTagRelease = async ({
374
+ isBetaRelease,
375
+ publishable
376
+ }) => {
377
+ const message = ['Releasing will commit', isBetaRelease ? ' and push' : ', push, and tag', ' the version in git', publishable ? ' and npm' : '', '. Proceed?'].join('');
378
+ const {
379
+ confirmResponse
380
+ } = await prompt({
381
+ type: 'select',
382
+ name: 'confirmResponse',
383
+ message,
384
+ choices: ['yes', 'no', 'advanced'],
385
+ initial: 'yes'
386
+ });
387
+ if (confirmResponse === 'no') {
388
+ console.log('Aborting...');
389
+ process.exit();
390
+ }
391
+ return confirmResponse;
392
+ };
393
+ const isWorkspacePackage = async () => {
394
+ const gitRootDirectory = await getGitRootDirectory();
395
+ try {
396
+ const packageJson = await (0, _readPkg.readPackage)({
397
+ cwd: gitRootDirectory
398
+ });
399
+ return packageJson?.workspaces?.length > 0;
400
+ } catch (err) {
401
+ return false;
402
+ }
403
+ };
404
+ const updateNpmPackageJsonAndLock = async config => {
405
+ const {
406
+ version,
407
+ packagePath,
408
+ isPackageInRepositoryRoot
409
+ } = config;
410
+ const isWorkspace = await isWorkspacePackage();
411
+ try {
412
+ if (!isPackageInRepositoryRoot) {
413
+ await (0, _zx.$)`npm version --no-git-tag-version ${version} --prefix ${packagePath}`.quiet().nothrow();
414
+ if (isWorkspace) {
415
+ await (0, _zx.$)`npm install`;
416
+ } else {
417
+ await (0, _zx.$)`npm install --prefix ${packagePath}`;
418
+ }
419
+ } else {
420
+ await (0, _zx.$)`npm version --no-git-tag-version ${version}`.quiet().nothrow();
421
+ }
422
+ } catch (err) {
423
+ console.log(err.stderr || err);
424
+ process.exit(1);
425
+ }
426
+ };
427
+ const createNewBuildCommit = async ({
428
+ buildMessage
429
+ }) => {
430
+ try {
431
+ await (0, _zx.$)`git add .`;
432
+ await (0, _zx.$)`git commit --allow-empty -m ${buildMessage}`;
433
+ } catch (err) {
434
+ console.log(err.stderr || err);
435
+ process.exit(1);
436
+ }
437
+ };
438
+ const pushToGitRemote = async () => {
439
+ try {
440
+ await (0, _zx.$)`git push`;
441
+ } catch (err) {
442
+ console.log(err.stderr || err);
443
+ process.exit(1);
444
+ }
445
+ };
446
+ const commitAndPushNewBuild = async config => {
447
+ const {
448
+ buildMessage,
449
+ noConfirm
450
+ } = config;
451
+ const confirmAnswer = noConfirm || (await confirmPushCommit(buildMessage));
452
+ if (!confirmAnswer) {
453
+ console.log('Aborting...');
454
+ process.exit();
455
+ }
456
+ await updateNpmPackageJsonAndLock(config);
457
+ await createNewBuildCommit(config);
458
+ await pushToGitRemote();
459
+ };
460
+ const confirmPushTag = async (tagName, annotationMessage) => {
461
+ const {
462
+ confirm
463
+ } = await prompt([{
464
+ type: 'confirm',
465
+ name: 'confirm',
466
+ message: `${_ansiColors.default.bold.red('[Warning]')} Push new tag ${_ansiColors.default.bold.yellow(tagName)} with annotation message "${_ansiColors.default.bold.yellow(annotationMessage)}" to git remote?`
467
+ }]);
468
+ return confirm;
469
+ };
470
+ const createGitTag = async (tagName, annotationMessage) => {
471
+ try {
472
+ await (0, _zx.$)`git tag -a ${tagName} -m "${annotationMessage}"`;
473
+ } catch (err) {
474
+ console.log(err.stderr || err);
475
+ process.exit(1);
476
+ }
477
+ };
478
+ const pushGitTag = async tagName => {
479
+ try {
480
+ await (0, _zx.$)`git push origin ${tagName}`;
481
+ } catch (err) {
482
+ console.log(err.stderr || err);
483
+ process.exit(1);
484
+ }
485
+ };
486
+ const createAndPushGitTag = async ({
487
+ tagName,
488
+ annotationMessage,
489
+ noConfirm
490
+ }) => {
491
+ const confirmAnswer = noConfirm || (await confirmPushTag(tagName, annotationMessage));
492
+ if (confirmAnswer) {
493
+ await createGitTag(tagName, annotationMessage);
494
+ await pushGitTag(tagName);
495
+ }
496
+ };
497
+ const confirmPublishToNpmjs = async (version, npmjsTag) => {
498
+ const {
499
+ confirm
500
+ } = await prompt([{
501
+ type: 'confirm',
502
+ name: 'confirm',
503
+ message: `${_ansiColors.default.bold.red('[Warning]')} Publish new version ${_ansiColors.default.bold.yellow(version)} to npmjs with tag ${_ansiColors.default.bold.yellow(npmjsTag)}?`
504
+ }]);
505
+ return confirm;
506
+ };
507
+ const publishToNpmjs = async ({
508
+ version,
509
+ npmjsTag,
510
+ noConfirm
511
+ }) => {
512
+ const confirmAnswer = noConfirm || (await confirmPublishToNpmjs(version, npmjsTag));
513
+ if (!confirmAnswer) {
514
+ console.log('Aborting...');
515
+ process.exit();
516
+ }
517
+ try {
518
+ await (0, _zx.$)`npm publish --tag ${npmjsTag}`;
519
+ } catch (err) {
520
+ console.log(err.stderr || err);
521
+ process.exit(1);
522
+ }
523
+ };
524
+ const displayReleaseInfo = config => {
525
+ const {
526
+ branch,
527
+ version,
528
+ repositoryRoot,
529
+ packageName,
530
+ packagePath,
531
+ buildMessage,
532
+ tagName,
533
+ annotationMessage,
534
+ publishable,
535
+ npmjsTag,
536
+ isBetaRelease,
537
+ noGitTag
538
+ } = config;
539
+ console.log(`
540
+
541
+ ${_ansiColors.default.bold.green('============ Tag Release Summary ============')}
542
+ ${_ansiColors.default.blue('Branch:')} ${branch}
543
+ ${_ansiColors.default.blue('Version:')} ${version}
544
+ ${_ansiColors.default.blue('Root directory:')} ${repositoryRoot}
545
+ ${_ansiColors.default.blue('Package name:')} ${packageName}
546
+ ${_ansiColors.default.blue('package.json path:')} ${_nodePath.default.join(packagePath, 'package.json')}${buildMessage ? `
547
+ ${_ansiColors.default.blue('Commit message:')} ${buildMessage}` : ''}${isBetaRelease || noGitTag ? '' : `
548
+ ${_ansiColors.default.blue('Git tag:')} ${tagName}`}${isBetaRelease || noGitTag ? '' : `
549
+ ${_ansiColors.default.blue('Git tag annotation:')} ${annotationMessage}`}${publishable ? `
550
+ ${_ansiColors.default.blue('Npmjs tag:')} ${npmjsTag}` : ''}
551
+ ${_ansiColors.default.bold.green('=============================================')}
552
+ `);
553
+ };
554
+
555
+ /**
556
+ * Script
557
+ */
558
+
559
+ const optionList = [{
560
+ name: 'branch',
561
+ type: String,
562
+ alias: 'b',
563
+ description: 'branch where the tag will be created'
564
+ }, {
565
+ name: 'npmjs-tag',
566
+ type: String,
567
+ alias: 'n',
568
+ description: 'npmjs package tag to be used when publishing (for npmjs lib repositories)',
569
+ typeLabel: 'alpha|beta|latest'
570
+ }, {
571
+ name: 'version',
572
+ type: String,
573
+ alias: 'v',
574
+ description: 'version to be tagged'
575
+ }, {
576
+ name: 'publishable',
577
+ type: Boolean,
578
+ alias: 'p',
579
+ description: 'flag to indicate the repository is publishable to npmjs'
580
+ }, {
581
+ name: 'package-path',
582
+ type: String,
583
+ alias: 'a',
584
+ description: 'relative path to the package from the projec\'s root in case it\'s a monorepo'
585
+ }, {
586
+ name: 'tag-suffix',
587
+ type: String,
588
+ alias: 't',
589
+ description: 'tag suffix to be appended to the version when pushing to git'
590
+ }, {
591
+ name: 'annotation-message',
592
+ type: String,
593
+ alias: 'm',
594
+ description: 'annotation message that will annotate the git tag'
595
+ }, {
596
+ name: 'branch-filter',
597
+ type: String,
598
+ alias: 'f',
599
+ description: 'branch filter used to filter available branches in interactive mode'
600
+ }, {
601
+ name: 'no-commit',
602
+ type: Boolean,
603
+ description: 'do not create a new commit on git (in case the goal is just tagging it)'
604
+ }, {
605
+ name: 'no-git-tag',
606
+ type: Boolean,
607
+ description: 'do not create a new tag on git'
608
+ }, {
609
+ name: 'no-confirm',
610
+ type: Boolean,
611
+ description: 'push to git and publish to npmjs without asking for confirmation'
612
+ }, {
613
+ name: 'help',
614
+ type: Boolean,
615
+ alias: 'h',
616
+ description: 'show this help'
617
+ }];
618
+ const sections = [{
619
+ header: 'Tag release script',
620
+ content: 'This script is intended to give users a simple way to create git tags, push them and publish to Npmjs (if the --publishable flag is passed)'
621
+ }, {
622
+ header: 'Options',
623
+ optionList
624
+ }];
625
+ const args = (0, _commandLineArgs.default)(optionList, {
626
+ partial: true
627
+ });
628
+ const help = (0, _commandLineUsage.default)(sections);
629
+ if (args.help) {
630
+ console.log(help);
631
+ process.exit();
632
+ }
633
+ validateArgs(args);
634
+ const config = {};
635
+ config.noConfirm = !!args['no-confirm'];
636
+ config.noCommit = !!args['no-commit'];
637
+ config.noGitTag = !!args['no-git-tag'];
638
+ config.repositoryRoot = await getGitRootDirectory();
639
+ config.branch = args.branch || (await getBranch({
640
+ branchFilter: args['branch-filter']
641
+ }));
642
+ await checkoutToBranch(config);
643
+ const argsPackagePath = args['package-path'] && _nodePath.default.join(config.repositoryRoot, args['package-path']);
644
+ config.packagePath = argsPackagePath || (await getPackagePath(config));
645
+ config.isPackageInRepositoryRoot = await isPackageInRepositoryRoot(config);
646
+ config.version = args.version || (await getVersion(config));
647
+ config.packageName = await getPackageName(config);
648
+ config.buildMessage = config.noCommit ? '' : getBuildMessage(config);
649
+ config.isBetaRelease = config.version.includes('-beta.');
650
+ if (!config.isBetaRelease && !config.noGitTag) {
651
+ const tagSuffix = args['tag-suffix'] ?? (await getGitTagSuffix());
652
+ const tagPrefix = config.isPackageInRepositoryRoot ? '' : `${config.packageName}/`;
653
+ config.tagName = `${tagPrefix}v${config.version}${tagSuffix}`;
654
+ const annotationMessage = args['annotation-message'] ?? (await getGitAnnotationMessage(config));
655
+ config.annotationMessage = annotationMessage;
656
+ }
657
+ config.publishable = !!args.publishable;
658
+ if (config.publishable) {
659
+ validateNpmjsTag({
660
+ config,
661
+ args
662
+ });
663
+ config.npmjsTag = args['npmjs-tag'] || (await promptForNpmjsTag(config));
664
+ }
665
+ displayReleaseInfo(config);
666
+ if (!config.noConfirm) {
667
+ const confirmResponse = await confirmTagRelease(config);
668
+ if (confirmResponse === 'yes') {
669
+ config.noConfirm = true;
670
+ }
671
+ }
672
+ if (!config.noCommit) {
673
+ await commitAndPushNewBuild(config);
674
+ }
675
+ if (!config.isBetaRelease && !config.noGitTag) {
676
+ await createAndPushGitTag(config);
677
+ }
678
+ if (config.publishable) {
679
+ await publishToNpmjs(config);
680
+ }
681
+ process.exit();