-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.js
117 lines (93 loc) · 3.57 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var debug = require('gulp-debug');
var del = require('del');
var merge = require('merge-stream');
var path = require('path');
var shell = require('shelljs');
var minimist = require('minimist');
var semver = require('semver');
var fs = require('fs');
var _buildRoot = path.join(__dirname, '_build');
var _packagesRoot = path.join(__dirname, '_packages');
gulp.task('default', ['build']);
gulp.task('build', ['clean'], function () {
var extension = gulp.src(['README.md', 'LICENSE.txt', 'images/**/*', '!images/**/*.pdn', 'vss-extension.json'], { base: '.' })
.pipe(debug({title: 'extension:'}))
.pipe(gulp.dest(_buildRoot));
var task = gulp.src('task/**/*', { base: '.' })
.pipe(debug({title: 'task:'}))
.pipe(gulp.dest(_buildRoot));
return merge(extension, task);
});
gulp.task('clean', function() {
return del([_buildRoot]);
});
gulp.task('test', ['build'], function() {
});
gulp.task('package', ['build'], function() {
var args = minimist(process.argv.slice(2), {});
var options = {
version: args.version,
stage: args.stage,
public: args.public,
private: args.private,
taskId: args.taskId
}
if (options.version) {
if (options.version === 'auto') {
var ref = new Date(2000, 1, 1);
var now = new Date();
var major = 0
var minor = Math.floor((now - ref) / 86400000);
var patch = Math.floor(Math.floor(now.getSeconds() + (60 * (now.getMinutes() + (60 * now.getHours())))) * 0.5)
options.version = major + '.' + minor + '.' + patch
}
if (!semver.valid(options.version)) {
throw new gutil.PluginError('package', 'Invalid semver version: ' + options.version);
}
}
switch (options.stage) {
case 'dev':
options.taskId = '0664FF86-F509-4392-A33C-B2D9239B9AE5';
options.public = false;
options.private = false;
break;
}
updateExtensionManifest(options);
updateTaskManifest(options);
shell.exec('tfx extension create --root "' + _buildRoot + '" --output-path "' + _packagesRoot +'"')
});
updateExtensionManifest = function(options) {
var manifestPath = path.join(_buildRoot, 'vss-extension.json')
var manifest = JSON.parse(fs.readFileSync(manifestPath));
if (options.version) {
manifest.version = options.version;
}
if (options.stage) {
manifest.id = manifest.id + '-' + options.stage
manifest.name = manifest.name + ' (' + options.stage + ')'
}
manifest.public = options.public;
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 4));
}
updateTaskManifest = function(options) {
var manifestPath = path.join(_buildRoot, 'task', 'task.json')
var manifest = JSON.parse(fs.readFileSync(manifestPath));
if (options.version) {
manifest.version.Major = semver.major(options.version);
manifest.version.Minor = semver.minor(options.version);
manifest.version.Patch = semver.patch(options.version);
}
if (options.stage) {
manifest.friendlyName = manifest.friendlyName + ' (' + options.stage
if (options.version) {
manifest.friendlyName = manifest.friendlyName + ' ' + options.version
}
manifest.friendlyName = manifest.friendlyName + ')'
}
if (options.taskId) {
manifest.id = options.taskId
}
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 4));
}