Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Create Block] Allows custom keys to be generated in block.json files and package.json files #44649

Merged
merged 10 commits into from
Oct 7, 2022
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.
Copy link
Member

@gziolo gziolo Oct 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a bit of overlap with customScripts, npmDependencies, and npmDevDependencies. It doesn’t have to be a bad thing as we would have to put special care to handle them in a similar way through customPackageJSON. I’m mostly noticing here that this new option might override all other settings.

Copy link
Contributor Author

@ryanwelcher ryanwelcher Oct 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I wonder if we just filter those keys out of customPackageJSON before adding it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn’t a blocker. We can look into it once it starts to confuse people.


**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