diff --git a/README.md b/README.md index ee9b53a..2c02b6c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/gulpfile.js b/gulpfile.js index 53ede9f..702e795 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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 = []; @@ -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, @@ -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(); }); }); @@ -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, @@ -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) { diff --git a/package.json b/package.json index c559c67..ca942bc 100644 --- a/package.json +++ b/package.json @@ -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",