Skip to content

Instantly share code, notes, and snippets.

@joeLepper
Created January 10, 2014 18:59
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joeLepper/8360399 to your computer and use it in GitHub Desktop.
Save joeLepper/8360399 to your computer and use it in GitHub Desktop.
My Gulpfile
var gulp = require('gulp')
, jshint = require('gulp-jshint')
, csslint = require('gulp-csslint')
, sass = require('gulp-sass')
, gconcat = require('gulp-concat')
, uglify = require('gulp-uglify')
, rename = require('gulp-rename')
, ngmin = require('gulp-ngmin')
, gzip = require('gulp-gzip')
, jade = require('gulp-jade')
, refresh = require('gulp-livereload')
, lr = require('tiny-lr')
, html2js = require('gulp-ng-html2js')
, stylish = require('jshint-stylish')
, htmlmin = require('gulp-minify-html')
, spawn = require('child_process').spawn
, lrServer = lr()
, node
// ------------------------- //
// ---- location arrays ---- //
// ------------------------- //
, jsLocations = ['src/js/index.js', 'src/js/**/*.js']
, cssLocations = ['public/css/*.css']
, sassLocations = ['src/sass/*.scss', 'src/sass/**/*.scss']
, jadeLocations = ['src/jade/views/*.jade']
, indexLocation = ['src/jade/index.jade']
, viewLocations = ['src/html/*.html'];
// -------------------------- //
// ---- individual tasks ---- //
// -------------------------- //
gulp.task('jsLint', function(){
gulp.src(jsLocations)
.pipe(jshint({laxcomma:true}))
.pipe(jshint.reporter(stylish));
});
gulp.task('karma', function(){
spawn('karma',
['start', 'karma.config.js'],
{ stdio : 'inherit' });
});
gulp.task('cssLint', function(){
gulp.src(cssLocations)
.pipe(csslint())
.pipe(csslint.reporter());
});
gulp.task('sass', function(){
gulp.src(sassLocations)
.pipe(sass())
.pipe(gulp.dest('public/css'))
.pipe(refresh(lrServer));
});
gulp.task('build', function(){
gulp.src(jsLocations)
.pipe(gconcat('app.js'))
.pipe(ngmin())
.pipe(rename({suffix: '.noted'}))
.pipe(gulp.dest('./public/js'))
.pipe(uglify())
.pipe(rename(function(dir,base,ext){
var trunc = base.split('.')[0];
return trunc + '.min' + ext;
}))
.pipe(gulp.dest('public/js'))
.pipe(gzip())
.pipe(gulp.dest('public/js'))
.pipe(refresh(lrServer));
});
gulp.task('jade', function(){
gulp.src(jadeLocations)
.pipe(jade({ pretty : true }))
.pipe(gulp.dest('src/html'));
});
gulp.task('index', function(){
gulp.src(indexLocation)
.pipe(jade({ pretty : true }))
.pipe(gulp.dest('public'));
});
gulp.task('cacheTemplates', function(){
gulp.src(viewLocations)
.pipe(html2js({
moduleName : 'templates',
prefix : 'templates/'
}))
.pipe(gulp.dest('src/js/templates'));
});
gulp.task('server', function() {
if (node) node.kill();
node = spawn('node', ['app.js'], {stdio: 'inherit'});
node.on('close', function (code) {
if (code === 8) {
gulp.log('Error detected, waiting for changes...');
}
});
});
// -------------------------- //
// ---- watch statements ---- //
// -------------------------- //
gulp.task('default', function(){
gulp.run('karma', 'jsLint', 'sass', 'cssLint', 'jade', 'build', 'server');
gulp.watch(jsLocations, function(){
gulp.run('jsLint', 'build');
});
gulp.watch(cssLocations, function(){
gulp.run('cssLint');
});
gulp.watch(sassLocations, function(){
gulp.run('sass');
});
gulp.watch(jadeLocations, function(){
gulp.run('jade');
});
gulp.watch(indexLocation, function(){
gulp.run('index');
});
gulp.watch(viewLocations, function(){
gulp.run('cacheTemplates');
});
lrServer.listen(35729, function (err) {
if (err) return console.log(err);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment