Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

Commit

Permalink
fixes #31: review generator gulpfile - add all paths automatically, m…
Browse files Browse the repository at this point in the history
…ove linter at the end of watch
  • Loading branch information
Jonathan Grupp committed Feb 4, 2015
1 parent 2169046 commit fa1079d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
2 changes: 1 addition & 1 deletion app/templates/_gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ gulp.task('default', function () {
else if (options.cordova) {
return gulp.start('cordova');
}
// just watch when no cordova option
// just watch when cordova option not present
else {
return gulp.start('watch');
}
Expand Down
72 changes: 41 additions & 31 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,63 @@

// tasks based on : https://github.com/youngmountain/generator-node-gulp/blob/master/gulpfile.js

var gulp = require('gulp');
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();

var packageJSON = require('./package.json');

// ADD PATHS AUTOMATICALLY
var paths = {
lint: [
coverage: [ // code actually run by the generator
],
lint: [ // code to lint
'./gulpfile.js',
'./app/index.js',
'./app/templates/gulp_tasks/*.js',
'./controller/index.js',
'./service/index.js',
'./template/index.js'
],
watch: [
watch: [ // code that should be watched
'./gulpfile.js',
'./app/**',
'./test/**/*.js',
'./utils/**',
'./module/**',
'./controller/**',
'./service/**',
'./template/**'
],
tests: [
test: [
'./test/**/*.js',
'!./test/temp/**/*.js'
],
source: []
extra: [
'app/sources/**/*.js',
'utils/**/*.js'
]
};
paths.watch = paths.watch.concat(paths.lint);
paths.source = paths.source.concat(paths.lint);

var plumberConf = {};
// package.json files
for (var i = 0, folder; (folder = packageJSON.files[i]); i++) {
// coverage: add every generator's index.js
paths.coverage.push('./' + folder + '/index.js');
// lint: index.js & add untemplated files
paths.lint.push('./' + folder + '/templates/**/*.js');
paths.lint.push('!./' + folder + '/templates/**/_*.js');
// watch: add all files in folders
paths.watch.push('./' + folder + '/**');
}
// add extra files
paths.coverage = paths.coverage.concat(paths.extra);
paths.lint = paths.lint.concat(paths.extra);
paths.watch = paths.watch.concat(paths.extra);
// add test files
paths.lint = paths.lint.concat(paths.test);
paths.watch = paths.watch.concat(paths.test);

// when running in CI environment (Travis), abort and throw error on error
var plumberConf = {};
if (process.env.CI) {
plumberConf.errorHandler = function (err) {
throw err;
};
}

// will run istanbul & lint while you develop
gulp.task('watch', ['lint', 'istanbul'], function () {
gulp.watch(paths.watch, ['lint', 'istanbul']);
});

// will run coding style checks
gulp.task('lint', function () {
gulp.task('lint', ['istanbul'], function () {
return gulp.src(paths.lint)
.pipe($.jshint('.jshintrc'))
.pipe($.plumber(plumberConf))
Expand All @@ -54,11 +69,11 @@ gulp.task('lint', function () {

// will run mocha and print reports
gulp.task('istanbul', function (cb) {
gulp.src(paths.source)
gulp.src(paths.coverage)
.pipe($.istanbul()) // Covering files
.pipe($.istanbul.hookRequire())
.on('finish', function () {
gulp.src(paths.tests, {cwd: __dirname})
gulp.src(paths.test, {cwd: __dirname})
.pipe($.plumber(plumberConf))
.pipe($.mocha())
.pipe($.istanbul.writeReports()) // Creating the reports after tests ran
Expand All @@ -69,6 +84,8 @@ gulp.task('istanbul', function (cb) {
});
});

gulp.task('release', ['bump']);

// bump your version
gulp.task('bump', ['test'], function () {
var bumpType = $.util.env.type || 'patch'; // major.minor.patch
Expand All @@ -78,13 +95,6 @@ gulp.task('bump', ['test'], function () {
.pipe(gulp.dest('./'));
});

// will run istanbul while you develop
gulp.task('watch', ['lint', 'istanbul'], function () {
gulp.watch(paths.watch, ['lint', 'istanbul']);
});

gulp.task('test', ['lint', 'istanbul']);

gulp.task('release', ['bump']);

gulp.task('default', ['test']);

0 comments on commit fa1079d

Please sign in to comment.