Skip to content

Commit

Permalink
Add block.json schema to generated file (#35843)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mkaz authored Oct 22, 2021
1 parent 2c69968 commit 2d8e60c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/create-block/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
## Unreleased

### New Features

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

- Add $schema definition to generated `block.json` file.

## 2.5.0 (2021-07-21)

### Enhancements
Expand Down
1 change: 1 addition & 0 deletions packages/create-block/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ module.exports = {

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:

- `$schema` (default: `https://json.schemastore.org/block.json`)
- `apiVersion` (default: `2`) - see https://make.wordpress.org/core/2020/11/18/block-api-version-2/.
- `slug` (no default)
- `namespace` (default: `'create-block'`)
Expand Down
2 changes: 2 additions & 0 deletions packages/create-block/lib/init-block-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { writeFile } = require( 'fs' ).promises;
const { info } = require( './log' );

module.exports = async ( {
$schema,
apiVersion,
slug,
namespace,
Expand All @@ -34,6 +35,7 @@ module.exports = async ( {
JSON.stringify(
omitBy(
{
$schema,
apiVersion,
name: namespace + '/' + slug,
version,
Expand Down
2 changes: 2 additions & 0 deletions packages/create-block/lib/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const { code, info, success } = require( './log' );
module.exports = async (
blockTemplate,
{
$schema,
apiVersion,
namespace,
slug,
Expand Down Expand Up @@ -48,6 +49,7 @@ module.exports = async (

const { outputTemplates, outputAssets } = blockTemplate;
const view = {
$schema,
apiVersion,
namespace,
namespaceSnakeCase: snakeCase( namespace ),
Expand Down
1 change: 1 addition & 0 deletions packages/create-block/lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ const getBlockTemplate = async ( templateName ) => {

const getDefaultValues = ( blockTemplate ) => {
return {
$schema: 'https://json.schemastore.org/block.json',
apiVersion: 2,
namespace: 'create-block',
category: 'widgets',
Expand Down

0 comments on commit 2d8e60c

Please sign in to comment.