Преглед изворни кода

Adjusted bundling to new creators.

Oskar Wrobel пре 9 година
родитељ
комит
9a2f8897cf

+ 1 - 1
dev/tasks/build/tasks.js

@@ -73,7 +73,7 @@ module.exports = ( config ) => {
 				 * @returns {Stream}
 				 */
 				main( watch ) {
-					const glob = path.join( config.ROOT_DIR, config.MAIN_FILE );
+					const glob = path.join( config.ROOT_DIR, 'ckeditor.js' );
 
 					return gulp.src( glob )
 						.pipe( watch ? gulpWatch( glob ) : utils.noop() );

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

@@ -0,0 +1,56 @@
+/**
+ * @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: should be injected by bundle task.
+ */
+import '../../../node_modules/regenerator-runtime/runtime.js';
+
+import ClassicEditor from '../../../build/esnext/ckeditor5/creator-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 );
+	}
+}

+ 0 - 30
dev/tasks/bundle/classiccreatorbundle.js

@@ -1,30 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-'use strict';
-
-/**
- * Bundle configuration for {@link ckeditor5.creator-classic.ClassiCcreator}.
- *
- * 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.
- */
-
-import CKEDITOR from '../../../build/esnext/ckeditor.js';
-import ClassicCreator from '../../../build/esnext/ckeditor5/creator-classic/classiccreator.js';
-
-/**
- * Wrapper for {@link CKEDITOR.create} which passes default setting
- * for {@link ckeditor5.creator-classic.ClassiCcreator}. This settings could be extended.
- * API of this function is exactly the same as {@link CKEDITOR.create}.
- */
-export default function createEditor( element, config ) {
-	return CKEDITOR.create( element, Object.assign( {
-		creator: ClassicCreator,
-		toolbar: [ 'bold', 'italic' ]
-	}, config ) );
-}

+ 15 - 11
dev/tasks/bundle/tasks.js

@@ -11,11 +11,13 @@ const gulpCssnano = require( 'gulp-cssnano' );
 const runSequence = require( 'run-sequence' );
 const utils = require( './utils' );
 const rollup = require( 'rollup' ).rollup;
+const rollupBabel = require( 'rollup-plugin-babel' );
+const gulpUglify = require( 'gulp-uglify' );
 
 module.exports = ( config ) => {
 	const sourceBuildDir = path.join( config.ROOT_DIR, config.BUILD_DIR, 'esnext' );
 	const bundleDir = path.join( config.ROOT_DIR, config.BUNDLE_DIR );
-	const entryFilePath = path.join( config.ROOT_DIR, 'dev', 'tasks', 'bundle', 'classiccreatorbundle.js' );
+	const entryFilePath = path.join( config.ROOT_DIR, 'dev', 'tasks', 'bundle', 'buildclassiceditor.js' );
 
 	const tasks = {
 		/**
@@ -37,19 +39,23 @@ module.exports = ( config ) => {
 			 * we have created a custom entry file where we defined some of imports with features
 			 * needed to initialize editor.
 			 *
-			 * Bundled `ckeditor.js` file exposes a global function `createEditor`.
-			 * For more details see docs from `classiccreatorbundle.js`.
+			 * For more details see `buildclassiceditor.js`.
 			 */
 			function bundleJS() {
-				const outputFile = path.join( bundleDir, config.MAIN_FILE );
+				const outputFile = path.join( bundleDir, 'ckeditor.js' );
 
 				return rollup( {
-					entry: entryFilePath
+					entry: entryFilePath,
+					plugins: [
+						rollupBabel( {
+							presets: [ 'es2015-rollup' ]
+						} )
+					]
 				} ).then( ( bundle ) => {
 					return bundle.write( {
 						dest: outputFile,
 						format: 'iife',
-						moduleName: 'createEditor'
+						moduleName: 'ClassicEditor'
 					} );
 				} );
 			}
@@ -70,12 +76,10 @@ module.exports = ( config ) => {
 		minify: {
 			/**
 			 * JS minification by UglifyJS.
-			 *
-			 * At this moment we don't minify JS file because there is no minifier fully sports esnext syntax.
-			 * For consistency `ckeditor.min.js` file is created, but is not minified yed.
 			 */
 			js() {
-				let stream = gulp.src( path.join( bundleDir, config.MAIN_FILE ) );
+				let stream = gulp.src( path.join( bundleDir, 'ckeditor.js' ) )
+					.pipe( gulpUglify() );
 
 				return utils.saveFileFromStreamAsMinified( stream, bundleDir );
 			},
@@ -101,7 +105,7 @@ module.exports = ( config ) => {
 	gulp.task( 'bundle', ( callback ) => {
 		runSequence( 'bundle:generate', [ 'bundle:minify:js', 'bundle:minify:css' ], () => {
 			// Print files size on console just before the end of the task.
-			const files = [ 'ckeditor.js', 'ckeditor.css', 'ckeditor.min.js', 'ckeditor.min.css' ];
+			const files = [ 'ckeditor.js', 'ckeditor.min.js', 'ckeditor.css', 'ckeditor.min.css' ];
 			utils.logFilesSize( files, bundleDir );
 
 			// Finish the task.

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

@@ -66,10 +66,14 @@ const utils = {
 	 *
 	 * @param {String} from file path
 	 * @param {String} to copied file destination
-	 * @return {Stream}
+	 * @return {Promise}
 	 */
 	copyFile( from, to ) {
-		return gulp.src( from ).pipe( gulp.dest( to ) );
+		return new Promise( ( resolve ) => {
+			gulp.src( from )
+				.pipe( gulp.dest( to ) )
+				.on( 'finish', resolve );
+		} );
 	}
 };
 

+ 2 - 3
dev/tests/bundle/tasks.js

@@ -15,8 +15,7 @@ describe( 'build-tasks', () => {
 	const config = {
 		ROOT_DIR: '.',
 		BUILD_DIR: 'build',
-		BUNDLE_DIR: 'bundle',
-		MAIN_FILE: 'ckeditor.js'
+		BUNDLE_DIR: 'bundle'
 	};
 
 	beforeEach( () => {
@@ -57,7 +56,7 @@ describe( 'build-tasks', () => {
 			sinon.assert.calledWithExactly( rollupBundleWriteMock, {
 				dest: 'bundle/ckeditor.js',
 				format: 'iife',
-				moduleName: 'createEditor'
+				moduleName: 'ClassicEditor'
 			} );
 		} );
 	} );

+ 0 - 1
gulpfile.js

@@ -9,7 +9,6 @@ const config = {
 	BUILD_DIR: 'build',
 	BUNDLE_DIR: 'bundle',
 	WORKSPACE_DIR: '..',
-	MAIN_FILE: 'ckeditor.js',
 
 	// Files ignored by jshint and jscs tasks. Files from .gitignore will be added automatically during tasks execution.
 	IGNORED_FILES: [

+ 4 - 0
package.json

@@ -27,6 +27,7 @@
     "babel-core": "^6.4.0",
     "babel-plugin-transform-es2015-modules-amd": "^6.1.18",
     "babel-plugin-transform-es2015-modules-commonjs": "^6.2.0",
+    "babel-preset-es2015-rollup": "^1.1.1",
     "benderjs": "^0.4.1",
     "benderjs-chai": "^0.2.0",
     "benderjs-coverage": "^0.2.1",
@@ -55,6 +56,7 @@
     "gulp-replace": "^0.5.4",
     "gulp-sourcemaps": "^1.6.0",
     "gulp-svg-sprite": "^1.2.19",
+    "gulp-uglify": "^1.5.3",
     "gulp-util": "^3.0.7",
     "gulp-watch": "4.3.5",
     "guppy-pre-commit": "^0.3.0",
@@ -70,8 +72,10 @@
     "multipipe": "^0.3.0",
     "ncp": "^2.0.0",
     "node-sass": "^3.7.0",
+    "regenerator-runtime": "^0.9.5",
     "replace": "^0.3.0",
     "rollup": "^0.26.3",
+    "rollup-plugin-babel": "^2.4.0",
     "run-sequence": "^1.1.5",
     "semver": "^5.1.0",
     "shelljs": "^0",