Parcourir la source

Added dev-status grunt task.

Szymon Kupś il y a 10 ans
Parent
commit
2b5176222e
3 fichiers modifiés avec 59 ajouts et 0 suppressions
  1. 6 0
      dev/tasks/dev.js
  2. 49 0
      dev/tasks/utils/dev-status.js
  3. 4 0
      dev/tasks/utils/git.js

+ 6 - 0
dev/tasks/dev.js

@@ -9,6 +9,7 @@ const initTask = require( './utils/dev-init' );
 const pluginCreateTask = require( './utils/dev-plugin-create' );
 const pluginInstallTask = require( './utils/dev-plugin-install' );
 const pluginUpdateTask = require( './utils/dev-update' );
+const pluginStatusTask = require( './utils/dev-status' );
 const ckeditor5Path = process.cwd();
 
 module.exports = ( grunt ) => {
@@ -36,6 +37,11 @@ module.exports = ( grunt ) => {
 		pluginUpdateTask( ckeditor5Path, packageJSON, options, grunt.log.writeln, grunt.log.error );
 	} );
 
+	grunt.registerTask( 'dev-status', function() {
+		const options = getOptions( this );
+		pluginStatusTask( ckeditor5Path, packageJSON, options, grunt.log.writeln, grunt.log.error );
+	} );
+
 	function getOptions( context ) {
 		const options = {
 			workspaceRoot: '..'

+ 49 - 0
dev/tasks/utils/dev-status.js

@@ -0,0 +1,49 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+const tools = require( './tools' );
+const git = require( './git' );
+const path = require( 'path' );
+
+/**
+ * 1. Get CKEditor5 dependencies from package.json file.
+ * 2. Scan workspace for repositories that match dependencies from package.json file.
+ * 3. Print GIT status using `git status --porcelain -sb` command.
+ *
+ * @param {String} ckeditor5Path Path to main CKEditor5 repository.
+ * @param {Object} packageJSON Parsed package.json file from CKEditor5 repository.
+ * @param {Object} options grunt options.
+ * @param {Function} writeln Function for log output.
+ * @param {Function} writeError Function of error output
+ */
+module.exports = ( ckeditor5Path, packageJSON, options, writeln, writeError ) => {
+	const workspaceAbsolutePath = path.join( ckeditor5Path, options.workspaceRoot );
+
+	// Get all CKEditor dependencies from package.json.
+	const dependencies = tools.getCKEditorDependencies( packageJSON.dependencies );
+
+	if ( dependencies ) {
+		const directories = tools.getCKE5Directories( workspaceAbsolutePath );
+
+		for ( let dependency in dependencies ) {
+			const repositoryAbsolutePath = path.join( workspaceAbsolutePath, dependency );
+			let status;
+
+			// Check if repository's directory already exists.
+			if ( directories.indexOf( dependency ) > -1 ) {
+				try {
+					status = git.getStatus( repositoryAbsolutePath );
+					writeln( `\x1b[1m\x1b[36m${ dependency }\x1b[0m\n${ status }` );
+				} catch ( error ) {
+					writeError( error );
+				}
+			}
+		}
+	} else {
+		writeln( 'No CKEditor5 dependencies found in package.json file.' );
+	}
+};

+ 4 - 0
dev/tasks/utils/git.js

@@ -94,5 +94,9 @@ module.exports = {
 		];
 
 		tools.shExec( initializeCommands.join( ' && ' ) );
+	},
+
+	getStatus( repositoryPath ) {
+		return tools.shExec( `cd ${ repositoryPath } && git status --porcelain -sb` ).trim();
 	}
 };