Last active
August 29, 2015 14:06
-
-
Save geoffreydhuyvetters/9075781fdd924f96deea to your computer and use it in GitHub Desktop.
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 gulp = require("gulp"); | |
var watchify = require('watchify'); | |
var browserify = require('browserify'); | |
var source = require('vinyl-source-stream'); | |
var buffer = require('vinyl-buffer'); | |
var config = require('./config.json'); | |
var plugins = require("gulp-load-plugins")({ | |
pattern: ['gulp-*', 'gulp.*'], | |
replaceString: /\bgulp[\-.]/, | |
}); | |
function getFilePath(target,type){ | |
return config[type][target].folder + "/" + config[type][target].file; | |
} | |
var scripts = ["**/*.js","!node_modules/**/*.js","!public/**/*.js"]; | |
//alias for size(), errors on .size. | |
plugins.filesize = plugins.size; | |
gulp.task('stylesheets', function() { | |
return gulp.src(getFilePath("src","stylesheets")) | |
.pipe(plugins.plumber()) | |
.pipe(plugins.scssLint()) | |
.pipe(plugins.compass({ | |
css: config.stylesheets.dest.folder, | |
sass: config.stylesheets.src.folder, | |
})) | |
.pipe(plugins.autoprefixer({ | |
browsers: ['last 2 versions','ie 9'], | |
cascade: false | |
})) | |
.pipe(plugins.util.env.type === 'production' ? plugins.minifyCss() : plugins.util.noop()) | |
.pipe(plugins.filesize()) | |
.pipe(gulp.dest(config.stylesheets.dest.folder)); | |
}); | |
gulp.task("scripts",function(){ | |
function rebundle() { | |
return bundler.bundle() | |
.on('error', function(error){ | |
console.log(error); | |
this.emit("end"); | |
}) | |
.pipe(source(config.scripts.dest.file)) | |
.pipe(buffer()) | |
.pipe(plugins.util.env.type === 'production' ? plugins.uglify() : plugins.util.noop()) | |
.pipe(plugins.filesize()) | |
.pipe(gulp.dest(config.scripts.dest.folder)); | |
} | |
var bundler = watchify(browserify(getFilePath("src","scripts"), watchify.args)); | |
bundler.on('update', rebundle); | |
return rebundle(); | |
}); | |
gulp.task("hinting", function(){ | |
return gulp.src(scripts) | |
.pipe(plugins.plumber()) | |
.pipe(plugins.jshintCached()) | |
.pipe(plugins.jshintCached.reporter('jshint-stylish')) | |
.pipe(plugins.jshintCached.reporter("fail")) | |
.on('error', function(error){ | |
plugins.util.beep(); | |
this.emit("end"); | |
}); | |
}); | |
gulp.task("server",function(){ | |
plugins.nodemon({script: ".", ignore: ["public/**", "_js/**", "_components/**", "gulpfile.js"]}); | |
}); | |
gulp.task("database", function(){ | |
require('child_process').exec("mongod", function(err, stdout, stderr){ | |
console.log(stdout, stderr, err); | |
}); | |
}); | |
gulp.task('watch', function() { | |
gulp.watch(getFilePath("src","stylesheets"), ['stylesheets']); | |
gulp.watch(scripts, ['hinting']); | |
}); | |
gulp.task('default', ['watch','stylesheets','hinting','scripts','server','database']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment