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

Scripts: Add create-block script for bootstrapping a minimal block development plugin. #18650

Closed
wants to merge 3 commits into from

Conversation

epiqueras
Copy link
Contributor

Description

This PR adds a new command to @wordpress/scripts that takes a new name for a block and creates a minimal plugin development environment for it in the current working directory.

Example:

$ wp-scripts create-block "My Fancy Block"
$ cd ./my-fancy-block-plugin
$ npm install
$ npm run start # Start WordPress instance.
$ npm run dev # Build and watch files.

It's good to have a tool like this in the monorepo so that it can be kept up to date with updates to block registration APIs.

How has this been tested?

It was verified that running the commands in the example works as expected.

Types of Changes

New Feature: @wordpress/scripts now has a create-block command for bootstrapping a minimal block plugin development environment.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR. .

@epiqueras epiqueras added [Type] Build Tooling Issues or PRs related to build tooling [Package] Scripts /packages/scripts labels Nov 21, 2019
@epiqueras epiqueras added this to the Future milestone Nov 21, 2019
@epiqueras epiqueras self-assigned this Nov 21, 2019

```sh
$ wp-scripts create-block "My Fancy Block"
$ cd ./my-fancy-block-plugin
Copy link
Member

Choose a reason for hiding this comment

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

If the plugin is called "My Fancy Block" does it append -plugin to the folder created?

If not, then:

Suggested change
$ cd ./my-fancy-block-plugin
$ cd ./my-fancy-block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the plugin is called "My Fancy Block" does it append -plugin to the folder created?

Yes, "My Fancy Block" is the block name.

Copy link
Member

Choose a reason for hiding this comment

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

Why append -plugin to the plugin name? Why not just my-fancy-block for the slug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So that they are not the same.

Is there a convention for this?

Copy link
Member

@ntwb ntwb Nov 21, 2019

Choose a reason for hiding this comment

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

With create-react-app whatever name I use is converted to kebab-case, no extra -app or -plugin is appended to the name.

And for the most part if I would expect the name to be what name I gave, if I gave "My Fancy Block Plugin" then I would expect the -plugin included in the slug

Copy link
Member

Choose a reason for hiding this comment

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

So that they are not the same.

Is there any concerns where having the plugin name and plugin slug the same that would be of concern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With create-react-app whatever name I use is converted to snake-case, no extra -app or -plugin is appended to the name.

Yes, because you are naming the app, and the app only.

And for the most part if I would expect the name to be what name I gave, if I gave "My Fancy Block Plugin" then I would expect the -plugin included in the slug

You are not naming the plugin, you are naming the block, and the plugin name gets generated from that.

Is there any concerns where having the plugin name and plugin slug the same that would be of concern?

No, I think it's just a style thing. I don't have a strong opinion on it.

@gziolo
Copy link
Member

gziolo commented Nov 21, 2019

Previous work by @ajitbohra #10628. There is also a related full proposal what could be implemented in #10629.

*
* @since 1.0.0
*/
function block_plugin_name_enqueue_block_assets() {
Copy link
Member

Choose a reason for hiding this comment

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

Testing this PR

Uncaught Error: syntax error, unexpected '-', expecting '(' in /wp-content/plugins/my-block-plugin/plugin.php on line 16

The function name is being generated as:

my-block-plugin_enqueue_block_assets()

Instead of kebabCase, the my-block-plugin needs to be snakeCase:

my_block_plugin_enqueue_block_assets()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, should be fixed now. Thanks for catching this!

@ntwb
Copy link
Member

ntwb commented Nov 23, 2019

Having now read and tested the other PR @gziolo highlighted above I'd prefer we continued working on that plugin, thoughts @epiqueras ?

@epiqueras
Copy link
Contributor Author

That makes sense.

Do you think it's worth our time to be working on this at all right now though?

The block registration RFC should make this so much easier right? Maybe that's a better start to making block authoring easier.

@epiqueras epiqueras closed this Nov 23, 2019
@youknowriad youknowriad deleted the add/wp-scripts-create-block branch November 24, 2019 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Scripts /packages/scripts [Type] Build Tooling Issues or PRs related to build tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants