forked from microsoft/vsts-tomcat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
113 lines (99 loc) · 3.5 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
var del = require("del");
var fs = require('fs');
var gulp = require("gulp");
var istanbul = require("gulp-istanbul");
var mocha = require("gulp-mocha");
var path = require("path");
var shell = require("shelljs");
var tsb = require("gulp-tsb");
var tslint = require("gulp-tslint");
var buildDirectory = "_build";
var srcBuildDirectory = "_build/src";
var codeCoverageDirectory = buildDirectory + "/codeCoverage";
var packageDirectory = buildDirectory + "/package";
var sourcePaths = {
typescriptFiles: "src/**/*.ts",
copyFiles: ["src/**/*.png", "src/**/*.json", "src/**/*.md", "src/tasks/**/invoke*.js"],
tasksPath: "src/tasks"
};
var testPaths = {
typescriptFiles: "tests/**/*.ts",
compiledTestFiles: buildDirectory + "/tests/**/*Tests.js"
};
var packageManifestFile = "vss-extension.json";
var nodeModulesDirectory = "node_modules";
var compilation = tsb.create({
target: 'es5',
module: 'commonjs',
declaration: false,
verbose: false
});
exports.clean = gulp.series(clean);
exports.lint = gulp.series(clean, lint);
exports.compile = gulp.series(clean, lint, compile);
exports.build = gulp.series(clean, lint, compile, build);
exports.test = gulp.series(clean, lint, compile, build, test);
exports.package = gulp.series(clean, lint, compile, build, test, package);
exports.default = gulp.series(clean, lint, compile, build, test);
function clean() {
return del([buildDirectory]);
}
function lint() {
return gulp.src([sourcePaths.typescriptFiles, testPaths.typescriptFiles])
.pipe(tslint({ formatter: "verbose" }))
.pipe(tslint.report());
}
function compile() {
return gulp.src([sourcePaths.typescriptFiles, testPaths.typescriptFiles], { base: "." })
.pipe(compilation())
.pipe(gulp.dest(buildDirectory))
.pipe(istanbul({includeUntested: true}))
.pipe(istanbul.hookRequire());
}
function build() {
return gulp.src(sourcePaths.copyFiles, { base: "." })
.pipe(gulp.dest(buildDirectory));
}
function test() {
return gulp.src(testPaths.compiledTestFiles, {read: false})
.pipe(mocha());
}
async function package() {
return getNodeDependencies(function() {
copyNodeModulesToTasks();
createVsixPackage();
});
}
var getNodeDependencies = function(callback) {
del(packageDirectory);
shell.mkdir("-p", path.join(packageDirectory, nodeModulesDirectory));
shell.cp("-f", "package.json", packageDirectory);
shell.pushd(packageDirectory);
var npmPath = shell.which("npm");
var npmInstallCommand = '"' + npmPath + '" install --production';
executeCommand(npmInstallCommand, function() {
shell.popd();
callback();
});
}
var copyNodeModulesToTasks = function() {
fs.readdirSync(sourcePaths.tasksPath).forEach(function(taskName) {
var taskpath = path.join(buildDirectory, sourcePaths.tasksPath, taskName);
del(path.join(taskpath, nodeModulesDirectory));
shell.cp("-rf", path.join(packageDirectory, nodeModulesDirectory), taskpath);
});
}
var createVsixPackage = function() {
var packagingCmd = "tfx extension create --manifeset-globs " + packageManifestFile + " --root " + srcBuildDirectory + " --output-path " + packageDirectory;
executeCommand(packagingCmd, function() {});
}
var executeCommand = function(cmd, callback) {
shell.exec(cmd, {silent: true}, function(code, output) {
if(code != 0) {
console.error("command failed: " + cmd + "\nManually execute to debug");
}
else {
callback();
}
});
}