8
0
Просмотр исходного кода

Gulp refactoring: All tasks registraion has moved to dedicated method.

More: https://github.com/ckeditor/ckeditor5/issues/167#issuecomment-225629139
Kamil Piechaczek 9 лет назад
Родитель
Сommit
94b590cd8c
6 измененных файлов с 130 добавлено и 109 удалено
  1. 22 20
      dev/tasks/build/tasks.js
  2. 55 48
      dev/tasks/dev/tasks.js
  3. 32 24
      dev/tasks/docs/tasks.js
  4. 5 3
      dev/tasks/lint/tasks.js
  5. 11 9
      dev/tasks/test/tasks.js
  6. 5 5
      gulpfile.js

+ 22 - 20
dev/tasks/build/tasks.js

@@ -313,32 +313,34 @@ module.exports = ( config ) => {
 					.pipe( filter( '*.js' ) )
 					.pipe( mirror( formatStreams ) );
 			}
-		}
-	};
+		},
 
-	gulp.task( 'build', callback => {
-		runSequence( 'build:clean:all', 'build:themes', 'build:js', callback );
-	} );
+		register() {
+			gulp.task( 'build', callback => {
+				runSequence( 'build:clean:all', 'build:themes', 'build:js', callback );
+			} );
 
-	gulp.task( 'build:clean:all', tasks.clean.all );
-	gulp.task( 'build:clean:themes', tasks.clean.themes );
-	gulp.task( 'build:clean:js', () => tasks.clean.js( args ) );
+			gulp.task( 'build:clean:all', tasks.clean.all );
+			gulp.task( 'build:clean:themes', tasks.clean.themes );
+			gulp.task( 'build:clean:js', () => tasks.clean.js( args ) );
 
-	gulp.task( 'build:themes', ( callback ) => {
-		runSequence( 'build:clean:themes', 'build:icons', 'build:sass', callback );
-	} );
+			gulp.task( 'build:themes', ( callback ) => {
+				runSequence( 'build:clean:themes', 'build:icons', 'build:sass', callback );
+			} );
 
-	gulp.task( 'build:sass', () => tasks.build.sass( args ) );
-	gulp.task( 'build:icons', () => tasks.build.icons( args ) );
-	gulp.task( 'build:js', [ 'build:clean:js' ], () => tasks.build.js( args ) );
+			gulp.task( 'build:sass', () => tasks.build.sass( args ) );
+			gulp.task( 'build:icons', () => tasks.build.icons( args ) );
+			gulp.task( 'build:js', [ 'build:clean:js' ], () => tasks.build.js( args ) );
 
-	// Tasks specific for `gulp docs` builder.
-	gulp.task( 'build:clean:js:esnext', () => tasks.clean.js( { formats: [ 'esnext' ] } ) );
-	gulp.task( 'build:js:esnext', [ 'build:clean:js:esnext' ], () => tasks.build.js( { formats: [ 'esnext' ] } ) );
+			// Tasks specific for `gulp docs` builder.
+			gulp.task( 'build:clean:js:esnext', () => tasks.clean.js( { formats: [ 'esnext' ] } ) );
+			gulp.task( 'build:js:esnext', [ 'build:clean:js:esnext' ], () => tasks.build.js( { formats: [ 'esnext' ] } ) );
 
-	// Tasks specific for testing under node.
-	gulp.task( 'build:clean:js:cjs', () => tasks.clean.js( { formats: [ 'cjs' ] } ) );
-	gulp.task( 'build:js:cjs', [ 'build:clean:js:cjs' ], () => tasks.build.js( { formats: [ 'cjs' ] } ) );
+			// Tasks specific for testing under node.
+			gulp.task( 'build:clean:js:cjs', () => tasks.clean.js( { formats: [ 'cjs' ] } ) );
+			gulp.task( 'build:js:cjs', [ 'build:clean:js:cjs' ], () => tasks.build.js( { formats: [ 'cjs' ] } ) );
+		}
+	};
 
 	return tasks;
 };

+ 55 - 48
dev/tasks/dev/tasks.js

@@ -26,55 +26,62 @@ module.exports = ( config ) => {
 		( msg ) => gutil.log( gutil.colors.red( msg ) )
 	);
 
-	gulp.task( 'init', () => {
-		initTask( installTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
-	} );
-
-	gulp.task( 'create-package', ( done ) => {
-		pluginCreateTask( ckeditor5Path, config.WORKSPACE_DIR )
-			.then( done )
-			.catch( ( error )  => done( error ) );
-	} );
-
-	gulp.task( 'update', updateTaskHandler );
-
-	gulp.task( 'pull', updateTaskHandler );
-
-	gulp.task( 'status', statusTaskHandler );
-
-	gulp.task( 'st', statusTaskHandler );
-
-	gulp.task( 'relink', () => {
-		relinkTask( ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
-	} );
-
-	gulp.task( 'install', () => {
-		const options = minimist( process.argv.slice( 2 ), {
-			string: [ 'package' ],
-			default: {
-				plugin: ''
+	const tasks = {
+		updateRepositories() {
+			const options = minimist( process.argv.slice( 2 ), {
+				boolean: [ 'npm-update' ],
+				default: {
+					'npm-update': false
+				}
+			} );
+
+			return updateTask( installTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR, options[ 'npm-update' ] );
+		},
+
+		checkStatus() {
+			return statusTask( ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
+		},
+
+		initRepository() {
+			return initTask( installTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
+		},
+
+		createPackage( done ) {
+			return pluginCreateTask( ckeditor5Path, config.WORKSPACE_DIR )
+				.then( done )
+				.catch( ( error ) => done( error ) );
+		},
+
+		relink() {
+			return relinkTask( ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
+		},
+
+		installPackage() {
+			const options = minimist( process.argv.slice( 2 ), {
+				string: [ 'package' ],
+				default: {
+					plugin: ''
+				}
+			} );
+
+			if ( options.package ) {
+				return installTask( ckeditor5Path, config.WORKSPACE_DIR, options.package );
+			} else {
+				throw new Error( 'Please provide a package to install: gulp dev-install --plugin <path|GitHub URL|name>' );
 			}
-		} );
-
-		if ( options.package ) {
-			installTask( ckeditor5Path, config.WORKSPACE_DIR, options.package );
-		} else {
-			throw new Error( 'Please provide a package to install: gulp dev-install --plugin <path|GitHub URL|name>' );
+		},
+
+		register() {
+			gulp.task( 'init', tasks.initRepository );
+			gulp.task( 'create-package', tasks.createPackage );
+			gulp.task( 'update', tasks.updateRepositories );
+			gulp.task( 'pull', tasks.updateRepositories );
+			gulp.task( 'status', tasks.checkStatus );
+			gulp.task( 'st', tasks.checkStatus );
+			gulp.task( 'relink', tasks.relink );
+			gulp.task( 'install', tasks.installPackage );
 		}
-	} );
-
-	function updateTaskHandler() {
-		const options = minimist( process.argv.slice( 2 ), {
-			boolean: [ 'npm-update' ],
-			default: {
-				'npm-update': false
-			}
-		} );
-
-		return updateTask( installTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR, options[ 'npm-update' ] );
-	}
+	};
 
-	function statusTaskHandler() {
-		return statusTask( ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
-	}
+	return tasks;
 };

+ 32 - 24
dev/tasks/docs/tasks.js

@@ -10,30 +10,38 @@ const jsdoc = require( 'gulp-jsdoc3' );
 const path = require( 'path' );
 
 module.exports = ( config ) => {
-	gulp.task( 'docs', [ 'build:js:esnext' ], function( cb ) {
-		const esnextBuildPath = path.join( config.ROOT_DIR, config.BUILD_DIR, 'esnext' );
-		const jsDocConfig = {
-			opts: {
-				encoding: 'utf8',
-				destination: path.join( config.BUILD_DIR, 'docs' ),
-				recurse: true,
-				access: 'all'
-			},
-			plugins: [
-				'node_modules/jsdoc/plugins/markdown',
-				'dev/tasks/docs/plugins/comment-fixer'
-			]
-		};
+	const tasks = {
+		buildDocs( cb ) {
+			const esnextBuildPath = path.join( config.ROOT_DIR, config.BUILD_DIR, 'esnext' );
+			const jsDocConfig = {
+				opts: {
+					encoding: 'utf8',
+					destination: path.join( config.BUILD_DIR, 'docs' ),
+					recurse: true,
+					access: 'all'
+				},
+				plugins: [
+					'node_modules/jsdoc/plugins/markdown',
+					'dev/tasks/docs/plugins/comment-fixer'
+				]
+			};
 
-		const patterns = [
-			'README.md',
-			// Add all js and jsdoc files, including tests (which can contain utils).
-			path.join( esnextBuildPath, '**', '*.@(js|jsdoc)' ),
-			// Filter out libs.
-			'!' + path.join( esnextBuildPath, 'ckeditor5', '*', 'lib', '**', '*' )
-		];
+			const patterns = [
+				'README.md',
+				// Add all js and jsdoc files, including tests (which can contain utils).
+				path.join( esnextBuildPath, '**', '*.@(js|jsdoc)' ),
+				// Filter out libs.
+				'!' + path.join( esnextBuildPath, 'ckeditor5', '*', 'lib', '**', '*' )
+			];
 
-		gulp.src( patterns, { read: false } )
-			.pipe( jsdoc( jsDocConfig, cb ) );
-	} );
+			return gulp.src( patterns, { read: false } )
+				.pipe( jsdoc( jsDocConfig, cb ) );
+		},
+
+		register() {
+			gulp.task( 'docs', [ 'build:js:esnext' ], tasks.buildDocs );
+		}
+	};
+
+	return tasks;
 };

+ 5 - 3
dev/tasks/lint/tasks.js

@@ -48,12 +48,14 @@ module.exports = ( config ) => {
 				gutil.log( gutil.colors.red( 'Linting failed, commit aborted' ) );
 				process.exit( 1 );
 			}
+		},
+
+		register() {
+			gulp.task( 'lint', tasks.lint );
+			gulp.task( 'lint-staged', tasks.lintStaged );
 		}
 	};
 
-	gulp.task( 'lint', tasks.lint );
-	gulp.task( 'lint-staged', tasks.lintStaged );
-
 	return tasks;
 
 	/**

+ 11 - 9
dev/tasks/test/tasks.js

@@ -139,17 +139,19 @@ module.exports = () => {
 			return gulp.src( 'dev/tasks/**/*.js' )
 				.pipe( istanbul() )
 				.pipe( istanbul.hookRequire() );
-		}
-	};
+		},
 
-	gulp.task( 'test:node:pre-coverage', [ 'build:js:cjs' ], tasks.prepareNodeCoverage );
-	gulp.task( 'test:node', tasks.testInNode );
-	gulp.task( 'test:node:build', [ 'build:js:cjs' ] , tasks.testInNode );
-	gulp.task( 'test:node:coverage', [ 'build:js:cjs', 'test:node:pre-coverage' ], tasks.testInNode );
+		register() {
+			gulp.task( 'test:node:pre-coverage', [ 'build:js:cjs' ], tasks.prepareNodeCoverage );
+			gulp.task( 'test:node', tasks.testInNode );
+			gulp.task( 'test:node:build', [ 'build:js:cjs' ] , tasks.testInNode );
+			gulp.task( 'test:node:coverage', [ 'build:js:cjs', 'test:node:pre-coverage' ], tasks.testInNode );
 
-	gulp.task( 'test:dev:pre-coverage', tasks.prepareDevCoverage );
-	gulp.task( 'test:dev', tasks.devTest );
-	gulp.task( 'test:dev:coverage', [ 'test:dev:pre-coverage' ], tasks.devTest );
+			gulp.task( 'test:dev:pre-coverage', tasks.prepareDevCoverage );
+			gulp.task( 'test:dev', tasks.devTest );
+			gulp.task( 'test:dev:coverage', [ 'test:dev:pre-coverage' ], tasks.devTest );
+		}
+	};
 
 	return tasks;
 };

+ 5 - 5
gulpfile.js

@@ -15,11 +15,11 @@ const config = {
 	]
 };
 
-require( './dev/tasks/build/tasks' )( config );
-require( './dev/tasks/dev/tasks' )( config );
-require( './dev/tasks/lint/tasks' )( config );
-require( './dev/tasks/test/tasks' )( config );
-require( './dev/tasks/docs/tasks' )( config );
+require( './dev/tasks/build/tasks' )( config ).register();
+require( './dev/tasks/dev/tasks' )( config ).register();
+require( './dev/tasks/lint/tasks' )( config ).register();
+require( './dev/tasks/test/tasks' )( config ).register();
+require( './dev/tasks/docs/tasks' )( config ).register();
 
 gulp.task( 'default', [ 'build' ] );
 gulp.task( 'pre-commit', [ 'lint-staged' ] );