Skip to content

Commit

Permalink
Code style: Run Prettier formatting on the package files
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Jan 30, 2020
1 parent e368568 commit 508516e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 38 deletions.
22 changes: 11 additions & 11 deletions packages/create-block/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ const CLIError = require( './cli-error' );
const log = require( './log' );
const { version } = require( '../package.json' );
const scaffold = require( './scaffold' );
const {
getDefaultValues,
getPrompts,
} = require( './templates' );
const { getDefaultValues, getPrompts } = require( './templates' );

const commandName = `wp-create-block`;
program
.name( commandName )
.description(
'Generates PHP, JS and CSS code for registering a block for a WordPress plugin.\n\n' +
'[slug] is optional. When provided it triggers the quick mode where it is used ' +
'as the block slug used for its identification, the output location for scaffolded files, ' +
'and the name of the WordPress plugin. The rest of the configuration is set to all default values.'
'[slug] is optional. When provided it triggers the quick mode where it is used ' +
'as the block slug used for its identification, the output location for scaffolded files, ' +
'and the name of the WordPress plugin. The rest of the configuration is set to all default values.'
)
.version( version )
.arguments( '[slug]' )
.option( '-t, --template <name>', 'template type name, allowed values: "es5", "esnext"', 'esnext' )
.option(
'-t, --template <name>',
'template type name, allowed values: "es5", "esnext"',
'esnext'
)
.action( async ( slug, { template } ) => {
try {
const defaultValues = getDefaultValues( template );
if ( slug ) {
const title = defaultValues.slug === slug ?
defaultValues.title :
startCase( slug.replace( /-/, ' ' ) );
const title =
defaultValues.slug === slug ? defaultValues.title : startCase( slug.replace( /-/, ' ' ) );
const answers = {
...defaultValues,
slug,
Expand Down
3 changes: 1 addition & 2 deletions packages/create-block/lib/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ const dashicon = {
return true;
},
filter( input ) {
return input &&
input.replace( /dashicon(s)?-/, '' );
return input && input.replace( /dashicon(s)?-/, '' );
},
};

Expand Down
20 changes: 5 additions & 15 deletions packages/create-block/lib/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,10 @@ const initWPScripts = require( './init-wp-scripts' );
const { code, info, success } = require( './log' );
const { hasWPScriptsEnabled, getOutputFiles } = require( './templates' );

module.exports = async function( templateName, {
namespace,
slug,
title,
description,
dashicon,
category,
author,
license,
version,
} ) {
module.exports = async function(
templateName,
{ namespace, slug, title, description, dashicon, category, author, license, version }
) {
info( '' );
info( `Creating a new WordPress block in "${ slug }" folder.` );

Expand All @@ -49,10 +42,7 @@ module.exports = async function( templateName, {
// Output files can have names that depend on the slug provided.
const outputFilePath = `${ slug }/${ file.replace( /\$slug/g, slug ) }`;
await makeDir( dirname( outputFilePath ) );
writeFile(
outputFilePath,
render( template, view )
);
writeFile( outputFilePath, render( template, view ) );
} )
);

Expand Down
14 changes: 4 additions & 10 deletions packages/create-block/lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,15 @@ const templates = {
license,
version,
},
outputFiles: [
'.editorconfig',
'editor.css',
'index.js',
'$slug.php',
'style.css',
],
outputFiles: [ '.editorconfig', 'editor.css', 'index.js', '$slug.php', 'style.css' ],
},
esnext: {
defaultValues: {
namespace,
slug: 'esnext-example',
title: 'ESNext Example',
description: 'Example block written with ESNext standard and JSX support – build step required.',
description:
'Example block written with ESNext standard and JSX support – build step required.',
dashicon,
category,
author,
Expand All @@ -59,8 +54,7 @@ const templates = {
const getTemplate = ( templateName ) => {
if ( ! templates[ templateName ] ) {
throw new CliError(
'Invalid template type name.' +
` Allowed values: ${ Object.keys( templates ).join( ', ' ) }.`
'Invalid template type name.' + ` Allowed values: ${ Object.keys( templates ).join( ', ' ) }.`
);
}
return templates[ templateName ];
Expand Down

0 comments on commit 508516e

Please sign in to comment.