-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequired-missing-information.ts
103 lines (92 loc) · 2.77 KB
/
required-missing-information.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
import { ListrEnquirerPromptAdapter } from '@listr2/prompt-adapter-enquirer';
import { Listr, type ListrTask } from 'listr2';
import semver from 'semver';
import c from 'tinyrainbow';
import { NpmRegistry } from '../registry/npm.js';
import { packageName, version } from '../utils/package-json.js';
const { RELEASE_TYPES, SemVer, prerelease } = semver;
interface Ctx {
version?: string;
tag: string;
}
export const requiredMissingInformationTasks: (
options?: Omit<ListrTask<Ctx>, 'title' | 'task'>,
) => Listr<Ctx> = (options) =>
new Listr({
...options,
title: 'Checking required information',
task: (_, parentTask) =>
parentTask.newListr([
{
title: 'Checking version information',
skip: (ctx) => !!ctx.version,
task: async (ctx, task) => {
const currentVersion = await version();
let nextVersion = await task
.prompt(ListrEnquirerPromptAdapter)
.run<string>({
type: 'select',
message: 'Select SemVer increment or specify new version',
choices: RELEASE_TYPES.map((releaseType) => {
const increasedVersion = new SemVer(currentVersion)
.inc(releaseType)
.toString();
return {
message: `${releaseType} ${c.dim(increasedVersion)}`,
name: increasedVersion,
};
}).concat([
{ message: 'Custom version (specify)', name: 'specify' },
]),
name: 'version',
});
if (nextVersion === 'specify') {
nextVersion = await task
.prompt(ListrEnquirerPromptAdapter)
.run<string>({
type: 'input',
message: 'Version',
name: 'version',
});
}
ctx.version = nextVersion;
},
exitOnError: true,
},
{
title: 'Checking tag information',
skip: (ctx) => !prerelease(`${ctx.version}`) && ctx.tag === 'latest',
task: async (ctx, task) => {
const npm = new NpmRegistry(await packageName());
const distTags = [...(await npm.distTags())].filter(
(tag) => tag !== 'latest',
);
if (distTags.length <= 0) distTags.push('next');
let tag = await task
.prompt(ListrEnquirerPromptAdapter)
.run<string>({
type: 'select',
message: 'Select the tag for this pre-release version in npm',
choices: distTags
.map((distTag) => ({
message: distTag,
name: distTag,
}))
.concat([
{ message: 'Custom version (specify)', name: 'specify' },
]),
name: 'tag',
});
if (tag === 'specify') {
tag = await task.prompt(ListrEnquirerPromptAdapter).run<string>({
type: 'input',
message: 'Tag',
name: 'tag',
});
}
ctx.tag = tag;
},
exitOnError: true,
},
]),
});