-
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: Add support for external templates hosted on npm #22175
Create block: Add support for external templates hosted on npm #22175
Conversation
Merge Master back into fork
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.
Love this. One thing that I think would be super helpful is an example added to the readme so that devs can see what a sample template npm package looks like.
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.
Impressive work so far @fabiankaegy. I'm really excited about this feature 💯
I left quite detailed feedback. Let me know how you feel about it.
packages/create-block/README.md
Outdated
|
||
Inside that bootstrapped directory _(it doesn't apply to `es5` template)_, you can run several commands: | ||
When bootstraped with the `esnext` templateyou can run several commands inside the directory: |
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.
One more thing, wpScriptsEnabled
enables those commands. Once we sort out the final shape of template definition we can update this section to reflect it.
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.
@gziolo Yes the commands get enabled by wpScriptsEnabled
but at the end it matters what the creator of the template has in their scripts
in the package.json
.
Thats why I changed it to only refer to the esnext
template.
"style.css", | ||
"readme.txt" | ||
], | ||
"wpScriptsEnabled": true |
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.
For the future PR:
Thinking about it now when documented, it should be opt-out rather than opt-in, we want people to use wp-scripts
:)
"licenseURI": "https://www.gnu.org/licenses/gpl-2.0.html", | ||
"version": "0.1.0" | ||
}, | ||
"outputFiles": [ |
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.
For the future PR:
I'm very interested to find a way to automate the discovery of templates with glob
call or something like this. It would be great to be able to default to templates
folder that the template author can override:
{
"templatesFolder": "./my-folder"
}
@gziolo I have fixed / implemented the suggestions you provided. I'm still struggling with the cleanup of the temp folder. (But it is now located in the os temp folder) |
For the future PR: I think it could be interesting to refactor Usecase: Example:
{
...,
"buildProject": true,
"buildCommand": "custom name"
} Wit this the scaffold tool would then run |
I was thinking about that as well. The simplest approach would be to use
In #22235, I tried to flip the flag and make wp-scripts enabled by default. Now, I tempted to implement what I outlined above in another PR. Any concerns regarding this proposal? |
- `namespaceSnakeCase` | ||
- `slugSnakeCase` |
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.
namespaceSnakeCase
and slugSnakeCase
ar sort of special here. We should omit them and find a way to apply those modifications inside the template.
packages/create-block/lib/index.js
Outdated
@@ -45,7 +45,7 @@ program | |||
) => { | |||
await checkSystemRequirements( engines ); | |||
try { | |||
const defaultValues = getDefaultValues( template ); | |||
const defaultValues = await getDefaultValues( template ); |
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.
The fact that all methods need to be converted to async here is a bit concerning. I'm coming to the conclusion that we should call async getTemplate( templateName );
first and then pass the object to all other methods. This way we avoid converting all methods to async, plus there is no need to check whether we don't download the template multiple time, or process it. I'm happy to apply all refactoring in the related PR I opened earlier.
When I run Before, it would be nice to align the version of Line 182 in f6a401b
Later, we can update it for the whole project. |
I test it locally with: $ npx wp-create-block -t gutenberg-esnext-template and it magically works. Super exciting 🎉 |
@fabiankaegy, I landed #22235 so you can expect some conflicts when rebasing but in general, it should be easier to integrate with 3rd party templates. |
Cool 👍 I saw that you integrated it and I will make sure to go over the changes and also fix @aduth's suggestions :) |
Co-authored-by: Andrew Duthie <[email protected]>
Co-authored-by: Andrew Duthie <[email protected]>
Co-authored-by: Andrew Duthie <[email protected]>
Work continues in #23712. |
Motivation
The biggest motivation to support templates comes from the fact that https://github.com/WordPress/gutenberg-examples contains multiple examples of blocks that are used in the block editor tutorials (https://developer.wordpress.org/block-editor/tutorials/block-tutorial/). The idea is that we make it easier for folks and let them running one command to install such block in the plugins directory in WordPress when going through the tutorial with one command:
As of today, they need to either copy the folder from the repository or recreate it manually when going through the tutorial.
Description
With this PR I have introduced the ability to pull templates for the
create-block
package fromnpm
. This would allow for anyone to contribute / use the starter template they would like with the ease of use thecreate-block
cli provides.External templates
The external templates need to contain the
.mustache
files and onetemplate.json
file with the metadata that is currently being stored in thetemplates.js
file.How has this been tested?
This is being tested by running
node index.js
with different-t
parameters. To test things directly from NPM I have created this example package: https://www.npmjs.com/package/gutenberg-esnext-templateTypes of changes
Checklist: