From 26bf6dbe9f0bae18f08d113cae967ef2e5076f66 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Sat, 22 Jul 2023 03:26:10 +0300 Subject: [PATCH] [Create Block] Add support for the example property and add template defaults. (#52803) * Add support for the example property and add template defaults. * Update changelog I also included the change of the last version that we forgot. * Fix small typo --------- Co-authored-by: Luis Herranz --- packages/create-block/CHANGELOG.md | 8 ++++++++ packages/create-block/lib/init-block.js | 2 ++ packages/create-block/lib/scaffold.js | 2 ++ packages/create-block/lib/templates.js | 2 ++ 4 files changed, 14 insertions(+) diff --git a/packages/create-block/CHANGELOG.md b/packages/create-block/CHANGELOG.md index b03a8aca72b50..05313fc10ec30 100644 --- a/packages/create-block/CHANGELOG.md +++ b/packages/create-block/CHANGELOG.md @@ -2,8 +2,16 @@ ## Unreleased +### Enhancement + +- Add support for the `example` property and add it to the default template ([#52803](https://github.com/WordPress/gutenberg/pull/52803)). + ## 4.22.0 (2023-07-20) +### Enhancement + +- Add support for the `viewScript` property ([#52612](https://github.com/WordPress/gutenberg/pull/52612)). + ## 4.21.0 (2023-07-05) ## 4.20.0 (2023-06-23) diff --git a/packages/create-block/lib/init-block.js b/packages/create-block/lib/init-block.js index d26ef4a909ab7..9c0bda20a4009 100644 --- a/packages/create-block/lib/init-block.js +++ b/packages/create-block/lib/init-block.js @@ -32,6 +32,7 @@ async function initBlockJSON( { render, viewScript, customBlockJSON, + example, } ) { info( '' ); info( 'Creating a "block.json" file.' ); @@ -53,6 +54,7 @@ async function initBlockJSON( { category, icon: dashicon, description, + example, attributes, supports, textdomain, diff --git a/packages/create-block/lib/scaffold.js b/packages/create-block/lib/scaffold.js index a8d9c3859e20d..568ec2f007457 100644 --- a/packages/create-block/lib/scaffold.js +++ b/packages/create-block/lib/scaffold.js @@ -48,6 +48,7 @@ module.exports = async ( variantVars, customPackageJSON, customBlockJSON, + example, } ) => { slug = slug.toLowerCase(); @@ -107,6 +108,7 @@ module.exports = async ( viewScript, customPackageJSON, customBlockJSON, + example, ...variantVars, }; diff --git a/packages/create-block/lib/templates.js b/packages/create-block/lib/templates.js index 4ce898617adde..29f713499e3f2 100644 --- a/packages/create-block/lib/templates.js +++ b/packages/create-block/lib/templates.js @@ -34,6 +34,7 @@ const predefinedPluginTemplates = { editorStyle: null, style: null, viewScript: 'file:./view.js', + example: {}, }, templatesPath: join( __dirname, 'templates', 'es5' ), variants: { @@ -55,6 +56,7 @@ const predefinedPluginTemplates = { html: false, }, viewScript: 'file:./view.js', + example: {}, }, variants: { static: {},