From 260345bb4c1dfaa68022467a77adc04d699998ed Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Thu, 23 Jan 2020 15:50:33 +0100 Subject: [PATCH] Promote action handler to async to make implementation simpler --- packages/create-block/lib/index.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/create-block/lib/index.js b/packages/create-block/lib/index.js index 88e1973c8c012a..51c8d56755f3ef 100644 --- a/packages/create-block/lib/index.js +++ b/packages/create-block/lib/index.js @@ -32,7 +32,7 @@ program .version( version ) .arguments( '[slug]' ) .option( '-t, --template ', 'template type name, allowed values: "es5", "esnext"', 'esnext' ) - .action( ( slug, { template } ) => { + .action( async ( slug, { template } ) => { try { const defaultAnswers = getDefaultAnswers( template ); if ( slug ) { @@ -44,19 +44,13 @@ program slug, title, }; - Promise.resolve() - .then( async () => { - await scaffold( template, answers ); - } ); + await scaffold( template, answers ); } else { - inquirer - .prompt( getPrompts( template ) ) - .then( async ( answers ) => { - await scaffold( template, { - ...defaultAnswers, - ...answers, - } ); - } ); + const answers = await inquirer.prompt( getPrompts( template ) ); + await scaffold( template, { + ...defaultAnswers, + ...answers, + } ); } } catch ( e ) { if ( e instanceof CLIError ) {