Created
May 20, 2015 13:40
-
-
Save AndrwM/a68e4424da68c61e8b66 to your computer and use it in GitHub Desktop.
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'), | |
$ = require('gulp-load-plugins')(), // this is an arbitrary object that loads all gulp plugins in package.json. | |
path = require('path'), | |
browserSync = require('browser-sync'), | |
reload = browserSync.reload, | |
del = require('del'), | |
fs = require('fs'), | |
renderer = require("./renderer"), | |
gulpBowerFiles = require('gulp-bower-files'), | |
wiredep = require('wiredep').stream; | |
//------- HOTFIX ERROR HANDLING | |
// https://github.com/gulpjs/gulp/issues/71#issuecomment-68062782 | |
var origSrc = gulp.src; | |
gulp.src = function () { | |
return fixPipe(origSrc.apply(this, arguments)); | |
}; | |
function fixPipe(stream) { | |
var origPipe = stream.pipe; | |
stream.pipe = function (dest) { | |
arguments[0] = dest.on('error', function (error) { | |
var nextStreams = dest._nextStreams; | |
if (nextStreams) { | |
nextStreams.forEach(function (nextStream) { | |
nextStream.emit('error', error); | |
}); | |
} else if (dest.listeners('error').length === 1) { | |
throw error; | |
} | |
}); | |
var nextStream = fixPipe(origPipe.apply(this, arguments)); | |
(this._nextStreams || (this._nextStreams = [])).push(nextStream); | |
return nextStream; | |
}; | |
return stream; | |
} | |
//------- END HOTFIX ERROR HANDLING | |
gulp.task("bower-files", function(){ | |
gulpBowerFiles().pipe(gulp.dest("./dist/bower_components/")); | |
}); | |
gulp.task('wiredep',['bower-files'], function () { | |
// del("./src/templates/includes/head.jade",function(err, data){console.log("ahhhhhh")} ); | |
gulp.src('./src/templates/includes/head.jade') | |
.pipe(wiredep({ | |
ignorePath: /^(\.\.\.\/)*\.\./ | |
})) | |
.pipe(gulp.dest('./src/templates/includes')); | |
}); | |
gulp.task('browser-sync', function() { | |
browserSync({ | |
open: false, | |
server: { | |
baseDir: "./dist", | |
} | |
}); | |
}); | |
gulp.task('styles', function() { | |
return gulp.src('./src/stylesheets/**/*.{scss,sass}') | |
.pipe($.sass({ | |
includePaths: ['./src/stylesheets'] | |
})) | |
.pipe(gulp.dest('./dist/stylesheets')); | |
}); | |
gulp.task('js', function() { | |
return gulp.src('src/scripts/*.js') | |
.pipe($.plumber()) | |
.pipe( $.browserify({ | |
debug: true | |
})) | |
// .pipe( $.uglify() ) | |
.pipe( $.rename('main.js')) | |
.pipe( gulp.dest('dist/scripts/')); | |
}); | |
gulp.task('clean', function(cb) { | |
del('./dist', cb); | |
}); | |
gulp.task('images', function() { | |
return gulp.src('./src/images/**/*') | |
.pipe($.imagemin({ | |
progressive: true | |
})) | |
.pipe(gulp.dest('./dist/images')) | |
}) | |
gulp.task('templates', function() { | |
// Disable county template from being renderd. | |
return gulp.src(['src/**/!(_)*.jade']) | |
.pipe($.plumber()) | |
.pipe($.jade({ | |
pretty: true | |
})) | |
.pipe( gulp.dest('dist/') ) | |
}); | |
gulp.task("build-out", function(){ | |
// Perfrom the templates task again but with the county-template | |
return gulp.src(['src/**/!(_)*.jade']) | |
.pipe($.plumber()) | |
.pipe($.jade({ | |
pretty: true | |
})) | |
.pipe( gulp.dest('dist/') ) | |
renderer() | |
}); | |
gulp.task('build', ['styles', 'js', 'templates', 'images', 'wiredep']); | |
gulp.task('serve', ['styles', 'js', 'templates', 'images', 'wiredep', 'browser-sync'], function () { | |
gulp.watch('src/stylesheets/**/*.{scss,sass}',['styles', reload]); | |
gulp.watch('src/scripts/*.js',['js', reload]); | |
gulp.watch('src/images/**/*',['images', reload]); | |
gulp.watch('src/**/*.jade',['templates', reload]); | |
}); | |
gulp.task('default', ['serve']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment