app/templates/_gulpfile.js._tpl
'use strict';
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();<% if (esnext) { %>
var isparta = require('isparta');
// Make babel preprocess the scripts the user tries to import from here on.
require('babel/register');<% } %>
var testFiles = ['./test/**/*.js', '!test/{temp,fixtures,temp/**,fixtures/**}'];
var paths = {
lint: ['./gulpfile.js', './src/**/*.js'],
watch: ['./gulpfile.js', './src/**'].concat(testFiles),
tests: testFiles<% if (istanbulModule) { %>,
source: ['./src/**/*.js']<% } %>
};
var plumberConf = {};
if (process.env.CI) {
plumberConf.errorHandler = function (err) {
throw err;
};
}
gulp.task('lint', function () {
return gulp.src(paths.lint)
.pipe(plugins.jshint())<% if (jscsModule) { %>
.pipe(plugins.plumber(plumberConf))
.pipe(plugins.jscs())<% } %>
.pipe(plugins.jshint.reporter('jshint-stylish'));
});<% if (istanbulModule) { %>
gulp.task('istanbul', function (cb) {
gulp.src(paths.source)
.pipe(plugins.istanbul(<% if (esnext) { %>{ instrumenter: isparta.Instrumenter }<% } %>)) // Covering files
.pipe(plugins.istanbul.hookRequire()) // Force `require` to return covered files
.on('finish', function () {
gulp.src(paths.tests)
.pipe(plugins.plumber(plumberConf))<% if (testFramework === 'jasmine') { %>
.pipe(plugins.jasmine())<% } %><% if (testFramework === 'mocha') { %>
.pipe(plugins.mocha())<% } %>
.pipe(plugins.istanbul.writeReports()) // Creating the reports after tests runned
.on('finish', function () {
process.chdir(__dirname);
cb();
});
});
});<% } else { %>
gulp.task('unitTest', function () {
gulp.src(paths.tests, {cwd: __dirname})
.pipe(plugins.plumber(plumberConf))<% if (testFramework === 'jasmine') { %>
.pipe(plugins.jasmine());<% } %><% if (testFramework === 'mocha') { %>
.pipe(plugins.mocha({ reporter: 'list' }));<% } %>
});<% } %>
<% if (releaseModule) { %>
gulp.task('bump', ['test'], function () {
var bumpType = plugins.util.env.type || 'patch'; // major.minor.patch
return gulp.src(['./package.json'])
.pipe(plugins.bump({ type: bumpType }))
.pipe(gulp.dest('./'));
});
<% } %>
<% if (esnext) { %>
gulp.task('build', function () {
return gulp.src(paths.source)
.pipe(plugins.babel())
.pipe(gulp.dest('build'));
});
<% } %>
gulp.task('watch', ['test'], function () {
gulp.watch(paths.watch, function () {
// use child process, otherwise will get error.
require('child_process').spawn('gulp', ['test'], {
env: process.env,
cwd: process.cwd(),
stdio: [
process.stdin,
process.stdout,
process.stderr
]
});
});
});
gulp.task('test', ['lint', <% if (istanbulModule) { %>'istanbul'<% } else { %>'unitTest'<% } %>]);<% if (releaseModule) { %>
gulp.task('release', ['bump']);<% } %>
gulp.task('default', ['watch']);