Make WordPress Core

Ticket #36394: 36394.2.patch

File 36394.2.patch, 3.6 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();
     696                var map = {
     697                        svn: 'svn status',
     698                        git: 'git diff --name-only'
     699                };
     700
     701                function run( type ) {
     702                        var command = map[ type ].split( ' ' );
     703                        var taskList = [ 'precommit:base' ];
     704
     705                        grunt.util.spawn( {
     706                                cmd: command.shift(),
     707                                args: command
     708                        }, ( error, result, code ) => {
     709                                if ( code !== 0 ) {
     710                                        grunt.fail.warn( 'The `' +  map[ type ] + '` command returned a non-zero exit code.', code );
     711                                }
    692712
    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'] );
    707                         }
    708                         grunt.task.run( taskList );
    709                         done();
    710                 }
    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 );
     713                                [ 'js', 'css', 'php' ].forEach( function( extension ) {
     714                                        if ( result.stdout.indexOf( '.' + extension + '\n' ) !== -1 ) {
     715                                                grunt.log.write( extension.toUpperCase() + ' files modified. ' + extension.toUpperCase() + ' tests will be run.\n');
     716                                                taskList.push( 'precommit:' + extension );
    723717                                        }
    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 );
     718                                } );
     719
     720                                grunt.task.run( taskList );
     721
     722                                done();
     723                        } );
     724                }
     725
     726                fs.access( __dirname + '/.svn', fs.F_OK, ( error ) => {
     727                        if ( error ) {
     728                                fs.access( __dirname + '/.git', fs.F_OK, ( error ) => {
     729                                        if ( error ) {
     730                                                grunt.log.write( 'This WordPress install is not under version control. No tests will be run.' );
     731                                        } else {
     732                                                run( 'git' );
    736733                                        }
    737                                 );
     734                                } );
    738735                        } else {
    739                                 grunt.log.write( 'This WordPress install is not under version control. No tests will be run.' );
     736                                run( 'svn' );
    740737                        }
    741                 });
    742         });
     738                } );
     739        } );
    743740
    744741        grunt.registerTask( 'copy:all', [
    745742                'copy:files',