-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
117 lines (98 loc) · 2.45 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
'use strict';
const gulp = require('gulp');
const githubRelease = require('gulp-github-release-maker');
const runTask = require('./run-tasks');
const git = require('gulp-git');
gulp.task('release:changelog', function (done) {
githubRelease.showChangelog(done);
});
gulp.task('release:do:patch', function (done) {
githubRelease.createRelease({ type: 'patch' }, done);
});
gulp.task('release:do:minor', function (done) {
githubRelease.createRelease({ type: 'minor' }, done);
});
gulp.task('release:do:major', function (done) {
githubRelease.createRelease({ type: 'major' }, done);
});
/**
* Wrap gulp-github-release-maker in a promise
*
* @param {any} type
* @returns
*/
function releaseReturnPromise (type) {
return new Promise((resolve, reject) => {
githubRelease.createRelease({ type: type }, (err, result)=> {
if (err) {
reject(err);
}
resolve(result);
});
})
}
/**
* Check if deploying for heroku or firebase
*
* @param {any} argv
* @returns
*/
function getDeployType(argv) {
let deployType = 'heroku';
return (argv.indexOf('--firebase') > -1) ? 'firebase' : deployType;
}
/**
* pull semver to increment from cli option
*
* @param {any} argv
* @returns
*/
function getVersionType (argv) {
let versionType = 'patch';
versionType = (argv.indexOf('--major') > -1) ? 'major' : versionType;
versionType = (argv.indexOf('--minor') > -1) ? 'minor' : versionType;
return versionType;
}
/**
* Check if on master
*/
gulp.task('check-master', function (done) {
git.exec({
args: 'rev-parse --abbrev-ref HEAD',
quiet: true
}, (err, stdout) => {
if (err) {
throw err;
}
if (stdout.trim() === 'master') {
done();
return;
}
done(new Error(`You must be on \`master\` branch to tag and deploy. Currently on branch: ${stdout}.`));
});
})
/**
* Build, tag, and publish
*/
gulp.task('deploy', ['check-master'], function (done) {
const versionType = getVersionType(process.argv);
const deployType = getDeployType(process.argv);
runTask('build', {DEBUG: false, NO_HMR: true})
.then(() => {
return releaseReturnPromise(versionType);
})
.then(() => {
if (deployType === 'firebase') {
return runTask('publish-post-tag', {DEBUG: false, NO_HMR: true})
} else {
console.log('Finished prep for deployment');
return true;
}
})
.then(() => {
done();
})
.catch((err) => {
done(err);
});
});