Created
August 23, 2015 17:28
-
-
Save ahmadawais/b5059b1f17bf12c4f891 to your computer and use it in GitHub Desktop.
Gulp: Theme Zip building task
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
/** | |
* Clean gulp cache | |
*/ | |
gulp.task('clear', function () { | |
cache.clearAll(); | |
}); | |
/** | |
* Clean tasks for zip | |
* | |
* Being a little overzealous, but we're cleaning out the build folder, codekit-cache directory and annoying DS_Store files and Also | |
* clearing out unoptimized image files in zip as those will have been moved and optimized | |
*/ | |
gulp.task('cleanup', function() { | |
return gulp.src(['./assets/bower_components', '**/.sass-cache','**/.DS_Store'], { read: false }) // much faster | |
.pipe(ignore('node_modules/**')) //Example of a directory to ignore | |
.pipe(rimraf({ force: true })) | |
// .pipe(notify({ message: 'Clean task complete', onLast: true })); | |
}); | |
gulp.task('cleanupFinal', function() { | |
return gulp.src(['./assets/bower_components','**/.sass-cache','**/.DS_Store'], { read: false }) // much faster | |
.pipe(ignore('node_modules/**')) //Example of a directory to ignore | |
.pipe(rimraf({ force: true })) | |
// .pipe(notify({ message: 'Clean task complete', onLast: true })); | |
}); | |
/** | |
* Build task that moves essential theme files for production-ready sites | |
* | |
* buildFiles copies all the files in buildInclude to build folder - check variable values at the top | |
* buildImages copies all the images from img folder in assets while ignoring images inside raw folder if any | |
*/ | |
gulp.task('buildFiles', function() { | |
return gulp.src(buildInclude) | |
.pipe(gulp.dest(build)) | |
.pipe(notify({ message: 'Copy from buildFiles complete', onLast: true })); | |
}); | |
/** | |
* Images | |
* | |
* Look at src/images, optimize the images and send them to the appropriate place | |
*/ | |
gulp.task('buildImages', function() { | |
return gulp.src(['assets/img/**/*', '!assets/images/raw/**']) | |
.pipe(gulp.dest(build+'assets/img/')) | |
.pipe(plugins.notify({ message: 'Images copied to buildTheme folder', onLast: true })); | |
}); | |
/** | |
* Zipping build directory for distribution | |
* | |
* Taking the build folder, which has been cleaned, containing optimized files and zipping it up to send out as an installable theme | |
*/ | |
gulp.task('buildZip', function () { | |
// return gulp.src([build+'/**/', './.jshintrc','./.bowerrc','./.gitignore' ]) | |
return gulp.src(build+'/**/') | |
.pipe(zip(project+'.zip')) | |
.pipe(gulp.dest('./')) | |
.pipe(notify({ message: 'Zip task complete', onLast: true })); | |
}); | |
// ==== TASKS ==== // | |
/** | |
* Gulp Default Task | |
* | |
* Compiles styles, fires-up browser sync, watches js and php files. Note browser sync task watches php files | |
* | |
*/ | |
// Package Distributable Theme | |
gulp.task('build', function(cb) { | |
runSequence('styles', 'cleanup', 'vendorsJs', 'scriptsJs', 'buildFiles', 'buildImages', 'buildZip','cleanupFinal', cb); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment