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

CLI Tools: update scaffolding, use block.json to register blocks. #33883

Merged
merged 11 commits into from
Nov 13, 2023

Conversation

jeherve
Copy link
Member

@jeherve jeherve commented Oct 31, 2023

Fixes #33173

Proposed changes:

Let's update our scaffolding to encourage others to use the new nomemclature introduced in #32602.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

  • No

Testing instructions:

  • On your local checkout, run jetpack docker wp -- jetpack scaffold block "Amazing Rock" --slug="good-music" --description="Rock the best music on your site" --keywords="music, audio, media, four, five", then build with jetpack build plugins/jetpack, and observe the new block in the block editor.

@jeherve jeherve added [Status] Needs Review To request a review from Crew. Label will be renamed soon. [Type] Janitorial [Pri] Normal [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Status] Needs Team Review labels Oct 31, 2023
@jeherve jeherve self-assigned this Oct 31, 2023
@jeherve jeherve requested a review from a team as a code owner October 31, 2023 13:19
@jeherve jeherve requested a review from a team October 31, 2023 13:20
@jeherve jeherve enabled auto-merge (squash) October 31, 2023 13:20
@github-actions
Copy link
Contributor

github-actions bot commented Oct 31, 2023

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the update/cli-blocks-scaffold branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack update/cli-blocks-scaffold
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Oct 31, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 31, 2023

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen daily.
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for December 5, 2023 (scheduled code freeze on November 28, 2023).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

monsieur-z
monsieur-z previously approved these changes Oct 31, 2023
Copy link
Contributor

@monsieur-z monsieur-z left a comment

Choose a reason for hiding this comment

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

Thanks, these changes are welcome.

I'm having some trouble running scaffolding commands locally (even on trunk), so you may want to ask for additional testing. But everything seems good codewise.

Copy link
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

When running the script, I note the following issues:

  • If you specify --keywords, this produces
    "keywords": [Array],
    
    in the block.json which is not terribly helpful.
  • It also doesn't properly encode the keywords, description, and such in the json, but the old version had that bug too.
  • Another existing bug is that for some reason --keywords only accepts three keywords. If you try to do more, the output has all of them combined as the third.

@@ -0,0 +1,18 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should new blocks be defaulting to a later api version?

For version 2, it looks like we'll also have to have the default edit function use useBlockProps as documented at https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/. And maybe something similar for the save function and useBlockProps.save.

Version 3 will probably have to wait until we're not using 'enqueue_block_editor_assets' to enqueue the monolithic editor.js though.

Copy link
Member Author

Choose a reason for hiding this comment

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

@monsieur-z What's your take on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

It makes sense to nudge people to use the latest version when possible. In this case (using 2 or 3), we'd probably need to edit the save and edit functions in the templates to include useBlockProps(); (as in the link Brad copied) and make it visible it's required.

As for which version to use, I can't say I fully understand what using version 3 involves. The iframing might be an issue for some, but it seems it wouldn't occur unless all blocks are registered with 3 anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

What I've managed to gather is that we have to make sure the scripts will be enqueued inside the iframe. Which it seems may involve somehow using the 'enqueue_block_assets' hook rather than 'enqueue_block_editor_assets', or else doing the enqueuing via block.json.

https://developer.wordpress.org/block-editor/how-to-guides/enqueueing-assets-in-the-editor/#editor-content-scripts-and-styles (and the following section) might be relevant.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 Discussion can continue in #34120

@anomiex anomiex added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Nov 1, 2023
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
@jeherve
Copy link
Member Author

jeherve commented Nov 6, 2023

@anomiex Thanks for the feedback. I addressed most of it above. I had a question about

It also doesn't properly encode the keywords, description, and such in the json, but the old version had that bug too.

What type of encoding issue did you have in mind in this case? I tried jetpack docker wp -- jetpack scaffold block "Block with accented characters éóőöàá" --slug="good-music" --description="Rock the best music of the 70’s" --keywords="mot clé, audio, media, four, five" and didn't run into any issues, but I assume you mean something else?

@anomiex
Copy link
Contributor

anomiex commented Nov 6, 2023

What type of encoding issue did you have in mind in this case?

Try putting " (or ' for the existing version) in the values. It doesn't encode them properly for JSON.

Newlines might be an issue too, if someone tries a multi-line description, but I didn't try that.

@jeherve
Copy link
Member Author

jeherve commented Nov 7, 2023

What type of encoding issue did you have in mind in this case?

Try putting " (or ' for the existing version) in the values. It doesn't encode them properly for JSON.

Newlines might be an issue too, if someone tries a multi-line description, but I didn't try that.

Would something like d4c48c3 help?

@jeherve jeherve added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Nov 7, 2023
@anomiex
Copy link
Contributor

anomiex commented Nov 7, 2023

Since we're dealing with json, it might be better to use actual json_encode() rather than addcslashes() which may handle things slightly differently.

Of course, that would mean that on the template side we'd need to not include the quotes since they're now in the source strings. Or else we'd need to do like substr( 1, -1 ) to remove the quotes so the templates can still re-add them.

@kraftbj kraftbj added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Nov 9, 2023
@jeherve
Copy link
Member Author

jeherve commented Nov 10, 2023

Since we're dealing with json, it might be better to use actual json_encode() rather than addcslashes() which may handle things slightly differently.

Of course, that would mean that on the template side we'd need to not include the quotes since they're now in the source strings. Or else we'd need to do like substr( 1, -1 ) to remove the quotes so the templates can still re-add them.

Is this what you had in mind? 1f39cf3

It doesn't support new lines, but I personally think that's okay, I don't believe that is something that will be commonly passed when using the CLI command.

@jeherve jeherve removed the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Nov 10, 2023
Copy link
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

Yes, that's what I had in mind. Also it supported newlines fine when I tested it.

@jeherve jeherve merged commit b89fb3f into trunk Nov 13, 2023
52 of 55 checks passed
@jeherve jeherve deleted the update/cli-blocks-scaffold branch November 13, 2023 15:13
@github-actions github-actions bot added this to the jetpack/12.9 milestone Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] Normal [Type] Janitorial
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update jetpack CLI command to generate new blocks using block.json
4 participants