Przeglądaj źródła

Added dev-relink grunt task.

Szymon Kupś 10 lat temu
rodzic
commit
db5fa25cb2
2 zmienionych plików z 53 dodań i 0 usunięć
  1. 5 0
      dev/tasks/dev.js
  2. 48 0
      dev/tasks/utils/dev-relink.js

+ 5 - 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 relinkTask = require( './utils/dev-relink' );
 const boilerplateUpdateTask = require( './utils/dev-boilerplate-update' );
 const ckeditor5Path = process.cwd();
 
@@ -46,5 +47,9 @@ module.exports = ( grunt ) => {
 	grunt.registerTask( 'dev-boilerplate-update', function() {
 		boilerplateUpdateTask( ckeditor5Path, packageJSON, workspaceRoot, grunt.log.writeln, grunt.log.error );
 	} );
+
+	grunt.registerTask( 'dev-relink', function() {
+		relinkTask( ckeditor5Path, packageJSON, workspaceRoot, grunt.log.writeln, grunt.log.error );
+	} );
 };
 

+ 48 - 0
dev/tasks/utils/dev-relink.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 path = require( 'path' );
+
+/**
+ * 1. Get CKEditor5 dependencies from package.json file.
+ * 2. Scan workspace for repositories that match dependencies from package.json file.
+ * 3. Link repositories to node_modules in CKEditor5 repository.
+ *
+ * @param {String} ckeditor5Path Path to main CKEditor5 repository.
+ * @param {Object} packageJSON Parsed package.json file from CKEditor5 repository.
+ * @param {String} workspaceRoot Relative path to workspace root.
+ * @param {Function} writeln Function for log output.
+ * @param {Function} writeError Function of error output
+ */
+module.exports = ( ckeditor5Path, packageJSON, workspaceRoot, writeln, writeError ) => {
+	const workspaceAbsolutePath = path.join( ckeditor5Path, 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 );
+			const repositoryURL = dependencies[ dependency ];
+
+			// Check if repository's directory exists.
+			if ( directories.indexOf( dependency ) > -1 ) {
+				try {
+					writeln( `Linking ${ repositoryURL }...` );
+					tools.linkDirectories( repositoryAbsolutePath, path.join( ckeditor5Path, 'node_modules' , dependency ) );
+				} catch ( error ) {
+					writeError( error );
+				}
+			}
+		}
+	} else {
+		writeln( 'No CKEditor5 dependencies found in package.json file.' );
+	}
+};