2015-12-02 15:16:46 +03:00
|
|
|
var gulp = require("gulp");
|
|
|
|
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-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",
|
|
|
|
copyFiles: ["src/*.json", "src/*.md", "src/Images/*", "src/Tasks/**/*.json", "src/Tasks/**/*.js", "src/Tasks/**/*.md", "src/Tasks/**/*.png", "src/Tasks/**/*.svg"]
|
|
|
|
};
|
|
|
|
var testPaths = {
|
|
|
|
typescriptFiles: "tests/**/*.ts",
|
|
|
|
copyfiles: ["tests/**/*.js"],
|
|
|
|
compiledJSFiles: buildDirectory + "/**/*Tests*.js"
|
|
|
|
};
|
2015-12-21 19:05:34 +03:00
|
|
|
var manifestFile = "vss-extension.json";
|
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-21 18:37:57 +03:00
|
|
|
gulp.task("compile", ["lint"], function() {
|
|
|
|
return gulp.src([sourcePaths.typescriptFiles, testPaths.typescriptFiles], { base: "." })
|
2015-12-02 15:16:46 +03:00
|
|
|
.pipe(compilation())
|
2015-12-21 18:37:57 +03:00
|
|
|
.pipe(gulp.dest(__dirname))
|
2015-12-11 16:16:23 +03:00
|
|
|
.pipe(istanbul({includeUntested: true}))
|
|
|
|
.pipe(istanbul.hookRequire());
|
2015-12-02 15:16:46 +03:00
|
|
|
});
|
|
|
|
|
2015-12-21 18:37:57 +03:00
|
|
|
gulp.task("build", ["compile"], function() {
|
|
|
|
var copyFiles = sourcePaths.copyFiles.concat(testPaths.copyfiles);
|
|
|
|
return gulp.src(copyFiles, { base: "." })
|
|
|
|
.pipe(gulp.dest(buildDirectory));
|
|
|
|
});
|
|
|
|
|
2015-12-09 12:27:51 +03:00
|
|
|
gulp.task("lint", 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"))
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("clean", function(done) {
|
|
|
|
return rimraf(buildDirectory, function() {
|
|
|
|
// rimraf deletes the directory asynchronously
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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-21 19:05:34 +03:00
|
|
|
gulp.task("package", ["build"], function() {
|
|
|
|
var srcBuildDirectory = buildDirectory + "/src";
|
|
|
|
if(shell.exec("tfx extension create --manifest-globs " + manifestFile + " --root " + srcBuildDirectory + " --output-path " + packageDirectory).code !== 0) {
|
2015-12-21 18:37:57 +03:00
|
|
|
throw new gutil.PluginError({
|
|
|
|
plugin: "package",
|
|
|
|
message: "Unable to create package."
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-08 15:56:26 +03:00
|
|
|
gulp.task("watch", function() {
|
2015-12-21 18:37:57 +03:00
|
|
|
gulp.watch([sourcePaths.typescriptFiles, testPaths.typescriptFiles], ["test"]);
|
2015-12-02 15:16:46 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("default", ["build"]);
|