Skip to content

Instantly share code, notes, and snippets.

@cranesandcaff
Created April 29, 2014 17:03
Show Gist options
  • Save cranesandcaff/11406210 to your computer and use it in GitHub Desktop.
Save cranesandcaff/11406210 to your computer and use it in GitHub Desktop.
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var mocha = require('gulp-mocha');
var seq = require('run-sequence');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var logger = require('./lib/logger');
var nodemon = require('gulp-nodemon');
var sass = require('gulp-ruby-sass');
var minCSS = require('gulp-minify-css');
var bower = require('gulp-bower-files');
var watch = require('gulp-watch');
var sync = require('browser-sync');
var open = require('open');
var prefix = require("gulp-autoprefixer");
//Some names truncated or alterered to keep everything lined up. Style choice,
//can be changed
var paths = {
scripts: ['./*.js', './lib/**/*.js', './models/**/*.js', './routes/**/*.js', './client/scripts/**/*.js'],
clientScripts: ['./client/scripts/**/*.js'],
styles: ['./client/styles/**/*.sass']
};
function startBrowserSync(){
sync.init(null, {
files: paths,
ports: {
min: 3001,
max: 3002
},
injectChanges: false,
logConnections: true,
debugInfo: true
});
}
function styles(){
var stream = gulp.src(paths.styles)
.pipe(sass())
.pipe(prefix('last 2 version', 'safari 5', 'ie 9', 'ie 8', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest('./client/build/'))
.pipe(minCSS())
.pipe(gulp.dest('./public/build/'));
return stream;
}
gulp.task('server', function () {
nodemon({
script: 'app.js',
ext: 'jade js sass',
env: { 'NODE_ENV': 'development' }
})
.on('start', ['test'])
.on('change', ['test'])
.on('restart', function () {
});
});
//The bower task relies on the original author using the proper main file convention
//In the event that an author didn't do this you can override it. Check the docs for override instructions.
gulp.task('bower', function(){
bower()
.pipe(concat('lib.js'))
.pipe(gulp.dest('./client/build'))
.pipe(uglify())
.pipe(concat('lib.min.js'))
.pipe(gulp.dest('./public/build'))
});
gulp.task('scripts', function(){
return gulp.src(paths.clientScripts)
.pipe(concat('app.js'))
.pipe(gulp.dest('./client/build'))
.pipe(uglify())
.pipe(concat('app.min.js'))
.pipe(gulp.dest('./public/build'))
.pipe(sync.reload({stream:true}));
});
gulp.task('styles', function(){
return styles();
})
gulp.task('browserSync', ['server'], function(){
startBrowserSync();
setTimeout(function(){
open('http://localhost:3000');
}, 3000);
});
gulp.task('reloadSync', function(){
sync.reload();
})
gulp.task('watchScripts', function(){
gulp.watch(paths.clientScripts, ['scripts', 'reloadSync']);
})
gulp.task('watchStyles', function(){
return watch({
name: 'styles',
glob: paths.styles
}, function(){
return styles()
.pipe(sync.reload({stream: true, once: true}));
});
});
gulp.task('serve', ['scripts', 'styles', 'watchScripts', 'watchStyles', 'browserSync']);
gulp.task('lint', function(){
return gulp.src(paths.scripts)
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
gulp.task('mocha', function(){
gulp.src(['./test/*.js'])
.pipe(mocha({
reporter: 'spec',
globals: {
should: require('should')
}
}));
});
gulp.task('test', function(cb) {
seq('lint', 'mocha', cb);
});
gulp.task('default', ['server']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment