Skip to content

Commit

Permalink
Create Block: Optimize the default template for multiple blocks case (#…
Browse files Browse the repository at this point in the history
…68175)

* Create Block: Optimize the default template for multiple blocks case

* Add changelog entry

* Update the integration test to reflect changes

Co-authored-by: gziolo <[email protected]>
Co-authored-by: sirreal <[email protected]>
  • Loading branch information
3 people authored Jan 2, 2025
1 parent 5b06788 commit ec0317e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions bin/test-create-block.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if [ "$expected" -ne "$actual" ]; then
exit 1
fi
expected=7
actual=$( find src -maxdepth 1 -type f | wc -l )
actual=$( find src -maxdepth 2 -type f | wc -l )
if [ "$expected" -ne "$actual" ]; then
error "Expected $expected files in the \`src\` directory, but found $actual."
exit 1
Expand All @@ -70,7 +70,7 @@ status "Building block..."

status "Verifying build..."
expected=9
actual=$( find build -maxdepth 1 -type f | wc -l )
actual=$( find build -maxdepth 2 -type f | wc -l )
if [ "$expected" -ne "$actual" ]; then
error "Expected $expected files in the \`build\` directory, but found $actual."
exit 1
Expand Down
1 change: 1 addition & 0 deletions packages/create-block/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancement

- Add support for custom `textdomain` property for the scaffolded block ([#57197](https://github.com/WordPress/gutenberg/pull/57197)).
- Update the default template to scaffold a block in its subfolder to make it easier to update to multiple blocks in a single plugin ([#68175](https://github.com/WordPress/gutenberg/pull/68175)).

### Internal

Expand Down
5 changes: 2 additions & 3 deletions packages/create-block/lib/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ module.exports = async (
}
) => {
slug = slug.toLowerCase();
namespace = namespace.toLowerCase();
const rootDirectory = join( process.cwd(), targetDir || slug );
const transformedValues = transformer( {
$schema,
apiVersion,
plugin,
namespace,
namespace: namespace.toLowerCase(),
slug,
title,
description,
Expand All @@ -84,7 +83,7 @@ module.exports = async (
npmDependencies,
npmDevDependencies,
customScripts,
folderName,
folderName: folderName.replace( /\$slug/g, slug ),
editorScript,
editorStyle,
style,
Expand Down
1 change: 1 addition & 0 deletions packages/create-block/lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const predefinedPluginTemplates = {
},
viewScript: 'file:./view.js',
example: {},
folderName: './src/$slug',
},
variants: {
static: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ if ( ! defined( 'ABSPATH' ) ) {
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
register_block_type( __DIR__ . '/build' );
register_block_type( __DIR__ . '/build/{{slug}}' );
}
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );

1 comment on commit ec0317e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in ec0317e.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12582058223
📝 Reported issues:

Please sign in to comment.