-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[Create-block] Add --variant flag to allow creation of different block type variants
#41289
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
Merged
gziolo
merged 66 commits into
WordPress:trunk
from
ryanwelcher:try/adding-is-dynamic-flag
Aug 22, 2022
Merged
Changes from all commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
6438856
Add npmDevDependencies as a template variable. Update messaging to sh…
ryanwelcher 6f24eb8
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher 0b691cc
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher c847911
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher b0b836e
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher cdb77bc
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher e8d6cc3
Remove extra code block.
ryanwelcher 2b4e90c
Add --is-dynamic flag and some conditional logic as a first pass at m…
ryanwelcher df813af
Update templates and tutorial packages to use new templates.
ryanwelcher 8a59dff
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher b52fd0b
Merge branch 'trunk' into try/adding-is-dynamic-flag
ryanwelcher 505db7d
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher 85af639
Merge branch 'trunk' of github.com:ryanwelcher/gutenberg into trunk
ryanwelcher c69e955
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher 5363d2c
Merge branch 'trunk' into try/adding-is-dynamic-flag
ryanwelcher 7a2fd82
Revert code to check the slug of a file.
ryanwelcher a353949
Check for empty template files before writing them into the filesystem.
ryanwelcher 4bae818
Remove files with block type in the name.
ryanwelcher 211ae27
Add the {{isDynamic}} placeholders to the templates bundled with the …
ryanwelcher 2a1b2bf
Add readme and changelog entries.
ryanwelcher 9ab2889
Render the output files will whitespace maintained.
ryanwelcher 567a22c
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher 898d8e8
Updating the create-block-tutorial-template to use the mustache condi…
ryanwelcher 430a9f0
Add the --webpack-copy-php to the scripts based on the the --is-dynam…
ryanwelcher 1e7a1d5
Move the .trim call into the context of the if statement. Proof that …
ryanwelcher c3de411
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher 969eac8
Update packages/create-block/CHANGELOG.md
gziolo b31ab37
Update packages/create-block/lib/index.js
gziolo 9d61058
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher ffc4a63
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher ce4613d
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher 614bb81
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher 7d39306
Merge branch 'trunk' of github.com:ryanwelcher/gutenberg into trunk
ryanwelcher 5b079b5
Remove extra code block added in error.
ryanwelcher c809657
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher 7f680ab
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher a729ae0
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher 08488a0
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher 682510d
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher dc4dbfc
Merge branch 'trunk' into try/adding-is-dynamic-flag
ryanwelcher 2c52e09
Merge branch 'try/adding-is-dynamic-flag' of github.com:ryanwelcher/g…
ryanwelcher ba0c060
Adding variants array to the template and generating template variabl…
ryanwelcher d4388d7
Add isStatic check to save.js
ryanwelcher 6cdfed1
Add logic to return empty object if no variants are defined in the te…
ryanwelcher 903b0c9
Update the template variable names to be is{variantName}Variant.
ryanwelcher c841b26
Update templates to use new variable name convention and look for the…
ryanwelcher 987d7f8
If no variant is select via CLI, use the first one in the array of de…
ryanwelcher 689041b
Check that the passed variant is a valid variant and exit if not.
ryanwelcher 352869e
Define a single variant for the create-block-tutorial-template. Remov…
ryanwelcher 2db5457
Add template selection to interactive mode.
ryanwelcher 8c74ad2
Update changelog.
ryanwelcher 7a3dbab
Update isDynamic to isDynamicVariant
ryanwelcher ae65dee
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher 2ebd8f8
Merge branch 'trunk' into try/adding-is-dynamic-flag
ryanwelcher ca0b38b
Replace variantTypes with variantVars
ryanwelcher 5349b5f
Update isDynamic to isDynamicVariant... again.
ryanwelcher fb27be1
Update readme to use --variant flag.
ryanwelcher 6aae5e6
Add logic to conditionally show the variant prompt only if there are …
ryanwelcher d406438
Adds variants to the es5 block and removes "static" from various prop…
ryanwelcher 4149c35
Change "static" template to "standard".
ryanwelcher 4e304ad
Convert variants to an object where the property is the variant name …
ryanwelcher 50bb648
Define a dynamic variant for the create-block-tutorial and override t…
ryanwelcher 07d0614
Get the variant first and then retrieve the defaults based on that va…
ryanwelcher 1c0b85c
Update templates.js
gziolo e700c55
Update templates.js
gziolo 11a27c0
Update packages/create-block/lib/prompts.js
gziolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/create-block-tutorial-template/block-templates/template.php.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| {{#isDynamicVariant}} | ||
| <p <?php echo get_block_wrapper_attributes(); ?>> | ||
| <?php echo esc_html( $atts['message']) ?> | ||
| </p> | ||
| {{/isDynamicVariant}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,8 +34,8 @@ program | |
| .arguments( '[slug]' ) | ||
| .option( | ||
| '-t, --template <name>', | ||
| 'project template type name; allowed values: "static", "es5", the name of an external npm package, or the path to a local directory', | ||
| 'static' | ||
| 'project template type name; allowed values: "standard", "es5", the name of an external npm package, or the path to a local directory', | ||
| 'standard' | ||
| ) | ||
| .option( '--namespace <value>', 'internal namespace for the block name' ) | ||
| .option( | ||
|
|
@@ -58,6 +58,7 @@ program | |
| ) | ||
| .option( '--wp-env', 'enable integration with `@wordpress/env` package' ) | ||
| .option( '--no-plugin', 'scaffold only block files' ) | ||
| .option( '--variant <variant>', 'the variant of the template to use' ) | ||
| .action( | ||
| async ( | ||
| slug, | ||
|
|
@@ -70,12 +71,16 @@ program | |
| title, | ||
| wpScripts, | ||
| wpEnv, | ||
| variant, | ||
| } | ||
| ) => { | ||
| await checkSystemRequirements( engines ); | ||
| try { | ||
| const pluginTemplate = await getPluginTemplate( templateName ); | ||
| const defaultValues = getDefaultValues( pluginTemplate ); | ||
| const defaultValues = getDefaultValues( | ||
| pluginTemplate, | ||
| variant | ||
| ); | ||
| const optionsValues = Object.fromEntries( | ||
| Object.entries( { | ||
| plugin, | ||
|
|
@@ -85,6 +90,7 @@ program | |
| title, | ||
| wpScripts, | ||
| wpEnv, | ||
| variant, | ||
| } ).filter( ( [ , value ] ) => value !== undefined ) | ||
| ); | ||
|
|
||
|
|
@@ -107,14 +113,30 @@ program | |
|
|
||
| const filterOptionsProvided = ( { name } ) => | ||
| ! Object.keys( optionsValues ).includes( name ); | ||
| const blockPrompts = getPrompts( pluginTemplate, [ | ||
| 'slug', | ||
| 'namespace', | ||
| 'title', | ||
| 'description', | ||
| 'dashicon', | ||
| 'category', | ||
| ] ).filter( filterOptionsProvided ); | ||
|
|
||
| // Get the variant prompt first. This will help get the default values | ||
| const variantPrompt = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I provide the variant from the CLI, it asks again for the variant. We can address it seperately.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in #43481. |
||
| Object.keys( pluginTemplate.variants )?.length > 1 | ||
| ? getPrompts( pluginTemplate, [ 'variant' ] ) | ||
| : false; | ||
|
|
||
| const variantSelection = variantPrompt | ||
| ? await inquirer.prompt( variantPrompt ) | ||
| : false; | ||
|
|
||
| const blockPrompts = getPrompts( | ||
| pluginTemplate, | ||
| [ | ||
| 'slug', | ||
| 'namespace', | ||
| 'title', | ||
| 'description', | ||
| 'dashicon', | ||
| 'category', | ||
| ], | ||
| variantSelection.variant | ||
| ).filter( filterOptionsProvided ); | ||
|
|
||
| const blockAnswers = await inquirer.prompt( blockPrompts ); | ||
|
|
||
| const pluginAnswers = plugin | ||
|
|
@@ -154,6 +176,7 @@ program | |
| ...defaultValues, | ||
| ...optionsValues, | ||
| ...blockAnswers, | ||
| ...variantSelection, | ||
| ...pluginAnswers, | ||
| } ); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.