Skip to content

Commit

Permalink
Create Block: Make it possible to provide most popular options as CLI…
Browse files Browse the repository at this point in the history
… options
  • Loading branch information
gziolo committed Apr 21, 2020
1 parent 39423a5 commit 6dafe2c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/create-block/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,36 @@ program
'template type name, allowed values: "es5", "esnext"',
'esnext'
)
.action( async ( slug, { template } ) => {
.option(
'--namespace <namespace>',
'internal namespace for the block name'
)
.option( '--title <title>', 'display title for the block' )
.option( '--category <category>', 'category name for the block' )
.action( async ( slug, commandObject ) => {
const { template } = commandObject;
const optionsProvided = [ 'namespace', 'title', 'category' ]
.filter( ( optionName ) => commandObject[ optionName ] )
.reduce( ( accumulator, optionName ) => {
accumulator[ optionName ] = commandObject[ optionName ];
return accumulator;
}, {} );

console.log( optionsProvided );
await checkSystemRequirements( engines );
try {
const defaultValues = getDefaultValues( template );
if ( slug ) {
const answers = {
...defaultValues,
slug,
// Transforms slug to title.
// Transforms slug to title as a fallback.
title: startCase( slug ),
};
await scaffold( template, answers );
} else {
const answers = await inquirer.prompt( getPrompts( template ) );
const propmpts = getPrompts( template );
const answers = await inquirer.prompt( propmpts );
await scaffold( template, {
...defaultValues,
...answers,
Expand Down

0 comments on commit 6dafe2c

Please sign in to comment.