Skip to content

Commit

Permalink
Upgraded Gulp to 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dmhendricks committed Sep 26, 2018
1 parent 80edca0 commit 5e0fd9b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ See the [Getting Started](https://github.com/dmhendricks/wordpress-base-plugin/w
## Future Goals

* Add plugin uninstall support
* Add support for Gulp 4.0
* Switch to npm and WebPack for frontend dependency management
* Remove or replace [tareq1988/wordpress-settings-api-class](https://github.com/tareq1988/wordpress-settings-api-class/) examples with something actively developed
* Clean up Carbon Fields custom CSS classes
Expand Down
50 changes: 40 additions & 10 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ var notify = require('gulp-notify'); // Displays notification message
var batchRename = require('gulp-simple-rename'); // Rename files with wildcard
var vinylPaths = require('vinyl-paths'); // Return each path in a stream
var del = require('del'); // Delete files that are renamed
var plumber = require( 'gulp-plumber' ); // Prevent pipe breaking caused by errors from gulp plugins.

/**
* Custom Error Handler.
*
* @param Mixed err
*/
const errorHandler = r => {
notify.onError( '\n\n ===> ERROR: <%= error.message %>\n' )( r );
beep();
};

/* Arrays to hold created task info */
var tasks_css = [];
Expand All @@ -135,8 +146,9 @@ styleTasks.forEach( function( task ) {

tasks_css.push( task.name + 'CSS' );

gulp.task( task.name + 'CSS', function () {
gulp.task( task.name + 'CSS', (done) => {
gulp.src( styleSourcePath + task.source )
.pipe( plumber( errorHandler ) )
.pipe( sourcemaps.init() )
.pipe( sass( {
sourceComments: cssOutputComments ? 'map' : null,
Expand Down Expand Up @@ -168,7 +180,8 @@ styleTasks.forEach( function( task ) {
.pipe( gulp.dest( styleDestination ) )

.pipe( filter( '**/*.css' ) ) // Filtering stream to only css files
.pipe( notify( { message: 'TASK: "' + task.name + 'CSS" completed.', onLast: true } ) )
.pipe( notify( { message: 'TASK: "' + task.name + 'CSS" completed.', onLast: true } ) );
done();
});

});
Expand Down Expand Up @@ -197,9 +210,10 @@ jsTasks.forEach( function( task ) {

tasks_js.push( { id: task.name + 'JS', name: task.name, watch: jsSources } );

gulp.task( task.name + 'JS', function() {
gulp.task( task.name + 'JS', (done) => {

gulp.src( jsSources )
.pipe( plumber( errorHandler ) )
.pipe( concat( task.source + '.js' ) )
.pipe( rename( {
basename: project + basename_suffix,
Expand All @@ -214,29 +228,45 @@ jsTasks.forEach( function( task ) {
.pipe( lineec() ) // Consistent Line Endings for non UNIX systems.
.pipe( gulp.dest( jsDestination ) )
.pipe( notify( { message: 'TASK: "' + task.name + 'JS" completed.', onLast: true } ) );
done();
});


});

/**
* Watches for file changes and runs specified tasks.
*/
gulp.task( 'default', object_property_to_array( tasks_js, 'id', tasks_css ), function () {
//gulp.task( 'default', object_property_to_array( tasks_js, 'id', tasks_css ), function () {

gulp.watch( styleSourcePath + '**/*.scss', tasks_css );
// gulp.watch( styleSourcePath + '**/*.scss', tasks_css );

tasks_js.forEach( function( task ) {
gulp.watch( task.watch, [ task.id ] );
});
// tasks_js.forEach( function( task ) {
// gulp.watch( task.watch, [ task.id ] );
// });

});
//});

gulp.task(
'default',
gulp.series( gulp.parallel( object_property_to_array( tasks_js, 'id', tasks_css ) ), () => {

gulp.watch( styleSourcePath + '**/*.scss', gulp.parallel( tasks_css ) );

tasks_js.forEach( function( task ) {
gulp.watch( task.watch, gulp.series( task.id ) );
});

})
);

/**
* Task to rename files and variables
*/
gulp.task( 'rename', function () {
gulp.task( 'rename', () => {

return gulp.src( [ './**/*.php', './*.json', './**/*.js', './**/*.scss', './*.txt', './*.md', '!./node_modules/**', '!./vendor/**', '!./.git/**', '!./languages/**', '!./*lock*', '!./gulpfile.js' ] )
.pipe( plumber( errorHandler ) )
.pipe( replace( renameStrings ) )
.pipe( vinylPaths( del ) )
.pipe( batchRename( function (path) {
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@
"zip-dev": "zip -q -r ../$npm_package_name.zip * -x 'node_modules/*' '.git*' '.DS_Store' './*.bak' "
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-sass": "^3.1.0",
"gulp-uglify": "^3.0.0",
"gulp-uglifycss": "^1.0.9",
"del": "^3.0",
"gulp": "^4.0",
"gulp-autoprefixer": "^3.1.0",
"gulp-batch-replace": "*",
"gulp-concat": "^2.6.1",
"gulp-filter": "^5.1.0",
"gulp-line-ending-corrector": "^1.0.2",
"gulp-line-ending-corrector": "^1.0.3",
"gulp-merge-media-queries": "^0.2.1",
"gulp-notify": "^3.1.0",
"gulp-rename": "^1.2.0",
"gulp-rename": "^1.4.0",
"gulp-sass": "^3.2.1",
"gulp-simple-rename": "^0.1.3",
"gulp-sourcemaps": "^1.5.2",
"gulp-uglify": "^3.0.1",
"gulp-uglifycss": "^1.1.0",
"vinyl-paths": "^2.1.0",
"wp-pot-cli": "^1.0",
"del": "^3.0"
"gulp-plumber": "^1.2",
"wp-pot-cli": "1.0.0"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 5e0fd9b

Please sign in to comment.