Kaynağa Gözat

Added dev-boilerplate-update grunt task.

Szymon Kupś 10 yıl önce
ebeveyn
işleme
552941bc9b

+ 6 - 0
dev/tasks/dev.js

@@ -10,6 +10,7 @@ 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 boilerplateUpdateTask = require( './utils/dev-boilerplate-update' );
 const ckeditor5Path = process.cwd();
 
 module.exports = ( grunt ) => {
@@ -42,6 +43,11 @@ module.exports = ( grunt ) => {
 		pluginStatusTask( ckeditor5Path, packageJSON, options, grunt.log.writeln, grunt.log.error );
 	} );
 
+	grunt.registerTask( 'dev-boilerplate-update', function() {
+		const options = getOptions( this );
+		boilerplateUpdateTask( ckeditor5Path, packageJSON, options, grunt.log.writeln, grunt.log.error );
+	} );
+
 	function getOptions( context ) {
 		const options = {
 			workspaceRoot: '..'

+ 48 - 0
dev/tasks/utils/dev-boilerplate-update.js

@@ -0,0 +1,48 @@
+/**
+ * @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. Fetch and merge boilerplate remote.
+ *
+ * @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 );
+
+			// Check if repository's directory already exists.
+			if ( directories.indexOf( dependency ) > -1 ) {
+				try {
+					writeln( `Updating boilerplate in ${ dependency }...` );
+					git.updateBoilerplate( repositoryAbsolutePath );
+				} catch ( error ) {
+					writeError( error );
+				}
+			}
+		}
+	} else {
+		writeln( 'No CKEditor5 dependencies found in package.json file.' );
+	}
+};

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

@@ -98,5 +98,20 @@ module.exports = {
 
 	getStatus( repositoryPath ) {
 		return tools.shExec( `cd ${ repositoryPath } && git status --porcelain -sb` ).trim();
+	},
+
+	updateBoilerplate( repositoryPath ) {
+		// Try to add boilerplate remote if one is not already added.
+		try {
+			tools.shExec( `cd ${ repositoryPath } && git remote add boilerplate ${ BOILERPLATE_REPOSITORY }` );
+		} catch ( error ) { }
+
+		const updateCommands = [
+			`cd ${ repositoryPath }`,
+			`git fetch boilerplate ${ BOILERPLATE_BRANCH }`,
+			`git merge boilerplate/${ BOILERPLATE_BRANCH }`
+		];
+
+		tools.shExec( updateCommands.join( ' && ' ) );
 	}
 };