Explorar el Código

Merge branch 't/5'

fredck hace 11 años
padre
commit
5077ab0808
Se han modificado 10 ficheros con 486 adiciones y 4 borrados
  1. 3 3
      LICENSE.md
  2. 112 0
      ckeditor.js
  3. 18 0
      dev/tasks/build.js
  4. 238 0
      dev/tasks/build/builder.js
  5. 1 0
      gruntfile.js
  6. 6 1
      package.json
  7. 18 0
      src/build/end.frag
  8. 28 0
      src/build/start.frag
  9. 28 0
      src/ckeditor-dev.js
  10. 34 0
      src/plugin.js

+ 3 - 3
LICENSE.md

@@ -6,11 +6,11 @@ Copyright (c) 2003-2014, [CKSource](http://cksource.com) Frederico Knabben. All
 
 
 Licensed under the terms of any of the following licenses at your choice:
 Licensed under the terms of any of the following licenses at your choice:
 
 
- - [GNU General Public License Version 2 or later (the "GPL")](http://www.gnu.org/licenses/gpl.html)
+ * [GNU General Public License Version 2 or later (the "GPL")](http://www.gnu.org/licenses/gpl.html)
 
 
- - [GNU Lesser General Public License Version 2.1 or later (the "LGPL")](http://www.gnu.org/licenses/lgpl.html)
+ * [GNU Lesser General Public License Version 2.1 or later (the "LGPL")](http://www.gnu.org/licenses/lgpl.html)
 
 
- - [Mozilla Public License Version 1.1 or later (the "MPL")](http://www.mozilla.org/MPL/MPL-1.1.html)
+ * [Mozilla Public License Version 1.1 or later (the "MPL")](http://www.mozilla.org/MPL/MPL-1.1.html)
 
 
 You are not required to, but if you want to explicitly declare the license you have chosen to be bound to when using,
 You are not required to, but if you want to explicitly declare the license you have chosen to be bound to when using,
 reproducing, modifying and distributing this software, just include a text file titled "legal.txt" in your version of
 reproducing, modifying and distributing this software, just include a text file titled "legal.txt" in your version of

+ 112 - 0
ckeditor.js

@@ -0,0 +1,112 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global requirejs, define, require, window, document, location */
+
+'use strict';
+
+// This file is shared by the dev and release versions of CKEditor. It bootstraps the API.
+
+( function( root ) {
+	var CKEDITOR = root.CKEDITOR = {
+		/**
+		 * Computes the value of the `basePath` property.
+		 *
+		 * @private
+		 * @method
+		 * @returns {String} A full URL.
+		 */
+		_getBasePath: getBasePath,
+
+		/**
+		 * The full URL for the CKEditor installation directory.
+		 *
+		 * It is possible to manually provide the base path by setting a global variable named `CKEDITOR_BASEPATH`. This
+		 * global variable must be set **before** the editor script loading.
+		 *
+		 *		console.log( CKEDITOR.basePath ); // e.g. 'http://www.example.com/ckeditor/'
+		 *
+		 * @property {String}
+		 */
+		basePath: getBasePath(),
+
+		/**
+		 * Defines an AMD module.
+		 *
+		 * See https://github.com/ckeditor/ckeditor5-design/wiki/AMD for more details about our AMD API.
+		 *
+		 * @method
+		 * @member CKEDITOR
+		 */
+		define: define,
+
+		/**
+		 * Retrieves one or more AMD modules.
+		 *
+		 * Note that the CKEditor AMD API does not download modules on demand so be sure to have their relative scripts
+		 * available in the page.
+		 *
+		 * See https://github.com/ckeditor/ckeditor5-design/wiki/AMD for more details about our AMD API.
+		 *
+		 * @method
+		 * @member CKEDITOR
+		 */
+		require: require
+	};
+
+	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 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 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;
+	} );
+
+	function getBasePath() {
+		if ( window.CKEDITOR_BASEPATH ) {
+			return window.CKEDITOR_BASEPATH;
+		}
+
+		var scripts = document.getElementsByTagName( 'script' );
+		var basePathSrcPattern = /(^|.*[\\\/])ckeditor\.js(?:\?.*|;.*)?$/i;
+		var path;
+
+		// Find the first script that src matches ckeditor.js.
+		[].some.call( scripts, function( script ) {
+			var match = script.src.match( basePathSrcPattern );
+
+			if ( match ) {
+				path = match[ 1 ];
+
+				return true;
+			}
+		} );
+
+		if ( path.indexOf( ':/' ) == -1 && path.slice( 0, 2 ) != '//' ) {
+			if ( path[ 0 ] == '/' ) {
+				path = location.href.match( /^.*?:\/\/[^\/]*/ )[ 0 ] + path;
+			} else {
+				path = location.href.match( /^[^\?]*\/(?:)/ )[ 0 ] + path;
+			}
+		}
+
+		return path;
+	}
+} )( window );

+ 18 - 0
dev/tasks/build.js

@@ -0,0 +1,18 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* jshint node: true */
+
+'use strict';
+
+var Builder = require( './build/builder' );
+
+module.exports = function( grunt ) {
+	grunt.registerTask( 'build', 'Build a release out of the current development code.', function() {
+		var done = this.async();
+		var builder = new Builder();
+		builder.build( done );
+	} );
+};

+ 238 - 0
dev/tasks/build/builder.js

@@ -0,0 +1,238 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* jshint node: true */
+
+'use strict';
+
+module.exports = Builder;
+
+/**
+ * A CKEditor 5 release builder.
+ *
+ * @class Builder
+ */
+function Builder( target ) {
+	/**
+	 * The target directory where to create the build.
+	 *
+	 * **Warning**: if existing, this directory will be deleted before processing.
+	 *
+	 * @property {String}
+	 */
+	this.target = target || 'build';
+
+	/**
+	 * The temporary directory to use for build processing.
+	 *
+	 * **Warning**: if existing, this directory will be deleted before processing.
+	 *
+	 * @property {String}
+	 */
+	this.tmp = 'build-tmp';
+
+	/**
+	 * The list of tasks to be executed by the `build()` method. Each entry is an Array containing the name of the
+	 * method inside `tasks` to execute and the message to show to the end user when executing it.
+	 *
+	 * @property {Array}
+	 */
+	this.taskList = [
+		[ 'cleanUp', 'Cleaning the "' + this.target + '" directory...' ],
+		[ 'copyToTmp', 'Copying source files for manipulation...' ],
+		[ 'removeAmdNamespace', 'AMD cleanup...' ],
+		[ 'optimize', 'Creating the optimized code...' ],
+		[ 'cleanUpTmp', 'Removing the "' + this.tmp + '" directory...' ]
+	];
+}
+
+Builder.prototype = {
+	/**
+	 * Builds a CKEditor release based on the current development code.
+	 *
+	 * @param {Function} [callback] Function to be called when build finishes. It receives `false` on error.
+	 */
+	build: function( callback ) {
+		var that = this;
+		var stepCounter = 0;
+
+		// Before starting, run the initial checkups.
+		if ( !this.checkUp() ) {
+			console.error( 'Build operation aborted.' );
+			callback( false );
+
+			return;
+		}
+
+		console.log( 'Building CKEditor into the "' + this.target + '" directory:')
+
+		runNext();
+
+		function runNext() {
+			var next = that.taskList.shift();
+
+			if ( next ) {
+				stepCounter++;
+				console.log( stepCounter + '. ' + next[ 1 ] );
+				that.tasks[ next[ 0 ] ].call( that, runNext );
+			} else {
+				if ( callback ) {
+					callback();
+				}
+			}
+		}
+	},
+
+	checkUp: function() {
+		var fs = require( 'fs' );
+
+		// Stop if the tmp folder already exists.
+		if ( fs.existsSync( this.tmp ) ) {
+			console.error( 'The "' + this.tmp + '" directory already exists. Delete it and try again.' );
+
+			return false;
+		}
+
+		return true;
+	},
+
+	/**
+	 * Holds individual methods for each task executed by the builder.
+	 *
+	 * All methods here MUST be called in the builder context by using
+	 * `builder.tasks.someMethod.call( builder, callback )`.
+	 */
+	tasks: {
+		/**
+		 * Deletes the `target` and `tmp` directories.
+		 *
+		 * @param {Function} callback Function to be called when the task is done.
+		 * @returns {Object} The callback returned value.
+		 */
+		cleanUp: function( callback ) {
+			var del = require( 'del' );
+			del.sync( this.target );
+			del.sync( this.tmp );
+
+			return callback();
+		},
+
+		/**
+		 * Copy the local source code of CKEditor and its dependencies to the `tmp` directory for processing.
+		 *
+		 * @param {Function} callback Function to be called when the task is done.
+		 * @returns {Object} The callback returned value.
+		 */
+		copyToTmp: function( callback ) {
+			var ncp = require( 'ncp' ).ncp;
+			var path = require( 'path' );
+			var fs = require( 'fs' );
+			var tmp = this.tmp;
+
+			var deps = require( '../../../package.json' ).dependencies;
+
+			var toCopy = Object.keys( deps ).filter( function( name ) {
+				return name.indexOf( 'ckeditor5-' ) === 0;
+			} );
+
+			fs.mkdirSync( tmp );
+
+			function copy() {
+				var module = toCopy.shift();
+
+				if ( !module ) {
+					return callback();
+				}
+
+				var dest = path.join( tmp + '/', module );
+
+				if ( !fs.existsSync( dest ) ) {
+					fs.mkdirSync( dest );
+				}
+
+				// Copy the "src" directory only.
+				ncp( path.join( 'node_modules', module, 'src' ), path.join( dest, 'src' ), {
+					dereference: true
+				}, function( err ) {
+					if ( err ) {
+						throw err;
+					}
+
+					copy();
+				} );
+			}
+
+			copy();
+		},
+
+		/**
+		 * Removes the `CKEDITOR` namespace from AMD calls in the `tmp` copy of the source code.
+		 *
+		 * @param {Function} callback Function to be called when the task is done.
+		 * @returns {Object} The callback returned value.
+		 */
+		removeAmdNamespace: function( callback ) {
+			var replace = require( 'replace' );
+
+			replace( {
+				regex: /^\s*CKEDITOR\.(define|require)/mg,
+				replacement: '$1',
+				paths: [ this.tmp ],
+				recursive: true,
+				silent: true
+			} );
+
+			callback();
+		},
+
+		/**
+		 * Creates the optimized release version of `ckeditor.js` in the `target` directory out of the `tmp` copy of the
+		 * source code.
+		 *
+		 * @param {Function} callback Function to be called when the task is done.
+		 * @returns {Object} The callback returned value.
+		 */
+		optimize: function( callback ) {
+			var requirejs = require( 'requirejs' );
+
+			var config = {
+				out: this.target + '/ckeditor.js',
+
+				baseUrl: this.tmp + '/ckeditor5-core/src/',
+				paths: {
+					'ckeditor': '../../../ckeditor',
+					'ckeditor-dev': '../../../src/ckeditor-dev',
+					'ckeditor-core': 'ckeditor'
+				},
+
+				include: [ 'ckeditor' ],
+				stubModules: [ 'ckeditor-dev' ],
+
+				//			optimize: 'none',
+				optimize: 'uglify2',
+				preserveLicenseComments: false,
+				wrap: {
+					startFile: [ 'src/build/start.frag', require.resolve( 'almond' ) ],
+					endFile: 'src/build/end.frag'
+				}
+			};
+
+			requirejs.optimize( config, callback );
+		},
+
+		/**
+		 * Deletes `tmp` directory.
+		 *
+		 * @param {Function} callback Function to be called when the task is done.
+		 * @returns {Object} The callback returned value.
+		 */
+		cleanUpTmp: function( callback ) {
+			var del = require( 'del' );
+			del.sync( this.tmp );
+
+			return callback();
+		}
+	}
+};

+ 1 - 0
gruntfile.js

@@ -9,6 +9,7 @@ module.exports = function( grunt ) {
 	// Files that will be ignored by the "jscs" and "jshint" tasks.
 	// Files that will be ignored by the "jscs" and "jshint" tasks.
 	var ignoreFiles = [
 	var ignoreFiles = [
 		// Automatically loaded from .gitignore. Add more if necessary.
 		// Automatically loaded from .gitignore. Add more if necessary.
+		'lib/**'
 	];
 	];
 
 
 	// Basic configuration which will be overloaded by the tasks.
 	// Basic configuration which will be overloaded by the tasks.

+ 6 - 1
package.json

@@ -8,9 +8,14 @@
     "WYSIWYG"
     "WYSIWYG"
   ],
   ],
   "dependencies": {
   "dependencies": {
-    "ckeditor-core": "ckeditor/ckeditor5-core"
+    "requirejs": "~2.1",
+    "ckeditor5-core": "ckeditor/ckeditor5-core"
   },
   },
   "devDependencies": {
   "devDependencies": {
+    "almond": "~0.3.0",
+    "del": "~1.1",
+    "ncp": "~1.0",
+    "replace": "~0.3.0",
     "grunt": "~0",
     "grunt": "~0",
     "grunt-jscs": "~1",
     "grunt-jscs": "~1",
     "grunt-contrib-jshint": "~0",
     "grunt-contrib-jshint": "~0",

+ 18 - 0
src/build/end.frag

@@ -0,0 +1,18 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+// This is the code that will go after the compiled source code in the ckeditor.js build.
+//
+// The following are the parts that compose the build:
+//
+//  * start.frag
+//  * Almond.js source code
+//  * CKEditor source code
+//  * end.frag
+
+/************************ end.frag START */
+
+	return require( 'ckeditor' );
+} );

+ 28 - 0
src/build/start.frag

@@ -0,0 +1,28 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+// This is the code that will precede the compiled source code in the ckeditor.js build.
+//
+// The following are the parts that compose the build:
+//
+//  * start.frag
+//  * Almond.js source code
+//  * CKEditor source code
+//  * end.frag
+
+( function( root, factory ) {
+	// Register the CKEDITOR global.
+	root.CKEDITOR = factory();
+
+	// Make the build an AMD module.
+	// https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property-
+	if ( typeof define == 'function' && define.amd ) {
+		define( function() {
+			return root.CKEDITOR;
+		} );
+	}
+} )( this, function() {
+
+/************************ start.frag END */

+ 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'
+	}
+} );

+ 34 - 0
src/plugin.js

@@ -0,0 +1,34 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global define */
+
+'use strict';
+
+// Plugin for RequireJS to properly load CKEditor plugins through the "plugin!name" scheme:
+// "plugin!name" => "node_modules/ckeditor5-plugin-name/name"
+//
+// Due to name conflict with the "ckeditor5-core/plugin" module, a workaround was needed. In this case, we extend the
+// core Plugin class with the necessary RequireJS plugin methods. This should have no harm on the use of the Plugin
+// class.
+
+define( 'plugin', [ 'plugin-core' ], function( CorePlugin ) {
+	// Called when a "plugin!" module is to be loaded.
+	// http://requirejs.org/docs/plugins.html#apiload
+	CorePlugin.load = function( name, require, onload ) {
+		var path = name.split( '/' );
+		path.splice( 1, 0, 'src' );
+
+		if ( path.length == 2 ) {
+			path.push( path[ 0 ] );
+		}
+
+		path = '../../ckeditor5-plugin-' + path.join( '/' );
+
+		require( [ path ], onload );
+	};
+
+	return CorePlugin;
+} );