浏览代码

Extracted the :git task check from jshint to tools, so it can be reused.

fredck 11 年之前
父节点
当前提交
a7aa0330fe
共有 2 个文件被更改,包括 20 次插入12 次删除
  1. 6 12
      packages/ckeditor5-ui/dev/tasks/jshint.js
  2. 14 0
      packages/ckeditor5-ui/dev/tasks/res/tools.js

+ 6 - 12
packages/ckeditor5-ui/dev/tasks/jshint.js

@@ -5,25 +5,19 @@
 var tools = require( './res/tools' );
 
 module.exports = function( grunt ) {
-	// Base task configuration, targeting "all" by default.
+	// Point to the default configurations.
 	var config = {
-		all: [ '**/*.js' ],
 		options: defaultConfig
 	};
 
-	// Get information about the task being executed.
-	var isGitTask = ( grunt.cli.tasks.indexOf( 'jshint:git' ) > -1 ),
-		isDefaultTask = ( grunt.cli.tasks.indexOf( 'default' ) > -1 ) || !grunt.cli.tasks.length,
-		// Hacking grunt hard.
-		isDefaultAndGit = isDefaultTask && ( grunt.task._tasks.default.info.indexOf( '"jshint:git"' ) > -1 );
-
-	// Create the :git configuration on the fly, if necessary.
-	if ( isGitTask || isDefaultAndGit ) {
-		delete config.all;
+	// Create the appropriate task target.
+	if ( tools.checkTaskInQueue( grunt, 'jshint:git' ) ) {
 		config.git = tools.getGitDirtyFiles();
+	} else {
+		config.all = [ '**/*.js' ];
 	}
 
-	// Merge with configurations set in gruntfile.js.
+	// Merge over configurations set in gruntfile.js.
 	grunt.config.merge( {
 		jshint: config
 	} );

+ 14 - 0
packages/ckeditor5-ui/dev/tasks/res/tools.js

@@ -5,6 +5,20 @@
 var dirtyFiles;
 
 module.exports = {
+	checkTaskInQueue: function( grunt, task ) {
+		var cliTasks = grunt.cli.tasks;
+
+		// Check if the task has been called directly.
+		var isDirectCall = ( cliTasks.indexOf( 'task' ) > -1 );
+
+		// Check if this is a "default" call and that the task is inside "default".
+		var isDefaultTask = ( cliTasks.indexOf( 'default' ) > -1 ) || !cliTasks.length,
+			// Hacking grunt hard.
+			isTaskInDefault = isDefaultTask && ( grunt.task._tasks.default.info.indexOf( '"jshint:git"' ) > -1 );
+
+		return isDirectCall || isDefaultTask;
+	},
+
 	getGitDirtyFiles: function() {
 		// Cache it, so it is executed only once when running multiple tasks.
 		if ( !dirtyFiles ) {