-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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] Adding a --no-plugin
flag to scaffold only block files.
#41642
[Create Block] Adding a --no-plugin
flag to scaffold only block files.
#41642
Conversation
…ow what packages are being installed.
This PR introduces a lot of conditionals and it would be a really good idea to start abstracting out some of the functionality to make it easier to work with. |
--block-only
flag to scaffold only block files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR introduces the
--block-only
flag to allow users to use the package to scaffold only block files.
This is great. We really need this option to make it possible to scaffold more blocks for existing plugins ❤️
I left some comments from my testing. In general, this PR is nearly ready. It just requires some final decisions like:
- Where to exactly output the block folder?
- How to name the flag? It's probably too late to have
npx @wordpress/create-block
andnpx @wordpress/create-block-plugin
😅 The only alternatives I can think of are--no-plugin
or--skip-plugin
which might be less clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything works great and I'm really excited about this new feature. I left my feedback for consideration. Let's also include an example with some details how it works in the README file.
Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>
I found an issue while testing where if a As a result, I have added some logic to check to see if there are block template files and if not, error out with a message. This can be tested by using the following command from the root of the create-block package.
|
--block-only
flag to scaffold only block files.--no-plugin
flag to scaffold only block files.
I can confirm that the newly added check for block templates works as expected: It makes me wonder whether we should bail out early when loading the config for the template. In effect we would have two checks:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work. I think it's ready feature-wise. There is only one remaining task left for the lodash
support, which isn't a blocker but nice to have.
The other comment about handling edge cases is my just musing that you can ignore in the first iteration 😄
here we could make it more universal for the time being so it fits also the case when user passes
In the long run, if we were to support multiple blocks scaffolding in one go, we might want to have two distinct slug prompts - one for the block and the other one for the plugin. I'm not sure about that yet, but I wanted to flag it. |
I'll make this update before merging.
I LOVE this idea. It's been something that always bugged me that the plugin and the block had the same name. Being able to pass different names for the plugin would be really handy. I'll open a new issue for it. |
…om:ryanwelcher/gutenberg into try/add-per-block-scaffolding-create-block
related #43235 |
What?
This PR introduces the
--no-plugin
flag to allow users to use the package to scaffold only block files.Why?
Currently, there is no way to scaffold additional blocks once the plugin has been created. Being able to create subsequent blocks quickly would be very helpful.
How?
When the
--no-plugin
flag is added, the script skips any plugin scaffolding and only outputs the files listed in theblockTemplatesPath
( just the block files ) intofolderName
as defined by the template with the default being./src
. It should be noted that the script is not "aware" of its location. Callingnpx @wordpress/create-block block-name --no-plugin
will create a new block inside thefolderName
directory where it's calledThe slug passed is used as the directory and block name any other flags not related to package.json items should function as expected for the block, i.e namespace.
Testing Instructions
packages/create-block
, runnode index.js test
to create a new plugin with a single blockcd
into thetest
directorynode ../index.js my-test-block --no-plugin
to scaffold a new blocksrc
directory has the existing block files and a new directory calledmy-test-block
that contains new block filesnpm start
to confirm that the build worksScreenshots or screencast