Created
September 9, 2015 15:10
-
-
Save kmassada/1457aab5aa8060a80059 to your computer and use it in GitHub Desktop.
gulpfile-basic-laravel.js
This file contains hidden or 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
/* | |
|---------------------------------------------------------------- | |
| Have a Drink! | |
|---------------------------------------------------------------- | |
| | |
*/ | |
// --- INIT | |
var gulp = require('gulp'), | |
sass = require('gulp-ruby-sass'), // compiles sass to CSS | |
minify = require('gulp-minify-css'), // minifies CSS | |
concat = require('gulp-concat'), // concat files | |
uglify = require('gulp-uglify'), // uglifies JS | |
rename = require('gulp-rename'), // rename files | |
notify = require('gulp-notify'), // notify using MAC | |
bower = require('gulp-bower'), // bower update tasks | |
phpunit = require('gulp-phpunit'); // PHP unit test | |
livereload = require('gulp-livereload'); // reload browser | |
sourcemaps = require('gulp-sourcemaps'); // debug tool by showing file reference | |
// Paths variables | |
var paths = { | |
'resources': { | |
'sass' : './public/sass/', | |
'scss' : './public/scss/', | |
'js' : './public/js/', | |
'vendor': './public/vendor/', | |
'fonts' : './public/fonts/', | |
'css' : './public/css/', | |
}, | |
'assets': { | |
'css' : './public/assets/css/', | |
'js' : './public/assets/js/', | |
'bower': './public/assets/bower_components/', | |
}, | |
'app': { | |
'tests': './app/tests', | |
} | |
}; | |
/** | |
* Run bower update on assets.bower folder | |
*/ | |
gulp.task('bower', function() { | |
return bower() | |
.pipe(gulp.dest(paths.assets.bower)) ; | |
}); | |
/** | |
* Copy fonts and icons to destination | |
*/ | |
gulp.task('icons', function() { | |
return gulp.src([ | |
paths.assets.bower+'font-awesome/fonts/**/*.*', | |
paths.assets.bower+'bootstrap-sass-official/assets/fonts/**/*.*' | |
]) .pipe(gulp.dest(paths.resources.fonts)); | |
}); | |
// PHP unit | |
gulp.task('phpunit', function() { | |
var options = {debug: false, notify: false}; | |
return gulp.src(paths.app.tests+'/*.php') | |
.pipe(phpunit(paths.resources.vendor+'bin/phpunit', options)) | |
// both notify and notify.onError will take optional notifier: growlNotifier for windows notifications | |
// if options.notify is true be sure to handle the error here or suffer the consequenses! | |
.on('error', notify.onError({ | |
title: 'PHPUnit Failed', | |
message: 'One or more tests failed, see the cli for details.' | |
})) | |
// will fire only if no error is caught | |
.pipe(notify({ | |
title: 'PHPUnit Passed', | |
message: 'All tests passed!' | |
})); | |
}); | |
/** | |
* Select each JS files required, concat, uglify, and minify them to app.min.js | |
*/ | |
gulp.task('js', function(){ | |
return gulp.src([ | |
paths.assets.bower+'jquery/dist/jquery.js', | |
paths.assets.bower+'bootstrap-sass-official/assets/javascripts/bootstrap.js', | |
paths.assets.bower+'jssor-slider/js/jssor.slider.mini.js', | |
paths.assets.bower+'bootstrap-table/dist/bootstrap-table.js', | |
paths.assets.bower+'bootstrap-table/dist/bootstrap-table-en-US.js' | |
]) | |
.pipe(sourcemaps.init()) | |
.pipe(gulp.dest(paths.resources.js)) | |
.pipe(sourcemaps.write()) | |
.pipe(concat('app.js')) | |
.pipe(gulp.dest(paths.resources.js)) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(uglify()) | |
.pipe(gulp.dest(paths.resources.js)) | |
.pipe(livereload()); | |
}); | |
/** | |
* Select each CSS files required, concat, uglify, and minify them to: other.min.css | |
*/ | |
gulp.task('css', function(){ | |
return gulp.src([ | |
paths.assets.bower+'bootstrap-table/dist/bootstrap-table.min.css', | |
paths.assets.bower+'bootstrap-social/bootstrap-social.css', | |
paths.assets.bower+'font-awesome/css/font-awesome.css' | |
]) | |
.pipe(concat('other.css')) | |
.pipe(gulp.dest(paths.resources.css)) | |
.pipe(minify({keepSpecialComments:0})) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest(paths.resources.css)) | |
.pipe(livereload()); | |
}); | |
/** | |
* On bootsrap SASS folder, watch for changes, compile, concat, uglify, and minify to: app.min.css | |
*/ | |
gulp.task('bootstrap-sass', function() { | |
return sass(paths.assets.bower+'bootstrap-sass-official/assets/stylesheets/_bootstrap.scss') | |
.pipe(concat('app.css')) | |
.pipe(gulp.dest(paths.resources.css)) | |
.pipe(minify({keepSpecialComments:0})) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest(paths.resources.css)) | |
.pipe(livereload()); | |
}); | |
gulp.task('watch', function() { | |
livereload.listen(); | |
// watch scss files | |
gulp.watch(paths.resources.css, function() { | |
gulp.run('bootstrap-sass'); | |
}); | |
// watch js files | |
gulp.watch(paths.resources.js, function() { | |
gulp.run('js'); | |
}); | |
}); | |
gulp.task('default',['bower', 'icons', 'js', 'css' , 'bootstrap-sass']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment