Skip to content

Instantly share code, notes, and snippets.

@howardpanton
Forked from chriskjaer/gulpfile.js
Last active August 29, 2015 14:05
Show Gist options
  • Save howardpanton/05184c92c5d024a3129e to your computer and use it in GitHub Desktop.
Save howardpanton/05184c92c5d024a3129e to your computer and use it in GitHub Desktop.
var gulp
= require('gulp'),
gutil = require('gulp-util'),
gutils = require('gulp-load-utils')(['date']);
sass = require('gulp-sass'),
csso = require('gulp-csso'),
uglify = require('gulp-uglify'),
jade = require('gulp-jade'),
concat = require('gulp-concat'),
livereload = require('gulp-livereload'), // Livereload plugin needed: https://chrome.google.com/webstore/detail/livereload/
tinylr = require('tiny-lr'),
express = require('express'),
app = express(),
marked = require('marked'), // For :markdown filter in jade
path = require('path'),
scsslint = require('gulp-scsslint'),
compass = require('gulp-compass'),
autoprefixer = require('gulp-autoprefixer'),
minifyCSS = require('gulp-minify-css'),
rename = require('gulp-rename'),
coffee = require("gulp-coffee"),
notify = require('gulp-notify'),
clean = require('gulp-clean'),
changed = require('gulp-changed')
server = tinylr(),
gzip = require('gulp-gzip'),
exec = require('gulp-exec'),
header = require('gulp-header'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
plumber = require('gulp-plumber'),
md5 = require('MD5'),
gulpif = require('gulp-if'),
del = require('del'),
cache = require('gulp-cache'),
imagemin = require('gulp-imagemin'),
args = require('yargs').argv;
var isStaging = args.type === 'staging';
var isProduction = args.type === 'production';
// gulp scripts --type production
// Build out Compass files
gulp.task('compass', function() {
gulp.src('source/assets/sass/**/*.scss')
.pipe(changed('build/assets/css')) // Check for changed files
.pipe(plumber()) // Keep Gulp running even if there are erros
.pipe(compass({
css: 'build/assets/css',
sass: 'source/assets/sass',
image: 'source/assets/img',
style: 'expanded'
}))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
.pipe( rename({suffix: '.min'}))
.pipe( csso()) // Compress CSS
.pipe(header('/* Last Updated:' + gutils.date('mmm d, yyyy h:MM:ss TT') + '*/\n')) // Add date top of the file
.pipe(gulpif(isStaging, gzip( {append: false})))
.pipe( gulp.dest('build/assets/css'))
.pipe(exec('rm -rf ~/Dropbox/htdocs/www.arts.ac.uk/html/assets/css; cp -r build/assets/css ~/Dropbox/htdocs/www.arts.ac.uk/html/assets/'))
.pipe(notify({ message: 'Compass task complete' }));
});
// Build out Coffescript
gulp.task('coffee', function () {
gulp.src(['source/assets/coffeescript/modules/**/*.coffee',
'source/assets/coffeescript/on_doc_ready/**/*.coffee',
'source/assets/coffeescript/on_window_load/**/*.coffee',
'source/assets/coffeescript/on_window_resize/**/*.coffee'])
.pipe(changed('build/assets/js'))
.pipe(plumber())
.pipe(coffee({bare: true}).on('error', gutil.log))
.pipe(concat('compiled.modules.js'))
//.pipe(jshint()) Too Many Errors
//.pipe(jshint.reporter('default'))
.pipe( rename('script.js'))
.pipe(gulp.dest('build/assets/js'))
.pipe( rename('script.min.js'))
.pipe(uglify())
.pipe(header('/* Last Updated:' + gutils.date('mmm d, yyyy h:MM:ss TT') + '*/\n'))
.pipe(gulpif(isStaging, gzip( {append: false})))
.pipe(gulp.dest('build/assets/js'))
.pipe(exec('rm -rf ~/Dropbox/htdocs/www.arts.ac.uk/html/assets/js; cp -r build/assets/js ~/Dropbox/htdocs/www.arts.ac.uk/html/assets/'))
.pipe(notify({ message: 'Coffee is complete' }));
});
gulp.task('jade', function() {
return gulp.src(
[
'source/**/*.jade',
'!source/_includes/**/*.jade',
'!source/_layout/**/*.jade',
'!source/blog/**/*.jade',
'!source/styleguide/**/*.jade',
'source/index.jade'
]
)
.pipe(changed('build/assets/js', {extension: '.html'}))
.pipe(jade({
pretty: true
}))
.pipe(gulp.dest('build'))
.pipe(notify({ message: 'Jade task is complete' }));
});
gulp.task('images', function() {
return gulp.src('source/assets/img/**/*')
.pipe(changed('build/assets/img'))
.pipe(cache(imagemin({ optimizationLevel: 5, progressive: true, interlaced: true })))
.pipe(gulp.dest('build/assets/img'))
});
gulp.task('express', function() {
app.use(express.static(path.resolve('build')));
app.listen(9000);
gutil.log('Listening on port: 9000');
});
gulp.task('clean', function(cb) {
del(['build'], cb)
});
gulp.task('watch', function () {
server.listen(35729, function (err) {
if (err) {
return console.log(err);
}
gulp.watch('src/assets/styles/*/*.scss',['compass']);
gulp.watch(['src/coffeescript/modules/**/*.coffee',
'src/coffeescript/on_doc_ready/**/*.coffee',
'src/coffeescript/on_window_load/**/*.coffee',
'src/coffeescript/on_window_resize/**/*.coffee'],['compass']);
gulp.watch('src/assets/js/*.js',['js']);
gulp.watch('src/jade/*/*.jade',['templates']);
});
});
//// Default Task
//gulp.task('default', ['compass','jade','coffee' , 'image', 'express','watch']);
// Default task
gulp.task('default', ['clean'], function() {
gulp.start('compass', 'jade', 'images', 'coffee', 'express', 'watch');
});
{
"name": "ual",
"version": "1.0.0",
"description": "UAL build system",
"main": "]index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Howard Panton",
"license": "ISC",
"devDependencies": {
"marked": "^0.3.2",
"tiny-lr": "^0.1.0",
"gulp-concat": "^2.3.4",
"gulp-livereload": "^2.1.0",
"gulp-util": "^3.0.0",
"gulp-uglify": "~0.3.2",
"gulp-jade": "^0.7.0",
"gulp": "^3.8.7",
"gulp-csso": "^0.2.9",
"gulp-sass": "^0.7.2",
"gulp-scss-lint": "^0.1.1",
"gulp-scsslint": "0.0.5",
"gulp-compass": "^1.2.0",
"gulp-minify-css": "^0.3.7",
"gulp-rename": "^1.2.0",
"gulp-autoprefixer": "0.0.8",
"gulp-coffee": "^2.1.1",
"gulp-changed": "~1.0.0",
"gulp-notify": "^1.4.2",
"gulp-clean": "^0.3.1",
"MD5": "^1.2.1",
"gulp-exec": "~2.1.0",
"gulp-gzip": "0.0.8",
"gulp-header": "~1.0.5",
"gulp-load-utils": "0.0.4",
"dateformat": "~1.0.8-1.2.3",
"gulp-jshint": "~1.8.4",
"gulp-plumber": "~0.6.5",
"yargs": "~1.3.1",
"gulp-if": "~1.2.4",
"del": "~0.1.2",
"imagemin": "~1.0.4",
"gulp-cache": "~0.2.1",
"gulp-cached": "~1.0.1",
"gulp-imagemin": "~1.0.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment