Skip to content

Commit

Permalink
Create Block: Add confirm prompt before showing the plugin options (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo authored Mar 3, 2022
1 parent 7265b2b commit 90a5f28
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
48 changes: 42 additions & 6 deletions packages/create-block/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,55 @@ program
};
await scaffold( pluginTemplate, answers );
} else {
const prompts = getPrompts( pluginTemplate ).filter(
( { name } ) =>
! Object.keys( optionsValues ).includes( name )
);
log.info( '' );
log.info(
"Let's customize your WordPress plugin with blocks:"
);
const answers = await inquirer.prompt( prompts );

const filterOptionsProvided = ( { name } ) =>
! Object.keys( optionsValues ).includes( name );
const blockPrompts = getPrompts( pluginTemplate, [
'slug',
'namespace',
'title',
'description',
'dashicon',
'category',
] ).filter( filterOptionsProvided );
const blockAnswers = await inquirer.prompt( blockPrompts );

const pluginAnswers = await inquirer
.prompt( {
type: 'confirm',
name: 'configurePlugin',
message:
'Do you want to customize the WordPress plugin?',
default: false,
} )
.then( async ( { configurePlugin } ) => {
if ( ! configurePlugin ) {
return {};
}

const pluginPrompts = getPrompts( pluginTemplate, [
'pluginURI',
'version',
'author',
'license',
'licenseURI',
'domainPath',
'updateURI',
] ).filter( filterOptionsProvided );
const result = await inquirer.prompt(
pluginPrompts
);
return result;
} );
await scaffold( pluginTemplate, {
...defaultValues,
...optionsValues,
...answers,
...blockAnswers,
...pluginAnswers,
} );
}
} catch ( error ) {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-block/lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ const getDefaultValues = ( pluginTemplate ) => {
};
};

const getPrompts = ( pluginTemplate ) => {
const getPrompts = ( pluginTemplate, keys ) => {
const defaultValues = getDefaultValues( pluginTemplate );
return Object.keys( prompts ).map( ( promptName ) => {
return keys.map( ( promptName ) => {
return {
...prompts[ promptName ],
default: defaultValues[ promptName ],
Expand Down

0 comments on commit 90a5f28

Please sign in to comment.