Skip to content

Commit

Permalink
Introduce the customScripts property to allow templates to define a…
Browse files Browse the repository at this point in the history
…dditional scripts in package.json (#38535)

* Introduce the customScript property to allow templates to define addtional scripts.

* Include PR references in the changelog file

* Clarify how the new field works for the template

Co-authored-by: Greg Ziółkowski <[email protected]>
  • Loading branch information
ryanwelcher and gziolo authored Feb 7, 2022
1 parent fd73067 commit 48da1d9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/create-block/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

### New Features

- Automatically add a `"env": "wp-env"` entry to scripts when the `--wp-env` is passed or when a template sets `wpEnv` to `true`.
- Automatically add a `"env": "wp-env"` entry to scripts when the `--wp-env` is passed or when a template sets `wpEnv` to `true` ([#38530](https://github.com/WordPress/gutenberg/pull/38530)).
- Introduce the `customScripts` property to allow templates to define additional scripts ([#38535](https://github.com/WordPress/gutenberg/pull/38535)).

## 2.8.0 (2022-01-27)

Expand Down
1 change: 1 addition & 0 deletions packages/create-block/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ The following configurable variables are used with the template files. Template
- `wpScripts` (default: `true`)
- `wpEnv` (default: `false`) - enables integration with the `@wordpress/env` package and adds the `env` command to the package.json.
- `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.
`customScripts` (default: {}) - the list of custom scripts to add to `package.json`. It also allows overriding default scripts.
- `folderName` (default: `.`) – the location for the `block.json` file and other optional block files generated from block templates included in the folder set with the `blockTemplatesPath` setting.
- `editorScript` (default: `'file:./build/index.js'`)
- `editorStyle` (default: `'file:./build/index.css'`)
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 @@ -21,6 +21,7 @@ module.exports = async ( {
wpEnv,
wpScripts,
npmDependencies,
customScripts,
} ) => {
const cwd = join( process.cwd(), slug );

Expand Down Expand Up @@ -48,6 +49,7 @@ module.exports = async ( {
start: 'wp-scripts start',
} ),
...( wpEnv && { env: 'wp-env' } ),
...customScripts,
},
},
isEmpty
Expand Down
2 changes: 2 additions & 0 deletions packages/create-block/lib/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = async (
wpScripts,
wpEnv,
npmDependencies,
customScripts,
folderName,
editorScript,
editorStyle,
Expand Down Expand Up @@ -67,6 +68,7 @@ module.exports = async (
wpScripts,
wpEnv,
npmDependencies,
customScripts,
folderName,
editorScript,
editorStyle,
Expand Down
1 change: 1 addition & 0 deletions packages/create-block/lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ const getDefaultValues = ( pluginTemplate ) => {
licenseURI: 'https://www.gnu.org/licenses/gpl-2.0.html',
version: '0.1.0',
wpScripts: true,
customScripts: {},
wpEnv: false,
npmDependencies: [],
folderName: '.',
Expand Down

0 comments on commit 48da1d9

Please sign in to comment.