Changeset 36906
- Timestamp:
- 03/09/2016 08:54:10 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Gruntfile.js
r36780 r36906 2 2 module.exports = function(grunt) { 3 3 var path = require('path'), 4 gitorsvn = require('git-or-svn'), 4 5 SOURCE_DIR = 'src/', 5 6 BUILD_DIR = 'build/', … … 659 660 } ); 660 661 661 grunt.registerTask( 'precommit', 'Runs front-end dev/test tasks in preparation for a commit.', [ 662 'postcss:core', 663 'imagemin:core', 662 grunt.registerTask( 'precommit:core', [ 663 'imagemin:core' 664 ] ); 665 666 grunt.registerTask( 'precommit:js', [ 664 667 'browserify', 665 668 'jshint:corejs', … … 667 670 'qunit:compiled' 668 671 ] ); 672 673 grunt.registerTask( 'precommit:css', [ 674 'postcss:core' 675 ] ); 676 677 grunt.registerTask( 'precommit:php', [ 678 'phpunit' 679 ] ); 680 681 grunt.registerTask( 'precommit', 'Runs test and build tasks in preparation for a commit', function() { 682 var done = this.async(); 683 684 // Figure out what tasks to run based on what files have been modified. 685 function enqueueTestingTasksForModifiedFiles( filesModified ) { 686 var taskList = ['precommit:core']; 687 if ( /.*\.js/.test( filesModified ) ) { 688 grunt.log.write( 'JavaScript source files modified, will run JavaScript tests.\n'); 689 taskList = taskList.concat( ['precommit:js'] ); 690 } 691 if ( /src.*\.css/.test( filesModified ) ) { 692 grunt.log.write( 'CSS source files modified, will run CSS tests.\n'); 693 taskList = taskList.concat( ['postcss:core'] ); 694 } 695 if ( /.*\.php/.test( filesModified ) ) { 696 grunt.log.write( 'PHP source files modified, will run PHP tests.\n'); 697 taskList = taskList.concat( ['precommit:php'] ); 698 } 699 grunt.task.run( taskList ); 700 done(); 701 } 702 gitorsvn( __dirname, function(gitorsvn) { 703 if ( gitorsvn === 'svn' ) { 704 grunt.util.spawn( 705 { 706 cmd: 'svn', 707 args: ['status'] 708 }, 709 function(error, result, code) { 710 if ( code !== 0 ) { 711 grunt.fail.warn( 'The `svn status` command returned a non-zero exit code.', code ); 712 } 713 enqueueTestingTasksForModifiedFiles( result.stdout ); 714 } 715 ); 716 } else if ( gitorsvn === 'git' ) { 717 grunt.util.spawn( 718 { 719 cmd: 'git', 720 args: ['diff', '--name-only'] 721 }, 722 function(error, result, code) { 723 if ( code !== 0 ) { 724 grunt.fail.warn( 'The `git diff --name-only` command returned a non-zero exit code.', code ); 725 } 726 enqueueTestingTasksForModifiedFiles( result.stdout ); 727 } 728 ); 729 } else { 730 grunt.log.write( 'This WordPress install is not under version control, no tests will be run.' ); 731 } 732 }); 733 }); 669 734 670 735 grunt.registerTask( 'copy:all', [ -
trunk/package.json
r36865 r36906 11 11 "devDependencies": { 12 12 "autoprefixer": "~6.3.3", 13 "git-or-svn": "~0.1.0", 13 14 "grunt": "~0.4.5", 14 15 "grunt-browserify": "~4.0.1",
Note: See TracChangeset
for help on using the changeset viewer.