/
prepare.js
168 lines (160 loc) · 4.42 KB
/
prepare.js
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
import { getAppName, loadConfig, getReleaseType } from 'shipjs-lib';
import printHelp from '../step/prepare/printHelp';
import printDryRunBanner from '../step/printDryRunBanner';
import validate from '../step/prepare/validate';
import getRevisionRange from '../step/prepare/getRevisionRange';
import pull from '../step/pull';
import fetchTags from '../step/prepare/fetchTags';
import push from '../step/prepare/push';
import getNextVersion from '../step/prepare/getNextVersion';
import confirmNextVersion from '../step/prepare/confirmNextVersion';
import prepareStagingBranch from '../step/prepare/prepareStagingBranch';
import checkoutToStagingBranch from '../step/prepare/checkoutToStagingBranch';
import updateVersion from '../step/prepare/updateVersion';
import updateVersionMonorepo from '../step/prepare/updateVersionMonorepo';
import installDependencies from '../step/prepare/installDependencies';
import updateChangelog from '../step/prepare/updateChangelog';
import commitChanges from '../step/prepare/commitChanges';
import createPullRequest from '../step/prepare/createPullRequest';
import notifyPrepared from '../step/prepare/notifyPrepared';
import pushToStagingBranch from '../step/prepare/pushToStagingBranch';
import validatePreparationConditions from '../step/prepare/validatePreparationConditions';
import checkGitHubToken from '../step/checkGitHubToken';
import finished from '../step/prepare/finished';
import { print } from '../util';
import { warning } from '../color';
async function prepare({
help = false,
dir = '.',
yes = false,
firstRelease = false,
releaseCount,
dryRun = false,
noBrowse = false,
commitFrom,
}) {
if (help) {
printHelp();
return;
}
if (dryRun) {
printDryRunBanner();
}
printDeprecated({ firstRelease, releaseCount });
checkGitHubToken({ dryRun });
const config = await loadConfig(dir);
const { currentVersion, baseBranch } = validate({ config, dir });
const { remote, forcePushBranches } = config;
pull({ remote, currentBranch: baseBranch, dir, dryRun });
fetchTags({ dir, dryRun });
push({ remote, currentBranch: baseBranch, forcePushBranches, dir, dryRun });
const currentTag = config.getTagName({ version: currentVersion });
const { revisionRange } = await getRevisionRange({
yes,
commitFrom,
currentTag,
dir,
});
let { nextVersion } = getNextVersion({
config,
revisionRange,
currentVersion,
dir,
});
nextVersion = await confirmNextVersion({
yes,
currentVersion,
nextVersion,
dryRun,
});
const releaseType = getReleaseType(nextVersion);
await validatePreparationConditions({
config,
releaseType,
nextVersion,
revisionRange,
dir,
dryRun,
});
const { stagingBranch } = prepareStagingBranch({
config,
nextVersion,
releaseType,
dir,
});
checkoutToStagingBranch({ stagingBranch, dir, dryRun });
const updateVersionFn = config.monorepo
? updateVersionMonorepo
: updateVersion;
await updateVersionFn({ config, nextVersion, releaseType, dir, dryRun });
installDependencies({ config, dir, dryRun });
await updateChangelog({
config,
revisionRange,
firstRelease,
nextVersion,
releaseCount,
dir,
dryRun,
});
await commitChanges({
nextVersion,
releaseType,
dir,
config,
baseBranch,
dryRun,
});
pushToStagingBranch({ remote, stagingBranch, dir, dryRun });
const { pullRequestUrl } = await createPullRequest({
baseBranch,
stagingBranch,
currentVersion,
currentTag,
nextVersion,
releaseType,
noBrowse,
config,
dir,
dryRun,
});
const appName = await getAppName(dir);
await notifyPrepared({
config,
appName,
version: nextVersion,
pullRequestUrl,
});
finished({ baseBranch, stagingBranch, pullRequestUrl, dryRun });
}
const arg = {
'--dir': String,
'--yes': Boolean,
'--help': Boolean,
'--first-release': Boolean,
'--release-count': Number,
'--dry-run': Boolean,
'--no-browse': Boolean,
'--commit-from': String,
// Aliases
'-d': '--dir',
'-y': '--yes',
'-h': '--help',
'-f': '--first-release',
'-r': '--release-count',
'-D': '--dry-run',
'-N': '--no-browse',
'-c': '--commit-from',
};
function printDeprecated({ firstRelease, releaseCount }) {
if (firstRelease) {
print(warning(`DEPRECATED: --first-release, -f`));
}
if (releaseCount) {
print(warning(`DEPRECATED: --release-count, -r`));
}
}
export default {
arg,
fn: prepare,
};