This repository was archived by the owner on May 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
140 lines (126 loc) · 4.23 KB
/
gulpfile.js
File metadata and controls
140 lines (126 loc) · 4.23 KB
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
137
138
139
140
"use strict";
var gulp = require('gulp');
var runSequence = require('run-sequence');
var conventionalChangelog = require('gulp-conventional-changelog');
var bump = require('gulp-bump');
var gutil = require('gulp-util');
var insert = require('gulp-insert');
var trim = require('gulp-trim');
var xmlpoke = require('gulp-xmlpoke');
var replace = require('gulp-replace');
var assemblyInfo = require('gulp-dotnet-assembly-info');
var git = require('gulp-git');
var fs = require('fs');
var es = require('event-stream');
function getVersion(format) {
var version = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
if (format) {
var match = /((?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*))(?:-([\da-z\-]+)\.(0|[1-9][0-9]?))?/i.exec(version);
if (format === 'nuget') {
if (match[2]) {
version = match[1] + '-' + match[2] + ('0' + match[3]).slice(-2);
}
} else if (format === 'no-pr') {
version = match[1];
}
}
return version;
}
gulp.task('bump-version', function () {
var type = 'patch';
var types = ['major', 'minor', 'patch', 'prerelease'];
for (var i = 0; i < 4; i++) {
if (process.argv.indexOf('--' + types[i]) > -1) {
type = types[i];
break;
}
}
return gulp.src(['./package.json'])
.pipe(bump({ type: type, preid: 'prerelease' }).on('error', gutil.log))
.pipe(gulp.dest('.'));
});
gulp.task('changelog', function () {
return gulp.src('CHANGELOG.md', { buffer: false })
.pipe(conventionalChangelog({ preset: 'angular' }))
.pipe(gulp.dest('.'));
});
gulp.task('releasenotes', function () {
return gulp.src('RELEASENOTES.md')
.pipe(insert.transform(function () { return ''; }))
.pipe(conventionalChangelog({ preset: 'angular' }, {}, {}, {}, { headerPartial: '' }))
.pipe(trim())
.pipe(gulp.dest('.'));
});
gulp.task('update-nuspec', function () {
var version = getVersion('nuget');
return gulp.src('NuGet.nuspec')
.pipe(xmlpoke({
replacements: [
{ xpath: '/x:package/x:metadata/x:version', namespaces: { "x": "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" }, value: version }
]
}))
.pipe(gulp.dest('./'));
});
gulp.task('update-setup', function () {
var version = getVersion('no-pr');
return gulp.src('./SMLogging.Setup/Product.wxs')
.pipe(xmlpoke({
replacements: [
{ xpath: '/x:Wix/x:Product/@Version', namespaces: { "x": "http://schemas.microsoft.com/wix/2006/wi" }, value: version }
]
}))
.pipe(gulp.dest('./SMLogging.Setup/'));
});
gulp.task('update-assemblyinfo', function () {
var version = getVersion('no-pr');
return gulp.src('**/AssemblyInfo.cs')
.pipe(assemblyInfo({
version: version + '.0',
fileVersion: version + '.0'
}))
.pipe(gulp.dest('.'));
});
gulp.task('update-appveyor', function () {
var version = getVersion('no-pr');
return gulp.src('./appveyor.yml')
.pipe(replace(/VERSION_PREFIX:.*/, 'VERSION_PREFIX: ' + version))
.pipe(gulp.dest('.'));
});
gulp.task('commit-changes', function () {
return gulp.src('.')
.pipe(git.add())
.pipe(git.commit('chore(release): bump version, update changelog'));
});
gulp.task('push-changes', function (cb) {
return git.push('origin', 'master', cb);
});
gulp.task('create-new-tag', function (cb) {
var version = getVersion();
return git.tag(version, 'create tag for version: ' + version, function (error) {
if (error) {
return cb(error);
}
return git.push('origin', 'master', { args: '--tags' }, cb);
});
});
gulp.task('release', function (callback) {
runSequence(
'bump-version',
'changelog',
'releasenotes',
'update-nuspec',
'update-setup',
'update-assemblyinfo',
'update-appveyor',
'commit-changes',
'push-changes',
'create-new-tag',
function (error) {
if (error) {
console.log(error.message);
} else {
console.log('Release successful');
}
callback(error);
});
});