@wordpress/create-block 2.8.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +75 -52
- package/lib/index.js +55 -14
- package/lib/init-package-json.js +17 -8
- package/lib/prompts.js +36 -12
- package/lib/scaffold.js +19 -7
- package/lib/templates/{esnext/block → block}/edit.js.mustache +0 -0
- package/lib/templates/{esnext/block → block}/editor.scss.mustache +0 -0
- package/lib/templates/{esnext/block → block}/index.js.mustache +0 -1
- package/lib/templates/{esnext/block → block}/save.js.mustache +0 -0
- package/lib/templates/{esnext/block → block}/style.scss.mustache +0 -0
- package/lib/templates/es5/$slug.php.mustache +9 -0
- package/lib/templates/{esnext/plugin → plugin}/$slug.php.mustache +9 -0
- package/lib/templates/{esnext/plugin → plugin}/.editorconfig.mustache +0 -0
- package/lib/templates/{esnext/plugin → plugin}/.gitignore.mustache +0 -0
- package/lib/templates/{esnext/plugin → plugin}/readme.txt.mustache +0 -0
- package/lib/templates.js +35 -23
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 3.0.0 (2022-03-03)
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- It is no longer mandatory to provide the deprecated `templatesPath` option when configuring the custom project template ([#39049](https://github.com/WordPress/gutenberg/pull/39049)).
|
|
10
|
+
- Custom project templates will use default template files during scaffolding for the WordPress plugin shell and/or individual blocks. It is possible to replace them with a custom set of template files by using the `pluginTemplatesPath` and/or `blockTemplatesPath` options ([#39049](https://github.com/WordPress/gutenberg/pull/39049)).
|
|
11
|
+
- The default `esnext` project template got renamed to `static` ([#39049](https://github.com/WordPress/gutenberg/pull/39049)).
|
|
12
|
+
|
|
13
|
+
### New Features
|
|
14
|
+
|
|
15
|
+
- Added CLI prompts for three additional plugin header fields: `Plugin URI`, `Domain Path`, and `Update URI` ([#39096](https://github.com/WordPress/gutenberg/pull/39096)).
|
|
16
|
+
|
|
17
|
+
### Deprecations
|
|
18
|
+
|
|
19
|
+
- To remove confusion when configuring custom project templates, the `templatesPath` option got renamed to `pluginTemplatesPath`. The old name still works but is considered deprecated, and it might get removed in the future ([#39049](https://github.com/WordPress/gutenberg/pull/39049)).
|
|
20
|
+
|
|
21
|
+
### Documentation
|
|
22
|
+
|
|
23
|
+
- Include a missing note on how to create a zip file for a WordPress plugin ([#39049](https://github.com/WordPress/gutenberg/pull/39049))
|
|
24
|
+
|
|
25
|
+
## 2.9.0 (2022-02-10)
|
|
26
|
+
|
|
27
|
+
### New Features
|
|
28
|
+
|
|
29
|
+
- 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)).
|
|
30
|
+
- Introduce the `customScripts` property to allow templates to define additional scripts ([#38535](https://github.com/WordPress/gutenberg/pull/38535)).
|
|
31
|
+
|
|
5
32
|
## 2.8.0 (2022-01-27)
|
|
6
33
|
|
|
7
34
|
### New Features
|
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# Create Block
|
|
2
2
|
|
|
3
|
-
Create Block is an officially supported
|
|
3
|
+
Create Block is an officially supported tool for scaffolding WordPress plugins with blocks. It generates PHP, JS, CSS code, and everything you need to start the project. It integrates a modern build setup with no configuration.
|
|
4
4
|
|
|
5
5
|
It is largely inspired by [create-react-app](https://create-react-app.dev/docs/getting-started). Major kudos to [@gaearon](https://github.com/gaearon), the whole Facebook team, and the React community.
|
|
6
6
|
|
|
7
7
|
## Description
|
|
8
8
|
|
|
9
|
-
Blocks are the fundamental element of the WordPress block editor. They are the primary way in which plugins
|
|
9
|
+
Blocks are the fundamental element of the WordPress block editor. They are the primary way in which plugins can register their functionality and extend the editor's capabilities.
|
|
10
10
|
|
|
11
11
|
Visit the [Gutenberg handbook](https://developer.wordpress.org/block-editor/developers/block-api/block-registration/) to learn more about Block API.
|
|
12
12
|
|
|
13
13
|
## Quick start
|
|
14
14
|
|
|
15
|
-
You
|
|
15
|
+
You only need to provide the `slug` – the target location for scaffolded plugin files and the internal block name.
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
18
|
$ npx @wordpress/create-block todo-list
|
|
@@ -26,7 +26,7 @@ It creates a WordPress plugin that you need to [install manually](https://wordpr
|
|
|
26
26
|
|
|
27
27
|
## Usage
|
|
28
28
|
|
|
29
|
-
The following command generates PHP, JS and CSS code for registering a block.
|
|
29
|
+
The following command generates a project with PHP, JS, and CSS code for registering a block with a WordPress plugin.
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
$ npx @wordpress/create-block [options] [slug]
|
|
@@ -34,16 +34,16 @@ $ npx @wordpress/create-block [options] [slug]
|
|
|
34
34
|
|
|
35
35
|

|
|
36
36
|
|
|
37
|
-
`[slug]` is optional. When provided it triggers the quick mode where it is used as the block slug used for its identification, the output location for scaffolded files, and the name of the WordPress plugin. The rest of the configuration is set to all default values unless overridden with some
|
|
37
|
+
`[slug]` is optional. When provided, it triggers the quick mode where it is used as the block slug used for its identification, the output location for scaffolded files, and the name of the WordPress plugin. The rest of the configuration is set to all default values unless overridden with some options listed below.
|
|
38
38
|
|
|
39
39
|
Options:
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
42
|
-V, --version output the version number
|
|
43
|
-
-t, --template <name>
|
|
43
|
+
-t, --template <name> project template type name; allowed values: "static" (default), "es5", the name of an external npm package, or the path to a local directory
|
|
44
44
|
--namespace <value> internal namespace for the block name
|
|
45
|
-
--title <value> display title for the plugin
|
|
46
|
-
--short-description <value> short description for the plugin
|
|
45
|
+
--title <value> display title for the block and the WordPress plugin
|
|
46
|
+
--short-description <value> short description for the block and the WordPress plugin
|
|
47
47
|
--category <name> category name for the block
|
|
48
48
|
--wp-scripts enable integration with `@wordpress/scripts` package
|
|
49
49
|
--no-wp-scripts disable integration with `@wordpress/scripts` package
|
|
@@ -59,16 +59,16 @@ More examples:
|
|
|
59
59
|
$ npx @wordpress/create-block
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
2.
|
|
62
|
+
2. External npm package – it is also possible to select an external npm package as a template.
|
|
63
63
|
|
|
64
64
|
```bash
|
|
65
|
-
$ npx @wordpress/create-block --template
|
|
65
|
+
$ npx @wordpress/create-block --template my-template-package
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
3. Local template directory – it is also possible to pick a local directory as a template.
|
|
69
69
|
|
|
70
70
|
```bash
|
|
71
|
-
$ npx @wordpress/create-block --template ./path/to/template
|
|
71
|
+
$ npx @wordpress/create-block --template ./path/to/template-directory
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
4. Help – you need to use `npx` to output usage information.
|
|
@@ -77,61 +77,67 @@ $ npx @wordpress/create-block --template ./path/to/template
|
|
|
77
77
|
$ npx @wordpress/create-block --help
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
When you scaffold a block, you must provide at least a `slug` name, the `namespace` which usually corresponds to either the `theme` or `plugin` name
|
|
80
|
+
When you scaffold a block, you must provide at least a `slug` name, the `namespace` which usually corresponds to either the `theme` or `plugin` name. In most cases, we recommended pairing blocks with WordPress plugins rather than themes, because only using plugin ensures that all blocks still work when your theme changes.
|
|
81
81
|
|
|
82
82
|
## Available Commands
|
|
83
83
|
|
|
84
|
-
When bootstrapped with the `
|
|
84
|
+
When bootstrapped with the `static` template (or any other project template with `wpScripts` flag enabled), you can run several commands inside the directory:
|
|
85
85
|
|
|
86
86
|
```bash
|
|
87
87
|
$ npm start
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
Starts the build for development. [Learn more](/packages/scripts#start).
|
|
90
|
+
Starts the build for development. [Learn more](https://github.com/WordPress/gutenberg/tree/HEAD/packages/scripts#start).
|
|
91
91
|
|
|
92
92
|
```bash
|
|
93
93
|
$ npm run build
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
Builds the code for production. [Learn more](/packages/scripts#build).
|
|
96
|
+
Builds the code for production. [Learn more](https://github.com/WordPress/gutenberg/tree/HEAD/packages/scripts#build).
|
|
97
97
|
|
|
98
98
|
```bash
|
|
99
99
|
$ npm run format
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
Formats files. [Learn more](/packages/scripts#format).
|
|
102
|
+
Formats files. [Learn more](https://github.com/WordPress/gutenberg/tree/HEAD/packages/scripts#format).
|
|
103
103
|
|
|
104
104
|
```bash
|
|
105
105
|
$ npm run lint:css
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
-
Lints CSS files. [Learn more](/packages/scripts#lint-style).
|
|
108
|
+
Lints CSS files. [Learn more](https://github.com/WordPress/gutenberg/tree/HEAD/packages/scripts#lint-style).
|
|
109
109
|
|
|
110
110
|
```bash
|
|
111
111
|
$ npm run lint:js
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
Lints JavaScript files. [Learn more](/packages/scripts#lint-js).
|
|
114
|
+
Lints JavaScript files. [Learn more](https://github.com/WordPress/gutenberg/tree/HEAD/packages/scripts#lint-js).
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
$ npm run plugin-zip
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Creates a zip file for a WordPress plugin. [Learn more](https://github.com/WordPress/gutenberg/tree/HEAD/packages/scripts#plugin-zip).
|
|
115
121
|
|
|
116
122
|
```bash
|
|
117
123
|
$ npm run packages-update
|
|
118
124
|
```
|
|
119
125
|
|
|
120
|
-
Updates WordPress packages to the latest version. [Learn more](/packages/scripts#packages-update).
|
|
126
|
+
Updates WordPress packages to the latest version. [Learn more](https://github.com/WordPress/gutenberg/tree/HEAD/packages/scripts#packages-update).
|
|
121
127
|
|
|
122
128
|
_Note: You don’t need to install or configure tools like [webpack](https://webpack.js.org), [Babel](https://babeljs.io) or [ESLint](https://eslint.org) yourself. They are preconfigured and hidden so that you can focus on coding._
|
|
123
129
|
|
|
124
|
-
## External Templates
|
|
130
|
+
## External Project Templates
|
|
125
131
|
|
|
126
|
-
|
|
132
|
+
Are you looking for a way to share your project configuration? Creating an external project template hosted on npm or located in a local directory is possible. These npm packages can provide custom `.mustache` files that replace default files included in the tool for the WordPress plugin or/and the block. It's also possible to override default configuration values used during the scaffolding process.
|
|
127
133
|
|
|
128
|
-
### Template Configuration
|
|
134
|
+
### Project Template Configuration
|
|
129
135
|
|
|
130
|
-
|
|
136
|
+
Providing the main file (`index.js` by default) for the package that returns a configuration object is mandatory. Several options allow customizing the scaffolding process.
|
|
131
137
|
|
|
132
|
-
#### `
|
|
138
|
+
#### `pluginTemplatesPath`
|
|
133
139
|
|
|
134
|
-
|
|
140
|
+
This optional field allows overriding file templates related to **the WordPress plugin shell**. The path points to a location with template files ending with the `.mustache` extension (nested folders are also supported). When not set, the tool uses its own set of templates.
|
|
135
141
|
|
|
136
142
|
_Example:_
|
|
137
143
|
|
|
@@ -139,13 +145,13 @@ _Example:_
|
|
|
139
145
|
const { join } = require( 'path' );
|
|
140
146
|
|
|
141
147
|
module.exports = {
|
|
142
|
-
|
|
148
|
+
pluginTemplatesPath: join( __dirname, 'plugin-templates' ),
|
|
143
149
|
};
|
|
144
150
|
```
|
|
145
151
|
|
|
146
152
|
#### `blockTemplatesPath`
|
|
147
153
|
|
|
148
|
-
|
|
154
|
+
This optional field allows overriding file templates related to **the individual block**. The path points to a location with template files ending with the `.mustache` extension (nested folders are also supported). When not set, the tool uses its own set of templates.
|
|
149
155
|
|
|
150
156
|
_Example:_
|
|
151
157
|
|
|
@@ -159,7 +165,7 @@ module.exports = {
|
|
|
159
165
|
|
|
160
166
|
#### `assetsPath`
|
|
161
167
|
|
|
162
|
-
This setting is useful when your template scaffolds a plugin that uses static assets like images or fonts, which should not be processed. It provides the path pointing to the location where assets are located. They will be copied to the `assets` subfolder in the generated plugin.
|
|
168
|
+
This setting is useful when your template scaffolds a WordPress plugin that uses static assets like images or fonts, which should not be processed. It provides the path pointing to the location where assets are located. They will be copied to the `assets` subfolder in the generated plugin.
|
|
163
169
|
|
|
164
170
|
_Example:_
|
|
165
171
|
|
|
@@ -185,32 +191,49 @@ module.exports = {
|
|
|
185
191
|
dashicon: 'palmtree',
|
|
186
192
|
version: '1.2.3',
|
|
187
193
|
},
|
|
188
|
-
templatesPath: __dirname,
|
|
189
194
|
};
|
|
190
195
|
```
|
|
191
196
|
|
|
192
|
-
The following configurable variables are used with the template files. Template authors can change default values to use when users don't provide their data
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
- `
|
|
197
|
-
- `
|
|
198
|
-
- `
|
|
199
|
-
- `description` (no default) - a short description for your block.
|
|
200
|
-
- `dashicon` (no default) - an icon property thats makes it easier to identify a block, see https://developer.wordpress.org/resource/dashicons/.
|
|
201
|
-
- `category` (default: `'widgets'`) - blocks are grouped into categories to help users browse and discover them. The categories provided by core are `text`, `media`, `design`, `widgets`, `theme`, and `embed`.
|
|
202
|
-
- `attributes` (no default) - see https://developer.wordpress.org/block-editor/developers/block-api/block-attributes/.
|
|
203
|
-
- `supports` (no default) - optional block extended support features, see https://developer.wordpress.org/block-editor/developers/block-api/block-supports/.
|
|
204
|
-
- `author` (default: `'The WordPress Contributors'`)
|
|
205
|
-
- `license` (default: `'GPL-2.0-or-later'`)
|
|
206
|
-
- `licenseURI` (default: `'https://www.gnu.org/licenses/gpl-2.0.html'`)
|
|
207
|
-
- `version` (default: `'0.1.0'`)
|
|
208
|
-
- `wpScripts` (default: `true`)
|
|
209
|
-
- `wpEnv` (default: `false`)
|
|
197
|
+
The following configurable variables are used with the template files. Template authors can change default values to use when users don't provide their data.
|
|
198
|
+
|
|
199
|
+
**Project**:
|
|
200
|
+
|
|
201
|
+
- `wpScripts` (default: `true`) – enables integration with the `@wordpress/scripts` package and adds common scripts to the `package.json`.
|
|
202
|
+
- `wpEnv` (default: `false`) – enables integration with the `@wordpress/env` package and adds the `env` script to the `package.json`.
|
|
203
|
+
- `customScripts` (default: {}) – the list of custom scripts to add to `package.json` . It also allows overriding default scripts.
|
|
210
204
|
- `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.
|
|
211
|
-
- `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.
|
|
212
|
-
- `editorScript` (default: `'file:./build/index.js'`)
|
|
213
|
-
- `editorStyle` (default: `'file:./build/index.css'`)
|
|
214
|
-
- `style` (default: `'file:./build/style-index.css'`)
|
|
215
205
|
|
|
216
|
-
|
|
206
|
+
**Plugin header fields** ([learn more](https://developer.wordpress.org/plugins/plugin-basics/header-requirements/)):
|
|
207
|
+
|
|
208
|
+
- `pluginURI` (no default) – the home page of the plugin.
|
|
209
|
+
- `version` (default: `'0.1.0'`) – the current version number of the plugin.
|
|
210
|
+
- `author` (default: `'The WordPress Contributors'`) – the name of the plugin author(s).
|
|
211
|
+
- `license` (default: `'GPL-2.0-or-later'`) – the short name of the plugin’s license.
|
|
212
|
+
- `licenseURI` (default: `'https://www.gnu.org/licenses/gpl-2.0.html'`) – a link to the full text of the license.
|
|
213
|
+
- `domainPath` (no default) – a custom domain path for the translations ([more info](https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#domain-path)).
|
|
214
|
+
- `updateURI:` (no default) – a custom update URI for the plugin ([related dev note](https://make.wordpress.org/core/2021/06/29/introducing-update-uri-plugin-header-in-wordpress-5-8/)).
|
|
215
|
+
|
|
216
|
+
**Block metadata** ([learn more](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/)):
|
|
217
|
+
|
|
218
|
+
- `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.
|
|
219
|
+
- `$schema` (default: `https://schemas.wp.org/trunk/block.json`) – the schema URL used for block validation.
|
|
220
|
+
- `apiVersion` (default: `2`) – the block API version ([related dev note](https://make.wordpress.org/core/2020/11/18/block-api-version-2/)).
|
|
221
|
+
- `slug` (no default) – the block slug used for identification in the block name.
|
|
222
|
+
- `namespace` (default: `'create-block'`) – the internal namespace for the block name.
|
|
223
|
+
- `title` (no default) – a display title for your block.
|
|
224
|
+
- `description` (no default) – a short description for your block.
|
|
225
|
+
- `dashicon` (no default) – an icon property thats makes it easier to identify a block ([available values](https://developer.wordpress.org/resource/dashicons/)).
|
|
226
|
+
- `category` (default: `'widgets'`) – blocks are grouped into categories to help users browse and discover them. The categories provided by core are `text`, `media`, `design`, `widgets`, `theme`, and `embed`.
|
|
227
|
+
- `attributes` (no default) – block attributes ([more details](https://developer.wordpress.org/block-editor/developers/block-api/block-attributes/)).
|
|
228
|
+
- `supports` (no default) – optional block extended support features ([more details](https://developer.wordpress.org/block-editor/developers/block-api/block-supports/).
|
|
229
|
+
- `editorScript` (default: `'file:./index.js'`) – an editor script definition.
|
|
230
|
+
- `editorStyle` (default: `'file:./index.css'`) – an editor style definition.
|
|
231
|
+
- `style` (default: `'file:./style-index.css'`) – a frontend and editor style definition.
|
|
232
|
+
|
|
233
|
+
## Contributing to this package
|
|
234
|
+
|
|
235
|
+
This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
|
|
236
|
+
|
|
237
|
+
To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md).
|
|
238
|
+
|
|
239
|
+
<br /><br /><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
|
package/lib/index.js
CHANGED
|
@@ -23,26 +23,29 @@ const commandName = `wp-create-block`;
|
|
|
23
23
|
program
|
|
24
24
|
.name( commandName )
|
|
25
25
|
.description(
|
|
26
|
-
'Generates PHP, JS and CSS code for registering a
|
|
27
|
-
'[slug] is optional. When provided it triggers the quick mode where ' +
|
|
26
|
+
'Generates PHP, JS and CSS code for registering a WordPress plugin with blocks.\n\n' +
|
|
27
|
+
'[slug] is optional. When provided, it triggers the quick mode where ' +
|
|
28
28
|
'it is used as the block slug used for its identification, the output ' +
|
|
29
29
|
'location for scaffolded files, and the name of the WordPress plugin.' +
|
|
30
30
|
'The rest of the configuration is set to all default values unless ' +
|
|
31
|
-
'overridden with some
|
|
31
|
+
'overridden with some options listed below.'
|
|
32
32
|
)
|
|
33
33
|
.version( version )
|
|
34
34
|
.arguments( '[slug]' )
|
|
35
35
|
.option(
|
|
36
36
|
'-t, --template <name>',
|
|
37
|
-
'
|
|
38
|
-
'
|
|
37
|
+
'project template type name; allowed values: "static", "es5", the name of an external npm package, or the path to a local directory',
|
|
38
|
+
'static'
|
|
39
39
|
)
|
|
40
40
|
.option( '--namespace <value>', 'internal namespace for the block name' )
|
|
41
|
-
.option(
|
|
41
|
+
.option(
|
|
42
|
+
'--title <value>',
|
|
43
|
+
'display title for the block and the WordPress plugin'
|
|
44
|
+
)
|
|
42
45
|
// The name "description" is used internally so it couldn't be used.
|
|
43
46
|
.option(
|
|
44
47
|
'--short-description <value>',
|
|
45
|
-
'short description for the plugin
|
|
48
|
+
'short description for the block and the WordPress plugin'
|
|
46
49
|
)
|
|
47
50
|
.option( '--category <name>', 'category name for the block' )
|
|
48
51
|
.option(
|
|
@@ -93,17 +96,55 @@ program
|
|
|
93
96
|
};
|
|
94
97
|
await scaffold( pluginTemplate, answers );
|
|
95
98
|
} else {
|
|
96
|
-
const prompts = getPrompts( pluginTemplate ).filter(
|
|
97
|
-
( { name } ) =>
|
|
98
|
-
! Object.keys( optionsValues ).includes( name )
|
|
99
|
-
);
|
|
100
99
|
log.info( '' );
|
|
101
|
-
log.info(
|
|
102
|
-
|
|
100
|
+
log.info(
|
|
101
|
+
"Let's customize your WordPress plugin with blocks:"
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const filterOptionsProvided = ( { name } ) =>
|
|
105
|
+
! Object.keys( optionsValues ).includes( name );
|
|
106
|
+
const blockPrompts = getPrompts( pluginTemplate, [
|
|
107
|
+
'slug',
|
|
108
|
+
'namespace',
|
|
109
|
+
'title',
|
|
110
|
+
'description',
|
|
111
|
+
'dashicon',
|
|
112
|
+
'category',
|
|
113
|
+
] ).filter( filterOptionsProvided );
|
|
114
|
+
const blockAnswers = await inquirer.prompt( blockPrompts );
|
|
115
|
+
|
|
116
|
+
const pluginAnswers = await inquirer
|
|
117
|
+
.prompt( {
|
|
118
|
+
type: 'confirm',
|
|
119
|
+
name: 'configurePlugin',
|
|
120
|
+
message:
|
|
121
|
+
'Do you want to customize the WordPress plugin?',
|
|
122
|
+
default: false,
|
|
123
|
+
} )
|
|
124
|
+
.then( async ( { configurePlugin } ) => {
|
|
125
|
+
if ( ! configurePlugin ) {
|
|
126
|
+
return {};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const pluginPrompts = getPrompts( pluginTemplate, [
|
|
130
|
+
'pluginURI',
|
|
131
|
+
'version',
|
|
132
|
+
'author',
|
|
133
|
+
'license',
|
|
134
|
+
'licenseURI',
|
|
135
|
+
'domainPath',
|
|
136
|
+
'updateURI',
|
|
137
|
+
] ).filter( filterOptionsProvided );
|
|
138
|
+
const result = await inquirer.prompt(
|
|
139
|
+
pluginPrompts
|
|
140
|
+
);
|
|
141
|
+
return result;
|
|
142
|
+
} );
|
|
103
143
|
await scaffold( pluginTemplate, {
|
|
104
144
|
...defaultValues,
|
|
105
145
|
...optionsValues,
|
|
106
|
-
...
|
|
146
|
+
...blockAnswers,
|
|
147
|
+
...pluginAnswers,
|
|
107
148
|
} );
|
|
108
149
|
}
|
|
109
150
|
} catch ( error ) {
|
package/lib/init-package-json.js
CHANGED
|
@@ -16,15 +16,19 @@ module.exports = async ( {
|
|
|
16
16
|
author,
|
|
17
17
|
description,
|
|
18
18
|
license,
|
|
19
|
+
pluginURI,
|
|
19
20
|
slug,
|
|
20
21
|
version,
|
|
22
|
+
wpEnv,
|
|
21
23
|
wpScripts,
|
|
22
24
|
npmDependencies,
|
|
25
|
+
customScripts,
|
|
23
26
|
} ) => {
|
|
24
27
|
const cwd = join( process.cwd(), slug );
|
|
25
28
|
|
|
26
29
|
info( '' );
|
|
27
30
|
info( 'Creating a "package.json" file.' );
|
|
31
|
+
|
|
28
32
|
await writePkg(
|
|
29
33
|
cwd,
|
|
30
34
|
omitBy(
|
|
@@ -34,15 +38,20 @@ module.exports = async ( {
|
|
|
34
38
|
description,
|
|
35
39
|
author,
|
|
36
40
|
license,
|
|
41
|
+
homepage: pluginURI,
|
|
37
42
|
main: wpScripts && 'build/index.js',
|
|
38
|
-
scripts:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
scripts: {
|
|
44
|
+
...( wpScripts && {
|
|
45
|
+
build: 'wp-scripts build',
|
|
46
|
+
format: 'wp-scripts format',
|
|
47
|
+
'lint:css': 'wp-scripts lint-style',
|
|
48
|
+
'lint:js': 'wp-scripts lint-js',
|
|
49
|
+
'packages-update': 'wp-scripts packages-update',
|
|
50
|
+
'plugin-zip': 'wp-scripts plugin-zip',
|
|
51
|
+
start: 'wp-scripts start',
|
|
52
|
+
} ),
|
|
53
|
+
...( wpEnv && { env: 'wp-env' } ),
|
|
54
|
+
...customScripts,
|
|
46
55
|
},
|
|
47
56
|
},
|
|
48
57
|
isEmpty
|
package/lib/prompts.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
const { isEmpty, upperFirst } = require( 'lodash' );
|
|
5
5
|
|
|
6
|
+
// Block metadata.
|
|
6
7
|
const slug = {
|
|
7
8
|
type: 'input',
|
|
8
9
|
name: 'slug',
|
|
@@ -73,6 +74,29 @@ const category = {
|
|
|
73
74
|
choices: [ 'text', 'media', 'design', 'widgets', 'theme', 'embed' ],
|
|
74
75
|
};
|
|
75
76
|
|
|
77
|
+
// Plugin header fields.
|
|
78
|
+
const pluginURI = {
|
|
79
|
+
type: 'input',
|
|
80
|
+
name: 'pluginURI',
|
|
81
|
+
message:
|
|
82
|
+
'The home page of the plugin (optional). Unique URL outside of WordPress.org:',
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const version = {
|
|
86
|
+
type: 'input',
|
|
87
|
+
name: 'version',
|
|
88
|
+
message: 'The current version number of the plugin:',
|
|
89
|
+
validate( input ) {
|
|
90
|
+
// Regular expression was copied from https://semver.org.
|
|
91
|
+
const validSemVerPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
92
|
+
if ( ! validSemVerPattern.test( input ) ) {
|
|
93
|
+
return 'Invalid Semantic Version provided. Visit https://regex101.com/r/vkijKf/1/ to discover all valid patterns.';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return true;
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
76
100
|
const author = {
|
|
77
101
|
type: 'input',
|
|
78
102
|
name: 'author',
|
|
@@ -92,19 +116,16 @@ const licenseURI = {
|
|
|
92
116
|
message: 'A link to the full text of the license (optional):',
|
|
93
117
|
};
|
|
94
118
|
|
|
95
|
-
const
|
|
119
|
+
const domainPath = {
|
|
96
120
|
type: 'input',
|
|
97
|
-
name: '
|
|
98
|
-
message: '
|
|
99
|
-
|
|
100
|
-
// Regular expression was copied from https://semver.org.
|
|
101
|
-
const validSemVerPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
102
|
-
if ( ! validSemVerPattern.test( input ) ) {
|
|
103
|
-
return 'Invalid Semantic Version provided. Visit https://regex101.com/r/vkijKf/1/ to discover all valid patterns.';
|
|
104
|
-
}
|
|
121
|
+
name: 'domainPath',
|
|
122
|
+
message: 'A custom domain path for the translations (optional):',
|
|
123
|
+
};
|
|
105
124
|
|
|
106
|
-
|
|
107
|
-
|
|
125
|
+
const updateURI = {
|
|
126
|
+
type: 'input',
|
|
127
|
+
name: 'updateURI',
|
|
128
|
+
message: 'A custom update URI for the plugin (optional):',
|
|
108
129
|
};
|
|
109
130
|
|
|
110
131
|
module.exports = {
|
|
@@ -114,8 +135,11 @@ module.exports = {
|
|
|
114
135
|
description,
|
|
115
136
|
dashicon,
|
|
116
137
|
category,
|
|
138
|
+
pluginURI,
|
|
139
|
+
version,
|
|
117
140
|
author,
|
|
118
141
|
license,
|
|
119
142
|
licenseURI,
|
|
120
|
-
|
|
143
|
+
domainPath,
|
|
144
|
+
updateURI,
|
|
121
145
|
};
|
package/lib/scaffold.js
CHANGED
|
@@ -14,7 +14,7 @@ const { code, info, success } = require( './log' );
|
|
|
14
14
|
const { writeOutputAsset, writeOutputTemplate } = require( './output' );
|
|
15
15
|
|
|
16
16
|
module.exports = async (
|
|
17
|
-
{ blockOutputTemplates,
|
|
17
|
+
{ blockOutputTemplates, pluginOutputTemplates, outputAssets },
|
|
18
18
|
{
|
|
19
19
|
$schema,
|
|
20
20
|
apiVersion,
|
|
@@ -27,12 +27,16 @@ module.exports = async (
|
|
|
27
27
|
attributes,
|
|
28
28
|
supports,
|
|
29
29
|
author,
|
|
30
|
+
pluginURI,
|
|
30
31
|
license,
|
|
31
32
|
licenseURI,
|
|
33
|
+
domainPath,
|
|
34
|
+
updateURI,
|
|
32
35
|
version,
|
|
33
36
|
wpScripts,
|
|
34
37
|
wpEnv,
|
|
35
38
|
npmDependencies,
|
|
39
|
+
customScripts,
|
|
36
40
|
folderName,
|
|
37
41
|
editorScript,
|
|
38
42
|
editorStyle,
|
|
@@ -43,7 +47,7 @@ module.exports = async (
|
|
|
43
47
|
namespace = namespace.toLowerCase();
|
|
44
48
|
|
|
45
49
|
info( '' );
|
|
46
|
-
info( `Creating a new WordPress plugin in "${ slug }"
|
|
50
|
+
info( `Creating a new WordPress plugin in the "${ slug }" directory.` );
|
|
47
51
|
|
|
48
52
|
const view = {
|
|
49
53
|
$schema,
|
|
@@ -61,11 +65,16 @@ module.exports = async (
|
|
|
61
65
|
supports,
|
|
62
66
|
version,
|
|
63
67
|
author,
|
|
68
|
+
pluginURI,
|
|
64
69
|
license,
|
|
65
70
|
licenseURI,
|
|
66
71
|
textdomain: slug,
|
|
72
|
+
domainPath,
|
|
73
|
+
updateURI,
|
|
67
74
|
wpScripts,
|
|
75
|
+
wpEnv,
|
|
68
76
|
npmDependencies,
|
|
77
|
+
customScripts,
|
|
69
78
|
folderName,
|
|
70
79
|
editorScript,
|
|
71
80
|
editorStyle,
|
|
@@ -73,10 +82,10 @@ module.exports = async (
|
|
|
73
82
|
};
|
|
74
83
|
|
|
75
84
|
await Promise.all(
|
|
76
|
-
Object.keys(
|
|
85
|
+
Object.keys( pluginOutputTemplates ).map(
|
|
77
86
|
async ( outputFile ) =>
|
|
78
87
|
await writeOutputTemplate(
|
|
79
|
-
|
|
88
|
+
pluginOutputTemplates[ outputFile ],
|
|
80
89
|
outputFile,
|
|
81
90
|
view
|
|
82
91
|
)
|
|
@@ -108,11 +117,11 @@ module.exports = async (
|
|
|
108
117
|
|
|
109
118
|
info( '' );
|
|
110
119
|
success(
|
|
111
|
-
`Done:
|
|
120
|
+
`Done: WordPress plugin "${ title }" bootstrapped in the "${ slug }" directory.`
|
|
112
121
|
);
|
|
113
122
|
if ( wpScripts ) {
|
|
114
123
|
info( '' );
|
|
115
|
-
info( '
|
|
124
|
+
info( 'You can run several commands inside:' );
|
|
116
125
|
info( '' );
|
|
117
126
|
code( ' $ npm start' );
|
|
118
127
|
info( ' Starts the build for development.' );
|
|
@@ -129,11 +138,14 @@ module.exports = async (
|
|
|
129
138
|
code( ' $ npm run lint:js' );
|
|
130
139
|
info( ' Lints JavaScript files.' );
|
|
131
140
|
info( '' );
|
|
141
|
+
code( ' $ npm run plugin-zip' );
|
|
142
|
+
info( ' Creates a zip file for a WordPress plugin.' );
|
|
143
|
+
info( '' );
|
|
132
144
|
code( ' $ npm run packages-update' );
|
|
133
145
|
info( ' Updates WordPress packages to the latest version.' );
|
|
134
146
|
}
|
|
135
147
|
info( '' );
|
|
136
|
-
info( 'To enter the
|
|
148
|
+
info( 'To enter the directory type:' );
|
|
137
149
|
info( '' );
|
|
138
150
|
code( ` $ cd ${ slug }` );
|
|
139
151
|
if ( wpScripts ) {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
/**
|
|
3
3
|
* Plugin Name: {{title}}
|
|
4
|
+
{{#pluginURI}}
|
|
5
|
+
* Plugin URI: {{{pluginURI}}}
|
|
6
|
+
{{/pluginURI}}
|
|
4
7
|
{{#description}}
|
|
5
8
|
* Description: {{description}}
|
|
6
9
|
{{/description}}
|
|
@@ -17,6 +20,12 @@
|
|
|
17
20
|
* License URI: {{{licenseURI}}}
|
|
18
21
|
{{/licenseURI}}
|
|
19
22
|
* Text Domain: {{textdomain}}
|
|
23
|
+
{{#domainPath}}
|
|
24
|
+
* Domain Path: {{{domainPath}}}
|
|
25
|
+
{{/domainPath}}
|
|
26
|
+
{{#updateURI}}
|
|
27
|
+
* Update URI: {{{updateURI}}}
|
|
28
|
+
{{/updateURI}}
|
|
20
29
|
*
|
|
21
30
|
* @package {{namespace}}
|
|
22
31
|
*/
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
/**
|
|
3
3
|
* Plugin Name: {{title}}
|
|
4
|
+
{{#pluginURI}}
|
|
5
|
+
* Plugin URI: {{{pluginURI}}}
|
|
6
|
+
{{/pluginURI}}
|
|
4
7
|
{{#description}}
|
|
5
8
|
* Description: {{description}}
|
|
6
9
|
{{/description}}
|
|
@@ -17,6 +20,12 @@
|
|
|
17
20
|
* License URI: {{{licenseURI}}}
|
|
18
21
|
{{/licenseURI}}
|
|
19
22
|
* Text Domain: {{textdomain}}
|
|
23
|
+
{{#domainPath}}
|
|
24
|
+
* Domain Path: {{{domainPath}}}
|
|
25
|
+
{{/domainPath}}
|
|
26
|
+
{{#updateURI}}
|
|
27
|
+
* Update URI: {{{updateURI}}}
|
|
28
|
+
{{/updateURI}}
|
|
20
29
|
*
|
|
21
30
|
* @package {{namespace}}
|
|
22
31
|
*/
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/templates.js
CHANGED
|
@@ -22,10 +22,10 @@ const prompts = require( './prompts' );
|
|
|
22
22
|
const predefinedPluginTemplates = {
|
|
23
23
|
es5: {
|
|
24
24
|
defaultValues: {
|
|
25
|
-
slug: 'es5
|
|
26
|
-
title: 'ES5
|
|
25
|
+
slug: 'example-static-es5',
|
|
26
|
+
title: 'Example Static (ES5)',
|
|
27
27
|
description:
|
|
28
|
-
'Example block
|
|
28
|
+
'Example static block scaffolded with Create Block tool – no build step required.',
|
|
29
29
|
dashicon: 'smiley',
|
|
30
30
|
wpScripts: false,
|
|
31
31
|
editorScript: 'file:./index.js',
|
|
@@ -34,23 +34,17 @@ const predefinedPluginTemplates = {
|
|
|
34
34
|
},
|
|
35
35
|
templatesPath: join( __dirname, 'templates', 'es5' ),
|
|
36
36
|
},
|
|
37
|
-
|
|
37
|
+
static: {
|
|
38
38
|
defaultValues: {
|
|
39
|
-
slug: '
|
|
40
|
-
title: '
|
|
39
|
+
slug: 'example-static',
|
|
40
|
+
title: 'Example Static',
|
|
41
41
|
description:
|
|
42
|
-
'Example block
|
|
42
|
+
'Example static block scaffolded with Create Block tool.',
|
|
43
43
|
dashicon: 'smiley',
|
|
44
44
|
supports: {
|
|
45
45
|
html: false,
|
|
46
46
|
},
|
|
47
|
-
folderName: 'src',
|
|
48
|
-
editorScript: 'file:./index.js',
|
|
49
|
-
editorStyle: 'file:./index.css',
|
|
50
|
-
style: 'file:./style-index.css',
|
|
51
47
|
},
|
|
52
|
-
templatesPath: join( __dirname, 'templates', 'esnext', 'plugin' ),
|
|
53
|
-
blockTemplatesPath: join( __dirname, 'templates', 'esnext', 'block' ),
|
|
54
48
|
},
|
|
55
49
|
};
|
|
56
50
|
|
|
@@ -103,22 +97,39 @@ const externalTemplateExists = async ( templateName ) => {
|
|
|
103
97
|
};
|
|
104
98
|
|
|
105
99
|
const configToTemplate = async ( {
|
|
106
|
-
|
|
100
|
+
pluginTemplatesPath,
|
|
107
101
|
blockTemplatesPath,
|
|
108
102
|
defaultValues = {},
|
|
109
|
-
|
|
103
|
+
assetsPath,
|
|
104
|
+
...deprecated
|
|
110
105
|
} ) => {
|
|
111
|
-
if ( ! isObject( defaultValues )
|
|
106
|
+
if ( ! isObject( defaultValues ) ) {
|
|
112
107
|
throw new CLIError( 'Template found but invalid definition provided.' );
|
|
113
108
|
}
|
|
114
109
|
|
|
110
|
+
if ( deprecated.templatesPath ) {
|
|
111
|
+
pluginTemplatesPath = deprecated.templatesPath;
|
|
112
|
+
defaultValues = {
|
|
113
|
+
folderName: '.',
|
|
114
|
+
editorScript: 'file:./build/index.js',
|
|
115
|
+
editorStyle: 'file:./build/index.css',
|
|
116
|
+
style: 'file:./build/style-index.css',
|
|
117
|
+
...defaultValues,
|
|
118
|
+
};
|
|
119
|
+
} else {
|
|
120
|
+
pluginTemplatesPath =
|
|
121
|
+
pluginTemplatesPath || join( __dirname, 'templates', 'plugin' );
|
|
122
|
+
blockTemplatesPath =
|
|
123
|
+
blockTemplatesPath || join( __dirname, 'templates', 'block' );
|
|
124
|
+
}
|
|
125
|
+
|
|
115
126
|
return {
|
|
116
127
|
blockOutputTemplates: blockTemplatesPath
|
|
117
128
|
? await getOutputTemplates( blockTemplatesPath )
|
|
118
129
|
: {},
|
|
119
130
|
defaultValues,
|
|
120
131
|
outputAssets: assetsPath ? await getOutputAssets( assetsPath ) : {},
|
|
121
|
-
|
|
132
|
+
pluginOutputTemplates: await getOutputTemplates( pluginTemplatesPath ),
|
|
122
133
|
};
|
|
123
134
|
};
|
|
124
135
|
|
|
@@ -198,19 +209,20 @@ const getDefaultValues = ( pluginTemplate ) => {
|
|
|
198
209
|
licenseURI: 'https://www.gnu.org/licenses/gpl-2.0.html',
|
|
199
210
|
version: '0.1.0',
|
|
200
211
|
wpScripts: true,
|
|
212
|
+
customScripts: {},
|
|
201
213
|
wpEnv: false,
|
|
202
214
|
npmDependencies: [],
|
|
203
|
-
folderName: '
|
|
204
|
-
editorScript: 'file:./
|
|
205
|
-
editorStyle: 'file:./
|
|
206
|
-
style: 'file:./
|
|
215
|
+
folderName: './src',
|
|
216
|
+
editorScript: 'file:./index.js',
|
|
217
|
+
editorStyle: 'file:./index.css',
|
|
218
|
+
style: 'file:./style-index.css',
|
|
207
219
|
...pluginTemplate.defaultValues,
|
|
208
220
|
};
|
|
209
221
|
};
|
|
210
222
|
|
|
211
|
-
const getPrompts = ( pluginTemplate ) => {
|
|
223
|
+
const getPrompts = ( pluginTemplate, keys ) => {
|
|
212
224
|
const defaultValues = getDefaultValues( pluginTemplate );
|
|
213
|
-
return
|
|
225
|
+
return keys.map( ( promptName ) => {
|
|
214
226
|
return {
|
|
215
227
|
...prompts[ promptName ],
|
|
216
228
|
default: defaultValues[ promptName ],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/create-block",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Generates PHP, JS and CSS code for registering a block for a WordPress plugin.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"wp-create-block": "./index.js"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@wordpress/lazy-import": "^1.4.
|
|
34
|
+
"@wordpress/lazy-import": "^1.4.1",
|
|
35
35
|
"chalk": "^4.0.0",
|
|
36
36
|
"check-node-version": "^4.1.0",
|
|
37
37
|
"commander": "^4.1.0",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "bc1ccad6698ada7ea0096df8e55a188fcd3a1a26"
|
|
52
52
|
}
|