Explorar o código

Moved the buildEditorForSamples function from the bundler package as it doesn't make sense there.

Piotrek Koszuliński %!s(int64=9) %!d(string=hai) anos
pai
achega
9a6a8952ee
Modificáronse 2 ficheiros con 95 adicións e 9 borrados
  1. 90 7
      gulpfile.js
  2. 5 2
      package.json

+ 90 - 7
gulpfile.js

@@ -101,7 +101,7 @@ gulp.task( 'compile:themes:esnext', callback => {
 
 // Building tasks. ------------------------------------------------------------
 
-const ckeditor5DevBundle = require( '@ckeditor/ckeditor5-dev-bundler-rollup' )( config );
+const ckeditor5DevBundler = require( '@ckeditor/ckeditor5-dev-bundler-rollup' )( config );
 
 gulp.task( 'build', callback => {
 	runSequence(
@@ -110,15 +110,15 @@ gulp.task( 'build', callback => {
 			'bundle:minify:js',
 			'bundle:minify:css'
 		],
-		() => ckeditor5DevBundle.showSummaryFromConfig( callback )
+		() => ckeditor5DevBundler.showSummaryFromConfig( callback )
 	);
 } );
 
 // Helpers. ---------------------------
 
-gulp.task( 'bundle:clean', ckeditor5DevBundle.cleanFromConfig );
-gulp.task( 'bundle:minify:js', ckeditor5DevBundle.minify.jsFromConfig );
-gulp.task( 'bundle:minify:css', ckeditor5DevBundle.minify.cssFromConfig );
+gulp.task( 'bundle:clean', ckeditor5DevBundler.cleanFromConfig );
+gulp.task( 'bundle:minify:js', ckeditor5DevBundler.minify.jsFromConfig );
+gulp.task( 'bundle:minify:css', ckeditor5DevBundler.minify.cssFromConfig );
 
 // Generates the bundle without minifying it.
 gulp.task( 'bundle:generate',
@@ -127,7 +127,7 @@ gulp.task( 'bundle:generate',
 		'compile:js:esnext',
 		'compile:themes:esnext'
 	],
-	ckeditor5DevBundle.generateFromConfig
+	ckeditor5DevBundler.generateFromConfig
 );
 
 // Task specific for building editors for testing releases.
@@ -136,7 +136,7 @@ gulp.task( 'compile:bundled-sample-tests:build-editors',
 		'compile:js:esnext',
 		'compile:themes:esnext'
 	],
-	ckeditor5DevBundle.buildEditorsForSamples
+	buildEditorsForSamples
 );
 
 // Documentation. -------------------------------------------------------------
@@ -144,3 +144,86 @@ gulp.task( 'compile:bundled-sample-tests:build-editors',
 const docsBuilder = ckeditor5DevCompiler.docs;
 
 gulp.task( 'docs', [ 'compile:js:esnext' ], docsBuilder.buildDocs );
+
+// Testing. -------------------------------------------------------------------
+
+// TODO The below code is here only temporarily. It will be extracted to a separat package
+// once we'll understand better where it should belong. Right now it's somewhere beyond testing
+// environment, compilation and documentation.
+
+/**
+ * Prepares configurations for bundler based on sample files and builds editors
+ * based on prepared configuration.
+ *
+ * You can find more details in: https://github.com/ckeditor/ckeditor5/issues/260
+ *
+ * @returns {Stream}
+ */
+function buildEditorsForSamples() {
+	const { utils: compilerUtils } = require( '@ckeditor/ckeditor5-dev-compiler' )( config );
+	const { stream, tools: tools } = require( '@ckeditor/ckeditor5-dev-utils' );
+
+	const gulpFilter = require( 'gulp-filter' );
+	const gulpRename = require( 'gulp-rename' );
+	const path = require( 'path' );
+
+	const bundleDir = path.join( config.ROOT_DIR, config.BUNDLE_DIR );
+
+	return compilerUtils.getFilesStream( config.ROOT_DIR, config.DOCUMENTATION.SAMPLES )
+		.pipe( gulpFilter( ( file ) => path.extname( file.path ) === '.js' ) )
+		.pipe( gulpRename( ( file ) => {
+			file.dirname = file.dirname.replace( '/docs/samples', '' );
+		} ) )
+		.pipe( stream.noop( ( file ) => {
+			const contents = file.contents.toString( 'utf-8' );
+			const bundleConfig = {};
+
+			// Prepare the config based on sample.
+
+			bundleConfig.format = 'iife';
+
+			// Find `moduleName` from line which ends with "// editor:name".
+			bundleConfig.moduleName = contents.match( /([a-z]+)\.create(.*)\/\/ ?editor:name/i )[ 1 ];
+
+			// Find `editor` from line which ends with "// editor:module".
+			bundleConfig.editor = contents.match( /([-a-z0-9]+\/[-a-z0-9]+)(\.js)?'; ?\/\/ ?editor:module/i )[ 1 ];
+
+			// Find `features` from line which ends with "// editor:features".
+			bundleConfig.features = contents.match( /(\[[^\]]+\]),? ?\/\/ ?(.*)editor:features/i )[ 1 ]
+				.match( /([a-z-\/]+)/gi );
+
+			// Extract `path` from Sample's path.
+			bundleConfig.path = file.path.match( /ckeditor5-(.*)\.js$/ )[ 1 ];
+
+			const splitPath = bundleConfig.path.split( path.sep );
+			const packageName = splitPath[ 0 ];
+
+			// Clean the output paths.
+			return ckeditor5DevBundler.clean( bundleConfig )
+				// Then bundle a editor.
+				.then( () => ckeditor5DevBundler.generate( bundleConfig ) )
+				// Then copy created files.
+				.then( () => {
+					const beginPath = splitPath.slice( 1, -1 ).join( path.sep ) || '.';
+					const fileName = splitPath.slice( -1 ).join();
+					const builtEditorPath = path.join( bundleDir, bundleConfig.path, bundleConfig.moduleName );
+					const destinationPath = path.join.apply( null, [
+						config.MODULE_DIR.amd,
+						'tests',
+						packageName,
+						'samples',
+						beginPath,
+						'_assets',
+						fileName
+					] );
+
+					// Copy editor builds to proper directory.
+					return Promise.all( [
+						tools.copyFile( `${ builtEditorPath }.js`, destinationPath ),
+						tools.copyFile( `${ builtEditorPath }.css`, destinationPath )
+					] );
+				} )
+				// And clean up.
+				.then( () => tools.clean( path.join( config.BUNDLE_DIR, packageName, '..' ), packageName ) );
+		} ) );
+}

+ 5 - 2
package.json

@@ -31,11 +31,14 @@
     "benderjs-mocha": "^0.3.0",
     "benderjs-promise": "^0.1.0",
     "benderjs-sinon": "^0.3.0",
-    "@ckeditor/ckeditor5-dev-bundler-rollup": "^1.0.1",
-    "@ckeditor/ckeditor5-dev-compiler": "^1.0.0",
+    "@ckeditor/ckeditor5-dev-bundler-rollup": "ckeditor/ckeditor5-dev-bundler-rollup",
+    "@ckeditor/ckeditor5-dev-compiler": "ckeditor/ckeditor5-dev-compiler",
     "@ckeditor/ckeditor5-dev-env": "^1.0.0",
     "@ckeditor/ckeditor5-dev-lint": "^1.0.1",
+    "@ckeditor/ckeditor5-dev-utils": "ckeditor/ckeditor5-dev-utils",
     "gulp": "^3.9.0",
+    "gulp-filter": "^4.0.0",
+    "gulp-rename": "^1.2.2",
     "guppy-pre-commit": "^0.3.0",
     "run-sequence": "^1.1.5"
   },