From 48da1d92f5ffc5ea3369f19498aa3dbab7aed1cc Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Mon, 7 Feb 2022 08:45:20 -0500 Subject: [PATCH] Introduce the `customScripts` property to allow templates to define additional scripts in package.json (#38535) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- packages/create-block/CHANGELOG.md | 3 ++- packages/create-block/README.md | 1 + packages/create-block/lib/init-package-json.js | 2 ++ packages/create-block/lib/scaffold.js | 2 ++ packages/create-block/lib/templates.js | 1 + 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/create-block/CHANGELOG.md b/packages/create-block/CHANGELOG.md index 2ca9b0284dbf28..51e2b1536ad4f7 100644 --- a/packages/create-block/CHANGELOG.md +++ b/packages/create-block/CHANGELOG.md @@ -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) diff --git a/packages/create-block/README.md b/packages/create-block/README.md index 0e46538cf14c40..657826227b5798 100644 --- a/packages/create-block/README.md +++ b/packages/create-block/README.md @@ -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'`) diff --git a/packages/create-block/lib/init-package-json.js b/packages/create-block/lib/init-package-json.js index eea222539a7d1a..2ba4eace09dbf5 100644 --- a/packages/create-block/lib/init-package-json.js +++ b/packages/create-block/lib/init-package-json.js @@ -21,6 +21,7 @@ module.exports = async ( { wpEnv, wpScripts, npmDependencies, + customScripts, } ) => { const cwd = join( process.cwd(), slug ); @@ -48,6 +49,7 @@ module.exports = async ( { start: 'wp-scripts start', } ), ...( wpEnv && { env: 'wp-env' } ), + ...customScripts, }, }, isEmpty diff --git a/packages/create-block/lib/scaffold.js b/packages/create-block/lib/scaffold.js index fcb4012866161b..f751ceed768f49 100644 --- a/packages/create-block/lib/scaffold.js +++ b/packages/create-block/lib/scaffold.js @@ -33,6 +33,7 @@ module.exports = async ( wpScripts, wpEnv, npmDependencies, + customScripts, folderName, editorScript, editorStyle, @@ -67,6 +68,7 @@ module.exports = async ( wpScripts, wpEnv, npmDependencies, + customScripts, folderName, editorScript, editorStyle, diff --git a/packages/create-block/lib/templates.js b/packages/create-block/lib/templates.js index 155a306c033ba2..1887eadf0d5db6 100644 --- a/packages/create-block/lib/templates.js +++ b/packages/create-block/lib/templates.js @@ -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: '.',