diff --git a/packages/create-block/CHANGELOG.md b/packages/create-block/CHANGELOG.md index a8d54848ad791..cea0e6800d8bd 100644 --- a/packages/create-block/CHANGELOG.md +++ b/packages/create-block/CHANGELOG.md @@ -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 diff --git a/packages/create-block/README.md b/packages/create-block/README.md index 2ae2ad98590d1..60978c4e792ec 100644 --- a/packages/create-block/README.md +++ b/packages/create-block/README.md @@ -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'`) diff --git a/packages/create-block/lib/init-block-json.js b/packages/create-block/lib/init-block-json.js index 29e65a0b67c7d..1520c6d0c5910 100644 --- a/packages/create-block/lib/init-block-json.js +++ b/packages/create-block/lib/init-block-json.js @@ -11,6 +11,7 @@ const { writeFile } = require( 'fs' ).promises; const { info } = require( './log' ); module.exports = async ( { + $schema, apiVersion, slug, namespace, @@ -34,6 +35,7 @@ module.exports = async ( { JSON.stringify( omitBy( { + $schema, apiVersion, name: namespace + '/' + slug, version, diff --git a/packages/create-block/lib/scaffold.js b/packages/create-block/lib/scaffold.js index 5255139576733..f5c89bad0768f 100644 --- a/packages/create-block/lib/scaffold.js +++ b/packages/create-block/lib/scaffold.js @@ -19,6 +19,7 @@ const { code, info, success } = require( './log' ); module.exports = async ( blockTemplate, { + $schema, apiVersion, namespace, slug, @@ -48,6 +49,7 @@ module.exports = async ( const { outputTemplates, outputAssets } = blockTemplate; const view = { + $schema, apiVersion, namespace, namespaceSnakeCase: snakeCase( namespace ), diff --git a/packages/create-block/lib/templates.js b/packages/create-block/lib/templates.js index f2bc47f69a7cf..cd74938167b3f 100644 --- a/packages/create-block/lib/templates.js +++ b/packages/create-block/lib/templates.js @@ -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',