vsts-docker/gulpfile.js

126 строки
4.0 KiB
JavaScript
Исходник Обычный вид История

2016-03-03 11:48:30 +03:00
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",
2016-11-01 19:22:31 +03:00
copyFiles: ["src/**/*", "!src/**/*.ts"],
2016-04-01 14:15:30 +03:00
lcaFiles: ["ThirdPartyNotices.txt", "DockerIntegration_ExtensionForVisualStudioTeamServices_Pre-ReleaseEULA.docx"],
2016-03-03 11:48:30 +03:00
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
});
gulp.task("clean", function () {
2016-03-03 11:48:30 +03:00
return del([buildDirectory]);
});
gulp.task("lint", ["clean"], function () {
2016-03-03 11:48:30 +03:00
return gulp.src([sourcePaths.typescriptFiles, testPaths.typescriptFiles])
.pipe(tslint())
.pipe(tslint.report("verbose"));
});
gulp.task("compile", ["lint"], function () {
return gulp.src([sourcePaths.typescriptFiles, testPaths.typescriptFiles], { base: "." })
.pipe(compilation())
.pipe(gulp.dest(buildDirectory))
.pipe(istanbul({ includeUntested: true }))
2016-03-03 11:48:30 +03:00
.pipe(istanbul.hookRequire());
});
gulp.task("build", ["compile"], function () {
2016-04-01 14:15:30 +03:00
return gulp.src(sourcePaths.copyFiles.concat(sourcePaths.lcaFiles), { base: "." })
2016-03-03 11:48:30 +03:00
.pipe(gulp.dest(buildDirectory));
});
gulp.task("test", ["build"], function () {
shell.chmod(755, 'pytests.sh');
shell.exec('./pytests.sh');
shell.rm('./r.sh');
return gulp.src(testPaths.compiledTestFiles, { read: false })
2016-03-03 11:48:30 +03:00
.pipe(mocha())
.pipe(istanbul.writeReports({ dir: codeCoverageDirectory }))
.pipe(istanbul.enforceThresholds({ thresholds: { global: 100 } }));
2016-03-03 11:48:30 +03:00
});
2016-03-06 22:07:11 +03:00
gulp.task("default", ["build"]);
2016-03-03 11:48:30 +03:00
gulp.task("package", ["build"], function () {
getNodeDependencies(function () {
2016-04-01 14:15:30 +03:00
copyLcaFiles();
2016-03-03 11:48:30 +03:00
copyNodeModulesToTasks();
createVsixPackage();
2016-03-03 11:48:30 +03:00
});
});
var getNodeDependencies = function (callback) {
2016-03-03 11:48:30 +03:00
del(packageDirectory);
shell.mkdir("-p", path.join(packageDirectory, nodeModulesDirectory));
shell.cp("-f", "package.json", packageDirectory);
shell.pushd(packageDirectory);
2016-03-03 11:48:30 +03:00
var npmPath = shell.which("npm");
var npmInstallCommand = '"' + npmPath + '" install --production';
executeCommand(npmInstallCommand, function () {
2016-03-03 11:48:30 +03:00
shell.popd();
callback();
});
}
var copyLcaFiles = function () {
gulp.src(sourcePaths.lcaFiles, { base: "." })
2016-04-01 14:15:30 +03:00
.pipe(gulp.dest(srcBuildDirectory));
2016-04-01 14:15:30 +03:00
fs.readdirSync(sourcePaths.tasksPath).forEach(function (taskName) {
var taskpath = path.join(buildDirectory, sourcePaths.tasksPath, taskName);
gulp.src(sourcePaths.lcaFiles, { base: "." })
2016-04-01 14:15:30 +03:00
.pipe(gulp.dest(taskpath));
})
}
var copyNodeModulesToTasks = function () {
fs.readdirSync(sourcePaths.tasksPath).forEach(function (taskName) {
2016-03-03 11:48:30 +03:00
var taskpath = path.join(buildDirectory, sourcePaths.tasksPath, taskName);
del(path.join(taskpath, nodeModulesDirectory));
shell.cp("-rf", path.join(packageDirectory, nodeModulesDirectory), taskpath);
});
}
var createVsixPackage = function () {
2016-10-08 01:26:47 +03:00
var packagingCmd = "tfx extension create --manifest-globs " + packageManifestFile + " --root " + srcBuildDirectory + " --output-path " + packageDirectory;
executeCommand(packagingCmd, function () { });
2016-03-03 11:48:30 +03:00
}
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();
}
2016-03-03 11:48:30 +03:00
});
}