Repository navigation
Create block: Add support for external templates hosted on npm #22175
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
Changes from all commits
e324e8e
48c7ee1
14611a3
3714b20
b0b617f
e81dd27
db93598
4b55cdf
62811e3
11072bf
7036078
4b0b246
86f7327
083a990
ea9dc1b
5be44cc
22cdbb3
fac8b18
0a7169e
06a3051
574f212
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ $ npm init @wordpress/block [options] [slug] | |
| Options: | ||
| ``` | ||
| -V, --version output the version number | ||
| -t, --template <name> template type name, allowed values: "es5", "esnext" (default: "esnext") | ||
| -t, --template <name> template name: "es5", "esnext" or the name of an external npm package (default: "esnext") | ||
| --namespace <value> internal namespace for the block name | ||
| --title <value> display title for the block | ||
| --short-description <value> short description for the block | ||
|
|
@@ -65,9 +65,9 @@ More examples: | |
|
|
||
| When you scaffold a block, you must provide at least a `slug` name, the `namespace` which usually corresponds to either the `theme` or `plugin` name, and the `category`. In most cases, we recommended pairing blocks with plugins rather than themes, because only using plugin ensures that all blocks still work when your theme changes. | ||
|
|
||
| ## Available Commands | ||
| ## Available Commands [ESNext template] | ||
|
|
||
| Inside that bootstrapped directory _(it doesn't apply to `es5` template)_, you can run several commands: | ||
| When bootstraped with the `esnext` template, you can run several commands inside the directory: | ||
|
|
||
| ```bash | ||
| $ npm start | ||
|
|
@@ -99,6 +99,53 @@ $ npm run packages-update | |
| ``` | ||
| Updates WordPress packages to the latest version. [Learn more](/packages/scripts#packages-update). | ||
|
|
||
| ## External Templates | ||
| Since version 0.12.0 it is possible to use external templates hosted on NPM. These templates need to contain `.mustache` files that will be used in the scaffolding and one `template.json` for the metadata. | ||
|
|
||
| ### Available Variables: | ||
| - `namespace` | ||
| - `slug` | ||
| - `title` | ||
| - `textdomain` | ||
| - `description` | ||
| - `category` | ||
| - `dashicon` | ||
| - `license` | ||
| - `licenseURI` | ||
| - `namespaceSnakeCase` | ||
| - `slugSnakeCase` | ||
|
|
||
| ### `template.json` | ||
| ```json | ||
| { | ||
| "defaultValues": { | ||
| "namespace": "create-block", | ||
| "slug": "esnext-example", | ||
| "title": "ESNext Example", | ||
| "description": | ||
| "Example block written with ESNext standard and JSX support – build step required.", | ||
| "dashicon": "smiley", | ||
| "category": "widgets", | ||
| "author": "The WordPress Contributors", | ||
| "license": "GPL-2.0-or-later", | ||
| "licenseURI": "https://www.gnu.org/licenses/gpl-2.0.html", | ||
| "version": "0.1.0" | ||
| }, | ||
| "outputFiles": [ | ||
|
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. For the future PR: I'm very interested to find a way to automate the discovery of templates with {
"templatesFolder": "./my-folder"
} |
||
| ".editorconfig", | ||
| ".gitignore", | ||
| "editor.css", | ||
| "src/edit.js", | ||
| "src/index.js", | ||
| "src/save.js", | ||
| "$slug.php", | ||
| "style.css", | ||
| "readme.txt" | ||
| ], | ||
| "wpScriptsEnabled": true | ||
|
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. 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-CLI | ||
|
|
||
| Another way of making a developer’s life easier is to use [WP-CLI](https://wp-cli.org), which provides a command-line interface for many actions you might perform on the WordPress instance. One of the commands `wp scaffold block` was used as the baseline for this tool and ES5 template in particular. | ||
|
|
||
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.
namespaceSnakeCaseandslugSnakeCasear sort of special here. We should omit them and find a way to apply those modifications inside the template.