2017-03-23 09:51:12 +03:00
|
|
|
var gulp = require("gulp");
|
|
|
|
var karma = require('karma');
|
|
|
|
var ts = require("gulp-typescript");
|
|
|
|
var tsProject = ts.createProject("tsconfig.json");
|
|
|
|
var tslint = require("gulp-tslint");
|
2017-03-28 11:51:42 +03:00
|
|
|
var exec = require('child_process').execSync;
|
2017-03-23 09:51:12 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compile the source and ship to dist folder
|
|
|
|
*/
|
|
|
|
gulp.task("compile:dist", function () {
|
|
|
|
return tsProject.src()
|
|
|
|
.pipe(tsProject())
|
|
|
|
.js.pipe(gulp.dest("dist"));
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run test once and exit
|
|
|
|
*/
|
|
|
|
gulp.task('test', function (done) {
|
|
|
|
new karma.Server({
|
|
|
|
configFile: __dirname + '/karma.conf.js',
|
|
|
|
singleRun: true
|
|
|
|
}, done).start();
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run lint on source and spec
|
|
|
|
*/
|
|
|
|
gulp.task('lint', () => {
|
2017-03-23 13:12:18 +03:00
|
|
|
return gulp.src(['src/**/*.ts', 'test/**/*.ts'])
|
2017-03-23 09:51:12 +03:00
|
|
|
.pipe(tslint({
|
|
|
|
formatter: "verbose"
|
|
|
|
}))
|
|
|
|
.pipe(tslint.report())
|
|
|
|
});
|
2017-03-28 11:51:42 +03:00
|
|
|
|
|
|
|
gulp.task('version', () => {
|
2017-03-28 12:18:23 +03:00
|
|
|
if (process.env["NPM_TOKEN"] === undefined)
|
|
|
|
throw new Error("Task 'publish:npm' is only applicable for CI");
|
|
|
|
|
2017-03-28 11:51:42 +03:00
|
|
|
var releaseType = "patch";
|
|
|
|
// Fetching last commit message
|
|
|
|
var commitmsg = exec("git log -n 1 --format=%s").toString("utf8").replace(/\n/g, " ");
|
|
|
|
|
|
|
|
// Looking for keyword "breaking-change" to mark this release as major
|
|
|
|
if (/breaking-change/i.test(commitmsg)) {
|
|
|
|
releaseType = "major";
|
|
|
|
}
|
|
|
|
// Looking for prefix "feature" to mark this release as minor
|
|
|
|
else if (commitmsg.split(":", 2)[0].toLowerCase() == "feature") {
|
|
|
|
releaseType = "minor";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Executing npm version command.
|
|
|
|
exec(`npm version ${releaseType} --no-git-tag-version -m "${commitmsg}"`);
|
|
|
|
|
|
|
|
// Committing the package.json
|
|
|
|
exec(`git commit --no-verify package.json -m "ci-skip: version update"`);
|
|
|
|
|
|
|
|
// Pushing the changes to current branch
|
|
|
|
exec("git push --force");
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('publish:npm', ["version"], () => {
|
2017-03-28 12:18:23 +03:00
|
|
|
|
|
|
|
// Writing npm authentication token in .npmrc file
|
|
|
|
exec(`echo //registry.npmjs.org/:_authToken=${process.env["NPM_TOKEN"]} > .npmrc`);
|
|
|
|
|
2017-03-28 11:51:42 +03:00
|
|
|
// Executing npm publish command.
|
|
|
|
exec("npm publish");
|
|
|
|
});
|