Skip to content

Commit

Permalink
[Create Block] Allows custom keys to be generated in block.json files…
Browse files Browse the repository at this point in the history
… and package.json files (#44649)

* Add any custom fields added to template defaults or variants to the block.json file.

* Introduce customPackageJSON to template to allow customization of the resulting package.json file.

* Update changelog.

* Update changelog to include PR reference.

* Provide a dedicated key for customBlockJSON.

* Update changelog.

* Add docs for new template properties.
  • Loading branch information
ryanwelcher authored Oct 7, 2022
1 parent f1ce1ad commit 3b13372
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/create-block/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### New Feature

- 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.3.0 (2022-10-05)

## 4.2.0 (2022-09-21)
Expand Down
2 changes: 2 additions & 0 deletions packages/create-block/docs/external-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)):

Expand Down Expand Up @@ -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.
2 changes: 2 additions & 0 deletions packages/create-block/lib/init-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async function initBlockJSON( {
editorScript,
editorStyle,
style,
customBlockJSON,
} ) {
info( '' );
info( 'Creating a "block.json" file.' );
Expand Down Expand Up @@ -56,6 +57,7 @@ async function initBlockJSON( {
editorScript,
editorStyle,
style,
...customBlockJSON,
} ).filter( ( [ , value ] ) => !! value )
),
null,
Expand Down
2 changes: 2 additions & 0 deletions packages/create-block/lib/init-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = async ( {
npmDevDependencies,
customScripts,
isDynamicVariant,
customPackageJSON,
} ) => {
const cwd = join( process.cwd(), slug );

Expand Down Expand Up @@ -58,6 +59,7 @@ module.exports = async ( {
...( wpEnv && { env: 'wp-env' } ),
...customScripts,
},
...customPackageJSON,
} ).filter( ( [ , value ] ) => !! value )
)
);
Expand Down
4 changes: 4 additions & 0 deletions packages/create-block/lib/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ module.exports = async (
editorStyle,
style,
variantVars,
customPackageJSON,
customBlockJSON,
}
) => {
slug = slug.toLowerCase();
Expand Down Expand Up @@ -99,6 +101,8 @@ module.exports = async (
editorScript,
editorStyle,
style,
customPackageJSON,
customBlockJSON,
...variantVars,
};

Expand Down

0 comments on commit 3b13372

Please sign in to comment.