Make WordPress Core

Ticket #36394: 36394.4.patch

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

     
    1 /* jshint node:true */
     1'use strict';
     2
    23module.exports = function(grunt) {
    34        var path = require('path'),
    4                 gitorsvn = require('git-or-svn'),
     5                fs = require( 'fs' ),
    56                SOURCE_DIR = 'src/',
    67                BUILD_DIR = 'build/',
    78                autoprefixer = require('autoprefixer'),
    … …  
    295296                jshint: {
    296297                        options: grunt.file.readJSON('.jshintrc'),
    297298                        grunt: {
     299                                options: {
     300                                        es3: false,
     301                                        esversion: 6,
     302                                        node: true
     303                                },
    298304                                src: ['Gruntfile.js']
    299305                        },
    300306                        tests: {
    … …  
    689695
    690696        grunt.registerTask( 'precommit', 'Runs test and build tasks in preparation for a commit', function() {
    691697                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'] );
     698                var map = {
     699                        svn: 'svn status --ignore-externals',
     700                        git: 'git status -s'
     701                };
     702
     703                find( [
     704                        __dirname + '/.svn',
     705                        __dirname + '/.git',
     706                        path.dirname( __dirname ) + '/.svn'
     707                ] );
     708
     709                function find( set ) {
     710                        if ( set.length ) {
     711                                let dir = set.shift();
     712
     713                                fs.access( dir, fs.F_OK, ( error ) => {
     714                                        error ? find( set ) : run( path.basename( dir ).substr( 1 ) );
     715                                } );
     716                        } else {
     717                                grunt.fatal( 'This WordPress install is not under version control.' );
    707718                        }
    708                         grunt.task.run( taskList );
    709                         done();
    710719                }
    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 );
     720
     721                function run( type ) {
     722                        var command = map[ type ].split( ' ' );
     723
     724                        grunt.util.spawn( {
     725                                cmd: command.shift(),
     726                                args: command
     727                        }, ( error, result, code ) => {
     728                                let taskList = [ 'precommit:base' ];
     729
     730                                if ( code !== 0 ) {
     731                                        grunt.fatal( 'The `' +  map[ type ] + '` command returned a non-zero exit code.', code );
     732                                }
     733
     734                                [ 'js', 'css', 'php' ].forEach( function( extension ) {
     735                                        if ( ( result.stdout + '\n' ).indexOf( '.' + extension + '\n' ) !== -1 ) {
     736                                                grunt.log.writeln( extension.toUpperCase() + ' files modified. ' + extension.toUpperCase() + ' tests will be run.');
     737                                                taskList.push( 'precommit:' + extension );
    736738                                        }
    737                                 );
    738                         } else {
    739                                 grunt.log.write( 'This WordPress install is not under version control. No tests will be run.' );
    740                         }
    741                 });
    742         });
     739                                } );
     740
     741                                grunt.task.run( taskList );
     742
     743                                done();
     744                        } );
     745                }
     746        } );
    743747
    744748        grunt.registerTask( 'copy:all', [
    745749                'copy:files',
  • package.json

     
    1010  "license": "GPL-2.0+",
    1111  "devDependencies": {
    1212    "autoprefixer": "~6.3.3",
    13     "git-or-svn": "~0.1.0",
    1413    "grunt": "~0.4.5",
    1514    "grunt-browserify": "~5.0.0",
    1615    "grunt-contrib-clean": "~1.0.0",