Last active
October 7, 2016 18:02
-
-
Save ccurtin/9b86018591940b0de98b to your computer and use it in GitHub Desktop.
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
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
/* | |
Plugins | |
*/ | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
var gulp = require('gulp'), | |
shell = require('gulp-shell'), | |
compass = require('gulp-compass'), | |
gutil = require('gulp-util'), | |
minifyHTML = require('gulp-minify-html'), | |
uglifyjs = require('gulp-uglifyjs'), | |
beautifyjs = require('gulp-jsbeautify'), | |
minifyCSS = require('gulp-minify-css'); | |
concat = require('gulp-concat'), | |
livereload = require('gulp-livereload'), | |
plumber = require('gulp-plumber'), | |
beep = require('beepbeep'), | |
wait = require('gulp-wait'), | |
rimraf = require('gulp-rimraf'), | |
watch = require('gulp-watch'), | |
jshint = require('gulp-jshint'), | |
stylish = require('jshint-stylish'), | |
image = require('gulp-image'); | |
nukeWhitespace = require('gulp-nuke-whitespace'); | |
lr = require('tiny-lr'), | |
server = lr(); | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
/* | |
Deploying ( runs `prepare` task ) | |
*/ | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
gulp.task('git-it', shell.task([ | |
'git add -A .', | |
'git commit -am updates', | |
])); | |
gulp.task('deploy-sd',['prepare','git-it'], shell.task([ | |
'git push origin master:working', | |
'dploy sftp-dev' | |
])); | |
gulp.task('deploy-d',['prepare'], shell.task([ | |
'git push origin master:working', | |
'dploy ftp-dev' | |
])); | |
gulp.task('deploy-sp',['prepare','git-it'], shell.task([ | |
'git push origin master:working', | |
'dploy sftp-pro' | |
])) | |
gulp.task('deploy-p',['prepare','git-it'], shell.task([ | |
'git push origin master:working', | |
'dploy ftp-pro' | |
])); | |
gulp.task('ftp', shell.task([ | |
'start X:/Portable-Apps/FileZillaPortable/FileZillaPortable.exe' | |
])); | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
/* | |
Project Variables | |
*/ | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
var themeName = 'html5blank'; | |
//----------------------------------// | |
var themeRoot = 'wordpress/wp-content/themes/'+ themeName +'/'; | |
var productionFolder = 'production'; | |
var distributionFolder = 'dist'; | |
var componentsFolder = 'components'; | |
//----------------------------------// | |
var themeStyles = 'wordpress/wp-content/themes/' + themeName + '/style.css'; | |
var themeFunctions = 'wordpress/wp-content/themes/' + themeName + '/functions.php'; | |
var themeFunctionsImport = componentsFolder + '/php/functions/functions-theme-import.php'; | |
var themeFunctionsCustom = componentsFolder + '/php/functions/'; | |
var imageSources =[componentsFolder + '/images/*.*']; | |
var jsSources = componentsFolder + '/js/**/*.js'; | |
var pageSources =['wordpress/wp-content/themes/' + themeName + '/*.php']; | |
var sassSources = [ | |
componentsFolder + '/sass/*.scss', | |
componentsFolder + '/sass/partials/*.scss', | |
componentsFolder + '/sass/modules/*.scss' | |
]; | |
//----------------------------------// | |
var onErrorJS = function (err) { | |
beep([200, 250, 250]); | |
gutil.log(gutil.colors.green(err)); | |
}; | |
var onErrorStyles = function (err) { | |
beep([500, 500, 500]); | |
gutil.log(gutil.colors.magenta(err)); | |
}; | |
var onErrorHTML = function (err) { | |
beep([500, 500, 500]); | |
gutil.log(gutil.colors.cyan(err)); | |
}; | |
var onError = function (err) { | |
gutil.beep(); | |
gutil.log(gutil.colors.red(err)); | |
}; | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
/* | |
Prepare for > `Dploy` command | |
*/ | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
gulp.task('prepare', function(){ | |
// Pulls all js from components folder and any js libraries in the wordpress/js folder | |
// Don't be an idiot! ... just move the lib folder over to the components folder and concat all .js there on 'prepare' | |
gulp.src([jsSources, themeRoot + 'js/lib/*.js']) | |
.pipe(uglifyjs('scripts.js', { | |
outSourceMap: true | |
})) | |
.pipe(gulp.dest(themeRoot + '/js')); | |
gulp.src([themeFunctionsImport,themeFunctionsCustom + '/**.*',!themeFunctionsCustom + 'dev/**.*',themeFunctionsCustom + 'pro/**.*']) | |
.pipe(concat('functions.php', {newLine: ''})) // ** BE SURE TO INCLUDE THE NEWLINE ARGUMENT ** otherwise whitespace between php tags will appear and damage functionality | |
.pipe(gulp.dest(themeRoot)); | |
gulp.src(themeRoot + 'style.css') | |
.pipe(minifyCSS({keepBreaks:false})) | |
.pipe(gulp.dest(themeRoot)); | |
}) | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
/* | |
Theme Updates | |
*/ | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
//----------------update-theme-styles------------------// | |
gulp.task('update-theme-styles',['clean-update-theme-styles'], function(){ | |
gulp.src(themeStyles) | |
.pipe(concat('_style-theme-import.scss')) | |
.pipe(gulp.dest(componentsFolder + '/sass/partials')); | |
gulp.watch([sassSources], ['default']); | |
}); | |
gulp.task('clean-update-theme-styles', function(){ | |
return gulp.src(componentsFolder + '/sass/partials/_style-theme-import.scss', {read: false}) | |
.pipe(rimraf()); | |
}); | |
//----------------update-theme-functions------------------// | |
gulp.task('update-theme-functions', function(){ | |
gulp.src(themeFunctions) | |
.pipe(concat('functions-theme-import.php')) | |
.pipe(gulp.dest(componentsFolder + '/php/functions')); | |
gulp.watch([themeFunctionsCustom + '**/*.php'], ['concatFunctions']); | |
}); | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
/* | |
Watch | |
*/ | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
gulp.task('watch', function() { | |
var server = livereload(); | |
gulp.watch([sassSources], ['sass']); | |
gulp.watch(jsSources, ['jsBeautify']); | |
gulp.watch([jsSources, pageSources, themeStyles,themeFunctions,themeFunctionsCustom + '**/*.php'], function(e) { | |
server.changed(e.path); | |
}); | |
gulp.watch([themeFunctionsCustom + '**/*.php'], ['concatFunctions']); | |
gulp.watch(imageSources, ['image']); | |
}); | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
/* | |
Concatenate & Beautify SASS/CSS | |
*/ | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
gulp.task('sass', function(){ | |
gulp.src(sassSources) | |
.pipe(plumber({ | |
errorHandler: onErrorStyles | |
})) | |
// the config.rb file holds the 'sass-css-importer' | |
// to use in scss : @import "CSS:partials/style-theme-import"; //path is relative to scss file | |
.pipe(compass({ | |
require: ['susy','sass-css-importer'], | |
sass: componentsFolder + '/sass', | |
image: componentsFolder + '/images', | |
css: componentsFolder + '/sass/compassOutput', | |
style: 'expanded' | |
})) | |
.pipe(concat('style.css')) | |
.pipe(gulp.dest(themeRoot)) | |
}); | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
/* | |
Concat. & Beautify JS | |
*/ | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
gulp.task('jsBeautify', function() { | |
gulp.src(jsSources) | |
.pipe(plumber({ | |
errorHandler: onErrorJS | |
})) | |
.pipe(beautifyjs({indent_size: 4,brace_style:"expand",})) | |
.pipe(gulp.dest(themeRoot + '/js')); | |
}); | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
/* | |
Concat. Functions | |
*/ | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
gulp.task('concatFunctions', function(){ | |
gulp.src([themeFunctionsCustom + 'dev/pre-functions.php',themeFunctionsImport,themeFunctionsCustom +'**/*.php',!themeFunctionsCustom +'dev/pre-functions.php',!themeFunctionsCustom +'pro/**.*']) | |
.pipe(concat('functions.php',{newLine:""})) | |
.pipe(gulp.dest(themeRoot)); | |
}); | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
/* | |
Compress Images (NOT part of the prepare task!) | |
*/ | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
gulp.task('image', function () { | |
gulp.src('components/images/*.*') | |
.pipe(plumber({ | |
errorHandler: onError | |
})) | |
.pipe(image()) | |
.pipe(gulp.dest(themeRoot + '/img/')); | |
}); | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
/* | |
Report JS Errors | |
*/ | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
gulp.task('lint', function() { | |
return gulp.src(themeRoot + 'js/scripts.js') | |
.pipe(plumber({ | |
errorHandler: onErrorJS | |
})) | |
.pipe(jshint('.jshintrc')) | |
.pipe(jshint.reporter(stylish)); | |
}); | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
/* | |
Run Default Task | |
*/ | |
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ | |
gulp.task('default', ['sass','jsBeautify','concatFunctions','watch']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment