Browse Source

Got rid of compilation step.

Maciek 9 years ago
parent
commit
cceeaf2952

+ 32 - 0
build/test-library.html

@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="utf-8">
+	<title>CKEditor library splitting</title>
+</head>
+<body>
+
+<div id="editor">
+	<p><em>This</em> is an <strong>editor</strong> instance.</p>
+</div>
+
+<script src="./dist/ClassicEditor.ckeditor.js"></script>
+<script src="./dist/CKEditorPresetBasic.ckeditor.js"></script>
+<script src="./dist/CKEditorList.ckeditor.js"></script>
+<script src="./dist/CKEditorLink.ckeditor.js"></script>
+<script src="./dist/CKEditorHeading.ckeditor.js"></script>
+<script>
+	'use strict';
+
+	ClassicEditor.default.create( document.querySelector( '#editor' ), {
+		plugins: [ CKEditorPresetBasic.default, CKEditorList.default, CKEditorLink.default, CKEditorHeading.default, ],
+		toolbar: [ 'undo', 'redo', 'headings', 'bulletedList', 'numberedList', 'link', 'bold', 'italic' ]
+	} ).then( editor => {
+		window.editor = editor;
+	} ).catch( err => {
+		console.error( err.stack );
+	} );
+</script>
+
+</body>
+</html>

+ 16 - 0
build/test.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="utf-8">
+	<title>CKEditor simple test</title>
+</head>
+<body>
+
+<div id="editor">
+	<p><em>This</em> is an <strong>editor</strong> instance.</p>
+</div>
+<script src="./dist/ckeditor.js"></script>
+
+</body>
+</html>
+

+ 21 - 0
ckeditor-preset-basic.js

@@ -0,0 +1,21 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* jshint browser: true */
+
+import Plugin from 'ckeditor5-core/src/plugin';
+import Enter from 'ckeditor5-enter/src/enter';
+import Typing from 'ckeditor5-typing/src/typing';
+import Paragraph from 'ckeditor5-paragraph/src/paragraph';
+import Clipboard from 'ckeditor5-clipboard/src/clipboard';
+import Undo from 'ckeditor5-undo/src/undo';
+import Bold from 'ckeditor5-basic-styles/src/bold';
+import Italic from 'ckeditor5-basic-styles/src/italic';
+
+export default class PresetBasic extends Plugin {
+	static get requires() {
+		return [ Enter, Typing, Paragraph, Clipboard, Undo, Bold, Italic ];
+	}
+}

+ 27 - 0
ckeditor-rollup-plugin.js

@@ -0,0 +1,27 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* jshint browser: false, node: true, strict: true */
+
+'use strict';
+
+const resolveImportPathInContext = require( './compiler-utils/resolveimportpathincontext' );
+const path = require( 'path' );
+
+function ckeditorRollupPlugin( options ) {
+	return {
+		resolveId( importPath, requesterPath ) {
+			if ( options.useMainPackageModules ) {
+				const resolvedPath = resolveImportPathInContext( requesterPath, importPath, options.mainPackagePath );
+
+				if ( resolvedPath ) {
+					return path.join( resolvedPath.packagePath, resolvedPath.filePath );
+				}
+			}
+		}
+	};
+}
+
+module.exports = ckeditorRollupPlugin;

+ 6 - 31
gulpfile.js

@@ -164,40 +164,15 @@ gulp.task( 'docs:build', () => {
 // Tests. ---------------------------------------------------------------------
 
 gulp.task( 'test', () => {
-	const tests = require( '@ckeditor/ckeditor5-dev-tests' );
-
-	return tests.tasks.automated.test( getTestOptions() );
+	return require( '@ckeditor/ckeditor5-dev-tests' )
+		.runAutomatedTests( getTestOptions() );
 } );
 
-// Requires compiled sources. Task should be used in parallel with `gulp compile --formats=esnext --watch`.
-gulp.task( 'test:server', () => {
-	const tests = require( '@ckeditor/ckeditor5-dev-tests' );
-	const options = getTestOptions();
-
-	options.sourcePath = path.resolve( config.MODULE_DIR.esnext );
-
-	return tests.tasks.automated.runTests( options );
-} );
-
-gulp.task( 'test:manual', ( done ) => {
-	const tests = require( '@ckeditor/ckeditor5-dev-tests' );
-
-	tests.tasks.manual.run( {
-		packages: getCKEditor5PackagesPaths()
-	}, done );
+gulp.task( 'test:manual', () => {
+	return require( '@ckeditor/ckeditor5-dev-tests' )
+		.runManualTests( getTestOptions() );
 } );
 
 function getTestOptions() {
-	const tests = require( '@ckeditor/ckeditor5-dev-tests' );
-	const options = tests.utils.parseArguments();
-
-	options.packages = getCKEditor5PackagesPaths();
-
-	// If --paths weren't specified, then test all packages.
-	if ( !options.paths ) {
-		options.paths = options.packages
-			.map( ( packagePath ) => tests.utils.getPackageName( path.resolve( packagePath ) ) );
-	}
-
-	return options;
+	return require( '@ckeditor/ckeditor5-dev-tests' ).parseArguments( process.argv.slice( 2 ) );
 }

+ 0 - 1
package.json

@@ -24,7 +24,6 @@
     "ckeditor5-theme-lark": "ckeditor/ckeditor5-theme-lark",
     "ckeditor5-typing": "ckeditor/ckeditor5-typing",
     "ckeditor5-ui": "ckeditor/ckeditor5-ui",
-    "ckeditor5-ui-default": "ckeditor/ckeditor5-ui-default",
     "ckeditor5-undo": "ckeditor/ckeditor5-undo",
     "ckeditor5-utils": "ckeditor/ckeditor5-utils"
   },

+ 51 - 0
rollup.config.js

@@ -0,0 +1,51 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* jshint browser: false, node: true, strict: true */
+
+'use strict';
+
+const path = require( 'path' );
+const ckeditorRollupPlugin = require( './ckeditor-rollup-plugin' );
+const nodeResolve = require( 'rollup-plugin-node-resolve' );
+const stringRollupPlugin = require( 'rollup-plugin-string' );
+const sassRollupPlugin = require( 'rollup-plugin-sass' );
+
+export default {
+	entry: './webpack-entry-point.js',
+	format: 'iife',
+
+	dest: path.join( 'build', 'dist', 'ckeditor.js' ),
+
+	plugins: [
+		ckeditorRollupPlugin( {
+			useMainPackageModules: true,
+			mainPackagePath: process.cwd()
+		} ),
+		nodeResolve(),
+
+		// TODO is it possible to include that in the CKEditor plugin?
+		stringRollupPlugin( {
+			include: '**/ckeditor5-*/theme/icons/*.svg'
+		} ),
+
+		sassRollupPlugin( {
+			insert: true,
+			include: '**/*.scss',
+			exclude: [],
+			options: {
+				importer( url /*, prev */ ) {
+					if ( url.startsWith( '~' ) ) {
+						const path = process.cwd() + '/node_modules/' + url.slice( 1 );
+
+						return {
+							file: path
+						};
+					}
+				}
+			}
+		} )
+	]
+};

+ 39 - 0
scripts/fix-src-imports.js

@@ -0,0 +1,39 @@
+#!/usr/bin/env node
+
+const fs = require( 'fs' );
+const path = require( 'path' );
+const glob = require( 'glob' );
+
+const srcDir = path.join( process.cwd(), 'src' );
+const srcPath = path.join( srcDir , '**', '*.js' );
+
+for ( const filePath of glob.sync( srcPath ) ) {
+	const fileDepth = countOcurrences( filePath.replace( srcDir + '/', '' ), path.sep );
+	const fix = ( wholeImport, pathStart ) => fixImport( wholeImport, pathStart, fileDepth );
+
+	const fileContent = fs.readFileSync( filePath, 'utf-8' )
+		.replace( /\nimport[^']+?'((\.\.\/)+[\w-]+)\/[^']+?'/gm, fix );
+
+	fs.writeFileSync( filePath, fileContent , 'utf-8' );
+}
+
+function fixImport( wholeImport, pathStart, fileDepth ) {
+	const indexOfPathStart = wholeImport.indexOf( '../' );
+	const packageShortName = pathStart.split( '/' ).slice( -1 )[0];
+	const importDepth = countOcurrences( pathStart, '../' );
+
+	if ( importDepth <= fileDepth ) {
+		return wholeImport;
+	}
+
+	return (
+		wholeImport.slice( 0, indexOfPathStart ) +
+		'ckeditor5-' + packageShortName +
+		'/src' +
+		wholeImport.slice( indexOfPathStart + pathStart.length )
+	);
+}
+
+function countOcurrences( str, pattern ) {
+	return str.split( pattern ).length - 1;
+}

+ 52 - 0
scripts/fix-test-imports.js

@@ -0,0 +1,52 @@
+#!/usr/bin/env node
+
+const fs = require( 'fs' );
+const path = require( 'path' );
+const glob = require( 'glob' );
+
+const testDir = path.join( process.cwd(), 'tests' );
+const testPath = path.join( testDir , '**', '*.js' );
+
+for ( const filePath of glob.sync( testPath ) ) {
+	const fileContent = fs.readFileSync( filePath, 'utf-8' )
+		.replace( /\nimport[^']+?'([^']+?)'/gm, fixImport );
+
+	fs.writeFileSync( filePath, fileContent , 'utf-8' );
+}
+
+function fixImport( wholeImport , path ) {
+	let fixedImport = fixCkeditorPaths( wholeImport, path );
+	fixedImport = fixTestPaths( fixedImport, path );
+
+	return fixedImport;
+}
+
+function fixCkeditorPaths( wholeImport, path ) {
+	if ( path.indexOf( 'ckeditor5/' ) !== 0 ) {
+		return wholeImport;
+	}
+
+	const index = wholeImport.indexOf( path );
+	const pathChunks = path.split( '/' );
+
+	return (
+		wholeImport.slice( 0, index ) +
+		'ckeditor5-' + pathChunks[1] + '/src/' + pathChunks.slice( 2 ).join( '/' ) +
+		wholeImport.slice( path.length + index )
+	);
+}
+
+function fixTestPaths( wholeImport, path ) {
+	if ( path.indexOf( 'tests/' ) !== 0 ) {
+		return wholeImport;
+	}
+
+	const index = wholeImport.indexOf( path );
+	const pathChunks = path.split( '/' );
+
+	return (
+		wholeImport.slice( 0, index ) +
+		'ckeditor5-' + pathChunks[1] + '/tests/' + pathChunks.slice( 2 ).join( '/' ) +
+		wholeImport.slice( path.length + index )
+	);
+}

+ 14 - 0
scripts/remove-js-extensions-from-imports.js

@@ -0,0 +1,14 @@
+#!/usr/bin/env node
+
+const fs = require( 'fs' );
+const path = require( 'path' );
+const glob = require( 'glob' );
+
+const srcPath = path.join( process.cwd(), '@(src|tests)', '**', '*.js' );
+
+for ( const filePath of glob.sync( srcPath ) ) {
+	const fileContent = fs.readFileSync( filePath, 'utf-8' )
+		.replace( /\nimport([^;]+)\.js';/g, '\nimport$1\';' );
+
+	fs.writeFileSync( filePath, fileContent , 'utf-8' );
+}

+ 27 - 0
scripts/switch-to-dev-dev.sh

@@ -0,0 +1,27 @@
+#!/bin/sh
+set -e
+
+# If it doesn't exist the following lines won't work.
+if [ ! -d node_modules/@ckeditor ]; then
+  mkdir node_modules/@ckeditor
+fi
+
+echo "Linking ckeditor5-dev-env..."
+
+rm -rf node_modules/@ckeditor/ckeditor5-dev-env
+ln -s ../../../ckeditor5-dev/packages/ckeditor5-dev-env node_modules/@ckeditor
+
+echo "Linking ckeditor5-dev-lint..."
+
+rm -rf node_modules/@ckeditor/ckeditor5-dev-lint
+ln -s ../../../ckeditor5-dev/packages/ckeditor5-dev-lint node_modules/@ckeditor
+
+echo "Linking ckeditor5-dev-tests..."
+
+rm -rf node_modules/@ckeditor/ckeditor5-dev-tests
+ln -s ../../../ckeditor5-dev/packages/ckeditor5-dev-tests node_modules/@ckeditor
+
+echo "Linking ckeditor5-dev-utils..."
+
+rm -rf node_modules/@ckeditor/ckeditor5-dev-utils
+ln -s ../../../ckeditor5-dev/packages/ckeditor5-dev-utils node_modules/@ckeditor

+ 40 - 0
webpack-chunks.config.js

@@ -0,0 +1,40 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* jshint browser: false, node: true, strict: true */
+
+const path = require( 'path' );
+const CKEditorWebpackPlugin = require( './ckeditor-webpack-plugin' );
+const webpack = require( 'webpack' );
+
+module.exports = {
+	context: __dirname,
+	target: 'web',
+
+	entry: {
+		core: './webpack-entry-point',
+		pluginList: 'ckeditor5-list/src/list',
+		pluginLink: 'ckeditor5-link/src/link',
+	},
+
+	output: {
+		path: path.join( 'build', 'dist' ),
+		filename: '[name].ckeditor.js',
+	},
+
+	devtool: 'cheap-source-map',
+
+	plugins: [
+		new CKEditorWebpackPlugin( {
+			useMainPackageModules: true,
+			mainPackagePath: process.cwd()
+		} ),
+		new webpack.optimize.CommonsChunkPlugin( {
+			names: [ 'core' ],
+			// children: true
+			// minChunks: Infinity
+		} )
+	],
+};

+ 23 - 0
webpack-entry-point.js

@@ -0,0 +1,23 @@
+/* jshint browser: true */
+/* global console */
+
+import ClassicEditor from 'ckeditor5-editor-classic/src/classic';
+import Enter from 'ckeditor5-enter/src/enter';
+import Typing from 'ckeditor5-typing/src/typing';
+import Paragraph from 'ckeditor5-paragraph/src/paragraph';
+import Undo from 'ckeditor5-undo/src/undo';
+import Bold from 'ckeditor5-basic-styles/src/bold';
+import Italic from 'ckeditor5-basic-styles/src/italic';
+import List from 'ckeditor5-list/src/list';
+import Link from 'ckeditor5-link/src/link';
+import Autoformat from 'ckeditor5-autoformat/src/autoformat';
+import Heading from 'ckeditor5-heading/src/heading';
+
+ClassicEditor.create( document.querySelector( '#editor' ), {
+	plugins: [ Enter, Typing, Paragraph, Undo, Bold, Italic, List, Link, Autoformat, Heading ],
+	toolbar: [ 'headings', 'bold', 'italic', 'undo', 'redo', 'numberedList', 'bulletedList', 'link', 'unlink' ]
+} ).then( editor => {
+	window.editor = editor;
+} ).catch( err => {
+	console.error( err.stack );
+} );

+ 5 - 0
webpack-library-entry-point.js

@@ -0,0 +1,5 @@
+/* jshint browser: true */
+
+import ClassicEditor from 'ckeditor5-editor-classic/src/classic';
+
+export default ClassicEditor;

+ 43 - 0
webpack-library.config.js

@@ -0,0 +1,43 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* jshint browser: false, node: true, strict: true */
+
+const path = require( 'path' );
+const CKEditorWebpackPlugin = require( './ckeditor-webpack-plugin' );
+const webpack = require( 'webpack' );
+
+module.exports = {
+	context: __dirname,
+	target: 'web',
+
+	entry: {
+		ClassicEditor: 'ckeditor5-editor-classic/src/classic',
+		CKEditorPresetBasic: './ckeditor-preset-basic',
+		CKEditorList: 'ckeditor5-list/src/list',
+		CKEditorLink: 'ckeditor5-link/src/link',
+		CKEditorHeading: 'ckeditor5-heading/src/heading',
+	},
+
+	output: {
+		path: path.join( 'build', 'dist' ),
+		filename: '[name].ckeditor.js',
+		library: '[name]',
+	},
+
+	devtool: 'cheap-source-map',
+
+	plugins: [
+		new CKEditorWebpackPlugin( {
+			useMainPackageModules: true,
+			mainPackagePath: process.cwd()
+		} ),
+		new webpack.optimize.CommonsChunkPlugin( {
+			name: 'ClassicEditor',
+			// children: true,
+			minChunks: 2
+		} )
+	],
+};

+ 54 - 0
webpack.config.js

@@ -0,0 +1,54 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* jshint browser: false, node: true, strict: true */
+
+const path = require( 'path' );
+const CKEditorWebpackPlugin = require( './node_modules/@ckeditor/ckeditor5-dev-tests/ckeditor-webpack-plugin' );
+
+module.exports = {
+	context: __dirname,
+	target: 'web',
+
+	entry: './webpack-entry-point',
+
+	output: {
+		path: path.join( 'build', 'dist' ),
+		filename: 'ckeditor.js',
+	},
+
+	// TODO is it possible to include that in the CKEditor plugin?
+	module: {
+		rules: [
+			{
+				// test: **/ckeditor5-*/theme/icons/*.svg
+				test: /ckeditor5-[^/]+\/theme\/icons\/[^/]+\.svg$/,
+				use: [ 'raw-loader' ]
+			},
+			{
+				// test: **/ckeditor5-*/theme/**/*.scss
+				test: /\.scss$/,
+				use: [ 'style-loader', 'css-loader', 'sass-loader' ]
+			}
+		]
+	},
+
+	// resolve: {
+	// 	modules: [
+	// 		path.resolve( __dirname, 'node_modules' ),
+	// 		'node_modules'
+	// 	]
+	// },
+
+	devtool: 'cheap-source-map',
+
+	plugins: [
+		new CKEditorWebpackPlugin( {
+			packages: {
+				'*': path.join( process.cwd(), 'node_modules' )
+			}
+		} )
+	],
+};