From f3a3185bd4d763f5226472cf5b87e7600831f59c Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 3 Oct 2017 15:19:23 +0000 Subject: [PATCH] Tools: enable Grunt precommit task to run without requiring SVN or GIT. Fixes #41957 git-svn-id: https://develop.svn.wordpress.org/trunk@41708 602fd350-edb4-49c9-b593-d223f7449a82 --- Gruntfile.js | 65 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index f2d296e63a..2d82878322 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -839,10 +839,24 @@ module.exports = function(grunt) { error ? find( set ) : run( path.basename( dir ).substr( 1 ) ); } ); } else { - grunt.fatal( 'This WordPress install is not under version control.' ); + runAllTasks(); } } + function runAllTasks() { + grunt.log.writeln( 'Cannot determine which files are modified as SVN and GIT are not available.' ); + grunt.log.writeln( 'Running all tasks and all tests.' ); + grunt.task.run([ + 'precommit:js', + 'precommit:css', + 'precommit:image', + 'precommit:emoji', + 'precommit:php' + ]); + + done(); + } + function run( type ) { var command = map[ type ].split( ' ' ); @@ -852,10 +866,6 @@ module.exports = function(grunt) { }, function( error, result, code ) { var taskList = []; - if ( code !== 0 ) { - grunt.fatal( 'The `' + map[ type ] + '` command returned a non-zero exit code.', code ); - } - // Callback for finding modified paths. function testPath( path ) { var regex = new RegExp( ' ' + path + '$', 'm' ); @@ -868,31 +878,34 @@ module.exports = function(grunt) { return regex.test( result.stdout ); } - if ( [ 'package.json', 'Gruntfile.js' ].some( testPath ) ) { - grunt.log.writeln( 'Configuration files modified. Running `prerelease`.' ); - taskList.push( 'prerelease' ); - } else { - if ( [ 'png', 'jpg', 'gif', 'jpeg' ].some( testExtension ) ) { - grunt.log.writeln( 'Image files modified. Minifying.' ); - taskList.push( 'precommit:image' ); - } - - [ 'js', 'css', 'php' ].forEach( function( extension ) { - if ( testExtension( extension ) ) { - grunt.log.writeln( extension.toUpperCase() + ' files modified. ' + extension.toUpperCase() + ' tests will be run.' ); - taskList.push( 'precommit:' + extension ); + if ( code === 0 ) { + if ( [ 'package.json', 'Gruntfile.js' ].some( testPath ) ) { + grunt.log.writeln( 'Configuration files modified. Running `prerelease`.' ); + taskList.push( 'prerelease' ); + } else { + if ( [ 'png', 'jpg', 'gif', 'jpeg' ].some( testExtension ) ) { + grunt.log.writeln( 'Image files modified. Minifying.' ); + taskList.push( 'precommit:image' ); } - } ); - if ( [ 'twemoji.js' ].some( testPath ) ) { - grunt.log.writeln( 'twemoji.js has updated. Running `precommit:emoji.' ); - taskList.push( 'precommit:emoji' ); + [ 'js', 'css', 'php' ].forEach( function( extension ) { + if ( testExtension( extension ) ) { + grunt.log.writeln( extension.toUpperCase() + ' files modified. ' + extension.toUpperCase() + ' tests will be run.' ); + taskList.push( 'precommit:' + extension ); + } + } ); + + if ( [ 'twemoji.js' ].some( testPath ) ) { + grunt.log.writeln( 'twemoji.js has updated. Running `precommit:emoji.' ); + taskList.push( 'precommit:emoji' ); + } } + + grunt.task.run( taskList ); + done(); + } else { + runAllTasks(); } - - grunt.task.run( taskList ); - - done(); } ); } } );