Grunt: when running precommit
use regex to check which files have been modified.
Fixes #36528. git-svn-id: https://develop.svn.wordpress.org/trunk@37749 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
3f050f87c3
commit
7e53f5e404
22
Gruntfile.js
22
Gruntfile.js
@ -725,21 +725,29 @@ module.exports = function(grunt) {
|
|||||||
grunt.fatal( 'The `' + map[ type ] + '` command returned a non-zero exit code.', code );
|
grunt.fatal( 'The `' + map[ type ] + '` command returned a non-zero exit code.', code );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( [ 'package.json', 'Gruntfile.js' ].some( function( path ) {
|
// Callback for finding modified paths.
|
||||||
return ( result.stdout + '\n' ).indexOf( ' ' + path + '\n' ) !== -1;
|
function testPath( path ) {
|
||||||
} ) ) {
|
var regex = new RegExp( ' ' + path + '$', 'm' );
|
||||||
|
return regex.test( result.stdout );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Callback for finding modified files by extension.
|
||||||
|
function testExtension( extension ) {
|
||||||
|
var regex = new RegExp( '\.' + extension + '$', 'm' );
|
||||||
|
return regex.test( result.stdout );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( [ 'package.json', 'Gruntfile.js' ].some( testPath ) ) {
|
||||||
grunt.log.writeln( 'Configuration files modified. Running `prerelease`.' );
|
grunt.log.writeln( 'Configuration files modified. Running `prerelease`.' );
|
||||||
taskList.push( 'prerelease' );
|
taskList.push( 'prerelease' );
|
||||||
} else {
|
} else {
|
||||||
if ( [ 'png', 'jpg', 'gif', 'jpeg' ].some( function( extension ) {
|
if ( [ 'png', 'jpg', 'gif', 'jpeg' ].some( testExtension ) ) {
|
||||||
return ( result.stdout + '\n' ).indexOf( '.' + extension + '\n' ) !== -1;
|
|
||||||
} ) ) {
|
|
||||||
grunt.log.writeln( 'Image files modified. Minifying.' );
|
grunt.log.writeln( 'Image files modified. Minifying.' );
|
||||||
taskList.push( 'precommit:image' );
|
taskList.push( 'precommit:image' );
|
||||||
}
|
}
|
||||||
|
|
||||||
[ 'js', 'css', 'php' ].forEach( function( extension ) {
|
[ 'js', 'css', 'php' ].forEach( function( extension ) {
|
||||||
if ( ( result.stdout + '\n' ).indexOf( '.' + extension + '\n' ) !== -1 ) {
|
if ( testExtension( extension ) ) {
|
||||||
grunt.log.writeln( extension.toUpperCase() + ' files modified. ' + extension.toUpperCase() + ' tests will be run.' );
|
grunt.log.writeln( extension.toUpperCase() + ' files modified. ' + extension.toUpperCase() + ' tests will be run.' );
|
||||||
taskList.push( 'precommit:' + extension );
|
taskList.push( 'precommit:' + extension );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user