|
|
@@ -19,6 +19,7 @@ const KNOWN_OPTIONS = {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+const fs = require( 'fs' );
|
|
|
const path = require( 'path' );
|
|
|
const gulp = require( 'gulp' );
|
|
|
const del = require( 'del' );
|
|
|
@@ -28,7 +29,6 @@ const gutil = require( 'gulp-util' );
|
|
|
const minimist = require( 'minimist' );
|
|
|
const utils = require( './utils' );
|
|
|
|
|
|
-const sep = path.sep;
|
|
|
const options = minimist( process.argv.slice( 2 ), KNOWN_OPTIONS[ process.argv[ 2 ] ] );
|
|
|
|
|
|
module.exports = ( config ) => {
|
|
|
@@ -56,37 +56,74 @@ module.exports = ( config ) => {
|
|
|
/**
|
|
|
* Returns a stream with just the main file (`ckeditor5/ckeditor.js`).
|
|
|
*
|
|
|
- * @param {Boolean} [watch] Whether the files should be watched.
|
|
|
+ * @param {Boolean} [watch] Whether to watch the files.
|
|
|
* @returns {Stream}
|
|
|
*/
|
|
|
main( watch ) {
|
|
|
- return utils.src( config.ROOT_DIR, 'ckeditor.js', watch );
|
|
|
+ const glob = path.join( config.ROOT_DIR, 'ckeditor.js' );
|
|
|
+
|
|
|
+ return gulp.src( glob )
|
|
|
+ .pipe( watch ? utils.watch( glob ) : utils.noop() );
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* Returns a stream of all source files from CKEditor 5.
|
|
|
*
|
|
|
- * @param {Boolean} [watch] Whether the files should be watched.
|
|
|
+ * @param {Boolean} [watch] Whether to watch the files.
|
|
|
* @returns {Stream}
|
|
|
*/
|
|
|
ckeditor5( watch ) {
|
|
|
- return utils.src( config.ROOT_DIR, 'src/**/*.js', watch )
|
|
|
+ const glob = path.join( config.ROOT_DIR, 'src', '**', '*.js' );
|
|
|
+
|
|
|
+ return gulp.src( glob )
|
|
|
+ .pipe( watch ? utils.watch( glob ) : utils.noop() )
|
|
|
.pipe( utils.wrapCKEditor5Module() );
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* Returns a stream of all source files from CKEditor 5 dependencies.
|
|
|
*
|
|
|
- * @param {Boolean} [watch] Whether the files should be watched.
|
|
|
+ * @param {Boolean} [watch] Whether to watch the files.
|
|
|
* @returns {Stream}
|
|
|
*/
|
|
|
modules( watch ) {
|
|
|
- // For an odd reason file.dirname does not contain `node_modules/`. Maybe the base dir
|
|
|
- // is automatically set to only the varying piece of the path.
|
|
|
- const modulePathPattern = new RegExp( `(ckeditor5-[^${ sep }]+)${ sep }src` );
|
|
|
-
|
|
|
- return utils.src( config.ROOT_DIR, 'node_modules/ckeditor5-*/src/**/*.js', watch )
|
|
|
- .pipe( utils.unpackModules( modulePathPattern ) );
|
|
|
+ // Find all CKEditor5 package directories. Resolve symlinks so we watch real directories
|
|
|
+ // in order to workaround https://github.com/paulmillr/chokidar/issues/419.
|
|
|
+ const dirs = fs.readdirSync( path.join( config.ROOT_DIR, 'node_modules' ) )
|
|
|
+ // Look for ckeditor5-* directories.
|
|
|
+ .filter( ( fileName ) => fileName.indexOf( 'ckeditor5-' ) === 0 )
|
|
|
+ // Resolve symlinks and keep only directories.
|
|
|
+ .map( ( fileName ) => {
|
|
|
+ let filePath = path.join( config.ROOT_DIR, 'node_modules', fileName );
|
|
|
+ let stat = fs.lstatSync( filePath );
|
|
|
+
|
|
|
+ if ( stat.isSymbolicLink() ) {
|
|
|
+ filePath = fs.realpathSync( filePath );
|
|
|
+ stat = fs.lstatSync( filePath );
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( stat.isDirectory() ) {
|
|
|
+ return filePath;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Filter...
|
|
|
+ return false;
|
|
|
+ } )
|
|
|
+ // ...those out.
|
|
|
+ .filter( ( filePath ) => filePath );
|
|
|
+
|
|
|
+ const streams = dirs.map( ( dirPath ) => {
|
|
|
+ const glob = path.join( dirPath, 'src', '**', '*.js' );
|
|
|
+ // Use parent as a base so we get paths starting with 'ckeditor5-*/src/*' in the stream.
|
|
|
+ const baseDir = path.parse( dirPath ).dir;
|
|
|
+ const opts = { base: baseDir };
|
|
|
+
|
|
|
+ return gulp.src( glob, opts )
|
|
|
+ .pipe( watch ? utils.watch( glob, opts ) : utils.noop() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ return merge.apply( null, streams )
|
|
|
+ .pipe( utils.unpackModules() );
|
|
|
}
|
|
|
}
|
|
|
};
|