From 71aa6c4e52f82898210ada5c509d54fe9baff109 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Mon, 3 Oct 2022 11:24:53 -0400 Subject: [PATCH 1/7] Add any custom fields added to template defaults or variants to the block.json file. --- packages/create-block/lib/init-block.js | 2 ++ packages/create-block/lib/scaffold.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/create-block/lib/init-block.js b/packages/create-block/lib/init-block.js index f58008e7f5252..5d5b8729181fd 100644 --- a/packages/create-block/lib/init-block.js +++ b/packages/create-block/lib/init-block.js @@ -29,6 +29,7 @@ async function initBlockJSON( { editorScript, editorStyle, style, + customVariantKeys, } ) { info( '' ); info( 'Creating a "block.json" file.' ); @@ -56,6 +57,7 @@ async function initBlockJSON( { editorScript, editorStyle, style, + ...customVariantKeys, } ).filter( ( [ , value ] ) => !! value ) ), null, diff --git a/packages/create-block/lib/scaffold.js b/packages/create-block/lib/scaffold.js index 5f603ed346633..df7fcbe2ce0fd 100644 --- a/packages/create-block/lib/scaffold.js +++ b/packages/create-block/lib/scaffold.js @@ -44,6 +44,7 @@ module.exports = async ( editorStyle, style, variantVars, + ...customVariantKeys } ) => { slug = slug.toLowerCase(); @@ -100,6 +101,7 @@ module.exports = async ( editorStyle, style, ...variantVars, + customVariantKeys, }; if ( plugin ) { From ed3fe1055ee76375964d77fa4d2ce1dede992751 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Mon, 3 Oct 2022 11:58:56 -0400 Subject: [PATCH 2/7] Introduce customPackageJSON to template to allow customization of the resulting package.json file. --- packages/create-block/lib/init-package-json.js | 2 ++ packages/create-block/lib/scaffold.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/create-block/lib/init-package-json.js b/packages/create-block/lib/init-package-json.js index 06bb170394d01..bbc4436ac1d0e 100644 --- a/packages/create-block/lib/init-package-json.js +++ b/packages/create-block/lib/init-package-json.js @@ -24,6 +24,7 @@ module.exports = async ( { npmDevDependencies, customScripts, isDynamicVariant, + customPackageJSON, } ) => { const cwd = join( process.cwd(), slug ); @@ -58,6 +59,7 @@ module.exports = async ( { ...( wpEnv && { env: 'wp-env' } ), ...customScripts, }, + ...customPackageJSON, } ).filter( ( [ , value ] ) => !! value ) ) ); diff --git a/packages/create-block/lib/scaffold.js b/packages/create-block/lib/scaffold.js index df7fcbe2ce0fd..5e2605ef1a95b 100644 --- a/packages/create-block/lib/scaffold.js +++ b/packages/create-block/lib/scaffold.js @@ -44,6 +44,7 @@ module.exports = async ( editorStyle, style, variantVars, + customPackageJSON, ...customVariantKeys } ) => { @@ -102,6 +103,7 @@ module.exports = async ( style, ...variantVars, customVariantKeys, + customPackageJSON, }; if ( plugin ) { From 014125c54c3ca41a6bd2de68b946b2282fd79d2e Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Mon, 3 Oct 2022 12:17:19 -0400 Subject: [PATCH 3/7] Update changelog. --- packages/create-block/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/create-block/CHANGELOG.md b/packages/create-block/CHANGELOG.md index ff68b2fc54034..2f2fb8ee5cc33 100644 --- a/packages/create-block/CHANGELOG.md +++ b/packages/create-block/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### New Feature + +- Allow passed custom elements from template `defaults` to be added to block.json. Add new `customPackageJSON` key to allow templates to define custom keys for the resulting package.json file. + ## 4.2.0 (2022-09-21) ## 4.0.0 (2022-08-24) From 977c9328b9c4be0d50b33676032f2e698c4431af Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Mon, 3 Oct 2022 12:34:50 -0400 Subject: [PATCH 4/7] Update changelog to include PR reference. --- packages/create-block/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-block/CHANGELOG.md b/packages/create-block/CHANGELOG.md index 2f2fb8ee5cc33..2c9813560ec51 100644 --- a/packages/create-block/CHANGELOG.md +++ b/packages/create-block/CHANGELOG.md @@ -4,7 +4,7 @@ ### New Feature -- Allow passed custom elements from template `defaults` to be added to block.json. Add new `customPackageJSON` key to allow templates to define custom keys for the resulting package.json file. +- Allow passed custom elements from template `defaults` to be added to block.json. Add new `customPackageJSON` key to allow templates to define custom keys for the resulting package.json file.[#44649](https://github.com/WordPress/gutenberg/pull/44649) ## 4.2.0 (2022-09-21) From 7549ca54cf86e7e1e48e811b2674054ee1124759 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Tue, 4 Oct 2022 09:45:43 -0400 Subject: [PATCH 5/7] Provide a dedicated key for customBlockJSON. --- packages/create-block/lib/init-block.js | 4 ++-- packages/create-block/lib/scaffold.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/create-block/lib/init-block.js b/packages/create-block/lib/init-block.js index 5d5b8729181fd..e8a321f85fed7 100644 --- a/packages/create-block/lib/init-block.js +++ b/packages/create-block/lib/init-block.js @@ -29,7 +29,7 @@ async function initBlockJSON( { editorScript, editorStyle, style, - customVariantKeys, + customBlockJSON, } ) { info( '' ); info( 'Creating a "block.json" file.' ); @@ -57,7 +57,7 @@ async function initBlockJSON( { editorScript, editorStyle, style, - ...customVariantKeys, + ...customBlockJSON, } ).filter( ( [ , value ] ) => !! value ) ), null, diff --git a/packages/create-block/lib/scaffold.js b/packages/create-block/lib/scaffold.js index 5e2605ef1a95b..6f57cdb85a393 100644 --- a/packages/create-block/lib/scaffold.js +++ b/packages/create-block/lib/scaffold.js @@ -45,7 +45,7 @@ module.exports = async ( style, variantVars, customPackageJSON, - ...customVariantKeys + customBlockJSON, } ) => { slug = slug.toLowerCase(); @@ -101,9 +101,9 @@ module.exports = async ( editorScript, editorStyle, style, - ...variantVars, - customVariantKeys, customPackageJSON, + customBlockJSON, + ...variantVars, }; if ( plugin ) { From 155d4604a5a4af58af358a277b5e27830d05dd15 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Tue, 4 Oct 2022 09:54:27 -0400 Subject: [PATCH 6/7] Update changelog. --- packages/create-block/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-block/CHANGELOG.md b/packages/create-block/CHANGELOG.md index 2c9813560ec51..585167ad3f38c 100644 --- a/packages/create-block/CHANGELOG.md +++ b/packages/create-block/CHANGELOG.md @@ -4,7 +4,7 @@ ### New Feature -- Allow passed custom elements from template `defaults` to be added to block.json. Add new `customPackageJSON` key to allow templates to define custom keys for the resulting package.json file.[#44649](https://github.com/WordPress/gutenberg/pull/44649) +- Add new `customPackageJSON` and `customBlockJSON` keys to allow templates to define custom keys for the resulting `package.json` and `block.json` files respectively.[#44649](https://github.com/WordPress/gutenberg/pull/44649) ## 4.2.0 (2022-09-21) From 7db6e212347d26a34aefb3ebc0f6e91fe3da83fc Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Wed, 5 Oct 2022 14:38:15 -0400 Subject: [PATCH 7/7] Add docs for new template properties. --- packages/create-block/docs/external-template.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/create-block/docs/external-template.md b/packages/create-block/docs/external-template.md index cb06530ee165a..5eac143a49f1a 100644 --- a/packages/create-block/docs/external-template.md +++ b/packages/create-block/docs/external-template.md @@ -74,6 +74,7 @@ The following configurable variables are used with the template files. Template - `customScripts` (default: {}) – the list of custom scripts to add to `package.json` . It also allows overriding default scripts. - `npmDependencies` (default: `[]`) – the list of remote npm packages to be installed in the project with [`npm install`](https://docs.npmjs.com/cli/v8/commands/npm-install) when `wpScripts` is enabled. - `npmDevDependencies` (default: `[]`) – the list of remote npm packages to be installed in the project with [`npm install --save-dev`](https://docs.npmjs.com/cli/v8/commands/npm-install) when `wpScripts` is enabled. +- `customPackageJSON` (no default) - allows definition of additional properties for the generated package.json file. **Plugin header fields** ([learn more](https://developer.wordpress.org/plugins/plugin-basics/header-requirements/)): @@ -101,3 +102,4 @@ The following configurable variables are used with the template files. Template - `editorScript` (default: `'file:./index.js'`) – an editor script definition. - `editorStyle` (default: `'file:./index.css'`) – an editor style definition. - `style` (default: `'file:./style-index.css'`) – a frontend and editor style definition. +- `customBlockJSON` (no default) - allows definition of additional properties for the generated block.json file.