Last active
August 29, 2015 13:56
-
-
Save kevnk/9224356 to your computer and use it in GitHub Desktop.
Be sure to replace `mytheme` with your theme's directory name on lines 59 and 62
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 less = require('gulp-less'); | |
var minifycss = require('gulp-minify-css'); | |
var jshint = require('gulp-jshint'); | |
var concat = require('gulp-concat'); | |
var uglify = require('gulp-uglify'); | |
var replace = require('gulp-replace'); | |
var notify = require('gulp-notify'); | |
gulp.task('less', function() { | |
gulp | |
.src('less/style.less') | |
.pipe(less().on("error", notify.onError(function (error) { | |
return "Error compiling LESS: " + error.message; | |
}))) | |
// .pipe(minifycss()) | |
.pipe(gulp.dest('dist/css')) | |
.pipe(notify({ | |
message: 'Successfully compiled LESS' | |
})); | |
}); | |
gulp.task('lint', function() { | |
gulp | |
.src('js/script.js') | |
.pipe(jshint()) | |
.pipe(jshint.reporter('default')); | |
}); | |
gulp.task('js', function() { | |
gulp | |
.src([ | |
'components/jquery/dist/jquery.min.js', | |
'components/bootstrap/js/transition.js', | |
'components/bootstrap/js/collapse.js', | |
'components/bootstrap/js/carousel.js', | |
'components/bootstrap/js/dropdown.js', | |
'components/bootstrap/js/modal.js', | |
'js/script.js' | |
]) | |
.pipe(concat('script.js')) | |
// .pipe(uglify()) | |
.pipe(gulp.dest('dist/js')) | |
.pipe(notify({ | |
message: 'Successfully compiled JS' | |
})); | |
}); | |
var hashes = {}; | |
gulp.task('hash', function(){ | |
hash('dist/js/script.js'); | |
hash('dist/css/style.css'); | |
}) | |
gulp.task('bust', function(){ | |
gulp.src(['../../design/responsive/layout/local.xml']) | |
.pipe(replace(/(dist\/js\/script\.js)[^<]*/, '$1?v='+hashes['dist/js/script.js'])) | |
.pipe(replace(/(dist\/css\/style\.css)[^<]*/, '$1?v='+hashes['dist/css/style.css'])) | |
.pipe(gulp.dest('../../design/responsive/layout')) | |
}) | |
function hash(filename) { | |
var crypto = require('crypto'); | |
var fs = require('fs'); | |
var shasum = crypto.createHash('sha1'); | |
hashes[filename] = hashes[filename] ? hashes[filename] : {}; | |
var s = fs.ReadStream(filename); | |
s.on('data', function(d) { | |
shasum.update(d); | |
}); | |
s.on('end', function() { | |
hashes[filename] = shasum.digest('hex').substr(0,8); | |
gulp.run('bust') | |
}); | |
} | |
gulp.task('default', ['less', 'lint', 'js', 'hash'], function() { | |
gulp.watch('less/**/*.less', function() { | |
gulp.run('less'); | |
gulp.run('hash'); | |
}); | |
gulp.watch('js/**/*.js', function() { | |
gulp.run('lint'); | |
gulp.run('js'); | |
gulp.run('hash'); | |
}); | |
}); |
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
{ | |
"devDependencies": { | |
"gulp": "~3.4.0", | |
"gulp-less": "~1.1.10", | |
"gulp-notify": "~0.3.4-2", | |
"gulp-minify-css": "~0.2.0", | |
"gulp-uglify": "~0.1.0", | |
"gulp-concat": "~2.1.7", | |
"gulp-jshint": "~1.3.4", | |
"gulp-replace": "~0.2.0", | |
"event-stream": "~3.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment