2015-12-02 15:16:46 +03:00
|
|
|
var gulp = require("gulp");
|
2015-12-30 19:32:21 +03:00
|
|
|
var del = require("del");
|
2015-12-02 15:16:46 +03:00
|
|
|
var rimraf = require("rimraf");
|
|
|
|
var tsb = require("gulp-tsb");
|
|
|
|
var mocha = require("gulp-mocha");
|
|
|
|
var tslint = require("gulp-tslint");
|
2015-12-11 16:16:23 +03:00
|
|
|
var istanbul = require("gulp-istanbul");
|
|
|
|
var path = require("path");
|
2015-12-21 18:37:57 +03:00
|
|
|
var shell = require('shelljs')
|
|
|
|
var gutil = require('gulp-util');
|
2015-12-24 21:15:42 +03:00
|
|
|
var fs = require('fs');
|
2015-12-02 15:16:46 +03:00
|
|
|
|
|
|
|
var buildDirectory = "_build";
|
2015-12-21 19:05:34 +03:00
|
|
|
var packageDirectory = "_package";
|
2015-12-21 18:37:57 +03:00
|
|
|
var sourcePaths = {
|
|
|
|
typescriptFiles: "src/**/*.ts",
|
2015-12-24 21:15:42 +03:00
|
|
|
copyFiles: ["src/*.json", "src/*.md", "src/Images/*", "src/Tasks/**/*.json", "src/Tasks/**/*.md", "src/Tasks/**/*.png", "src/Tasks/**/*.svg"],
|
|
|
|
tasksPath: "src/Tasks"
|
2015-12-21 18:37:57 +03:00
|
|
|
};
|
|
|
|
var testPaths = {
|
|
|
|
typescriptFiles: "tests/**/*.ts",
|
2015-12-23 14:35:23 +03:00
|
|
|
compiledJSFiles: buildDirectory + "/**/*Tests*.js"
|
2015-12-21 18:37:57 +03:00
|
|
|
};
|
2015-12-21 19:05:34 +03:00
|
|
|
var manifestFile = "vss-extension.json";
|
2015-12-30 19:32:21 +03:00
|
|
|
var tempPath = "_temp";
|
2015-12-24 21:15:42 +03:00
|
|
|
var tempNodeModules = path.join(tempPath, 'node_modules');
|
2015-12-21 18:37:57 +03:00
|
|
|
|
2015-12-11 16:16:23 +03:00
|
|
|
var jsCoverageDir = path.join(buildDirectory, "codecoverage");
|
2015-12-02 15:16:46 +03:00
|
|
|
|
|
|
|
// create and keep compiler
|
|
|
|
var compilation = tsb.create({
|
|
|
|
target: 'es5',
|
|
|
|
module: 'commonjs',
|
2015-12-09 12:27:51 +03:00
|
|
|
declaration: false,
|
|
|
|
verbose: false
|
2015-12-02 15:16:46 +03:00
|
|
|
});
|
|
|
|
|
2015-12-28 07:34:13 +03:00
|
|
|
gulp.task("compile", ["lint"], function () {
|
2015-12-24 21:15:42 +03:00
|
|
|
return gulp.src([sourcePaths.typescriptFiles, testPaths.typescriptFiles], { base: "." })
|
2015-12-02 15:16:46 +03:00
|
|
|
.pipe(compilation())
|
2015-12-23 11:59:54 +03:00
|
|
|
.pipe(gulp.dest(buildDirectory))
|
2015-12-24 21:15:42 +03:00
|
|
|
.pipe(istanbul({ includeUntested: true }))
|
2015-12-11 16:16:23 +03:00
|
|
|
.pipe(istanbul.hookRequire());
|
2015-12-02 15:16:46 +03:00
|
|
|
});
|
|
|
|
|
2015-12-28 12:49:56 +03:00
|
|
|
gulp.task("build", ["compile"], function() {
|
2015-12-23 14:35:23 +03:00
|
|
|
return gulp.src(sourcePaths.copyFiles, { base: "." })
|
2015-12-21 18:37:57 +03:00
|
|
|
.pipe(gulp.dest(buildDirectory));
|
|
|
|
});
|
|
|
|
|
2015-12-28 12:49:56 +03:00
|
|
|
gulp.task("lint", ["clean"], function() {
|
2015-12-21 18:37:57 +03:00
|
|
|
return gulp.src([sourcePaths.typescriptFiles, testPaths.typescriptFiles])
|
2015-12-02 15:16:46 +03:00
|
|
|
.pipe(tslint())
|
|
|
|
.pipe(tslint.report("verbose"))
|
|
|
|
});
|
|
|
|
|
2015-12-30 19:32:21 +03:00
|
|
|
gulp.task("clean", function() {
|
|
|
|
return del([buildDirectory, packageDirectory, tempPath]);
|
2015-12-02 15:16:46 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("test", ["build"], function() {
|
2015-12-21 18:37:57 +03:00
|
|
|
return gulp.src(testPaths.compiledJSFiles, { read: false })
|
2015-12-11 16:16:23 +03:00
|
|
|
.pipe(mocha())
|
|
|
|
.pipe(istanbul.writeReports({
|
|
|
|
dir: jsCoverageDir,
|
|
|
|
reportOpts: { dir: jsCoverageDir }
|
|
|
|
}))
|
|
|
|
.pipe(istanbul.enforceThresholds({ thresholds: { global: 95 } }));
|
2015-12-08 15:56:26 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("testci", ["build"], function() {
|
2015-12-21 18:37:57 +03:00
|
|
|
return gulp.src(testPaths.compiledJSFiles, { read: false })
|
2015-12-11 16:16:23 +03:00
|
|
|
.pipe(mocha({ reporter: "xunit", reporterOptions: { output: path.join(buildDirectory, "mochaTestResult.xml") } }))
|
|
|
|
.pipe(istanbul.writeReports({
|
|
|
|
dir: jsCoverageDir,
|
|
|
|
reportOpts: { dir: jsCoverageDir }
|
|
|
|
}))
|
|
|
|
.pipe(istanbul.enforceThresholds({ thresholds: { global: 95 } }));
|
2015-12-08 15:56:26 +03:00
|
|
|
});
|
|
|
|
|
2015-12-29 09:18:50 +03:00
|
|
|
gulp.task("package", ["gettasklib"], function(cb) {
|
2015-12-28 07:34:13 +03:00
|
|
|
fs.readdirSync(sourcePaths.tasksPath).filter(function (file) {
|
|
|
|
return fs.statSync(path.join(sourcePaths.tasksPath, file)).isDirectory();
|
|
|
|
}).forEach(copyTaskLib);
|
2015-12-23 14:35:23 +03:00
|
|
|
createPackage(cb);
|
2015-12-21 18:37:57 +03:00
|
|
|
});
|
|
|
|
|
2015-12-08 15:56:26 +03:00
|
|
|
gulp.task("watch", function() {
|
2015-12-23 14:35:23 +03:00
|
|
|
gulp.watch([sourcePaths.typescriptFiles, testPaths.typescriptFiles], ["test"]);
|
2015-12-02 15:16:46 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("default", ["build"]);
|
2015-12-23 11:59:54 +03:00
|
|
|
|
2016-01-12 11:02:02 +03:00
|
|
|
gulp.task("gettasklib", function (cb) {
|
2015-12-24 21:15:42 +03:00
|
|
|
getLatestTaskLib(cb);
|
|
|
|
});
|
|
|
|
|
2015-12-23 11:59:54 +03:00
|
|
|
var createPackage = function (cb) {
|
2015-12-24 21:15:42 +03:00
|
|
|
runMavenAndGenerateVsix(cb);
|
2015-12-23 11:59:54 +03:00
|
|
|
}
|
|
|
|
|
2015-12-24 21:15:42 +03:00
|
|
|
var runMavenAndGenerateVsix = function(cb) {
|
2015-12-23 11:59:54 +03:00
|
|
|
var mavenPath = shell.which('mvn');
|
2015-12-23 14:35:23 +03:00
|
|
|
if (!mavenPath) {
|
2015-12-24 21:15:42 +03:00
|
|
|
cb(createError('mvn.exe needs to be in the path. Could not find.'));
|
2015-12-23 14:35:23 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-12-23 11:59:54 +03:00
|
|
|
shell.exec("mvn package", {silent:true}, function(code, output) {
|
|
|
|
if (code !== 0) {
|
2015-12-24 21:15:42 +03:00
|
|
|
cb(createError(output));
|
|
|
|
return;
|
2015-12-23 11:59:54 +03:00
|
|
|
}
|
|
|
|
else {
|
2015-12-24 21:15:42 +03:00
|
|
|
var srcBuildDirectory = buildDirectory + "/src";
|
|
|
|
createVsix(manifestFile, srcBuildDirectory, packageDirectory, cb);
|
2015-12-23 11:59:54 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var createVsix = function(manifestFile, srcBuildDirectory, packageDirectory, cb) {
|
|
|
|
shell.exec("tfx extension create --manifest-globs " + manifestFile + " --root " + srcBuildDirectory + " --output-path " + packageDirectory, {silent:true}, function(code, output) {
|
|
|
|
if (code !== 0) {
|
2015-12-24 21:15:42 +03:00
|
|
|
cb(createError(output));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var getLatestTaskLib = function(cb) {
|
2016-01-07 20:20:20 +03:00
|
|
|
gutil.log('Getting latest vsts-task-lib');
|
2015-12-24 21:15:42 +03:00
|
|
|
shell.mkdir('-p', path.join(tempPath, 'node_modules'));
|
|
|
|
shell.cp("-f", "package.json", tempPath);
|
|
|
|
shell.pushd(tempPath);
|
|
|
|
|
|
|
|
var npmPath = shell.which('npm');
|
|
|
|
if (!npmPath) {
|
|
|
|
cb(createError('npm not found. ensure npm 3 or greater is installed'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var cmdline = '"' + npmPath + '" install --production';
|
|
|
|
shell.exec(cmdline, { silent: true }, function (code, output) {
|
|
|
|
shell.popd();
|
|
|
|
if (code !== 0) {
|
2016-01-08 12:50:06 +03:00
|
|
|
cb(createError('npm failed to install vsts-task-lib. Output : ' + output));
|
2015-12-24 16:27:47 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
});
|
2015-12-24 21:15:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var createError = function (err) {
|
|
|
|
return new gutil.PluginError({
|
|
|
|
plugin: "package",
|
|
|
|
message: err
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var copyTaskLib = function(taskName) {
|
|
|
|
var targetPath = path.join(buildDirectory, "src", "Tasks", taskName);
|
|
|
|
shell.mkdir('-p', targetPath);
|
|
|
|
shell.cp('-rf', path.join(tempPath, 'node_modules'), targetPath);
|
2015-12-25 09:53:31 +03:00
|
|
|
}
|