-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
123 lines (112 loc) · 3.46 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
var buildConfig = require('./build.config.js');
var conventionalChangelog = require('gulp-conventional-changelog');
var conventionalGithubReleaser = require('conventional-github-releaser');
var git = require('gulp-git');
var gulp = require('gulp');
var pkg = require('./package.json');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
var template = require('gulp-template');
/**
* Load Test Tasks
*/
gulp.task('changelog', function() {
var dest = argv.dest || 'CHANGELOG.md';
var toHtml = !!argv.html;
return makeChangelog(argv).then(function(log) {
if (toHtml) {
log = marked(log, {
gfm: true
});
}
fs.writeFileSync(dest, log);
});
});
function makeChangelog(options) {
var file = options.standalone ? '' : __dirname + '/CHANGELOG.md';
var subtitle = options.subtitle || '';
var from = options.from;
var version = options.version || pkg.version;
return new Promise(function (resolve, reject) {
changelog({
repository: 'https://github.com/sloops77/ngChatScroller',
version: version,
subtitle: subtitle,
file: file,
from: from,
preset: 'angular',
}, function(err, log) {
if (err) reject(err);
else resolve(log);
});
});
}
gulp.task('version', function() {
var d = new Date();
var date = d.toISOString().substring(0,10);
var time = pad(d.getUTCHours()) +
':' + pad(d.getUTCMinutes()) +
':' + pad(d.getUTCSeconds());
return gulp.src('version.template.json')
.pipe(template({
pkg: pkg,
date: date,
time: time
}))
.pipe(rename('version.json'))
.pipe(gulp.dest(buildConfig.dist));
});
gulp.task('changelog', function () {
return gulp.src('CHANGELOG.md', {
buffer: false
})
.pipe(conventionalChangelog({
preset: 'angular' // Or to any other commit message convention you use.
}))
.pipe(gulp.dest('./'));
});
gulp.task('github-release', function(done) {
conventionalGithubReleaser({
type: "oauth",
token: process.env.GH_TOKEN
}, {
preset: 'angular' // Or to any other commit message convention you use.
}, done);
});
gulp.task('release', function (done) {
runSequence(
'version',
'changelog',
'commit-changes',
'push-changes',
'create-new-tag',
'github-release',
function (error) {
if (error) {
console.log(error.message);
} else {
console.log('RELEASE FINISHED SUCCESSFULLY');
}
done(error);
});
});
gulp.task('commit-changes', function () {
return gulp.src('.')
.pipe(git.add())
.pipe(git.commit('[Prerelease] Bumped version number'));
});
gulp.task('push-changes', function (cb) {
git.push('origin', 'master', cb);
});
gulp.task('create-new-tag', function (cb) {
git.tag(version, 'Created Tag for version: ' + pkg.version, function (error) {
if (error) {
return cb(error);
}
git.push('origin', 'master', { args: '--tags' }, cb);
});
});
function pad(n) {
if (n<10) { return '0' + n; }
return n;
}