Created
February 17, 2014 18:39
-
-
Save cideveloper/9056407 to your computer and use it in GitHub Desktop.
gulp: Sample Gulp file
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 exec = require('child_process').exec; | |
var sys = require('sys'); | |
var path = require('path'); | |
var gulp = require('gulp'); | |
var gutil = require('gulp-util'); | |
var less = require('gulp-less'); | |
var minifycss = require('gulp-minify-css'); | |
var uglify = require('gulp-uglify'); | |
var rename = require("gulp-rename"); | |
var imagemin = require('gulp-imagemin'); | |
var refresh = require('gulp-livereload'); | |
var lr = require('tiny-lr'); | |
var server = lr(); | |
var webshot = require('webshot'); | |
gulp.task('default', ['lr-server', 'styles', 'scripts', 'screenshot', 'imageminifier', 'phpunit', 'watch']); | |
gulp.task('lr-server', function() { | |
server.listen(35729, function(err) { | |
if(err) return console.log(err); | |
}); | |
}) | |
gulp.task('styles', function() { | |
return gulp.src('public/assets/less/styles.less') | |
.pipe(less()) | |
.pipe(minifycss()) | |
.pipe(rename(function (dir, base, ext) { | |
return base + ".min" + ext; | |
})) | |
.pipe(gulp.dest('public/assets/css')) | |
.pipe(refresh(server)); | |
}); | |
gulp.task('scripts', function() { | |
return gulp.src('public/assets/js/src/*.js') | |
.pipe(uglify()) | |
.pipe(rename(function (dir, base, ext) { | |
return base + ".min" + ext; | |
})) | |
.pipe(gulp.dest('public/assets/js/dist')) | |
.pipe(refresh(server)); | |
}); | |
gulp.task('watch', function() { | |
//gulp.watch('public/assets/less/*.less', ['styles']); | |
//gulp.watch('tests/*Test.php', ['phpunit']); | |
//gulp.watch('public/assets/js/src/*.js', ['scripts']); | |
//gulp.watch('public/assets/images/screenshots/watchfile.txt', ['screenshot']); | |
//gulp.watch('views/**/**', ['scripts']); | |
}); | |
gulp.task('imageminifier', function() { | |
return gulp.src('public/assets/images/src/*') | |
.pipe(imagemin()) | |
.pipe(gulp.dest('public/assets/images/dist')); | |
}); | |
gulp.task('phpunit', function() { | |
exec('phpunit', function(error, stdout) { | |
sys.puts(stdout); | |
}); | |
}); | |
gulp.task('screenshot', function() { | |
var options = { | |
screenSize: { | |
width: 400 | |
, height: 480 | |
} | |
, shotSize: { | |
width: 400 | |
, height: 'all' | |
} | |
, userAgent: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us)' | |
+ ' AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g' | |
} | |
webshot('http://localhost:8000/', 'public/assets/images/screenshots/mobile.png', options, function(err) { | |
// screenshot now saved to google.png | |
}); | |
var options = { | |
screenSize: { | |
width: 1024 | |
, height: 768 | |
} | |
, shotSize: { | |
width: 1024 | |
, height: 'all' | |
} | |
, userAgent: 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0' | |
} | |
webshot('http://localhost:8000/', 'public/assets/images/screenshots/desktop.png', options, function(err) { | |
// screenshot now saved to google.png | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment