Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Block: Optimize the default template for multiple blocks case #68175

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Member Author

Choose a reason for hiding this comment

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

I modified that only for the default templates bundled with the package instead of for every project template, as I'm not entirely sure what implications it would have for developer docs. @ndiego, do you forsee any complications?

},
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' );
Loading