-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
121 lines (108 loc) · 2.6 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
require('dotenv').config();
const { series, src, dest } = require('gulp');
const rename = require('gulp-rename');
const git = require('gulp-git');
const conventionalGithubReleaser = require('conventional-github-releaser');
const fs = require('fs');
const bump = require('gulp-bump');
const color = require('gulp-color');
const devBuild =
(process.env.NODE_ENV || 'development').trim().toLowerCase() ===
'development';
const customer = process.env.CUSTOMER;
console.log(color(`Customer is ${customer}`, 'GREEN'));
const release =
(process.env.RELEASE || 'deploy').trim().toLowerCase() === 'release';
console.log(
color('Creating release', 'GREEN'),
color(release.toString(), 'RED'),
);
function setupConfig(done) {
done();
}
function commitChanges(done) {
if (!release) {
console.log(color('Skipping commit step', 'BLUE'));
done();
return;
}
return src('.')
.pipe(git.add())
.pipe(git.commit('Auto-deploy bumped version number'));
}
function pushChanges(done) {
if (!release) {
console.log(color('Skipping push step', 'BLUE'));
done();
return;
}
git.push('origin', 'master', done);
}
function githubRelease(done) {
if (!release) {
console.log(color('Skipping release step', 'BLUE'));
done();
return;
}
const AUTH = {
type: 'oauth',
token: process.env.GITHUB_KEY,
url: 'https://api.github.com',
};
conventionalGithubReleaser(
AUTH,
{
preset: '', // Or to any other commit message convention you use.
},
done,
);
}
function getPackageJsonVersion() {
// We parse the json file instead of using require because require caches
// multiple calls so the version number won't be updated
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
}
function createNewTag(done) {
if (!release) {
console.log(color('Skipping tag step', 'BLUE'));
done();
return;
}
let version = getPackageJsonVersion();
git.tag(version, 'Created Tag for version: ' + version, function (error) {
if (error) {
return done(error);
}
git.push(
'origin',
'master',
{
args: '--tags',
},
done,
);
});
}
function bumpVersion(done) {
if (!release) {
console.log(color('Skipping bumpVersion step', 'BLUE'));
done();
return;
}
src('./package.json')
.pipe(
bump({
type: process.env.RELEASE_TYPE ? process.env.RELEASE_TYPE : 'patch',
}),
)
.pipe(dest('./'));
return Promise.resolve('version bumped');
}
exports.default = series(
setupConfig,
bumpVersion,
commitChanges,
pushChanges,
createNewTag,
githubRelease,
);