Created
January 13, 2014 18:10
-
-
Save derekr/8405128 to your computer and use it in GitHub Desktop.
gulpfile(s). the string parsing in `tasks/bundle.js` is left over from a previous grunt file.
This file contains hidden or 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
/** | |
* Bundles clientside code and aliases controllers. Uses `public/js/init.js` | |
* as the main entry point. | |
* | |
* @param {object} grunt - Grunt instance. | |
* | |
* @author Derek Reynolds <drk@diy.org> | |
* @package admin | |
*/ | |
/** | |
* Dependencies | |
*/ | |
var browserify = require('gulp-browserify'); | |
var concat = require('gulp-concat'); | |
var glob = require('glob'); | |
module.exports = function (gulp) { | |
return function (callback) { | |
var req = []; | |
var controllerList = glob.sync('controllers/*.js'); | |
var viewList = glob.sync('views/*/index.js'); | |
for (var c = 0; c < controllerList.length; c++) { | |
var calias = controllerList[c].split('/').pop().replace('.js', ''); | |
req.push({ | |
cat: 'controller', | |
path: __dirname + '/../' + controllerList[c], | |
alias: calias | |
}); | |
} | |
for (var v = 0; v < viewList.length; v++) { | |
var split = viewList[v].split('/'); | |
var valias = split[split.length - 2]; | |
req.push({ | |
cat: 'view', | |
path: __dirname + '/../' + viewList[v], | |
alias: valias | |
}); | |
} | |
var alias = function (b) { | |
for (var r = 0; r < req.length; r++) { | |
b.require( | |
req[r].path, { | |
expose: req[r].cat + '-' + req[r].alias, | |
baseDir: __dirname + '/../' + req[r].cat + 's' | |
} | |
); | |
} | |
}; | |
var prebundle = function (b) { | |
alias(b); | |
b.transform('envify'); // hook up process.env variables | |
b.transform('brfs'); // clientside templates | |
}; | |
gulp.src('public/js/init.js', { buffer: false }) | |
.pipe(browserify({ baseDir: __dirname + '/..' }) | |
.on('prebundle', prebundle)) | |
.pipe(concat('bundle.js')) | |
.pipe(gulp.dest('public/build/js')); | |
gulp.src('public/build/js/bundle.js') | |
.pipe(concat('build.min.js')) | |
.pipe(gulp.dest('public/build/js')); | |
callback(null); | |
}; | |
}; |
This file contains hidden or 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
/** | |
* Compiles public/css/stylesheet.less for clientside consumption. | |
* | |
* @author Derek Reynolds <drk@diy.org> | |
* @package admin | |
*/ | |
/** | |
* Dependencies | |
*/ | |
var concat = require('gulp-concat'); | |
var prefix = require('gulp-autoprefixer'); | |
var less = require('gulp-less'); | |
/** | |
* Exports | |
*/ | |
module.exports = function (gulp) { | |
return function (callback) { | |
gulp.src('public/css/stylesheet.less') | |
.pipe(less()) | |
.pipe(prefix('last 1 version', 'ie 9', 'ie 8')) | |
.pipe(concat('build.min.css')) | |
.pipe(gulp.dest('public/build/css')); | |
callback(null); | |
}; | |
}; |
This file contains hidden or 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
/** | |
* Main task runner. | |
* | |
* @author Derek Reynolds <drk@diy.org> | |
* @package admin | |
*/ | |
/** | |
* Dependencies | |
*/ | |
var gulp = require('gulp'); | |
var nodemon = require('gulp-nodemon'); | |
require('./lib/environment')(); | |
/** | |
* Imported tasks | |
*/ | |
gulp.task('bundle', require('./tasks/bundle')(gulp)); | |
gulp.task('css', require('./tasks/css')(gulp)); | |
/** | |
* Copy fonts from diy-core-styles in to build directory for dev | |
*/ | |
gulp.task('fonts', function () { | |
gulp.src('node_modules/diy-core-styles/public/fonts/*') | |
.pipe(gulp.dest('public/build/fonts')); | |
}); | |
/** | |
* Default task that will watch clientside js and less and build | |
* respectively for each file type. | |
* | |
* Run: `gulp` | |
*/ | |
gulp.task('default', function () { | |
gulp.watch( | |
['views/**/*.js', 'views/**/*.html', 'controllers/*.js'], | |
function () { | |
gulp.run('bundle'); | |
} | |
); | |
gulp.watch('public/css/**/*.less', function () { | |
gulp.run('css'); | |
}); | |
// Nodemon - restart server | |
gulp.src('index.js').pipe(nodemon()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment