This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
forked from bigcommerce/stencil-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
136 lines (122 loc) · 5.01 KB
/
gulpfile.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
'use strict';
require('colors');
require('path');
const bump = require('gulp-bump');
const changelog = require('./tasks/changelog');
const constants = require('./constants');
const currentVersion = constants.packageInfo.version;
const exec = require('gulp-exec');
const git = require('gulp-git-streamed');
const gulp = require('gulp');
const gulpif = require('gulp-if');
const gutil = require('gulp-util');
const supportedLockFileVersion = [1];
const prompt = require('gulp-prompt');
const semver = require('semver');
let branch;
let remote;
let responses;
let targetVersion;
function installPrivateDependencies() {
return gulp.src('package.json')
.pipe(exec('npm run install-private-dependencies'), logError)
.on('error', logError);
}
function bumpTask() {
const questions = [{
type: 'list',
name: 'type',
message: 'What type of release would you like to do?',
choices: [{
value: 'patch',
name: 'Patch: '.yellow + semver.inc(currentVersion, 'patch').yellow + ' Backwards-compatible bug fixes.',
}, {
value: 'minor',
name: 'Minor: '.yellow + semver.inc(currentVersion, 'minor').yellow + ' Component release or significant update to existing one.',
}, {
value: 'major',
name: 'Major: '.yellow + semver.inc(currentVersion, 'major').yellow + ' Major UI refresh.',
}, {
value: 'custom',
name: 'Custom: ?.?.?'.yellow + ' Specify version...',
}],
}, {
type: 'input',
name: 'custom-version',
message: 'What specific version would you like',
when: answers => answers['type'] === 'custom',
validate: value => {
const valid = semver.valid(value) && true;
return valid || 'Must be a valid semver, such as 1.2.3';
},
}, {
name: 'confirmPush',
type: 'confirm',
message: 'Do you want to push this new tag?',
}, {
name: 'pushTo',
type: 'input',
message:'Where would you like to push to?',
default: 'origin master',
when: answers => answers['confirmPush'],
validate: pushResponse => pushResponse.split(' ').length === 2,
}];
return gulp.src('package.json')
.pipe(prompt.prompt(questions, res => {
const pushToSplit = res.pushTo.split(' ');
remote = pushToSplit[0];
branch = pushToSplit[1];
targetVersion = (res.type !== 'custom') ? semver.inc(currentVersion, res.type) : res['custom-version'];
responses = res;
const packageLock = require('./package-lock.json');
if (!supportedLockFileVersion.includes(packageLock["lockfileVersion"])) {
throw new Error(`Release script only supports version ${supportedLockFileVersion}`);
}
return gulp.src(['package.json', 'package-lock.json'])
// bump the version number in those files
.pipe(bump({ version: targetVersion }))
// save it back to filesystem
.pipe(gulp.dest(process.cwd()))
// change last modified date
.pipe(exec('touch -c package.json'))
// Fetch Remote Tags
.pipe(git.exec({ args: `fetch ${remote} --tags` }, logError));
}))
.on('error', logError);
}
function deployWebpack() {
return gulp.src('package.json')
.pipe(exec('npm run deploy'), logError)
.on('error', logError);
}
function uninstallPrivateDependencies() {
return gulp.src('package.json')
.pipe(exec('npm run uninstall-private-dependencies'), logError)
.on('error', logError);
}
function pushTask() {
return gulp.src(['package.json', 'package-lock.json', 'CHANGELOG.md', 'server/plugins/stencil-editor/public/dist/app.js', 'server/plugins/stencil-editor/public/dist/ng-stencil-editor/css/ng-stencil-editor.min.css', 'server/plugins/stencil-editor/public/dist/stencil-preview-sdk.js'])
// Add files
.pipe(git.add())
// Commit the changed version number
.pipe(git.commit(`docs(release): releasing ${targetVersion}`))
// Create a Tag
.pipe(git.tag(targetVersion, targetVersion, logError))
// Push Changes
.pipe(gulpif(responses.confirmPush, git.push(remote, branch, logError)))
// Push Tags
.pipe(gulpif(responses.confirmPush, git.push(remote, branch, { args: '--follow-tags' }, logError)))
.on('error', logError);
}
function logError(err) {
if (err) {
gutil.log(err);
}
}
gulp.task('install-private-dependencies', installPrivateDependencies);
gulp.task('bump', bumpTask);
gulp.task('deploy-webpack', deployWebpack);
gulp.task('changelog', (done) => changelog.changelogTask({}, done));
gulp.task('uninstall-private-dependencies', uninstallPrivateDependencies);
gulp.task('push', pushTask);
gulp.task('release', gulp.series('install-private-dependencies', 'bump', 'deploy-webpack', 'changelog', 'uninstall-private-dependencies', 'push'));