Changeset 37185
- Timestamp:
- 04/12/2016 10:33:18 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Gruntfile.js
r36955 r37185 2 2 module.exports = function(grunt) { 3 3 var path = require('path'), 4 gitorsvn = require('git-or-svn'),4 fs = require( 'fs' ), 5 5 SOURCE_DIR = 'src/', 6 6 BUILD_DIR = 'build/', … … 690 690 grunt.registerTask( 'precommit', 'Runs test and build tasks in preparation for a commit', function() { 691 691 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'] ); 707 } 708 grunt.task.run( taskList ); 709 done(); 692 var map = { 693 svn: 'svn status --ignore-externals', 694 git: 'git status --short' 695 }; 696 697 find( [ 698 __dirname + '/.svn', 699 __dirname + '/.git', 700 path.dirname( __dirname ) + '/.svn' 701 ] ); 702 703 function find( set ) { 704 var dir; 705 706 if ( set.length ) { 707 fs.stat( dir = set.shift(), function( error ) { 708 error ? find( set ) : run( path.basename( dir ).substr( 1 ) ); 709 } ); 710 } else { 711 grunt.fatal( 'This WordPress install is not under version control.' ); 712 } 710 713 } 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 ); 736 } 737 ); 738 } else { 739 grunt.log.write( 'This WordPress install is not under version control. No tests will be run.' ); 740 } 741 }); 742 }); 714 715 function run( type ) { 716 var command = map[ type ].split( ' ' ); 717 var taskList = [ 'precommit:base' ]; 718 719 grunt.util.spawn( { 720 cmd: command.shift(), 721 args: command 722 }, function( error, result, code ) { 723 if ( code !== 0 ) { 724 grunt.fatal( 'The `' + map[ type ] + '` command returned a non-zero exit code.', code ); 725 } 726 727 [ 'js', 'css', 'php' ].forEach( function( extension ) { 728 if ( ( result.stdout + '\n' ).indexOf( '.' + extension + '\n' ) !== -1 ) { 729 grunt.log.writeln( extension.toUpperCase() + ' files modified. ' + extension.toUpperCase() + ' tests will be run.'); 730 taskList.push( 'precommit:' + extension ); 731 } 732 } ); 733 734 grunt.task.run( taskList ); 735 736 done(); 737 } ); 738 } 739 } ); 743 740 744 741 grunt.registerTask( 'copy:all', [ -
trunk/package.json
r37183 r37185 11 11 "devDependencies": { 12 12 "autoprefixer": "~6.3.3", 13 "git-or-svn": "~0.1.0",14 13 "grunt": "~0.4.5", 15 14 "grunt-browserify": "~5.0.0",
Note: See TracChangeset
for help on using the changeset viewer.