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] Introduce the transformer property. #55423

Merged
merged 5 commits into from
Oct 18, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Sanitize the slug and namespace before running the transformer functi…
…on. They create the view based on the transformed values and access the view.slug for the CLI output.
  • Loading branch information
ryanwelcher committed Oct 18, 2023
commit 4800d7e6512fca67d535c3f19f88872b62ee604c
31 changes: 15 additions & 16 deletions packages/create-block/lib/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ module.exports = async (
transformer,
}
) => {
const transformedData = transformer( {
slug = slug.toLowerCase();
namespace = namespace.toLowerCase();

const transformedValues = transformer( {
$schema,
apiVersion,
plugin,
Expand Down Expand Up @@ -86,12 +89,17 @@ module.exports = async (
customPackageJSON,
customBlockJSON,
example,
textdomain: slug,
} );

const { slug: transformedSlug, namespace: transformedNamespace } =
transformedData;
slug = transformedSlug.toLowerCase();
namespace = transformedNamespace.toLowerCase();
const view = {
...transformedValues,
namespaceSnakeCase: snakeCase( transformedValues.slug ),
slugSnakeCase: snakeCase( transformedValues.slug ),
slugPascalCase: pascalCase( transformedValues.slug ),
...variantVars,
};

/**
* --no-plugin relies on the used template supporting the [blockTemplatesPath property](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/#blocktemplatespath).
* If the blockOutputTemplates object has no properties, we can assume that there was a custom --template passed that
Expand All @@ -107,19 +115,10 @@ module.exports = async (
info( '' );
info(
plugin
? `Creating a new WordPress plugin in the ${ slug } directory.`
: `Creating a new block in the ${ slug } directory.`
? `Creating a new WordPress plugin in the ${ view.slug } directory.`
: `Creating a new block in the ${ view.slug } directory.`
);

const view = {
...transformedData,
namespaceSnakeCase: snakeCase( namespace ),
slugSnakeCase: snakeCase( slug ),
slugPascalCase: pascalCase( slug ),
textdomain: slug,
...variantVars,
};

if ( plugin ) {
await Promise.all(
Object.keys( pluginOutputTemplates ).map(
Expand Down
Loading