8
0
Просмотр исходного кода

Added dev-plugin-install grunt task.

Szymon Kupś 10 лет назад
Родитель
Сommit
ac656b1ab8
3 измененных файлов с 79 добавлено и 3 удалено
  1. 8 2
      dev/tasks/dev.js
  2. 1 1
      dev/tasks/utils/dev-plugin-create.js
  3. 70 0
      dev/tasks/utils/dev-plugin-install.js

+ 8 - 2
dev/tasks/dev.js

@@ -7,8 +7,8 @@
 
 
 const initTask = require( './utils/dev-init' );
 const initTask = require( './utils/dev-init' );
 const pluginCreateTask = require( './utils/dev-plugin-create' );
 const pluginCreateTask = require( './utils/dev-plugin-create' );
-
-var ckeditor5Path = process.cwd();
+const pluginInstallTask = require( './utils/dev-plugin-install' );
+const ckeditor5Path = process.cwd();
 
 
 module.exports = ( grunt ) => {
 module.exports = ( grunt ) => {
 	const packageJSON = grunt.config.data.pkg;
 	const packageJSON = grunt.config.data.pkg;
@@ -25,6 +25,12 @@ module.exports = ( grunt ) => {
 		pluginCreateTask( ckeditor5Path, options, grunt.log.writeln, grunt.log.error ).then( done );
 		pluginCreateTask( ckeditor5Path, options, grunt.log.writeln, grunt.log.error ).then( done );
 	} );
 	} );
 
 
+	grunt.registerTask( 'dev-plugin-install', function() {
+		const done = this.async();
+		const options = getOptions( this );
+		pluginInstallTask( ckeditor5Path, options, grunt.log.writeln, grunt.log.error ).then( done );
+	} );
+
 	function getOptions( context ) {
 	function getOptions( context ) {
 		const options = {
 		const options = {
 			workspaceRoot: '..'
 			workspaceRoot: '..'

+ 1 - 1
dev/tasks/utils/dev-plugin-create.js

@@ -47,7 +47,7 @@ module.exports = ( ckeditor5Path, options, writeln, writeError ) => {
 
 
 				return inquiries.getPluginGitHubUrl( pluginName );
 				return inquiries.getPluginGitHubUrl( pluginName );
 			} )
 			} )
-			.then( ( result ) => {
+			.then( result => {
 				try {
 				try {
 					gitHubUrl = result;
 					gitHubUrl = result;
 
 

+ 70 - 0
dev/tasks/utils/dev-plugin-install.js

@@ -0,0 +1,70 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+const inquiries = require( './inquiries' );
+const git = require( './git' );
+const tools = require( './tools' );
+const path = require( 'path' );
+
+/**
+ * 1. Ask for plugin name.
+ * 2. Ask for GitHub URL.
+ * 3. Clone repository from provided GitHub URL.
+ * 4. Checkout repository to provided branch (or master if no branch is provided).
+ * 5. Update package.json file in CKEditor5 repository.
+ * 6. Link new plugin.
+ *
+ * @param {String} ckeditor5Path Path to main CKEditor5 repository.
+ * @param {Object} options grunt options.
+ * @param {Function} writeln Function for log output.
+ * @param {Function} writeError Function of error output
+ * @returns {Promise} Returns promise fulfilled after task is done.
+ */
+module.exports = ( ckeditor5Path, options, writeln, writeError ) => {
+	return new Promise( ( resolve, reject ) => {
+		const workspaceAbsolutePath = path.join( ckeditor5Path, options.workspaceRoot );
+		let pluginName;
+		let repositoryPath;
+		let gitHubUrl;
+
+		inquiries.getPluginName()
+			.then( result => {
+				pluginName = result;
+				repositoryPath = path.join( workspaceAbsolutePath, pluginName );
+
+				return inquiries.getPluginGitHubUrl( pluginName );
+			} )
+			.then( result => {
+				gitHubUrl = result;
+				let urlInfo = git.parseRepositoryUrl( gitHubUrl );
+
+				try {
+					writeln( `Clonning ${ gitHubUrl }...` );
+					git.cloneRepository( urlInfo, workspaceAbsolutePath );
+
+					writeln( `Checking out ${ gitHubUrl } to ${ urlInfo.branch }...` );
+					git.checkout( repositoryPath, urlInfo.branch );
+
+					writeln( `Updating package.json files...` );
+					tools.updateJSONFile( path.join( ckeditor5Path, 'package.json' ), ( json ) => {
+						if ( !json.dependencies ) {
+							json.dependencies = {};
+						}
+						json.dependencies[ pluginName ] = gitHubUrl;
+
+						return json;
+					} );
+
+					writeln( `Linking ${ pluginName } to node_modules...` );
+					tools.linkDirectories( repositoryPath, path.join( ckeditor5Path, 'node_modules', pluginName ) );
+				} catch ( error ) {
+					writeError( error );
+				}
+			} )
+			.catch( reject );
+	} );
+};