8
0
Szymon Kupś 10 лет назад
Родитель
Сommit
fd7edbd22b
4 измененных файлов с 68 добавлено и 4 удалено
  1. 6 1
      dev/tasks/dev.js
  2. 3 3
      dev/tasks/utils/dev-init.js
  3. 50 0
      dev/tasks/utils/dev-update.js
  4. 9 0
      dev/tasks/utils/git.js

+ 6 - 1
dev/tasks/dev.js

@@ -8,13 +8,13 @@
 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 ckeditor5Path = process.cwd();
 
 module.exports = ( grunt ) => {
 	const packageJSON = grunt.config.data.pkg;
 
 	grunt.registerTask( 'dev-init', function() {
-		// Get workspace root relative path from configuration and convert it to absolute path.
 		const options = getOptions( this );
 		initTask( ckeditor5Path, packageJSON, options, grunt.log.writeln, grunt.log.error );
 	} );
@@ -31,6 +31,11 @@ module.exports = ( grunt ) => {
 		pluginInstallTask( ckeditor5Path, options, grunt.log.writeln, grunt.log.error ).then( done );
 	} );
 
+	grunt.registerTask( 'dev-update', function() {
+		const options = getOptions( this );
+		pluginUpdateTask( ckeditor5Path, packageJSON, options, grunt.log.writeln, grunt.log.error );
+	} );
+
 	function getOptions( context ) {
 		const options = {
 			workspaceRoot: '..'

+ 3 - 3
dev/tasks/utils/dev-init.js

@@ -5,9 +5,9 @@
 
 'use strict';
 
-var tools = require( './tools' );
-var git = require( './git' );
-var path = require( 'path' );
+const tools = require( './tools' );
+const git = require( './git' );
+const path = require( 'path' );
 
 /**
  * 1. Get CKEditor5 dependencies from package.json file.

+ 50 - 0
dev/tasks/utils/dev-update.js

@@ -0,0 +1,50 @@
+/**
+ * @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. Run GIT pull command on each repository found.
+ *
+ * @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 repositoryURL = dependencies[ dependency ];
+			const urlInfo = git.parseRepositoryUrl( repositoryURL );
+			const repositoryAbsolutePath = path.join( workspaceAbsolutePath, dependency );
+
+			// Check if repository's directory already exists.
+			if ( directories.indexOf( dependency ) > -1 ) {
+				try {
+					writeln( `Updating ${ repositoryURL }...` );
+					git.pull( repositoryAbsolutePath, urlInfo.branch );
+				} catch ( error ) {
+					writeError( error );
+				}
+			}
+		}
+	} else {
+		writeln( 'No CKEditor5 dependencies found in package.json file.' );
+	}
+};

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

@@ -75,6 +75,15 @@ module.exports = {
 		tools.shExec( checkoutCommands.join( ' && ' ) );
 	},
 
+	pull( repositoryLocation, branchName ) {
+		const checkoutCommands = [
+			`cd ${ repositoryLocation }`,
+			`git pull origin ${ branchName }`
+		];
+
+		tools.shExec( checkoutCommands.join( ' && ' ) );
+	},
+
 	initializeRepository( repositoryPath ) {
 		const initializeCommands = [
 			`git init ${ repositoryPath }`,