-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
169 lines (147 loc) · 4.64 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
"use strict";
var fs = require("fs");
var path = require("path");
var del = require("del");
var eslint = require("gulp-eslint");
var gulp = require("gulp");
var istanbul = require("gulp-istanbul");
var mocha = require("gulp-mocha");
var plumber = require("gulp-plumber");
var shell = require("shelljs");
var gutil = require("gulp-util");
var merge = require("merge-stream");
var install = require("gulp-install");
// var executeCommand = (cmd, dir, done) => {
// gutil.log("Running command: " + cmd);
// var pwd = shell.pwd();
// if (undefined !== dir) {
// gutil.log(" Working directory: " + dir);
// shell.cd(dir);
// }
// shell.exec(cmd, { silent: true }, function (code, stdout, stderr) {
// gutil.log(" stdout: " + stdout);
// if (code !== 0) {
// gutil.log("Command failed: " + cmd + "\nManually execute to debug");
// gutil.log(" stderr: " + stderr);
// }
// shell.cd(pwd);
// done();
// });
// };
// var createVsixPackage = function (done) {
// if (!shell.which('tfx')) {
// gutil.log('Packaging requires tfx cli. Please install with `npm install tfx-cli -g`.');
// done();
// return;
// }
// var packagingCmd = 'tfx extension create --manifest-globs vss-extension.json --root dist/src --output-path dist';
// executeCommand(packagingCmd, shell.pwd(), done);
// };
// var getNodeDependencies = function (done) {
// gutil.log('Copy package.json to dist directory');
// shell.mkdir('-p', 'dist/node_modules');
// shell.cp('-f', 'package.json', 'dist');
// gutil.log('Fetch node modules to package with tasks');
// var npmPath = shell.which('npm');
// var npmInstallCommand = '"' + npmPath + '" install --production';
// executeCommand(npmInstallCommand, 'dist', done);
// };
// Tasks
gulp.task("lint", function () {
return gulp
.src([
"src/swagger-diff/swagger-diff-v1/task.js",
"src/swagger-diff/swagger-diff-v2/task.js",
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task("build", gulp.series("lint"));
gulp.task("pre-test", gulp.series("build"), function () {
return gulp
.src("src/**/*.js")
.pipe(istanbul({ includeUntested: true }))
.pipe(istanbul.hookRequire());
});
gulp.task("mocha-test", gulp.series(["pre-test"]), function (done) {
var mochaErr;
gulp
.src("test/**/*.js")
.pipe(plumber())
.pipe(mocha({ reporter: "spec" }))
.on("error", function (err) {
mochaErr = err;
})
.pipe(istanbul.writeReports())
.on("end", function () {
done(mochaErr);
});
});
gulp.task("test", gulp.series(["mocha-test"]));
// gulp.task('pester-test', ['pre-test'], function (done) {
// // Runs powershell unit tests based on pester
// var pester = spawn('powershell.exe', ['-Command', 'Invoke-Pester -EnableExit -Path test'], {stdio: 'inherit'});
// pester.on('exit', function (code) {
// if (code === 0) {
// done();
// } else {
// done('Pester tests failed!');
// }
// });
// pester.on('error', function () {
// // We may be in a non-windows machine or powershell.exe is not in path. Skip pester tests.
// done();
// });
// });
gulp.task("default", gulp.series(["test"]));
gulp.task("package:clean", function (cb) {
return del(["./package/*/**"], cb);
});
gulp.task(
"package:copy",
gulp.series("package:clean", () => {
var m1 = gulp
.src(
[
"./extension-icon*.png",
"PRIVACY.md",
"package.json",
"docs/**/*",
"!src/**",
"!**/node_modules/**/*",
],
{ base: "." }
)
.pipe(gulp.dest("./package"));
var m2 = gulp
.src(
[
"./src/vss-extension.json",
"./src/docs/*",
"./src/images/*",
"./src/swagger-diff/swagger-diff-v1/**/*.js",
"./src/swagger-diff/swagger-diff-v1/package.json",
"./src/swagger-diff/swagger-diff-v1/task.json",
"./src/swagger-diff/swagger-diff-v1/icon.png",
"./src/swagger-diff/swagger-diff-v2/**/*.js",
"./src/swagger-diff/swagger-diff-v2/package.json",
"./src/swagger-diff/swagger-diff-v2/task.json",
"./src/swagger-diff/swagger-diff-v2/icon.png",
"!**/node_modules/**/*",
],
{ base: "./src/" }
)
.pipe(gulp.dest("./package"));
return merge(m1, m2);
})
);
gulp.task("package:npminstall", () => {
return gulp
.src([
"./package/swagger-diff/swagger-diff-v1/package.json",
"./package/swagger-diff/swagger-diff-v2/package.json",
])
.pipe(install({ production: true }));
});
gulp.task("package", gulp.series("package:copy", "package:npminstall"));