chore(gulp): update gulp scripts

This commit is contained in:
Dan Bucholtz
2016-09-13 15:09:31 -05:00
committed by Adam Bradley
parent 17fe72e4bc
commit 12c9fd12bd
13 changed files with 938 additions and 1012 deletions

View File

@ -0,0 +1,64 @@
import { DIST_VENDOR_ROOT, NPM_VENDOR_FILES, PROJECT_ROOT, SCRIPTS_ROOT } from '../constants';
import path = require('path');
import { dest, src, task } from 'gulp';
task('test', ['test.assembleVendorJs', 'compile.karma'], (done: Function) => {
karmaTest(false, done);
});
task('test.watch', ['test.assembleVendorJs', 'compile.karma'], (done: Function) => {
karmaTest(true, done);
});
task('test.coverage', ['test.assembleVendorJs', 'compile.karma'], (done: Function) => {
karmaTest(false, () => {
createKarmaCoverageReport(done);
});
});
function karmaTest(watch: boolean, done: Function) {
const karma = require('karma');
const argv = require('yargs').argv;
let karmaConfig = {
configFile: path.join(SCRIPTS_ROOT, 'karma/karma.conf.js'),
};
if (watch) {
(karmaConfig as any).singleRun = false;
}
if (argv.testGrep) {
(<any>karmaConfig).client = {
args: ['--grep', argv.testGrep]
};
}
new karma.Server(karmaConfig, done).start();
}
task('test.assembleVendorJs', () => {
const files = NPM_VENDOR_FILES.map((root) => {
const glob = path.join(root, '**/*.+(js|js.map)');
return src(path.join('node_modules', glob))
.pipe(dest(path.join(DIST_VENDOR_ROOT, root)));
});
const gulpMerge = require('merge2');
return gulpMerge(files);
});
/* creates a karma code coverage report */
function createKarmaCoverageReport(done: Function) {
console.log('Generating Unit Test Coverage Report...');
let exec = require('child_process').exec;
let command = `node_modules/.bin/remap-istanbul -i coverage/coverage-final.json -o coverage -t html`;
exec(command, function(err: any, stdout: any, stderr: any) {
console.log(`file://${PROJECT_ROOT}/coverage/index.html`);
done(err);
});
}