Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
reaganthomas
committed
Jun 30, 2015
1 parent
98c13d6
commit 768cc7e
Showing
10 changed files
with
302 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
|
||
var async = require('async'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var _ = require('lodash'); | ||
|
||
function voidFunction() { | ||
return; | ||
} | ||
|
||
module.exports = { | ||
processTaskDirectory: function processTaskDirectory(options, gulp) { | ||
function processDirectory(dir) { | ||
function filterFilenames(filename) { | ||
var file = path.resolve(dir, filename); | ||
var extname = path.extname(filename); | ||
return extname === '.js' || extname === '.coffee' || fs.statSync(file).isDirectory(); | ||
} | ||
|
||
function mapFiles(filename) { | ||
var file = path.resolve(dir, filename); | ||
|
||
if (fs.statSync(file).isDirectory()) { | ||
return { directory: true, filename: filename }; | ||
} else { | ||
var taskname = path.basename(filename, path.extname(filename)); | ||
taskname = taskname.split(options.filenameDelimiter).join(options.tasknameDelimiter); | ||
return { file: file, filename: filename, taskname: taskname }; | ||
} | ||
} | ||
|
||
function handleFileOrDirectory(obj) { | ||
if (obj.directory) { | ||
processDirectory(dir + '/' + obj.filename); | ||
} else { | ||
createTask(obj); | ||
} | ||
} | ||
|
||
function createTask(obj) { | ||
var taskinfo = require(obj.file)(gulp, _.defaults(options.config, _.omit(options, ['config', 'plugins'])), options.plugins); | ||
var taskdeps = taskinfo.deps || []; | ||
var taskparams = taskinfo.params || []; | ||
var taskfn = taskinfo.deps || taskinfo.fn || taskinfo.params ? taskinfo.fn || voidFunction : taskinfo; | ||
|
||
if (taskparams.length > 0) { | ||
gulp.task(obj.taskname, taskdeps, function () { | ||
async.map(taskparams, function (params, callback) { | ||
taskfn(params, callback); | ||
}); | ||
}); | ||
} else { | ||
gulp.task(obj.taskname, taskdeps, taskfn); | ||
} | ||
} | ||
|
||
fs.readdirSync(dir).filter(filterFilenames).map(mapFiles).forEach(handleFileOrDirectory); | ||
} | ||
|
||
processDirectory(options.taskDirectory); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
|
||
module.exports = { | ||
validateOptions: function validateOptions(options) { | ||
if (typeof options.taskDirectory !== 'string') { | ||
throw new Error('Task directory must be a string containing the relative path to a task directory'); | ||
} | ||
|
||
if (typeof options.filenameDelimiter !== 'string') { | ||
throw new Error('Filename delimiter must be a string'); | ||
} | ||
|
||
if (typeof options.tasknameDelimiter !== 'string') { | ||
throw new Error('Taskname delimiter must be a string'); | ||
} | ||
|
||
if (typeof options.configFile !== 'string') { | ||
throw new Error('Config file must be a string containing the relative path to a config file'); | ||
} | ||
}, | ||
|
||
validateTaskDirectory: function validateTaskDirectory(taskDirectory) { | ||
var dirStat = fs.statSync(taskDirectory); | ||
|
||
if (!dirStat.isDirectory()) { | ||
throw new Error(taskDirectory + ' is not a directory'); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
'use strict'; | ||
(function() { | ||
'use strict'; | ||
|
||
var gulp = require('gulp'); | ||
var bump = require('gulp-bump'); | ||
var mocha = require('gulp-mocha'); | ||
var babel = require('gulp-babel'); | ||
var istanbul = require('gulp-istanbul'); | ||
var del = require('del'); | ||
var gulp = require('gulp'); | ||
var bump = require('gulp-bump'); | ||
var mocha = require('gulp-mocha'); | ||
var babel = require('gulp-babel'); | ||
var istanbul = require('gulp-istanbul'); | ||
|
||
gulp.task('build', function() { | ||
return gulp.src('index.js') | ||
.pipe(babel()) | ||
.pipe(gulp.dest('./build')); | ||
}); | ||
gulp.task('clean', function(cb) { | ||
del([ 'build/**' ], cb); | ||
}); | ||
|
||
gulp.task('test', [ 'build' ], function() { | ||
return gulp.src('./test/**/*.js', { read: false }) | ||
.pipe(mocha({ reporter: 'dot' })); | ||
}); | ||
gulp.task('build', [ 'clean' ], function() { | ||
return gulp.src('src/**/*.js') | ||
.pipe(babel()) | ||
.pipe(gulp.dest('./build')); | ||
}); | ||
|
||
gulp.task('coverage', [ 'build' ], function(cb) { | ||
gulp.src('./build/index.js') | ||
.pipe(istanbul()) | ||
.pipe(istanbul.hookRequire()) | ||
.on('finish', function() { | ||
gulp.src('./test/**/*.js') | ||
.pipe(mocha({ reporter: 'spec' })) | ||
.pipe(istanbul.writeReports()) | ||
.on('end', cb); | ||
}); | ||
}); | ||
gulp.task('test', [ 'build' ], function() { | ||
return gulp.src('./test/**/*.js', { read: false }) | ||
.pipe(mocha({ reporter: 'dot' })); | ||
}); | ||
|
||
gulp.task('bump', [ 'build', 'test' ], function() { | ||
return gulp.src('./package.json') | ||
.pipe(bump()) | ||
.pipe(gulp.dest('./')); | ||
}); | ||
gulp.task('coverage', [ 'build' ], function(cb) { | ||
gulp.src('build/**/*.js') | ||
.pipe(istanbul()) | ||
.pipe(istanbul.hookRequire()) | ||
.on('finish', function() { | ||
gulp.src('./test/**/*.js') | ||
.pipe(mocha({ reporter: 'spec' })) | ||
.pipe(istanbul.writeReports()) | ||
.on('end', cb); | ||
}); | ||
}); | ||
|
||
gulp.task('default', [ 'build', 'test', 'bump' ]); | ||
gulp.task('bump', [ 'build', 'test' ], function() { | ||
return gulp.src('./package.json') | ||
.pipe(bump()) | ||
.pipe(gulp.dest('./')); | ||
}); | ||
|
||
gulp.task('default', [ 'clean', 'build', 'test', 'bump' ]); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.