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
This commit is contained in:
Ella Iseulde Van Dorpe 2016-04-15 10:18:03 +00:00
parent 6fe6d25f01
commit f261cb7914

View File

@ -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.