Last active
August 29, 2015 14:18
-
-
Save vernonk/7cdd59dd32106d32889c to your computer and use it in GitHub Desktop.
A cleaner gulpfile? Inspired by Thomas Boyt's maintainable Gruntfile approach which I've used for a while now, I think that a similar separated structure makes the most sense for application maintenance and growth. Thoughts? Thomas Boyt's article: http://www.thomasboyt.com/2013/09/01/maintainable-grunt.html
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
Directory structure | |
--------------------------- | |
|--tasks/ | |
| |--app/ | |
| |customapptask.js # Exports custom gulp task | |
| |--plugins/ | |
| |uglify.js # Exports uglify gulp task | |
|--gulpfile.js |
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
var fs = require( "fs" ), | |
path = require( "path" ), | |
glob = require( "glob" ), | |
deasync = require( "deasync" ), | |
gulp = require( "gulp" ), | |
plugins = require( "gulp-load-plugins" )(), | |
tasks = {}, | |
done = false; | |
glob( path.join( __dirname, "tasks", "**/*.js" ), | |
function ( err, files ) { | |
var shortname; | |
if ( err ) throw err; | |
for ( var i = 0, l = files.length; i < l; i++ ) { | |
files[ i ].replace( /([^/]+$)/, function ( full, filename ) { | |
shortname = filename.substr( 0, filename.indexOf( "." ) ); | |
}); | |
tasks[ shortname ] = require( files[ i ] ); | |
} | |
done = true; | |
}); | |
while ( !done ) { | |
deasync.runLoopOnce(); | |
} | |
// tasks are now loaded and ready to be used. | |
// accessible from the command line as gulp taskname | |
// but also can be used within the gulpfile itself | |
// by invoking tasks.taskname(); | |
// e.g. tasks.localize(); | |
// The default task (called when you run `gulp` from cli) | |
gulp.task('default', ['watch', 'scripts', 'images']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment