Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Variables */
- var gulp = require('gulp'),
- jshint = require('gulp-jshint'),
- jsmin = require('gulp-jsmin'),
- uglify = require('gulp-uglify'),
- rename = require('gulp-rename'),
- concat = require('gulp-concat'),
- notify = require('gulp-notify'),
- imagemin = require('gulp-imagemin'),
- del = require('del'),
- connect = require('gulp-connect'),
- uglifycss = require('gulp-uglifycss'),
- csslint = require('gulp-csslint'),
- zip = require("gulp-zip"),
- concatCss = require('gulp-concat-css'),
- autoprefixer = require('gulp-autoprefixer'),
- gutil = require('gulp-util'),
- gulpif = require('gulp-if')
- // livereload = require('gulp-livereload'),
- // jade = require('gulp-jade'),
- // less = require('gulp-less'),
- // sass = require('gulp-sass')
- // historyApiFallback = require('connect-history-api-fallback')
- ;
- var shouldMinify = true; showReports = false;
- var paths = {
- dev: [
- 'wp-content/themes/entelperu/dev/css/*.css',
- 'wp-content/themes/entelperu/dev/js/*.js',
- 'wp-content/themes/entelperu/dev/images/**/*.*'
- ],
- prod: [
- 'wp-content/themes/entelperu/css',
- 'wp-content/themes/entelperu/js',
- 'wp-content/themes/entelperu/images'
- ],
- cleaned: [
- 'wp-content/themes/entelperu/css/*.*',
- 'wp-content/themes/entelperu/js/*.*',
- 'wp-content/themes/entelperu/images/**/*.*'
- ],
- backups: [
- 'wp-content/themes/entelperu/css/*.*',
- 'wp-content/themes/entelperu/js/*.*',
- 'wp-content/themes/entelperu/images/**/*.*'
- ]
- };
- var customReporter = function(file) {
- gutil.log(gutil.colors.cyan(file.csslint.errorCount)+' errors in '+gutil.colors.magenta(file.path));
- file.csslint.results.forEach(function(result) {
- gutil.log(result.error.message+' on line '+result.error.line);
- });
- };
- gulp.task('buildImg', ['buildCss'], function (cb) {
- return gulp.start("img");
- });
- gulp.task('img', function (cb) {
- return gulp
- .src([paths.dev[2]])
- .pipe(
- gulpif(shouldMinify, imagemin())
- )
- .pipe(gulp.dest(paths.prod[2]));
- // .pipe(notify({ message: 'Images task complete' }))
- cb(null)
- });
- // gulp.task('buildSass', function (cb) {
- // return gulp
- // .src([paths.dev[0]])
- // .pipe(sass())
- // .pipe(gulp.dest('../wp-content/themes/entelperu/dist/css'))
- // cb(null)
- // });
- gulp.task('buildCss', ['clean'], function (cb) {
- return gulp.start("css");
- });
- gulp.task('css', function (cb) {
- return gulp.src(paths.dev[0])
- .pipe(
- autoprefixer(
- 'last 2 version',
- 'safari 5',
- 'ie 8',
- 'ie 9',
- 'opera 12.1',
- 'ios 6',
- 'android 4'
- )
- )
- .pipe(
- gulpif(shouldMinify,
- uglifycss({
- 'max-line-len': 20
- })
- )
- )
- .pipe(csslint())
- .pipe(
- gulpif(showReports, csslint.reporter(customReporter))
- )
- .pipe(rename({suffix: '.min'}))
- .pipe(gulp.dest(paths.prod[0]));
- // .pipe(notify({ message: 'Images task complete' }));
- });
- gulp.task('buildJs', ['buildImg'], function (cb) {
- return gulp.start("js");
- });
- gulp.task('js', function (cb) {
- return gulp.src([paths.dev[1]])
- .pipe(
- gulpif(shouldMinify, uglify())
- ) /* Compresor del JS #1 */
- .pipe(jsmin()) /* Compresor del JS #2 */
- .pipe(
- gulpif(showReports, jshint())
- ) /* Reporte del JS */
- // .pipe(concat('app.js'))
- .pipe(rename({suffix: '.min'}))
- .pipe(gulp.dest(paths.prod[1]));
- // .pipe(notify({ message: 'Scripts task complete' }));
- });
- gulp.task('clean', ['backup'], function (cb) {
- return del(paths.cleaned, cb);
- });
- /* Init GulpServer PROD */
- gulp.task('default', function() {
- shouldMinify = true;
- showReports = false;
- return gulp.start("init");
- });
- /* Init GulpServer DEV */
- gulp.task('dev', function() {
- shouldMinify = false;
- showReports = true;
- return gulp.start("init");
- });
- /* Init Tasks */
- gulp.task('init', function() {
- return gulp
- .start("buildJs");
- });
- /* Cambio de archivos */
- gulp.task('watch', function() {
- gulp.watch(paths.dev[2], ['img']);
- gulp.watch(paths.dev[0], ['css']);
- gulp.watch(paths.dev[1], ['js']);
- });
- /* Compress Files CSS, JS and Images to .zip */
- gulp.task('backup', function(){
- var date = new Date().toISOString().replace(/[^0-9]/g, '');
- return gulp.src(paths.backups, {base: "wp-content/themes/entelperu"})
- .pipe(zip("package-" + date + ".zip"))
- .pipe(gulp.dest("backups"))
- .pipe(notify({ message: 'Backup task complete' }));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement