Skip to content

Instantly share code, notes, and snippets.

@hadifarnoud
Forked from hansent/gulpfile.js
Created October 19, 2016 19:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hadifarnoud/dd72f9987ccec342502c0001679ef5d9 to your computer and use it in GitHub Desktop.
//gulp & plugins
var gulp = require('gulp');
var gutil = require('gulp-util');
var jshint = require('gulp-jshint');
var browserify = require('gulp-browserify');
var jade = require('gulp-jade');
var stylus = require('gulp-stylus');
var mocha = require('gulp-mocha');
var nodemon = require('gulp-nodemon');
var livereload = require('gulp-livereload');
var clean = require('gulp-clean');
/**
* Tasks:
*
* build (default):
* builds the client into ./dist
*
* develop:
* builds client, and runs auto reloading dev server
*
* lint:
* lint all javascript sourcefiles
*
* test:
* run mocha tests in ./test/
*
* debug:
* like develop but also runs tests and linting
*/
gulp.task('default', ['build']);
gulp.task('build', ['scripts', 'jade', 'stylus', 'assets']);
gulp.task('develope', ['build', 'serve', 'livereload']);
gulp.task('debug', ['lint', 'test', 'build', 'serve', 'watch']);
/**
* path globs / expressions for targets below
*/
var paths = {
main : 'server.js',
tests : 'test/**/*.js',
sources : [ '**/*.js', '!node_modules/**', '!client/vendor/**', '!build/**'],
client : {
main : 'client/js/app.js',
sources : 'client/js/**.*.js',
stylus : 'client/**/*.styl',
jade : 'client/**/*.jade',
assets : ['client/**/*', '!**/*.js', '!**/*.styl', '!**/*.jade'],
build : './build/'
}
};
//clean build directory
gulp.task('clean', function(){
gulp.src(paths.client.build, {read: false} )
.pipe(clean());
});
// lint all of our js source files
gulp.task('lint', function (){
return gulp.src(paths.sources)
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// run mocha tests
gulp.task('test', function (){
return gulp.src(paths.tests, {read: false})
.pipe(mocha({reporter: 'list'}))
.on('error', gutil.log);
});
//run app using nodemon
gulp.task('serve', ['build'], function(){
return nodemon({
script: 'server.js', options: '-i client/*'
});
});
// will watch client files and rebuild on change
gulp.task('watch', function(){
gulp.watch(paths.client.assets, ['assets']);
gulp.watch(paths.client.stylus, ['stylus']);
gulp.watch(paths.client.jade, ['jade']);
gulp.watch(paths.client.tests, ['test']);
gulp.watch(paths.sources, ['lint']);
});
// livereload browser on client app changes
gulp.task('livereload', ['serve'], function(){
gulp.watch(paths.client.assets, ['assets']);
gulp.watch(paths.client.stylus, ['stylus']);
gulp.watch(paths.client.jade, ['jade']);
var server = livereload();
var all_build_files = paths.client.build + '/**/*';
return gulp.watch(all_build_files, function(evt){
server.changed(evt.path);
});
});
// build client side js app
gulp.task('scripts', function(){
return gulp.src(paths.client.main)
.pipe(browserify({
basedir: './client/js/',
debug : !gutil.env.production
}))
.pipe(gulp.dest(paths.client.build));
});
// copy static assets
gulp.task('assets', function(){
return gulp.src(paths.client.assets)
.pipe(gulp.dest(paths.client.build));
});
// build all stylus files
gulp.task('stylus', function(){
return gulp.src(paths.client.stylus)
.pipe(stylus({pretty:true}))
.pipe(gulp.dest(paths.client.build));
});
// build any jade tenplates
gulp.task('jade', function(){
return gulp.src(paths.client.jade)
.pipe(jade({pretty:true}))
.pipe(gulp.dest(paths.client.build));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment