/
release.js
285 lines (256 loc) · 7.61 KB
/
release.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
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
/*
* ADOBE CONFIDENTIAL
*
* Copyright 2017 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe.
*/
module.exports = function(gulp) {
const fs = require('fs');
const exec = require('child_process').exec;
const spawn = require('child_process').spawn;
const runSequence = require('run-sequence').use(gulp);
const del = require('del');
const inq = require('inquirer');
const semver = require('semver');
const gutil = require('gulp-util');
const git = require('gulp-git');
const bump = require('gulp-bump');
const util = require('../helpers/util');
const root = util.getRoot();
const CWD = process.cwd();
let modulePackageJson = util.getPackageJSON();
const registry = 'https://artifactory.corp.adobe.com/artifactory/api/npm/npm-coralui-local';
// The version we'll actually release
let releaseVersion;
// Push current branch commits to origin
gulp.task('push', function(cb) {
// Get the current branch name
exec('git rev-parse --abbrev-ref HEAD', function(err, stdout, stderr) {
if (err) {
console.error(stderr);
}
else {
const currentBranch = stdout.trim();
git.push('origin', currentBranch, function(err) {
if (err) {
console.error(err.message);
}
cb();
});
}
});
});
// Publish release to artifactory
gulp.task('npm-publish', function(cb) {
exec(`npm publish --registry=${registry}`, function(err, stdout, stderr) {
if (err) {
console.error(stderr);
}
else {
console.log(stdout);
cb();
}
});
});
// Tag and push release
gulp.task('tag-release', function(cb) {
// Read updated package.json
modulePackageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
releaseVersion = modulePackageJson.version;
const releaseMessage = `releng - Release ${releaseVersion}`;
git.tag(releaseVersion, releaseMessage, function(err) {
if (err) {
console.error(err.message);
}
git.push('origin', releaseVersion, function(err) {
if (err) {
console.error(err.message);
}
cb();
});
});
});
// Increase release version based on user choice
gulp.task('bump-version', function(cb) {
function doVersionBump() {
gulp.src([`${CWD}/package.json`, `${CWD}/package-lock.json`])
.pipe(bump({version: releaseVersion}))
.pipe(gulp.dest('./'))
.pipe(git.commit(`releng - Release ${releaseVersion}`));
cb();
}
const currentVersion = modulePackageJson.version;
// Potential versions
const patchVersion = semver.inc(currentVersion, 'patch');
const minorVersion = semver.inc(currentVersion, 'minor');
const majorVersion = semver.inc(currentVersion, 'major');
const preVersion = semver.inc(currentVersion, 'prerelease', 'beta');
const preMajorVersion = semver.inc(currentVersion, 'premajor', 'beta');
const preMinorVersion = semver.inc(currentVersion, 'preminor', 'beta');
const prePatchVersion = semver.inc(currentVersion, 'prepatch', 'beta');
// Command line bump shortcuts
if (gutil.env.pre) {
releaseVersion = preVersion;
}
else if (gutil.env.patch) {
releaseVersion = patchVersion;
}
else if (gutil.env.minor) {
releaseVersion = minorVersion;
}
else if (gutil.env.major) {
releaseVersion = majorVersion;
}
else if (gutil.env.prepatch) {
releaseVersion = prePatchVersion;
}
else if (gutil.env.preMinorVersion) {
releaseVersion = prePatchVersion;
}
else if (gutil.env.preMajorVersion) {
releaseVersion = prePatchVersion;
}
else if (gutil.env.releaseVersion) {
releaseVersion = gutil.env.releaseVersion;
}
if (releaseVersion) {
doVersionBump();
}
else {
let choices = [];
if (currentVersion.match('-beta')) {
choices = choices.concat([
{
name: 'prerelease - ' + preVersion,
value: preVersion
}
]);
}
if (patchVersion !== majorVersion) {
// Only provide these options if they're not identical
// These options will be identical if the current version is a beta of a major version
choices = choices.concat([
{
name: 'patch - ' + patchVersion,
value: patchVersion
},
{
name: 'minor - ' + minorVersion,
value: minorVersion
},
{
name: 'major - ' + majorVersion,
value: majorVersion
}
]);
}
else {
// Provide only the major version if the current version if a beta of a major version
choices = choices.concat([
{
name: 'major - ' + patchVersion,
value: patchVersion
}
]);
}
choices = choices.concat([
{
name: 'prepatch - ' + prePatchVersion,
value: prePatchVersion
},
{
name: 'preminor - ' + preMinorVersion,
value: preMinorVersion
},
{
name: 'premajor - ' + preMajorVersion,
value: preMajorVersion
},
{
name: 'custom',
value: 'custom'
}
]);
inq.prompt([{
type: 'list',
name: 'version',
message: `The current version is ${currentVersion}. What version would you like to release ?`,
choices: choices
}])
.then(function(res) {
if (res.version === 'custom') {
inq.prompt([{
type: 'input',
name: 'version',
message: 'What version would you like?'
}])
.then(function(res) {
releaseVersion = res.version;
doVersionBump();
});
}
else {
releaseVersion = res.version;
doVersionBump();
}
});
}
});
gulp.task('prepare', () => {
if (CWD !== root) {
console.error('Prepare aborted: not in root folder.');
return;
}
spawn(`
gulp build &&
gulp karma &&
gulp examples &&
gulp minify &&
cd coralui-component-playground && gulp build &&
cd .. &&
gulp playground &&
gulp docs &&
gulp push &&
gulp tag-release &&
gulp npm-publish
`, [], {shell: true, stdio: 'inherit'});
});
// Full release task
gulp.task('release', function() {
if (CWD !== root) {
console.error('Release aborted: not in root folder.');
return;
}
runSequence(
'bump-version',
function() {
// Command line shortcut
if (gutil.env.confirm) {
runSequence('prepare');
}
else {
inq.prompt({
type: 'confirm',
name: 'confirmed',
message: `Release ${releaseVersion} ?`
})
.then(function(res) {
if (res.confirmed) {
runSequence('prepare');
}
});
}
}
);
});
};