From f261cb791424d7beef4d7defe31839bdadf3787a Mon Sep 17 00:00:00 2001 From: Ella Iseulde Van Dorpe Date: Fri, 15 Apr 2016 10:18:03 +0000 Subject: [PATCH] Build/Test Tools: Run image tasks only if there are changes See #36528. git-svn-id: https://develop.svn.wordpress.org/trunk@37211 602fd350-edb4-49c9-b593-d223f7449a82 --- Gruntfile.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index d4a2271307..6b2b6f3dba 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -668,7 +668,7 @@ module.exports = function(grunt) { grunt.task.run( '_' + this.nameArgs ); } ); - grunt.registerTask( 'precommit:base', [ + grunt.registerTask( 'precommit:image', [ 'imagemin:core' ] ); @@ -714,16 +714,24 @@ module.exports = function(grunt) { function run( type ) { var command = map[ type ].split( ' ' ); - var taskList = [ 'precommit:base' ]; grunt.util.spawn( { cmd: command.shift(), args: command }, function( error, result, code ) { + var taskList = []; + if ( code !== 0 ) { grunt.fatal( 'The `' + map[ type ] + '` command returned a non-zero exit code.', code ); } + [ 'png', 'jpg', 'gif', 'jpeg' ].forEach( function( extension ) { + if ( ( result.stdout + '\n' ).indexOf( '.' + extension + '\n' ) !== -1 ) { + grunt.log.writeln( 'Image files modified. Minifying.'); + taskList.push( 'precommit:image' ); + } + } ); + [ 'js', 'css', 'php' ].forEach( function( extension ) { if ( ( result.stdout + '\n' ).indexOf( '.' + extension + '\n' ) !== -1 ) { grunt.log.writeln( extension.toUpperCase() + ' files modified. ' + extension.toUpperCase() + ' tests will be run.'); @@ -769,7 +777,7 @@ module.exports = function(grunt) { 'precommit:php', 'precommit:js', 'precommit:css', - 'precommit:base' + 'precommit:image' ] ); // Testing tasks.