Created
September 2, 2016 08:19
-
-
Save goper-leo/da47cb8270cf2ffc778cdecff243fc47 to your computer and use it in GitHub Desktop.
gulp
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
'use strict'; | |
var gulp = require('gulp'); | |
var sass = require('gulp-sass'); | |
var concat = require('gulp-concat'); | |
var minifyJS = require('gulp-uglify'); | |
var minifyCSS = require('gulp-minify-css'); | |
var watcher = require('gulp-watch'); | |
var gutil = require('gulp-util'); | |
var rename = require('gulp-rename'); | |
var plumber = require('gulp-plumber'); | |
var path = { // define helper paths for resources | |
// bower path | |
bower: function(path) { | |
return './resources/assets/bower_components/' + path; | |
}, | |
vendors: function(path) { | |
return './resources/assets/vendors/' + path; | |
}, | |
// images path | |
images: function(path) { | |
return './resources/assets/images/' + path; | |
}, | |
// script path | |
scripts: function(path) { | |
return './resources/assets/js/' + path; | |
}, | |
// assets path (public) | |
assets: function(path) { | |
return './public/assets/' + path; | |
}, | |
// resources path -- general | |
resources: function(path) { | |
return './resources/assets/' + path; | |
}, | |
// resources path -- general | |
cmanager: function(path) { | |
return './themes/cpanel/assets/' + path; | |
}, | |
// resources path -- general | |
themes: function(path) { | |
return './public/assets/themes/' + path; | |
} | |
}; | |
/** | |
* Default tasks | |
* @author Glen | |
*/ | |
gulp.task('default', ['sass', 'js', 'library', 'fonts', 'images', 'vendors']); | |
/** | |
* Compile SASS | |
* and minify | |
* @author Glen | |
*/ | |
gulp.task('sass', function () { | |
gutil.log(gutil.colors.blue('Compiling sass files >>>')); | |
gulp.src(path.resources('sass/bootstrap.scss')) | |
.pipe(plumber()) | |
.pipe(sass().on('error', sass.logError)) | |
.pipe(minifyCSS()) | |
.pipe(gulp.dest(path.assets('css'))); | |
gulp.src(path.resources('sass/theme.scss')) | |
.pipe(plumber()) | |
.pipe(sass().on('error', sass.logError)) | |
.pipe(minifyCSS()) | |
.pipe(gulp.dest(path.assets('css'))); | |
gulp.src( path.bower('rrssb/scss/rrssb.scss') ) | |
.pipe(plumber()) | |
.pipe(sass().on('error', sass.logError)) | |
.pipe(minifyCSS()) | |
.pipe(gulp.dest( path.assets('vendors/rrssb/css') )); | |
}); | |
/** | |
* Combine js files from js dir | |
* Copy js vendor files | |
* @author Glen | |
*/ | |
gulp.task('js', function() { | |
gutil.log(gutil.colors.blue('Copying required js files >>>')); | |
gulp.src(path.bower('jquery/dist/jquery.min.js')) | |
.pipe(gulp.dest(path.assets('js'))); | |
gulp.src(path.resources('vendors/**/*')) | |
.pipe(gulp.dest(path.assets('vendors'))); | |
gulp.src(path.bower('bootstrap-sass/assets/javascripts/bootstrap.min.js')) | |
.pipe(gulp.dest(path.assets('js'))); | |
gulp.src(path.bower('bootstrap-sass/assets/javascripts/bootstrap.min.js')) | |
.pipe(gulp.dest(path.assets('js'))); | |
gulp.src(path.bower('matchHeight/jquery.matchHeight.js')) | |
.pipe(gulp.dest(path.assets('vendors/matchHeight'))); | |
// @goper UPV-182 | |
gulp.src(path.bower('jquery-ui/jquery-ui.js')) | |
.pipe(gulp.dest(path.assets('vendors/jquery-ui'))); | |
// @goper Toastr | |
gulp.src(path.bower('toastr/toastr.js')) | |
.pipe(gulp.dest(path.assets('vendors/toastr'))); | |
//MM for Social Sharing | |
gulp.src(path.bower('rrssb/js/rrssb.min.js')) | |
.pipe(gulp.dest(path.assets('vendors/rrssb'))); | |
gutil.log(gutil.colors.green('Combining js files >>>')); | |
gulp.src(path.resources('js/*.js')) | |
.pipe(plumber()) | |
.pipe(concat('main.js')) | |
.pipe(minifyJS()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest(path.assets('js'))); | |
}); | |
/** | |
* Javascript libs that needs to be detached to the combined ones | |
* @author glen | |
*/ | |
gulp.task('library', function () { | |
gulp.src(path.resources('library/**/*')) | |
.pipe(plumber()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(minifyJS()) | |
.pipe(gulp.dest(path.assets('js'))); | |
}); | |
/** | |
* Copy fonts | |
* @author Glen | |
*/ | |
gulp.task('fonts', function() { | |
gutil.log(gutil.colors.green('Copying font files >>>')); | |
gulp.src(path.bower('font-awesome/fonts/**/*')) | |
.pipe(gulp.dest(path.assets('fonts'))); | |
gulp.src(path.bower('bootstrap-sass/assets/fonts/**/*')) | |
.pipe(gulp.dest(path.assets('fonts'))); | |
gulp.src(path.resources('fonts/**/*')) | |
.pipe(gulp.dest(path.assets('fonts'))); | |
}); | |
/** | |
* Copy images | |
* @author Glen | |
*/ | |
gulp.task('images', function() { | |
gutil.log(gutil.colors.green('Copying images >>>')); | |
gulp.src(path.resources('images/**/*')) | |
.pipe(gulp.dest(path.assets('images'))); | |
}); | |
/** | |
* Spy on font files updates (added, modified and deleted) | |
* @author Glen | |
*/ | |
gulp.task('monitor:fonts', function() { | |
gulp.src(path.bower('font-awesome/fonts/**/*')) | |
.pipe(watcher(path.bower('font-awesome/fonts'))) | |
.pipe(gulp.dest(path.assets('fonts'))); | |
gulp.src(path.bower('bootstrap-sass/assets/fonts/**/*')) | |
.pipe(watcher(path.bower('bootstrap-sass/assets/fonts/**/*'))) | |
.pipe(gulp.dest(path.assets('fonts'))); | |
gulp.src(path.resources('fonts/**/*')) | |
.pipe(watcher(path.resources('fonts/**/*'))) | |
.pipe(gulp.dest(path.assets('fonts'))); | |
}); | |
/** | |
* Spy on image updates (added,deleted and modified) | |
* @author Glen | |
*/ | |
gulp.task('monitor:images', function() { | |
gulp.src(path.resources('images/**/*')) | |
.pipe(watcher(path.resources('images/**/*'))) | |
.pipe(gulp.dest(path.assets('images'))); | |
}); | |
/** | |
* Attemp to remove unused images (deleted) | |
* @author Glen | |
*/ | |
gulp.task('clean:images', function() { | |
gutil.colors.green('Sweeping for wards...'); | |
}); | |
/** | |
* Vendor assets | |
* Folks add here your custom bower vendor assets/files | |
* Add @modified under if this block is edited | |
* with your name and branch | |
* @author Glen | |
*/ | |
gulp.task('vendors', function() { | |
gulp.src(path.bower('moment/min/**/*')) | |
.pipe(gulp.dest(path.assets('vendors/moment'))); | |
gulp.src(path.bower('moment-timezone/builds/**/*')) | |
.pipe(gulp.dest(path.assets('vendors/moment-timezone'))); | |
gulp.src(path.bower('eonasdan-bootstrap-datetimepicker/build/**/*')) | |
.pipe(gulp.dest(path.assets('vendors/bootstrap-datetimepicker'))); | |
// @goper UPV-182 | |
gulp.src(path.bower('jquery-ui/**/*')) | |
.pipe(gulp.dest(path.assets('vendors/jquery-ui'))); | |
// @goper For popop alert message | |
gulp.src(path.bower('toastr/**/*')) | |
.pipe(gulp.dest(path.assets('vendors/toastr'))); | |
// @goper For Color Picker | |
gulp.src(path.bower('tinyColorPicker/jqColorPicker.min.js')) | |
.pipe(gulp.dest(path.assets('vendors/tinyColorPicker'))); | |
// @goper For CKEDITOR | |
gulp.src(path.bower('ckeditor/**/*')) | |
.pipe(gulp.dest(path.assets('vendors/ckeditor'))); | |
// @glen UPV-131 | |
gulp.src(path.bower('intercooler-js/src/intercooler.js')) | |
.pipe(plumber()) | |
.pipe(minifyJS()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest(path.assets('vendors/intercooler'))); | |
// @glen UPV-132 | |
gulp.src(path.bower('eonasdan-bootstrap-datetimepicker/build/**/*')) | |
.pipe(plumber()) | |
.pipe(gulp.dest(path.assets('vendors/bootstrap-datetimepicker'))); | |
// @glen UPV-132 | |
gulp.src(path.vendors('tagsinput/**/*')) | |
.pipe(plumber()) | |
.pipe(minifyJS()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest(path.assets('vendors/tagsinput'))); | |
// @glen UPV-132 | |
gulp.src(path.bower('string/dist/**/*')) | |
.pipe(plumber()) | |
.pipe(gulp.dest(path.assets('vendors/stringjs'))); | |
// @glen UPV-150 | |
gulp.src(path.vendors('prevw/**/*')) | |
.pipe(plumber()) | |
.pipe(minifyJS()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest(path.assets('vendors/prevw'))); | |
// @glen UPV-150 | |
gulp.src(path.resources('custom/upvote-widget/**/*.js')) | |
.pipe(plumber()) | |
.pipe(minifyJS()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest(path.assets('widgets'))); | |
// @glen UPV-150 | |
gulp.src(path.resources('custom/upvote-widget/**/*.scss')) | |
.pipe(plumber()) | |
.pipe(sass().on('error', sass.logError)) | |
.pipe(minifyCSS()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest(path.assets('widgets'))); | |
// @glen UPV-150 | |
gulp.src(path.bower('dragula.js/dist/**/*')) | |
.pipe(plumber()) | |
.pipe(gulp.dest(path.assets('vendors/dragula'))); | |
// @glen UPV-230 | |
gulp.src(path.bower('bootbox.js/bootbox.js')) | |
.pipe(plumber()) | |
.pipe(minifyJS()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest(path.assets('vendors/bootbox'))); | |
// @goper Type-ahead | |
gulp.src(path.bower('magicsuggest/**/*')) | |
.pipe(plumber()) | |
.pipe(gulp.dest(path.assets('vendors/magicsuggest'))); | |
}); | |
gulp.task('cpanel', ['cpanel:sass', 'cpanel:fonts', 'cpanel:js', 'cpanel:library']); | |
gulp.task('cpanel:sass', function(){ | |
gulp.src(path.cmanager('sass/**/theme.scss')) | |
.pipe(plumber()) | |
.pipe(sass().on('error', sass.logError)) | |
.pipe(minifyCSS()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest(path.themes('cpanel'))); | |
}); | |
gulp.task('cpanel:js', function(){ | |
gulp.src(path.cmanager('js/*.js')) | |
.pipe(plumber()) | |
.pipe(minifyJS()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest(path.themes('cpanel/js'))); | |
}); | |
gulp.task('cpanel:fonts', function(){ | |
gulp.src(path.cmanager('fonts/**/*')) | |
.pipe(watcher(path.cmanager('fonts/**/*'))) | |
.pipe(gulp.dest(path.themes('cpanel/fonts'))); | |
}); | |
gulp.task('cpanel:library', function(){ | |
gulp.src(path.cmanager('library/**/*')) | |
.pipe(watcher(path.cmanager('library/**/*'))) | |
.pipe(gulp.dest(path.themes('cpanel/library'))); | |
}); | |
/** | |
* Gulp task watcher | |
* @author Glen | |
*/ | |
gulp.task('watch', function () { | |
gutil.log(gutil.colors.green('Spying ...')); | |
gulp.watch('./gulpfile.js', ['default']); | |
gulp.watch(path.resources('sass/**/*.scss'), ['sass']); | |
gulp.watch(path.bower('bootstrap-sass/assets/stylesheets/**/*.scss'), ['sass']); | |
gulp.watch(path.resources('js/*.js'), ['js']); | |
gulp.watch(path.resources('vendors/**/*.js'), ['vendors']); | |
gulp.watch(path.resources('library/**/*'), ['library']); | |
gulp.watch(path.resources('fonts/**/*.*'), ['fonts']); | |
gulp.watch(path.resources('images/**/*.*'), ['images']); | |
gulp.watch(path.resources('custom/**/*'), ['vendors']); | |
///gulp.watch(path.cmanager('sass/**/*'), ['cpanel:sass']); | |
//gulp.watch(path.cmanager('fonts/**/*.*'), ['cpanel:fonts']); | |
//gulp.watch(path.cmanager('js/**/*.js'), ['cpanel:js']); | |
//gulp.watch(path.cmanager('js/**/*.js'), ['cpanel:library']); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment