Browse Source

Simplified error handling in promise chains.

Szymon Kupś 10 năm trước cách đây
mục cha
commit
6b58b6176d

+ 2 - 2
dev/tasks/dev.js

@@ -24,7 +24,7 @@ module.exports = ( grunt ) => {
 	grunt.registerTask( 'dev-plugin-create', function() {
 	grunt.registerTask( 'dev-plugin-create', function() {
 		const done = this.async();
 		const done = this.async();
 		const options = getOptions( this );
 		const options = getOptions( this );
-		pluginCreateTask( ckeditor5Path, options, grunt.log.writeln, grunt.log.error )
+		pluginCreateTask( ckeditor5Path, options, grunt.log.writeln )
 			.then( done )
 			.then( done )
 			.catch( ( error )  => done( error ) );
 			.catch( ( error )  => done( error ) );
 	} );
 	} );
@@ -32,7 +32,7 @@ module.exports = ( grunt ) => {
 	grunt.registerTask( 'dev-plugin-install', function() {
 	grunt.registerTask( 'dev-plugin-install', function() {
 		const done = this.async();
 		const done = this.async();
 		const options = getOptions( this );
 		const options = getOptions( this );
-		pluginInstallTask( ckeditor5Path, options, grunt.log.writeln, grunt.log.error )
+		pluginInstallTask( ckeditor5Path, options, grunt.log.writeln )
 			.then( done )
 			.then( done )
 			.catch( ( error )  => done( error ) );
 			.catch( ( error )  => done( error ) );
 	} );
 	} );

+ 40 - 48
dev/tasks/utils/dev-plugin-create.js

@@ -26,65 +26,57 @@ const path = require( 'path' );
  * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  * @param {Object} options grunt options.
  * @param {Object} options grunt options.
  * @param {Function} writeln Function for log output.
  * @param {Function} writeln Function for log output.
- * @param {Function} writeError Function of error output
  * @returns {Promise} Returns promise fulfilled after task is done.
  * @returns {Promise} Returns promise fulfilled after task is done.
  */
  */
-module.exports = ( ckeditor5Path, options, writeln, writeError ) => {
-	return new Promise( ( resolve, reject ) => {
-		const workspaceAbsolutePath = path.join( ckeditor5Path, options.workspaceRoot );
-		let pluginName;
-		let repositoryPath;
-		let pluginVersion;
-		let gitHubUrl;
+module.exports = ( ckeditor5Path, options, writeln ) => {
+	const workspaceAbsolutePath = path.join( ckeditor5Path, options.workspaceRoot );
+	let pluginName;
+	let repositoryPath;
+	let pluginVersion;
+	let gitHubUrl;
 
 
-		inquiries.getPluginName()
-			.then( result => {
-				pluginName = result;
-				repositoryPath = path.join( workspaceAbsolutePath, pluginName );
+	return inquiries.getPluginName()
+		.then( result => {
+			pluginName = result;
+			repositoryPath = path.join( workspaceAbsolutePath, pluginName );
 
 
-				return inquiries.getPluginVersion();
-			} )
-			.then( result => {
-				pluginVersion = result;
+			return inquiries.getPluginVersion();
+		} )
+		.then( result => {
+			pluginVersion = result;
 
 
-				return inquiries.getPluginGitHubUrl( pluginName );
-			} )
-			.then( result => {
-				try {
-					gitHubUrl = result;
+			return inquiries.getPluginGitHubUrl( pluginName );
+		} )
+		.then( result => {
+			gitHubUrl = result;
 
 
-					writeln( `Initializing repository ${ repositoryPath }...` );
-					git.initializeRepository( repositoryPath );
+			writeln( `Initializing repository ${ repositoryPath }...` );
+			git.initializeRepository( repositoryPath );
 
 
-					writeln( `Updating package.json files...` );
-					tools.updateJSONFile( path.join( repositoryPath, 'package.json' ), ( json ) => {
-						json.name = pluginName;
-						json.version = pluginVersion;
+			writeln( `Updating package.json files...` );
+			tools.updateJSONFile( path.join( repositoryPath, 'package.json' ), ( json ) => {
+				json.name = pluginName;
+				json.version = pluginVersion;
 
 
-						return json;
-					} );
+				return json;
+			} );
 
 
-					tools.updateJSONFile( path.join( ckeditor5Path, 'package.json' ), ( json ) => {
-						if ( !json.dependencies ) {
-							json.dependencies = {};
-						}
-						json.dependencies[ pluginName ] = gitHubUrl;
+			tools.updateJSONFile( path.join( ckeditor5Path, 'package.json' ), ( json ) => {
+				if ( !json.dependencies ) {
+					json.dependencies = {};
+				}
+				json.dependencies[ pluginName ] = gitHubUrl;
 
 
-						return json;
-					} );
+				return json;
+			} );
 
 
-					writeln( `Linking ${ pluginName } to node_modules...` );
-					tools.linkDirectories( repositoryPath, path.join( ckeditor5Path, 'node_modules', pluginName ) );
+			writeln( `Linking ${ pluginName } to node_modules...` );
+			tools.linkDirectories( repositoryPath, path.join( ckeditor5Path, 'node_modules', pluginName ) );
 
 
-					writeln( `Running npm install in ${ pluginName }.` );
-					tools.npmInstall( repositoryPath );
+			writeln( `Running npm install in ${ pluginName }.` );
+			tools.npmInstall( repositoryPath );
 
 
-					writeln( `Installing GIT hooks in ${ pluginName }.` );
-					tools.installGitHooks( repositoryPath );
-				} catch ( error ) {
-					writeError( error );
-				}
-			} )
-			.catch( reject );
-	} );
+			writeln( `Installing GIT hooks in ${ pluginName }.` );
+			tools.installGitHooks( repositoryPath );
+		} );
 };
 };

+ 33 - 41
dev/tasks/utils/dev-plugin-install.js

@@ -23,56 +23,48 @@ const path = require( 'path' );
  * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  * @param {Object} options grunt options.
  * @param {Object} options grunt options.
  * @param {Function} writeln Function for log output.
  * @param {Function} writeln Function for log output.
- * @param {Function} writeError Function of error output
  * @returns {Promise} Returns promise fulfilled after task is done.
  * @returns {Promise} Returns promise fulfilled after task is done.
  */
  */
-module.exports = ( ckeditor5Path, options, writeln, writeError ) => {
-	return new Promise( ( resolve, reject ) => {
-		const workspaceAbsolutePath = path.join( ckeditor5Path, options.workspaceRoot );
-		let pluginName;
-		let repositoryPath;
-		let gitHubUrl;
+module.exports = ( ckeditor5Path, options, writeln ) => {
+	const workspaceAbsolutePath = path.join( ckeditor5Path, options.workspaceRoot );
+	let pluginName;
+	let repositoryPath;
+	let gitHubUrl;
 
 
-		inquiries.getPluginName()
-			.then( result => {
-				pluginName = result;
-				repositoryPath = path.join( workspaceAbsolutePath, pluginName );
+	return inquiries.getPluginName()
+		.then( result => {
+			pluginName = result;
+			repositoryPath = path.join( workspaceAbsolutePath, pluginName );
 
 
-				return inquiries.getPluginGitHubUrl( pluginName );
-			} )
-			.then( result => {
-				gitHubUrl = result;
-				let urlInfo = git.parseRepositoryUrl( gitHubUrl );
+			return inquiries.getPluginGitHubUrl( pluginName );
+		} )
+		.then( result => {
+			gitHubUrl = result;
+			let urlInfo = git.parseRepositoryUrl( gitHubUrl );
 
 
-				try {
-					writeln( `Clonning ${ gitHubUrl }...` );
-					git.cloneRepository( urlInfo, workspaceAbsolutePath );
+			writeln( `Clonning ${ gitHubUrl }...` );
+			git.cloneRepository( urlInfo, workspaceAbsolutePath );
 
 
-					writeln( `Checking out ${ gitHubUrl } to ${ urlInfo.branch }...` );
-					git.checkout( repositoryPath, urlInfo.branch );
+			writeln( `Checking out ${ gitHubUrl } to ${ urlInfo.branch }...` );
+			git.checkout( repositoryPath, urlInfo.branch );
 
 
-					writeln( `Updating package.json files...` );
-					tools.updateJSONFile( path.join( ckeditor5Path, 'package.json' ), ( json ) => {
-						if ( !json.dependencies ) {
-							json.dependencies = {};
-						}
-						json.dependencies[ pluginName ] = gitHubUrl;
+			writeln( `Updating package.json files...` );
+			tools.updateJSONFile( path.join( ckeditor5Path, 'package.json' ), ( json ) => {
+				if ( !json.dependencies ) {
+					json.dependencies = {};
+				}
+				json.dependencies[ pluginName ] = gitHubUrl;
 
 
-						return json;
-					} );
+				return json;
+			} );
 
 
-					writeln( `Linking ${ pluginName } to node_modules...` );
-					tools.linkDirectories( repositoryPath, path.join( ckeditor5Path, 'node_modules', pluginName ) );
+			writeln( `Linking ${ pluginName } to node_modules...` );
+			tools.linkDirectories( repositoryPath, path.join( ckeditor5Path, 'node_modules', pluginName ) );
 
 
-					writeln( `Running npm install in ${ pluginName }.` );
-					tools.npmInstall( repositoryPath );
+			writeln( `Running npm install in ${ pluginName }.` );
+			tools.npmInstall( repositoryPath );
 
 
-					writeln( `Installing GIT hooks in ${ pluginName }.` );
-					tools.installGitHooks( repositoryPath );
-				} catch ( error ) {
-					writeError( error );
-				}
-			} )
-			.catch( reject );
-	} );
+			writeln( `Installing GIT hooks in ${ pluginName }.` );
+			tools.installGitHooks( repositoryPath );
+		} );
 };
 };