Skip to content

Commit 2d8e60c

Browse files
authored
Add block.json schema to generated file (#35843)
This adds the schema defintinon to the top of the generated block.json file: "$schema": "https://json.schemastore.org/block.json", This makes it easier to work with the `block.json` file in devleopment, with supported editors it offers tooltips, autocomplete, and schema validation.
1 parent 2c69968 commit 2d8e60c

File tree

5 files changed

+9
-0
lines changed

5 files changed

+9
-0
lines changed

packages/create-block/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
## Unreleased
44

55
### New Features
6+
67
- Add passing local directories to --template. ([#35645](https://github.com/WordPress/gutenberg/pull/35645))
78
- Add `slugPascalCase` to the list of variables that can be used in templates ([#35462](https://github.com/WordPress/gutenberg/pull/35462))
89

10+
- Add $schema definition to generated `block.json` file.
11+
912
## 2.5.0 (2021-07-21)
1013

1114
### Enhancements

packages/create-block/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ module.exports = {
177177

178178
The following configurable variables are used with the template files. Template authors can change default values to use when users don't provide their data:
179179

180+
- `$schema` (default: `https://json.schemastore.org/block.json`)
180181
- `apiVersion` (default: `2`) - see https://make.wordpress.org/core/2020/11/18/block-api-version-2/.
181182
- `slug` (no default)
182183
- `namespace` (default: `'create-block'`)

packages/create-block/lib/init-block-json.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { writeFile } = require( 'fs' ).promises;
1111
const { info } = require( './log' );
1212

1313
module.exports = async ( {
14+
$schema,
1415
apiVersion,
1516
slug,
1617
namespace,
@@ -34,6 +35,7 @@ module.exports = async ( {
3435
JSON.stringify(
3536
omitBy(
3637
{
38+
$schema,
3739
apiVersion,
3840
name: namespace + '/' + slug,
3941
version,

packages/create-block/lib/scaffold.js

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const { code, info, success } = require( './log' );
1919
module.exports = async (
2020
blockTemplate,
2121
{
22+
$schema,
2223
apiVersion,
2324
namespace,
2425
slug,
@@ -48,6 +49,7 @@ module.exports = async (
4849

4950
const { outputTemplates, outputAssets } = blockTemplate;
5051
const view = {
52+
$schema,
5153
apiVersion,
5254
namespace,
5355
namespaceSnakeCase: snakeCase( namespace ),

packages/create-block/lib/templates.js

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ const getBlockTemplate = async ( templateName ) => {
185185

186186
const getDefaultValues = ( blockTemplate ) => {
187187
return {
188+
$schema: 'https://json.schemastore.org/block.json',
188189
apiVersion: 2,
189190
namespace: 'create-block',
190191
category: 'widgets',

0 commit comments

Comments
 (0)