Skip to content

Instantly share code, notes, and snippets.

@rimian
Created April 20, 2015 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rimian/0f9b88266a0f63696f21 to your computer and use it in GitHub Desktop.
Save rimian/0f9b88266a0f63696f21 to your computer and use it in GitHub Desktop.
My Gulp File Yo
var
concat = require('gulp-concat'),
del = require('del'),
gulp = require('gulp'),
karma = require('gulp-karma'),
args = require('yargs');
var Args = function(yargs) {
var _match = yargs.m || yargs.match;
var _file = yargs.f || yargs.file;
return {
file: function() { return _file; },
match: function() { if (_match) { return {args: ['--grep', _match]} } }
};
}(args.argv);
var Files = function(args) {
var globs = {
lib: 'lib/**/*.js',
public: 'public/**',
spec: 'spec/**/*.js'
};
var public = {
dest: './public/',
js: 'bam.js',
}
var dependencies = [
'node_modules/jasmine-ajax/lib/mock-ajax.js',
'bower_components/mootools/dist/mootools-core.min.js'
];
var testFiles = function() {
var files = dependencies.concat([globs.public]);
args.file() ? files.push(args.file()) : files.push(globs.spec);
return files;
};
return {
globs: globs,
testFiles: testFiles(),
karma: 'spec/karma.conf.js',
public: public
};
}(Args);
var Log = function() {
return {
error: function(message) { return console.error(message); },
warn: function(message) { return console.warn(message); },
info: function(message) { return console.log(message); }
};
}();
var Tasks = function() {
var build = function() {
return gulp.src(Files.globs.lib)
.pipe(concat(Files.public.js))
.pipe(gulp.dest(Files.public.dest));
};
var test = function() {
return gulp.src(Files.testFiles)
.pipe(karma({ configFile: Files.karma, client: Args.match()}))
.on('error', function(err) { throw err; });
};
var clean = function() {
return del([Files.globs.public]);
};
return {
build: function() { return build() },
clean: function() { return clean() },
test: function() { return test() }
}
}(Args);
gulp.task('default', ['build'], Tasks.test);
gulp.task('build', ['clean'], Tasks.build);
gulp.task('b', ['clean'], Tasks.build);
gulp.task('clean', Tasks.clean);
gulp.task('c', Tasks.clean);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment