浏览代码

Merge branch 'master' into t/ckeditor5-utils/33

Piotrek Koszuliński 9 年之前
父节点
当前提交
9d0b83a32d

+ 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;
 };

+ 49 - 34
dev/tasks/dev/tasks.js

@@ -26,47 +26,62 @@ module.exports = ( config ) => {
 		( msg ) => gutil.log( gutil.colors.red( msg ) )
 	);
 
-	gulp.task( 'init', () => {
-		initTask( installTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
-	} );
+	const tasks = {
+		updateRepositories() {
+			const options = minimist( process.argv.slice( 2 ), {
+				boolean: [ 'npm-update' ],
+				default: {
+					'npm-update': false
+				}
+			} );
 
-	gulp.task( 'create-package', ( done ) => {
-		pluginCreateTask( ckeditor5Path, config.WORKSPACE_DIR )
-			.then( done )
-			.catch( ( error )  => done( error ) );
-	} );
+			return updateTask( installTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR, options[ 'npm-update' ] );
+		},
 
-	gulp.task( 'update', () => {
-		const options = minimist( process.argv.slice( 2 ), {
-			boolean: [ 'npm-update' ],
-			default: {
-				'npm-update': false
-			}
-		} );
+		checkStatus() {
+			return statusTask( ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
+		},
+
+		initRepository() {
+			return initTask( installTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
+		},
 
-		updateTask( installTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR, options[ 'npm-update' ] );
-	} );
+		createPackage( done ) {
+			return pluginCreateTask( ckeditor5Path, config.WORKSPACE_DIR )
+				.then( done )
+				.catch( ( error ) => done( error ) );
+		},
 
-	gulp.task( 'status', () => {
-		statusTask( ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
-	} );
+		relink() {
+			return relinkTask( ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
+		},
 
-	gulp.task( 'relink', () => {
-		relinkTask( ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
-	} );
+		installPackage() {
+			const options = minimist( process.argv.slice( 2 ), {
+				string: [ 'package' ],
+				default: {
+					plugin: ''
+				}
+			} );
 
-	gulp.task( 'install', () => {
-		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 );
 		}
-	} );
+	};
+
+	return tasks;
 };

+ 3 - 2
dev/tasks/dev/utils/inquiries.js

@@ -6,6 +6,7 @@
 'use strict';
 
 const inquirer = require( 'inquirer' );
+const sanitize = require( './sanitize' );
 const DEFAULT_PLUGIN_NAME_PREFIX = 'ckeditor5-';
 const DEFAULT_PLUGIN_VERSION = '0.0.1';
 const DEFAULT_GITHUB_URL_PREFIX = 'ckeditor/';
@@ -68,9 +69,9 @@ module.exports = {
 		return new Promise( ( resolve ) => {
 			inquirer.prompt( [ {
 				name: 'description',
-				message: 'Package description (one sentence):'
+				message: 'Package description (one sentence, must end with period):'
 			} ], ( answers ) => {
-				resolve( answers.description || '' );
+				resolve( sanitize.appendPeriodIfMissing( answers.description || '' ) );
 			} );
 		} );
 	}

+ 18 - 0
dev/tasks/dev/utils/sanitize.js

@@ -0,0 +1,18 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+module.exports = {
+	appendPeriodIfMissing( text ) {
+		text = text.trim();
+
+		if ( text.length > 0 && !text.endsWith( '.' ) ) {
+			text += '.';
+		}
+
+		return text;
+	}
+};

+ 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;
 };

+ 7 - 4
dev/tasks/lint/tasks.js

@@ -6,7 +6,6 @@ const gulp = require( 'gulp' );
 const jshint = require( 'gulp-jshint' );
 const jscs = require( 'gulp-jscs' );
 const fs = require( 'fs' );
-const guppy = require( 'git-guppy' )( gulp );
 const gulpFilter = require( 'gulp-filter' );
 const gutil = require( 'gulp-util' );
 
@@ -30,6 +29,8 @@ module.exports = ( config ) => {
 		 * @returns {Stream}
 		 */
 		lintStaged() {
+			const guppy = require( 'git-guppy' )( gulp );
+
 			return guppy.stream( 'pre-commit', { base: './' } )
 				.pipe( gulpFilter( src ) )
 				.pipe( lint() )
@@ -48,12 +49,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;
 
 	/**

+ 48 - 10
dev/tasks/test/tasks.js

@@ -16,19 +16,27 @@ const buildUtils = require( '../build/utils' );
 const benderConfig = require( '../../../bender' );
 
 /**
- * Defines Node.js testing task.
+ * Defines Node.js testing task and development tools testing tasks.
  *
- * To run tests under node:
+ * To run tests under Node.js:
  *
  *		gulp test:node
  *
- * To run build before testing:
+ * To run build under Node.js before testing:
  *
  *		gulp test:node:build
  *
- * To run testing with code coverage:
+ * To run testing under Node.js with code coverage:
  *
  *		gulp test:node:coverage
+ *
+ * To run development tools tests:
+ *
+ * 		gulp test:dev
+ *
+ * To run development tools tests with coverage:
+ *
+ * 		gulp test:dev:coverage
  */
 module.exports = () => {
 	const ignoreRegexp = /\/\* ?bender-tags:.*\bbrowser-only\b.*\*\//;
@@ -52,7 +60,7 @@ module.exports = () => {
 		 *
 		 * @returns {Stream}
 		 */
-		prepareCoverage() {
+		prepareNodeCoverage() {
 			const src = benderConfig.coverage.paths.map( ( item ) => {
 				return item.replace( 'build/amd/', 'build/cjs/' );
 			} );
@@ -115,13 +123,43 @@ module.exports = () => {
 		 */
 		skipIgnored() {
 			return filterBy( file => !file.contents.toString().match( ignoreRegexp ) );
+		},
+
+		/**
+		 * Runs dev unit tests.
+		 *
+		 * @returns {Stream}
+		 */
+		devTest() {
+			return gulp.src( 'dev/tests/**/*.js' )
+				.pipe( mocha() )
+				.pipe( tasks.coverage ? istanbul.writeReports() : buildUtils.noop() );
+		},
+
+		/**
+		 * Prepares files for coverage report.
+		 *
+		 * @returns {Stream}
+		 */
+		prepareDevCoverage() {
+			tasks.coverage = true;
+
+			return gulp.src( 'dev/tasks/**/*.js' )
+				.pipe( istanbul() )
+				.pipe( istanbul.hookRequire() );
+		},
+
+		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:node:pre-coverage', [ 'build:js:cjs' ], tasks.prepareCoverage );
-	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 );
-
 	return tasks;
 };

+ 44 - 0
dev/tests/dev/sanitize.js

@@ -0,0 +1,44 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global describe, it */
+
+'use strict';
+
+const sanitize = require( '../../tasks/dev/utils/sanitize' );
+const chai = require( 'chai' );
+const expect = chai.expect;
+
+describe( 'utils', () => {
+	describe( 'sanitize', () => {
+		describe( 'appendPeriodIfMissing', () => {
+			it( 'should be defined', () => expect( sanitize.appendPeriodIfMissing ).to.be.a( 'function' ) );
+
+			it( 'should trim whitespace/new lines to empty string', () => {
+				const sanitized = sanitize.appendPeriodIfMissing( '\n\t\r ' );
+
+				expect( sanitized ).to.equal( '' );
+			} );
+
+			it( 'should add period at the end if missing ', () => {
+				const sanitized = sanitize.appendPeriodIfMissing( 'sometext' );
+
+				expect( sanitized ).to.equal( 'sometext.' );
+			} );
+
+			it( 'should not add period at the end if present', () => {
+				const sanitized = sanitize.appendPeriodIfMissing( 'sometext.' );
+
+				expect( sanitized ).to.equal( 'sometext.' );
+			} );
+
+			it( 'should leave empty string as is', () => {
+				const sanitized = sanitize.appendPeriodIfMissing( '' );
+
+				expect( sanitized ).to.equal( '' );
+			} );
+		} );
+	} );
+} );

+ 19 - 0
dev/tests/dev/status.js

@@ -11,6 +11,9 @@ const sinon = require( 'sinon' );
 const tools = require( '../../tasks/dev/utils/tools' );
 const git = require( '../../tasks/dev/utils/git' );
 const path = require( 'path' );
+const chai = require( 'chai' );
+const expect = chai.expect;
+const gulp = require( 'gulp' );
 
 describe( 'dev-status', () => {
 	const statusTask = require( '../../tasks/dev/tasks/status' );
@@ -109,3 +112,19 @@ describe( 'dev-status', () => {
 		sinon.assert.calledWithExactly( writeErrorSpy, error );
 	} );
 } );
+
+describe( 'gulp task status', () => {
+	const tasks = gulp.tasks;
+
+	it( 'should be available', () => {
+		expect( tasks ).to.have.property( 'status' );
+		expect( tasks.status.fn ).to.be.a( 'function' );
+	} );
+
+	it( 'should have an alias', () => {
+		expect( tasks ).to.have.property( 'st' );
+		expect( tasks.st.fn ).to.be.a( 'function' );
+
+		expect( tasks.st.fn ).to.equal( tasks.status.fn );
+	} );
+} );

+ 19 - 0
dev/tests/dev/update.js

@@ -11,6 +11,9 @@ const sinon = require( 'sinon' );
 const tools = require( '../../tasks/dev/utils/tools' );
 const git = require( '../../tasks/dev/utils/git' );
 const path = require( 'path' );
+const chai = require( 'chai' );
+const expect = chai.expect;
+const gulp = require( 'gulp' );
 
 describe( 'dev-update', () => {
 	const updateTask = require( '../../tasks/dev/tasks/update' );
@@ -236,3 +239,19 @@ describe( 'dev-update', () => {
 		sinon.assert.notCalled( spies.removeSymlink );
 	} );
 } );
+
+describe( 'gulp task update', () => {
+	const tasks = gulp.tasks;
+
+	it( 'should be available', () => {
+		expect( tasks ).to.have.property( 'update' );
+		expect( tasks.update.fn ).to.be.a( 'function' );
+	} );
+
+	it( 'should have an alias', () => {
+		expect( tasks ).to.have.property( 'pull' );
+		expect( tasks.pull.fn ).to.be.a( 'function' );
+
+		expect( tasks.pull.fn ).to.equal( tasks.update.fn );
+	} );
+} );

+ 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' ] );

+ 1 - 7
package.json

@@ -13,7 +13,7 @@
     "ckeditor5-delete": "ckeditor/ckeditor5-delete",
     "ckeditor5-engine": "ckeditor/ckeditor5-engine",
     "ckeditor5-enter": "ckeditor/ckeditor5-enter",
-    "ckeditor5-formats": "ckeditor/ckeditor5-formats",
+    "ckeditor5-headings": "ckeditor/ckeditor5-headings",
     "ckeditor5-paragraph": "ckeditor/ckeditor5-paragraph",
     "ckeditor5-theme-lark": "ckeditor/ckeditor5-theme-lark",
     "ckeditor5-typing": "ckeditor/ckeditor5-typing",
@@ -58,13 +58,11 @@
     "gulp-watch": "4.3.5",
     "guppy-pre-commit": "^0.3.0",
     "inquirer": "^0.11.0",
-    "istanbul": "^0.4.1",
     "jsdoc": "^3.4.0",
     "jshint": "^2.9.1",
     "jshint-reporter-jscs": "^0.1.0",
     "merge-stream": "^1.0.0",
     "minimist": "^1.2.0",
-    "mocha": "^2.2.5",
     "mockery": "^1.4.0",
     "multipipe": "^0.3.0",
     "ncp": "^2.0.0",
@@ -87,9 +85,5 @@
   "repository": {
     "type": "git",
     "url": "https://github.com/ckeditor/ckeditor5.git"
-  },
-  "scripts": {
-    "test": "mocha dev/tests --recursive",
-    "coverage": "istanbul cover _mocha dev/tests/ -- --recursive"
   }
 }