Skip to content

Commit

Permalink
Adding the "env" script when --wp-env or wpEnv is present. (#38530)
Browse files Browse the repository at this point in the history
* Adding the env script when --wp-env wpEnv is used.

* Update docs to reference adding the `env` command.

* Fixes issues where not having flag will add "env" : false.

* Build out the scripts so that wpEnv and wpScripts are independently added.

* Update changelog.

* Fix grammar.

* Update packages/create-block/CHANGELOG.md

Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>

Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>
  • Loading branch information
ryanwelcher and gziolo authored Feb 4, 2022
1 parent ea79ef6 commit e9f8e41
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 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 Features

- Automatically add a `"env": "wp-env"` entry to scripts when the `--wp-env` is passed or when a template sets `wpEnv` to `true`.

## 2.8.0 (2022-01-27)

### New Features
Expand Down
2 changes: 1 addition & 1 deletion packages/create-block/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ The following configurable variables are used with the template files. Template
- `licenseURI` (default: `'https://www.gnu.org/licenses/gpl-2.0.html'`)
- `version` (default: `'0.1.0'`)
- `wpScripts` (default: `true`)
- `wpEnv` (default: `false`)
- `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.
- `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'`)
Expand Down
21 changes: 13 additions & 8 deletions packages/create-block/lib/init-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ module.exports = async ( {
license,
slug,
version,
wpEnv,
wpScripts,
npmDependencies,
} ) => {
const cwd = join( process.cwd(), slug );

info( '' );
info( 'Creating a "package.json" file.' );

await writePkg(
cwd,
omitBy(
Expand All @@ -35,14 +37,17 @@ module.exports = async ( {
author,
license,
main: wpScripts && 'build/index.js',
scripts: wpScripts && {
build: 'wp-scripts build',
format: 'wp-scripts format',
'lint:css': 'wp-scripts lint-style',
'lint:js': 'wp-scripts lint-js',
'packages-update': 'wp-scripts packages-update',
'plugin-zip': 'wp-scripts plugin-zip',
start: 'wp-scripts start',
scripts: {
...( wpScripts && {
build: 'wp-scripts build',
format: 'wp-scripts format',
'lint:css': 'wp-scripts lint-style',
'lint:js': 'wp-scripts lint-js',
'packages-update': 'wp-scripts packages-update',
'plugin-zip': 'wp-scripts plugin-zip',
start: 'wp-scripts start',
} ),
...( wpEnv && { env: 'wp-env' } ),
},
},
isEmpty
Expand Down
1 change: 1 addition & 0 deletions packages/create-block/lib/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module.exports = async (
licenseURI,
textdomain: slug,
wpScripts,
wpEnv,
npmDependencies,
folderName,
editorScript,
Expand Down

0 comments on commit e9f8e41

Please sign in to comment.