Sfoglia il codice sorgente

Shared the ckeditor5/ckeditor.js code between dev and build versions so the basePath computation code is also shared.

fredck 11 anni fa
parent
commit
ef522dd79a
4 ha cambiato i file con 51 aggiunte e 39 eliminazioni
  1. 10 22
      ckeditor.js
  2. 12 10
      dev/tasks/build.js
  3. 1 7
      dev/tasks/build/end.frag
  4. 28 0
      src/ckeditor-dev.js

+ 10 - 22
ckeditor.js

@@ -7,13 +7,9 @@
 
 'use strict';
 
-// This file is required for the development version of CKEditor only. It bootstraps the API.
+// This file is shared by the dev and release versions of CKEditor. It bootstraps the API.
 
 ( function( root ) {
-	if ( root.CKEDITOR ) {
-		return;
-	}
-
 	var CKEDITOR = root.CKEDITOR = {
 		/**
 		 * The full URL for the CKEditor installation directory.
@@ -48,35 +44,27 @@
 		 * @method
 		 * @member CKEDITOR
 		 */
-		require: require,
-
-		// Documented in ckeditor-core/src/ckeditor.js.
-		// This is the development version of this method, which overrides the default one.
-		getPluginPath: function( name ) {
-			return this.basePath + 'node_modules/ckeditor-plugin-' + name + '/src/';
-		}
+		require: require
 	};
 
-	// Basic Require.js configuration for the dev version.
 	requirejs.config( {
 		// Modules are generally relative to the core project.
 		baseUrl: CKEDITOR.basePath + 'node_modules/ckeditor5-core/src/',
+
+		// These configurations will make no difference in the build version because the following paths will be
+		// already defined there.
 		paths: {
 			// Hide the core "ckeditor" under a different name.
 			'ckeditor-core': CKEDITOR.basePath + 'node_modules/ckeditor5-core/src/ckeditor',
 
-			// The RequireJS "plugin" plugin.
-			'plugin': CKEDITOR.basePath + 'src/plugin',
-
-			// Due to name conflict with the above, we have to save a reference to the core "plugin" module.
-			// See src/plugin.js for more details.
-			'plugin-core': CKEDITOR.basePath + 'node_modules/ckeditor5-core/src/plugin'
+			// The dev version overrides for the "ckeditor" module. This is empty on release.
+			'ckeditor-dev': CKEDITOR.basePath + 'src/ckeditor-dev'
 		}
 	} );
 
-	// Define a new "ckeditor" module, which override the core one with dev version stuff.
-	define( 'ckeditor', [ 'ckeditor-core', 'utils' ], function( core, utils ) {
-		utils.extend( core, root.CKEDITOR );
+	// Define a new "ckeditor" module, which overrides the core one with the above and the dev stuff.
+	define( 'ckeditor', [ 'ckeditor-core', 'ckeditor-dev', 'utils' ], function( core, dev, utils ) {
+		utils.extend( core, root.CKEDITOR, ( dev || {} ) );
 		root.CKEDITOR = core;
 
 		return core;

+ 12 - 10
dev/tasks/build.js

@@ -116,18 +116,22 @@ module.exports.build = function( done ) {
 			out: target + '/ckeditor.js',
 
 			baseUrl: tmp + '/ckeditor5-core/src/',
-			generateSourceMaps: false,
-			preserveLicenseComments: false,
-			include: [ 'ckeditor' ],
-//			include: ['depTree', 'ckeditor' ].concat( getPlugins() ),
-//			paths: {
+			paths: {
+				'ckeditor': '../../../ckeditor',
+				'ckeditor-dev': '../../../src/ckeditor-dev',
+				'ckeditor-core': 'ckeditor'
 //				depTree: '../../../lib/depTree',
 //				plugins: '../../../lib/plugins'
-//			},
+			},
+
+//			include: ['depTree', 'ckeditor' ].concat( getPlugins() ),
+			include: [ 'ckeditor' ],
+			stubModules: [ 'ckeditor-dev' ],
+
+//			onBuildWrite: replacePaths,
 //			optimize: 'uglify2',
 			optimize: 'none',
-//			onBuildWrite: replacePaths,
-//			stubModules: [ 'plugins' ],
+			preserveLicenseComments: false,
 			wrap: {
 				startFile: [ 'dev/tasks/build/start.frag', require.resolve( 'almond' ) ],
 				endFile: 'dev/tasks/build/end.frag'
@@ -136,8 +140,6 @@ module.exports.build = function( done ) {
 
 		requirejs.optimize( config, function() {
 			callback();
-		}, function( err ) {
-			throw err;
 		} );
 	}
 

+ 1 - 7
dev/tasks/build/end.frag

@@ -1,10 +1,4 @@
 /************************ end.frag START */
 
-	var CKEDITOR = require( 'ckeditor' );
-
-	// Setup the AMD API to use Almond.
-	CKEDITOR.define = define;
-	CKEDITOR.require = require;
-
-	return CKEDITOR;
+	return require( 'ckeditor' );
 } );

+ 28 - 0
src/ckeditor-dev.js

@@ -0,0 +1,28 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global define, requirejs, CKEDITOR */
+
+'use strict';
+
+define( 'ckeditor-dev', function() {
+	return {
+		getPluginPath: function( name ) {
+			return this.basePath + 'node_modules/ckeditor-plugin-' + name + '/src/';
+		}
+	};
+} );
+
+// For the dev version, we override the "plugin" module.
+requirejs.config( {
+	paths: {
+		// The RequireJS "plugin" plugin.
+		'plugin': CKEDITOR.basePath + 'src/plugin',
+
+		// Due to name conflict with the above, we have to save a reference to the core "plugin" module.
+		// See src/plugin.js for more details.
+		'plugin-core': CKEDITOR.basePath + 'node_modules/ckeditor5-core/src/plugin'
+	}
+} );