forked from eKoopmans/html2pdf.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
59 lines (52 loc) · 1.99 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
// Imports.
var gulp = require('gulp');
var util = require('util');
var exec = util.promisify(require('child_process').exec);
var minimist = require('minimist');
var fs = require('fs');
// Fetch command-line arguments.
var args = minimist(process.argv.slice(2), {
string: ['env', 'newversion', 'tagmessage'],
alias: { v: 'newversion', m: 'tagmessage' },
default: {
env: process.env.NODE_ENV || 'production',
newversion: 'patch',
tagmessage: ''
}
});
args.newversion = args.newversion || 'patch';
// Get package version from package.json.
function getVersion() {
var pkg = JSON.parse(fs.readFileSync('./package.json'));
return 'v' + pkg.version;
}
/* ----- TASKS ----- */
// Bump version using NPM (only affects package*.json, doesn't commit).
gulp.task('bump-version', function bumpVersion() {
console.log('Bumping version number.');
return exec('npm --no-git-tag-version version ' + args.newversion);
});
// Bump version, build, commit, tag, and merge into stable.
gulp.task('release', gulp.series('bump-version', function release() {
var version = getVersion();
var branch = 'master';
var cmd = 'git checkout ' + branch + ' && npm run build';
console.log('Running build process in master branch.');
return exec(cmd).then(function() {
console.log('Adding all changes and performing final commit.');
return exec('git add -A && git commit --allow-empty -m "Build ' + version + '"');
}).then(function () {
console.log('Tagging with provided tag message.');
return exec('git tag -a ' + version + ' -m "' + version + ' ' + args.tagmessage + '"');
}).then(function () {
console.log('Getting repo root location.');
return exec('git rev-parse --show-toplevel');
}).then(function (res) {
console.log('Pushing release to stable branch.');
var repoRoot = res.stdout.trim('\n');
return exec('git push --follow-tags ' + repoRoot + ' master:stable')
});
}));
gulp.task('publish-gh', function publishGH() {
return exec('git push origin master stable');
});