8
0
Quellcode durchsuchen

Refactored utils modules, moved common function to tools module.

Maksymilian Barnaś vor 9 Jahren
Ursprung
Commit
0640a797c5

+ 4 - 3
dev/tasks/build/tasks.js

@@ -15,6 +15,7 @@ const gutil = require( 'gulp-util' );
 const filter = require( 'gulp-filter' );
 const filter = require( 'gulp-filter' );
 const utils = require( './utils' );
 const utils = require( './utils' );
 const runSequence = require( 'run-sequence' );
 const runSequence = require( 'run-sequence' );
+const tools = require( '../../utils/tools' );
 
 
 module.exports = ( config ) => {
 module.exports = ( config ) => {
 	const buildDir = path.join( config.ROOT_DIR, config.BUILD_DIR );
 	const buildDir = path.join( config.ROOT_DIR, config.BUILD_DIR );
@@ -33,7 +34,7 @@ module.exports = ( config ) => {
 			themes( options = {} ) {
 			themes( options = {} ) {
 				let formats = options.formats || args.formats;
 				let formats = options.formats || args.formats;
 
 
-				return utils.clean( buildDir, path.join( `@(${ formats.join( '|' ) })`, 'theme' ) );
+				return tools.clean( buildDir, path.join( `@(${ formats.join( '|' ) })`, 'theme' ) );
 			},
 			},
 
 
 			/**
 			/**
@@ -43,14 +44,14 @@ module.exports = ( config ) => {
 				// TODO: ES6 default function parameters
 				// TODO: ES6 default function parameters
 				options = options || utils.parseArguments();
 				options = options || utils.parseArguments();
 
 
-				return utils.clean( buildDir, path.join( `@(${ options.formats.join( '|' ) })`, '!(theme)' ) );
+				return tools.clean( buildDir, path.join( `@(${ options.formats.join( '|' ) })`, '!(theme)' ) );
 			},
 			},
 
 
 			/**
 			/**
 			 * Removes the "./build" directory.
 			 * Removes the "./build" directory.
 			 */
 			 */
 			all() {
 			all() {
-				return utils.clean( buildDir, path.join() );
+				return tools.clean( buildDir, path.join() );
 			}
 			}
 		},
 		},
 
 

+ 1 - 3
dev/tasks/build/utils.js

@@ -21,7 +21,6 @@ const minimist = require( 'minimist' );
 const sprite = require( 'gulp-svg-sprite' );
 const sprite = require( 'gulp-svg-sprite' );
 const pipe = require( 'multipipe' );
 const pipe = require( 'multipipe' );
 const filter = require( 'gulp-filter' );
 const filter = require( 'gulp-filter' );
-const mainUtils = require( '../utils' );
 
 
 const utils = {
 const utils = {
 	/**
 	/**
@@ -612,5 +611,4 @@ require( [ 'tests' ], bender.defer(), function( err ) {
 	}
 	}
 };
 };
 
 
-// Extend top level utils.
-module.exports = Object.assign( utils, mainUtils );
+module.exports = utils;

+ 4 - 3
dev/tasks/bundle/tasks.js

@@ -16,6 +16,7 @@ const utils = require( './utils' );
 const rollup = require( 'rollup' ).rollup;
 const rollup = require( 'rollup' ).rollup;
 const rollupBabel = require( 'rollup-plugin-babel' );
 const rollupBabel = require( 'rollup-plugin-babel' );
 const mkdirp = require( 'mkdirp' );
 const mkdirp = require( 'mkdirp' );
+const tools = require( '../../utils/tools' );
 
 
 module.exports = ( config ) => {
 module.exports = ( config ) => {
 	const args = utils.parseArguments();
 	const args = utils.parseArguments();
@@ -29,7 +30,7 @@ module.exports = ( config ) => {
 		 * Removes all files from bundle directory.
 		 * Removes all files from bundle directory.
 		 */
 		 */
 		clean() {
 		clean() {
-			return utils.clean( bundleDir, '*.*' );
+			return tools.clean( bundleDir, '*.*' );
 		},
 		},
 
 
 		/**
 		/**
@@ -107,14 +108,14 @@ module.exports = ( config ) => {
 				} )
 				} )
 				.then( () => {
 				.then( () => {
 					// If everything went well then remove tmp directory.
 					// If everything went well then remove tmp directory.
-					utils.clean( bundleTmpDir, path.join( '' ) );
+					tools.clean( bundleTmpDir, path.join( '' ) );
 				} )
 				} )
 				.catch( ( err ) => {
 				.catch( ( err ) => {
 					// If something went wrong then log error.
 					// If something went wrong then log error.
 					gutil.log( gutil.colors.red( err.stack ) );
 					gutil.log( gutil.colors.red( err.stack ) );
 
 
 					// And remove tmp directory.
 					// And remove tmp directory.
-					utils.clean( bundleTmpDir, path.join( '' ) );
+					tools.clean( bundleTmpDir, path.join( '' ) );
 
 
 					throw new Error( 'Build error.' );
 					throw new Error( 'Build error.' );
 				} );
 				} );

+ 1 - 3
dev/tasks/bundle/utils.js

@@ -12,7 +12,6 @@ const gulpRename = require( 'gulp-rename' );
 const gutil = require( 'gulp-util' );
 const gutil = require( 'gulp-util' );
 const prettyBytes = require( 'pretty-bytes' );
 const prettyBytes = require( 'pretty-bytes' );
 const gzipSize = require( 'gzip-size' );
 const gzipSize = require( 'gzip-size' );
-const mainUtils = require( '../utils' );
 const minimist = require( 'minimist' );
 const minimist = require( 'minimist' );
 
 
 const utils = {
 const utils = {
@@ -236,5 +235,4 @@ export default class ${ data.moduleName } extends ${ creatorName } {
 	}
 	}
 };
 };
 
 
-// Extend top level utils.
-module.exports = Object.assign( utils, mainUtils );
+module.exports = utils;

+ 0 - 30
dev/tasks/utils.js

@@ -1,30 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-'use strict';
-
-const path = require( 'path' );
-const del = require( 'del' );
-const gutil = require( 'gulp-util' );
-
-const utils = {
-	/**
-	 * Removes files and directories specified by `glob` starting from `rootDir`
-	 * and gently informs about deletion.
-	 *
-	 * @param {String} rootDir The path to the root directory (i.e. "dist/").
-	 * @param {String} glob Glob specifying what to clean.
-	 * @returns {Promise}
-	 */
-	clean( rootDir, glob ) {
-		return del( path.join( rootDir, glob ) ).then( paths => {
-			paths.forEach( p => {
-				gutil.log( `Deleted file '${ gutil.colors.cyan( p ) }'.` );
-			} );
-		} );
-	}
-};
-
-module.exports = utils;

+ 0 - 5
dev/tests/build/utils.js

@@ -16,7 +16,6 @@ const path = require( 'path' );
 const stream = require( 'stream' );
 const stream = require( 'stream' );
 const Vinyl = require( 'vinyl' );
 const Vinyl = require( 'vinyl' );
 const through = require( 'through2' );
 const through = require( 'through2' );
-const mainUtils = require( '../../tasks/utils' );
 
 
 describe( 'build-utils', () => {
 describe( 'build-utils', () => {
 	const utils = require( '../../tasks/build/utils' );
 	const utils = require( '../../tasks/build/utils' );
@@ -30,10 +29,6 @@ describe( 'build-utils', () => {
 		sandbox.restore();
 		sandbox.restore();
 	} );
 	} );
 
 
-	it( 'should be extended by top level utils', () => {
-		expect( utils.clean ).to.be.equal( mainUtils.clean );
-	} );
-
 	describe( 'noop', () => {
 	describe( 'noop', () => {
 		it( 'should return PassTrough stream', () => {
 		it( 'should return PassTrough stream', () => {
 			const PassThrough = stream.PassThrough;
 			const PassThrough = stream.PassThrough;

+ 0 - 5
dev/tests/bundle/utils.js

@@ -12,7 +12,6 @@ const expect = chai.expect;
 const sinon = require( 'sinon' );
 const sinon = require( 'sinon' );
 const path = require( 'path' );
 const path = require( 'path' );
 const fs = require( 'fs' );
 const fs = require( 'fs' );
-const mainUtils = require( '../../tasks/utils' );
 const gzipSize = require( 'gzip-size' );
 const gzipSize = require( 'gzip-size' );
 
 
 describe( 'bundle-utils', () => {
 describe( 'bundle-utils', () => {
@@ -27,10 +26,6 @@ describe( 'bundle-utils', () => {
 		sandbox.restore();
 		sandbox.restore();
 	} );
 	} );
 
 
-	it( 'should be extended by top level utils', () => {
-		expect( utils.clean ).to.equal( mainUtils.clean );
-	} );
-
 	describe( 'getModuleFullPath', () => {
 	describe( 'getModuleFullPath', () => {
 		it( 'should return full path when passed path not relative', () => {
 		it( 'should return full path when passed path not relative', () => {
 			expect( utils.getModuleFullPath( 'editor-classic/classic' ) ).to.equal( './build/esnext/ckeditor5/editor-classic/classic.js' );
 			expect( utils.getModuleFullPath( 'editor-classic/classic' ) ).to.equal( './build/esnext/ckeditor5/editor-classic/classic.js' );

+ 18 - 0
dev/utils/tools.js

@@ -6,6 +6,8 @@
 'use strict';
 'use strict';
 
 
 const gutil = require( 'gulp-util' );
 const gutil = require( 'gulp-util' );
+const path = require( 'path' );
+const del = require( 'del' );
 
 
 module.exports = {
 module.exports = {
 	/**
 	/**
@@ -268,5 +270,21 @@ module.exports = {
 	removeSymlink( path ) {
 	removeSymlink( path ) {
 		const fs = require( 'fs' );
 		const fs = require( 'fs' );
 		fs.unlinkSync( path );
 		fs.unlinkSync( path );
+	},
+
+	/**
+	 * Removes files and directories specified by `glob` starting from `rootDir`
+	 * and gently informs about deletion.
+	 *
+	 * @param {String} rootDir The path to the root directory (i.e. "dist/").
+	 * @param {String} glob Glob specifying what to clean.
+	 * @returns {Promise}
+	 */
+	clean( rootDir, glob ) {
+		return del( path.join( rootDir, glob ) ).then( paths => {
+			paths.forEach( p => {
+				gutil.log( `Deleted file '${ gutil.colors.cyan( p ) }'.` );
+			} );
+		} );
 	}
 	}
 };
 };