diff --git a/packages/create-block/lib/index.js b/packages/create-block/lib/index.js index 0420446bf90ec6..08c86727a904de 100644 --- a/packages/create-block/lib/index.js +++ b/packages/create-block/lib/index.js @@ -14,8 +14,8 @@ const log = require( './log' ); const { engines, version } = require( '../package.json' ); const scaffold = require( './scaffold' ); const { - getPluginTemplate, getDefaultValues, + getProjectTemplate, runPrompts, } = require( './templates' ); @@ -81,9 +81,10 @@ program ) => { await checkSystemRequirements( engines ); try { - const pluginTemplate = await getPluginTemplate( templateName ); + const projectTemplate = + await getProjectTemplate( templateName ); const availableVariants = Object.keys( - pluginTemplate.variants + projectTemplate.variants ); if ( variant && ! availableVariants.includes( variant ) ) { if ( ! availableVariants.length ) { @@ -113,7 +114,7 @@ program if ( slug ) { const defaultValues = getDefaultValues( - pluginTemplate, + projectTemplate, variant ); const answers = { @@ -123,7 +124,7 @@ program title: capitalCase( slug ), ...optionsValues, }; - await scaffold( pluginTemplate, answers ); + await scaffold( projectTemplate, answers ); } else { log.info( '' ); log.info( @@ -143,12 +144,12 @@ program } const defaultValues = getDefaultValues( - pluginTemplate, + projectTemplate, variant ); const blockAnswers = await runPrompts( - pluginTemplate, + projectTemplate, [ 'slug', 'namespace', @@ -156,8 +157,8 @@ program 'description', 'dashicon', 'category', - 'textdomain', - ], + ! plugin && 'textdomain', + ].filter( Boolean ), variant, optionsValues ); @@ -170,7 +171,7 @@ program default: false, } ) ) ? await runPrompts( - pluginTemplate, + projectTemplate, [ 'pluginURI', 'version', @@ -185,7 +186,7 @@ program ) : {}; - await scaffold( pluginTemplate, { + await scaffold( projectTemplate, { ...defaultValues, ...optionsValues, variant, diff --git a/packages/create-block/lib/prompts.js b/packages/create-block/lib/prompts.js index 94cd50c47a9555..88bdaf22635d36 100644 --- a/packages/create-block/lib/prompts.js +++ b/packages/create-block/lib/prompts.js @@ -77,9 +77,8 @@ const category = { const textdomain = { type: 'input', - name: 'textdomain', message: - 'The text domain used to internationalize text in the block (by default it will be same as slug):', + 'The text domain used to make strings translatable in the block (optional):', validate( input ) { if ( input.length && ! /^[a-z][a-z0-9\-]*$/.test( input ) ) { return 'Invalid text domain specified. Text domain can contain only lowercase alphanumeric characters or dashes, and start with a letter.'; diff --git a/packages/create-block/lib/templates.js b/packages/create-block/lib/templates.js index d26170929c7702..db78ee80aa429a 100644 --- a/packages/create-block/lib/templates.js +++ b/packages/create-block/lib/templates.js @@ -158,7 +158,7 @@ const configToTemplate = async ( { }; }; -const getPluginTemplate = async ( templateName ) => { +const getProjectTemplate = async ( templateName ) => { if ( predefinedPluginTemplates[ templateName ] ) { return await configToTemplate( predefinedPluginTemplates[ templateName ] @@ -225,12 +225,13 @@ const getPluginTemplate = async ( templateName ) => { } }; -const getDefaultValues = ( pluginTemplate, variant ) => { +const getDefaultValues = ( projectTemplate, variant ) => { return { $schema: 'https://schemas.wp.org/trunk/block.json', apiVersion: 3, namespace: 'create-block', category: 'widgets', + textdomain: '', author: 'The WordPress Contributors', license: 'GPL-2.0-or-later', licenseURI: 'https://www.gnu.org/licenses/gpl-2.0.html', @@ -244,19 +245,19 @@ const getDefaultValues = ( pluginTemplate, variant ) => { editorStyle: 'file:./index.css', style: 'file:./style-index.css', transformer: ( view ) => view, - ...pluginTemplate.defaultValues, - ...pluginTemplate.variants?.[ variant ], - variantVars: getVariantVars( pluginTemplate.variants, variant ), + ...projectTemplate.defaultValues, + ...projectTemplate.variants?.[ variant ], + variantVars: getVariantVars( projectTemplate.variants, variant ), }; }; const runPrompts = async ( - pluginTemplate, + projectTemplate, promptNames, variant, optionsValues ) => { - const defaultValues = getDefaultValues( pluginTemplate, variant ); + const defaultValues = getDefaultValues( projectTemplate, variant ); const result = {}; for ( const promptName of promptNames ) { if ( Object.keys( optionsValues ).includes( promptName ) ) { @@ -291,7 +292,7 @@ const getVariantVars = ( variants, variant ) => { }; module.exports = { - getPluginTemplate, getDefaultValues, + getProjectTemplate, runPrompts, };