Make WordPress Core

Ticket #36394: 36394.3.patch

File 36394.3.patch, 3.7 KB (added by iseulde, 11 years ago)
  • Gruntfile.js

     
    11/* jshint node:true */
    22module.exports = function(grunt) {
    33        var path = require('path'),
    4                 gitorsvn = require('git-or-svn'),
     4                fs = require( 'fs' ),
    55                SOURCE_DIR = 'src/',
    66                BUILD_DIR = 'build/',
    77                autoprefixer = require('autoprefixer'),
    … …  
    295295                jshint: {
    296296                        options: grunt.file.readJSON('.jshintrc'),
    297297                        grunt: {
     298                                options: {
     299                                        es3: false,
     300                                        esversion: 6
     301                                },
    298302                                src: ['Gruntfile.js']
    299303                        },
    300304                        tests: {
    … …  
    689693
    690694        grunt.registerTask( 'precommit', 'Runs test and build tasks in preparation for a commit', function() {
    691695                var done = this.async();
    692 
    693                 // Figure out what tasks to run based on what files have been modified.
    694                 function enqueueTestingTasksForModifiedFiles( filesModified ) {
    695                         var taskList = ['precommit:base'];
    696                         if ( /.*\.js/.test( filesModified ) ) {
    697                                 grunt.log.write( 'JavaScript source files modified. JavaScript tests will be run.\n');
    698                                 taskList = taskList.concat( ['precommit:js'] );
    699                         }
    700                         if ( /src.*\.css/.test( filesModified ) ) {
    701                                 grunt.log.write( 'CSS source files modified. CSS tests will be run.\n');
    702                                 taskList = taskList.concat( ['postcss:core'] );
    703                         }
    704                         if ( /.*\.php/.test( filesModified ) ) {
    705                                 grunt.log.write( 'PHP source files modified. PHP tests will be run.\n');
    706                                 taskList = taskList.concat( ['precommit:php'] );
     696                var map = {
     697                        svn: 'svn status',
     698                        git: 'git diff --name-only'
     699                };
     700
     701                find( [
     702                        __dirname + '/.svn',
     703                        __dirname + '/.git',
     704                        path.dirname( __dirname ) + '/.svn'
     705                ] );
     706
     707                function find( set ) {
     708                        var dir;
     709
     710                        if ( set.length ) {
     711                                fs.access( dir = set.shift(), fs.F_OK, ( error ) => {
     712                                        error ? find( set ) : run( path.basename( dir ).substr( 1 ) );
     713                                } );
     714                        } else {
     715                                grunt.log.error( 'This WordPress install is not under version control. No tests will be run.' );
     716                                done( false );
    707717                        }
    708                         grunt.task.run( taskList );
    709                         done();
    710718                }
    711                 gitorsvn( __dirname, function(gitorsvn) {
    712                         if ( gitorsvn === 'svn' ) {
    713                                 grunt.util.spawn(
    714                                         {
    715                                                 cmd: 'svn',
    716                                                 args: ['status']
    717                                         },
    718                                         function(error, result, code) {
    719                                                 if ( code !== 0 ) {
    720                                                         grunt.fail.warn( 'The `svn status` command returned a non-zero exit code.', code );
    721                                                 }
    722                                                 enqueueTestingTasksForModifiedFiles( result.stdout );
    723                                         }
    724                                 );
    725                         } else if ( gitorsvn === 'git' ) {
    726                                 grunt.util.spawn(
    727                                         {
    728                                                 cmd: 'git',
    729                                                 args: ['diff', '--name-only']
    730                                         },
    731                                         function(error, result, code) {
    732                                                 if ( code !== 0 ) {
    733                                                         grunt.fail.warn( 'The `git diff --name-only` command returned a non-zero exit code.', code );
    734                                                 }
    735                                                 enqueueTestingTasksForModifiedFiles( result.stdout );
     719
     720                function run( type ) {
     721                        var command = map[ type ].split( ' ' );
     722                        var taskList = [ 'precommit:base' ];
     723
     724                        grunt.util.spawn( {
     725                                cmd: command.shift(),
     726                                args: command
     727                        }, ( error, result, code ) => {
     728                                if ( code !== 0 ) {
     729                                        grunt.fail.warn( 'The `' +  map[ type ] + '` command returned a non-zero exit code.', code );
     730                                }
     731
     732                                [ 'js', 'css', 'php' ].forEach( function( extension ) {
     733                                        if ( result.stdout.indexOf( '.' + extension + '\n' ) !== -1 ) {
     734                                                grunt.log.writeln( extension.toUpperCase() + ' files modified. ' + extension.toUpperCase() + ' tests will be run.');
     735                                                taskList.push( 'precommit:' + extension );
    736736                                        }
    737                                 );
    738                         } else {
    739                                 grunt.log.write( 'This WordPress install is not under version control. No tests will be run.' );
    740                         }
    741                 });
    742         });
     737                                } );
     738
     739                                grunt.task.run( taskList );
     740                                done();
     741                        } );
     742                }
     743        } );
    743744
    744745        grunt.registerTask( 'copy:all', [
    745746                'copy:files',