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

Added posiibility to pass only plugin name instead of whole path to bundle config.

Oskar Wrobel 9 лет назад
Родитель
Сommit
2c406812ce

+ 0 - 60
dev/tasks/bundle/buildclassiceditor.js

@@ -1,60 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-'use strict';
-
-/**
- * Bundle configuration with hard coded set of features.
- *
- * At this moment we don't know a list of every dependency needed in the bundle. It is because
- * editor features load automatically during initialization process. To work around this problem
- * we have created a custom entry file where we defined some of imports with features
- * needed to initialize editor.
- */
-
-/**
- * Babel helper.
- *
- * @TODO: Move to bundle task.
- * Should be injected by bundle task, because our source code don't have to know that will be transformed.
- * But it is not so easy. It is only possible to pass string with file path to rollup,
- * so to do it we need to create a temporary file.
- */
-import '../../../node_modules/regenerator-runtime/runtime.js';
-
-import ClassicEditor from '../../../build/esnext/ckeditor5/editor-classic/classic.js';
-import Delete from '../../../build/esnext/ckeditor5/delete/delete.js';
-import Enter from '../../../build/esnext/ckeditor5/enter/enter.js';
-import Typing from '../../../build/esnext/ckeditor5/typing/typing.js';
-import Paragraph from '../../../build/esnext/ckeditor5/paragraph/paragraph.js';
-import Undo from '../../../build/esnext/ckeditor5/undo/undo.js';
-import BasicStylesBold from '../../../build/esnext/ckeditor5/basic-styles/bold.js';
-import BasicStylesItalic from '../../../build/esnext/ckeditor5/basic-styles/italic.js';
-
-/**
- * Class for creating editor with defined set of features.
- *
- * @extends ckeditor5.creator-classic.classic
- * @param {HTMLElement} element See {@link ckeditor5.creator-classic.classic#create}'s param.
- * @param {Object} config See {@link ckeditor5.creator-classic.classic#create}'s param.
- * @returns {Promise} Promise resolved once editor is ready.
- * @returns {ckeditor5.editor.StandardEditor} return.editor The editor instance.
- */
-export default class BuildClassicEditor extends ClassicEditor {
-	static create( element, config = {} ) {
-		if ( !config.features ) {
-			config.features = [];
-		}
-
-		if ( !config.toolbar ) {
-			config.toolbar = [];
-		}
-
-		config.features = [ ...config.features, Delete, Enter, Typing, Paragraph, Undo, BasicStylesBold, BasicStylesItalic ];
-		config.toolbar = [ ...config.toolbar, 'bold', 'italic', 'undo', 'redo' ];
-
-		return ClassicEditor.create( element, config );
-	}
-}

+ 3 - 3
dev/tasks/bundle/bundle-config.js

@@ -6,11 +6,11 @@
 'use strict';
 
 module.exports = {
-	creator: './build/esnext/ckeditor5/editor-classic/classic.js',
 	moduleName: 'MyCKEditor',
+	creator: './build/esnext/ckeditor5/editor-classic/classic.js',
 	features: [
-		'./build/esnext/ckeditor5/enter/enter.js',
-		'./build/esnext/ckeditor5/paragraph/paragraph.js',
+		'enter',
+		'paragraph',
 		'./build/esnext/ckeditor5/typing/typing.js',
 		'./build/esnext/ckeditor5/undo/undo.js',
 		'./build/esnext/ckeditor5/headings/headings.js'

+ 18 - 2
dev/tasks/bundle/utils.js

@@ -33,11 +33,25 @@ const utils = {
 	},
 
 	/**
-	 * Render content for entry file which needs to be passed as main file to Rollup.
+	 * Resolves a simplified plugin name to a real path.
+	 *
+	 * @param {String} name
+	 * @returns {String} Path to the module.
+	 */
+	getPluginPath( name ) {
+		if ( name.indexOf( '/' ) > 0 ) {
+			return name;
+		}
+
+		return './build/esnext/ckeditor5/' + ( name + '/' + name ) + '.js';
+	},
+
+	/**
+	 * Render content for entry file which needs to be passed as main file to the Rollup.
 	 *
 	 * @param {Object} data
 	 * @param {String} [data.moduleName] Name of the editor class exposed in bundle. e.g. MyCKEditor.
-	 * @param {String} [data.creator] Path to the editor creator as ClassicEditor, StandardEditor etc.
+	 * @param {String} [data.creator] Path to the editor creator.
 	 * @param {Array<String>} [data.features] List of paths or names to features which need to be included in bundle.
 	 * @returns {string}
 	 */
@@ -55,6 +69,8 @@ const utils = {
 
 		// Imports editor features.
 		for ( let feature of data.features ) {
+			feature = utils.getPluginPath( feature );
+
 			const featureName = path.basename( feature, '.js' );
 			const featurePath = path.relative( './tmp', feature );