@wordpress/create-block 2.6.0 → 2.9.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 +31 -0
- package/LICENSE.md +1 -1
- package/README.md +40 -17
- package/lib/index.js +13 -10
- package/lib/{init-block-json.js → init-block.js} +26 -4
- package/lib/init-package-json.js +16 -8
- package/lib/output.js +28 -0
- package/lib/scaffold.js +30 -26
- package/lib/templates/es5/$slug.php.mustache +1 -1
- package/lib/templates/es5/readme.txt.mustache +1 -1
- package/lib/templates/esnext/{src → block}/edit.js.mustache +0 -0
- package/lib/templates/esnext/{src → block}/editor.scss.mustache +0 -0
- package/lib/templates/esnext/{src → block}/index.js.mustache +0 -0
- package/lib/templates/esnext/{src → block}/save.js.mustache +0 -0
- package/lib/templates/esnext/{src → block}/style.scss.mustache +0 -0
- package/lib/templates/esnext/{$slug.php.mustache → plugin/$slug.php.mustache} +2 -2
- package/lib/templates/esnext/{.editorconfig.mustache → plugin/.editorconfig.mustache} +0 -0
- package/lib/templates/esnext/{.gitignore.mustache → plugin/.gitignore.mustache} +4 -1
- package/lib/templates/esnext/{readme.txt.mustache → plugin/readme.txt.mustache} +1 -1
- package/lib/templates.js +25 -18
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,9 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 2.9.0 (2022-02-10)
|
|
6
|
+
|
|
7
|
+
### New Features
|
|
8
|
+
|
|
9
|
+
- 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)).
|
|
10
|
+
- Introduce the `customScripts` property to allow templates to define additional scripts ([#38535](https://github.com/WordPress/gutenberg/pull/38535)).
|
|
11
|
+
|
|
12
|
+
## 2.8.0 (2022-01-27)
|
|
13
|
+
|
|
14
|
+
### New Features
|
|
15
|
+
|
|
16
|
+
- Integrated a new `plugin-zip` command to create a zip file for a WordPress plugin ([#37687](https://github.com/WordPress/gutenberg/pull/37687)).
|
|
17
|
+
- Add support for handling block templates with the `blockTemplatesPath` field in the external template configuration ([#37612](https://github.com/WordPress/gutenberg/pull/37612)).
|
|
18
|
+
- Add a new field `folderName` for setting 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 ([#37612](https://github.com/WordPress/gutenberg/pull/37612)).
|
|
19
|
+
|
|
20
|
+
### Enhancement
|
|
21
|
+
|
|
22
|
+
- Speed up scaffolding process by omitting WordPress dependencies in the template ([#37639](https://github.com/WordPress/gutenberg/pull/37639)).
|
|
23
|
+
- Update link to block registration reference ([#37674](https://github.com/WordPress/gutenberg/pull/37674))
|
|
24
|
+
|
|
25
|
+
### Internal
|
|
26
|
+
|
|
27
|
+
- The bundled `npm-package-arg` dependency has been updated from requiring `^8.0.1` to requiring `^8.1.5` ([#37395](https://github.com/WordPress/gutenberg/pull/37395)).
|
|
28
|
+
|
|
29
|
+
## 2.7.0 (2021-11-07)
|
|
30
|
+
|
|
31
|
+
### New Features
|
|
32
|
+
|
|
33
|
+
- Add $schema definition to generated `block.json` file.
|
|
34
|
+
|
|
5
35
|
## 2.6.0 (2021-10-22)
|
|
6
36
|
|
|
7
37
|
### New Features
|
|
38
|
+
|
|
8
39
|
- Add passing local directories to --template. ([#35645](https://github.com/WordPress/gutenberg/pull/35645))
|
|
9
40
|
- Add `slugPascalCase` to the list of variables that can be used in templates ([#35462](https://github.com/WordPress/gutenberg/pull/35462))
|
|
10
41
|
|
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Visit the [Gutenberg handbook](https://developer.wordpress.org/block-editor/deve
|
|
|
12
12
|
|
|
13
13
|
## Quick start
|
|
14
14
|
|
|
15
|
-
You just need to provide the `slug` which is the target location for scaffolded files and the internal block name.
|
|
15
|
+
You just need to provide the `slug` which is 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
|
|
@@ -40,10 +40,10 @@ Options:
|
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
42
|
-V, --version output the version number
|
|
43
|
-
-t, --template <name>
|
|
43
|
+
-t, --template <name> plugin template type name, allowed values: "es5", "esnext", the name of an external npm package (default: "esnext"), or the path to a local directory.
|
|
44
44
|
--namespace <value> internal namespace for the block name
|
|
45
|
-
--title <value> display title for the block
|
|
46
|
-
--short-description <value> short description for the block
|
|
45
|
+
--title <value> display title for the plugin/block
|
|
46
|
+
--short-description <value> short description for the plugin/block
|
|
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
|
|
@@ -87,37 +87,37 @@ When bootstrapped with the `esnext` template (or any external template with `wpS
|
|
|
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
115
|
|
|
116
116
|
```bash
|
|
117
117
|
$ npm run packages-update
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
-
Updates WordPress packages to the latest version. [Learn more](/packages/scripts#packages-update).
|
|
120
|
+
Updates WordPress packages to the latest version. [Learn more](https://github.com/WordPress/gutenberg/tree/HEAD/packages/scripts#packages-update).
|
|
121
121
|
|
|
122
122
|
_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
123
|
|
|
@@ -131,7 +131,7 @@ It is mandatory to provide the main file (`index.js` by default) for the package
|
|
|
131
131
|
|
|
132
132
|
#### `templatesPath`
|
|
133
133
|
|
|
134
|
-
A mandatory field with the path pointing to the location where template files live (nested folders are also supported). All files without the `.mustache` extension will be ignored.
|
|
134
|
+
A mandatory field with the path pointing to the location where plugin template files live (nested folders are also supported). All files without the `.mustache` extension will be ignored.
|
|
135
135
|
|
|
136
136
|
_Example:_
|
|
137
137
|
|
|
@@ -139,13 +139,27 @@ _Example:_
|
|
|
139
139
|
const { join } = require( 'path' );
|
|
140
140
|
|
|
141
141
|
module.exports = {
|
|
142
|
-
templatesPath: join( __dirname, 'templates' ),
|
|
142
|
+
templatesPath: join( __dirname, 'plugin-templates' ),
|
|
143
|
+
};
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
#### `blockTemplatesPath`
|
|
147
|
+
|
|
148
|
+
An optional field with the path pointing to the location where template files for the individual block live (nested folders are also supported). All files without the `.mustache` extension will be ignored.
|
|
149
|
+
|
|
150
|
+
_Example:_
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
const { join } = require( 'path' );
|
|
154
|
+
|
|
155
|
+
module.exports = {
|
|
156
|
+
blockTemplatesPath: join( __dirname, 'block-templates' ),
|
|
143
157
|
};
|
|
144
158
|
```
|
|
145
159
|
|
|
146
160
|
#### `assetsPath`
|
|
147
161
|
|
|
148
|
-
This setting is useful when your template scaffolds a
|
|
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.
|
|
149
163
|
|
|
150
164
|
_Example:_
|
|
151
165
|
|
|
@@ -153,7 +167,7 @@ _Example:_
|
|
|
153
167
|
const { join } = require( 'path' );
|
|
154
168
|
|
|
155
169
|
module.exports = {
|
|
156
|
-
assetsPath: join( __dirname, 'assets' ),
|
|
170
|
+
assetsPath: join( __dirname, 'plugin-assets' ),
|
|
157
171
|
};
|
|
158
172
|
```
|
|
159
173
|
|
|
@@ -177,6 +191,7 @@ module.exports = {
|
|
|
177
191
|
|
|
178
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:
|
|
179
193
|
|
|
194
|
+
- `$schema` (default: `https://schemas.wp.org/trunk/block.json`)
|
|
180
195
|
- `apiVersion` (default: `2`) - see https://make.wordpress.org/core/2020/11/18/block-api-version-2/.
|
|
181
196
|
- `slug` (no default)
|
|
182
197
|
- `namespace` (default: `'create-block'`)
|
|
@@ -191,10 +206,18 @@ The following configurable variables are used with the template files. Template
|
|
|
191
206
|
- `licenseURI` (default: `'https://www.gnu.org/licenses/gpl-2.0.html'`)
|
|
192
207
|
- `version` (default: `'0.1.0'`)
|
|
193
208
|
- `wpScripts` (default: `true`)
|
|
194
|
-
- `wpEnv` (default: `false`)
|
|
195
|
-
- `npmDependencies` (default: `[]`) – the list of remote npm packages to be installed in the project with [`npm install`](https://docs.npmjs.com/cli/
|
|
209
|
+
- `wpEnv` (default: `false`) - enables integration with the `@wordpress/env` package and adds the `env` command to the package.json.
|
|
210
|
+
- `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
|
+
`customScripts` (default: {}) - the list of custom scripts to add to `package.json`. It also allows overriding default scripts.
|
|
212
|
+
- `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.
|
|
196
213
|
- `editorScript` (default: `'file:./build/index.js'`)
|
|
197
214
|
- `editorStyle` (default: `'file:./build/index.css'`)
|
|
198
215
|
- `style` (default: `'file:./build/style-index.css'`)
|
|
199
216
|
|
|
200
|
-
|
|
217
|
+
## Contributing to this package
|
|
218
|
+
|
|
219
|
+
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.
|
|
220
|
+
|
|
221
|
+
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).
|
|
222
|
+
|
|
223
|
+
<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
|
@@ -14,7 +14,7 @@ const log = require( './log' );
|
|
|
14
14
|
const { engines, version } = require( '../package.json' );
|
|
15
15
|
const scaffold = require( './scaffold' );
|
|
16
16
|
const {
|
|
17
|
-
|
|
17
|
+
getPluginTemplate,
|
|
18
18
|
getDefaultValues,
|
|
19
19
|
getPrompts,
|
|
20
20
|
} = require( './templates' );
|
|
@@ -34,13 +34,16 @@ program
|
|
|
34
34
|
.arguments( '[slug]' )
|
|
35
35
|
.option(
|
|
36
36
|
'-t, --template <name>',
|
|
37
|
-
'
|
|
37
|
+
'plugin template type name, allowed values: "es5", "esnext", or the name of an external npm package',
|
|
38
38
|
'esnext'
|
|
39
39
|
)
|
|
40
40
|
.option( '--namespace <value>', 'internal namespace for the block name' )
|
|
41
|
-
.option( '--title <value>', 'display title for the block' )
|
|
41
|
+
.option( '--title <value>', 'display title for the plugin/block' )
|
|
42
42
|
// The name "description" is used internally so it couldn't be used.
|
|
43
|
-
.option(
|
|
43
|
+
.option(
|
|
44
|
+
'--short-description <value>',
|
|
45
|
+
'short description for the plugin/block'
|
|
46
|
+
)
|
|
44
47
|
.option( '--category <name>', 'category name for the block' )
|
|
45
48
|
.option(
|
|
46
49
|
'--wp-scripts',
|
|
@@ -66,8 +69,8 @@ program
|
|
|
66
69
|
) => {
|
|
67
70
|
await checkSystemRequirements( engines );
|
|
68
71
|
try {
|
|
69
|
-
const
|
|
70
|
-
const defaultValues = getDefaultValues(
|
|
72
|
+
const pluginTemplate = await getPluginTemplate( templateName );
|
|
73
|
+
const defaultValues = getDefaultValues( pluginTemplate );
|
|
71
74
|
const optionsValues = pickBy(
|
|
72
75
|
{
|
|
73
76
|
category,
|
|
@@ -88,16 +91,16 @@ program
|
|
|
88
91
|
title: startCase( slug ),
|
|
89
92
|
...optionsValues,
|
|
90
93
|
};
|
|
91
|
-
await scaffold(
|
|
94
|
+
await scaffold( pluginTemplate, answers );
|
|
92
95
|
} else {
|
|
93
|
-
const prompts = getPrompts(
|
|
96
|
+
const prompts = getPrompts( pluginTemplate ).filter(
|
|
94
97
|
( { name } ) =>
|
|
95
98
|
! Object.keys( optionsValues ).includes( name )
|
|
96
99
|
);
|
|
97
100
|
log.info( '' );
|
|
98
|
-
log.info( "Let's customize your
|
|
101
|
+
log.info( "Let's customize your WordPress plugin:" );
|
|
99
102
|
const answers = await inquirer.prompt( prompts );
|
|
100
|
-
await scaffold(
|
|
103
|
+
await scaffold( pluginTemplate, {
|
|
101
104
|
...defaultValues,
|
|
102
105
|
...optionsValues,
|
|
103
106
|
...answers,
|
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
const { omitBy } = require( 'lodash' );
|
|
5
|
-
const { join } = require( 'path' );
|
|
5
|
+
const { dirname, join } = require( 'path' );
|
|
6
|
+
const makeDir = require( 'make-dir' );
|
|
6
7
|
const { writeFile } = require( 'fs' ).promises;
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Internal dependencies
|
|
10
11
|
*/
|
|
11
12
|
const { info } = require( './log' );
|
|
13
|
+
const { writeOutputTemplate } = require( './output' );
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
async function initBlockJSON( {
|
|
16
|
+
$schema,
|
|
14
17
|
apiVersion,
|
|
15
18
|
slug,
|
|
16
19
|
namespace,
|
|
@@ -22,18 +25,22 @@ module.exports = async ( {
|
|
|
22
25
|
supports,
|
|
23
26
|
dashicon,
|
|
24
27
|
textdomain,
|
|
28
|
+
folderName,
|
|
25
29
|
editorScript,
|
|
26
30
|
editorStyle,
|
|
27
31
|
style,
|
|
28
|
-
} )
|
|
29
|
-
const outputFile = join( process.cwd(), slug, 'block.json' );
|
|
32
|
+
} ) {
|
|
30
33
|
info( '' );
|
|
31
34
|
info( 'Creating a "block.json" file.' );
|
|
35
|
+
|
|
36
|
+
const outputFile = join( process.cwd(), slug, folderName, 'block.json' );
|
|
37
|
+
await makeDir( dirname( outputFile ) );
|
|
32
38
|
await writeFile(
|
|
33
39
|
outputFile,
|
|
34
40
|
JSON.stringify(
|
|
35
41
|
omitBy(
|
|
36
42
|
{
|
|
43
|
+
$schema,
|
|
37
44
|
apiVersion,
|
|
38
45
|
name: namespace + '/' + slug,
|
|
39
46
|
version,
|
|
@@ -54,4 +61,19 @@ module.exports = async ( {
|
|
|
54
61
|
'\t'
|
|
55
62
|
)
|
|
56
63
|
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = async function ( outputTemplates, view ) {
|
|
67
|
+
await Promise.all(
|
|
68
|
+
Object.keys( outputTemplates ).map(
|
|
69
|
+
async ( outputFile ) =>
|
|
70
|
+
await writeOutputTemplate(
|
|
71
|
+
outputTemplates[ outputFile ],
|
|
72
|
+
join( view.folderName, outputFile ),
|
|
73
|
+
view
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
await initBlockJSON( view );
|
|
57
79
|
};
|
package/lib/init-package-json.js
CHANGED
|
@@ -18,13 +18,16 @@ module.exports = async ( {
|
|
|
18
18
|
license,
|
|
19
19
|
slug,
|
|
20
20
|
version,
|
|
21
|
+
wpEnv,
|
|
21
22
|
wpScripts,
|
|
22
23
|
npmDependencies,
|
|
24
|
+
customScripts,
|
|
23
25
|
} ) => {
|
|
24
26
|
const cwd = join( process.cwd(), slug );
|
|
25
27
|
|
|
26
28
|
info( '' );
|
|
27
29
|
info( 'Creating a "package.json" file.' );
|
|
30
|
+
|
|
28
31
|
await writePkg(
|
|
29
32
|
cwd,
|
|
30
33
|
omitBy(
|
|
@@ -35,20 +38,25 @@ module.exports = async ( {
|
|
|
35
38
|
author,
|
|
36
39
|
license,
|
|
37
40
|
main: wpScripts && 'build/index.js',
|
|
38
|
-
scripts:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
scripts: {
|
|
42
|
+
...( wpScripts && {
|
|
43
|
+
build: 'wp-scripts build',
|
|
44
|
+
format: 'wp-scripts format',
|
|
45
|
+
'lint:css': 'wp-scripts lint-style',
|
|
46
|
+
'lint:js': 'wp-scripts lint-js',
|
|
47
|
+
'packages-update': 'wp-scripts packages-update',
|
|
48
|
+
'plugin-zip': 'wp-scripts plugin-zip',
|
|
49
|
+
start: 'wp-scripts start',
|
|
50
|
+
} ),
|
|
51
|
+
...( wpEnv && { env: 'wp-env' } ),
|
|
52
|
+
...customScripts,
|
|
45
53
|
},
|
|
46
54
|
},
|
|
47
55
|
isEmpty
|
|
48
56
|
)
|
|
49
57
|
);
|
|
50
58
|
|
|
51
|
-
if ( size( npmDependencies ) ) {
|
|
59
|
+
if ( wpScripts && size( npmDependencies ) ) {
|
|
52
60
|
info( '' );
|
|
53
61
|
info(
|
|
54
62
|
'Installing npm dependencies. It might take a couple of minutes...'
|
package/lib/output.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
const { dirname, join } = require( 'path' );
|
|
5
|
+
const makeDir = require( 'make-dir' );
|
|
6
|
+
const { render } = require( 'mustache' );
|
|
7
|
+
const { writeFile } = require( 'fs' ).promises;
|
|
8
|
+
|
|
9
|
+
const writeOutputAsset = async ( inputFile, outputFile, view ) => {
|
|
10
|
+
const outputFilePath = join( view.slug, 'assets', outputFile );
|
|
11
|
+
await makeDir( dirname( outputFilePath ) );
|
|
12
|
+
writeFile( outputFilePath, inputFile );
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const writeOutputTemplate = async ( inputFile, outputFile, view ) => {
|
|
16
|
+
// Output files can have names that depend on the slug provided.
|
|
17
|
+
const outputFilePath = join(
|
|
18
|
+
view.slug,
|
|
19
|
+
outputFile.replace( /\$slug/g, view.slug )
|
|
20
|
+
);
|
|
21
|
+
await makeDir( dirname( outputFilePath ) );
|
|
22
|
+
writeFile( outputFilePath, render( inputFile, view ) );
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
writeOutputAsset,
|
|
27
|
+
writeOutputTemplate,
|
|
28
|
+
};
|
package/lib/scaffold.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
const { writeFile } = require( 'fs' ).promises;
|
|
5
4
|
const { snakeCase, camelCase, upperFirst } = require( 'lodash' );
|
|
6
|
-
const makeDir = require( 'make-dir' );
|
|
7
|
-
const { render } = require( 'mustache' );
|
|
8
|
-
const { dirname, join } = require( 'path' );
|
|
9
5
|
|
|
10
6
|
/**
|
|
11
7
|
* Internal dependencies
|
|
12
8
|
*/
|
|
13
|
-
const
|
|
9
|
+
const initBlock = require( './init-block' );
|
|
14
10
|
const initPackageJSON = require( './init-package-json' );
|
|
15
11
|
const initWPScripts = require( './init-wp-scripts' );
|
|
16
12
|
const initWPEnv = require( './init-wp-env' );
|
|
17
13
|
const { code, info, success } = require( './log' );
|
|
14
|
+
const { writeOutputAsset, writeOutputTemplate } = require( './output' );
|
|
18
15
|
|
|
19
16
|
module.exports = async (
|
|
20
|
-
|
|
17
|
+
{ blockOutputTemplates, outputTemplates, outputAssets },
|
|
21
18
|
{
|
|
19
|
+
$schema,
|
|
22
20
|
apiVersion,
|
|
23
21
|
namespace,
|
|
24
22
|
slug,
|
|
@@ -35,6 +33,8 @@ module.exports = async (
|
|
|
35
33
|
wpScripts,
|
|
36
34
|
wpEnv,
|
|
37
35
|
npmDependencies,
|
|
36
|
+
customScripts,
|
|
37
|
+
folderName,
|
|
38
38
|
editorScript,
|
|
39
39
|
editorStyle,
|
|
40
40
|
style,
|
|
@@ -44,10 +44,10 @@ module.exports = async (
|
|
|
44
44
|
namespace = namespace.toLowerCase();
|
|
45
45
|
|
|
46
46
|
info( '' );
|
|
47
|
-
info( `Creating a new WordPress
|
|
47
|
+
info( `Creating a new WordPress plugin in "${ slug }" folder.` );
|
|
48
48
|
|
|
49
|
-
const { outputTemplates, outputAssets } = blockTemplate;
|
|
50
49
|
const view = {
|
|
50
|
+
$schema,
|
|
51
51
|
apiVersion,
|
|
52
52
|
namespace,
|
|
53
53
|
namespaceSnakeCase: snakeCase( namespace ),
|
|
@@ -66,35 +66,39 @@ module.exports = async (
|
|
|
66
66
|
licenseURI,
|
|
67
67
|
textdomain: slug,
|
|
68
68
|
wpScripts,
|
|
69
|
+
wpEnv,
|
|
69
70
|
npmDependencies,
|
|
71
|
+
customScripts,
|
|
72
|
+
folderName,
|
|
70
73
|
editorScript,
|
|
71
74
|
editorStyle,
|
|
72
75
|
style,
|
|
73
76
|
};
|
|
77
|
+
|
|
74
78
|
await Promise.all(
|
|
75
|
-
Object.keys( outputTemplates ).map(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
outputFilePath,
|
|
84
|
-
render( outputTemplates[ outputFile ], view )
|
|
85
|
-
);
|
|
86
|
-
} )
|
|
79
|
+
Object.keys( outputTemplates ).map(
|
|
80
|
+
async ( outputFile ) =>
|
|
81
|
+
await writeOutputTemplate(
|
|
82
|
+
outputTemplates[ outputFile ],
|
|
83
|
+
outputFile,
|
|
84
|
+
view
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
87
|
);
|
|
88
88
|
|
|
89
89
|
await Promise.all(
|
|
90
|
-
Object.keys( outputAssets ).map(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
Object.keys( outputAssets ).map(
|
|
91
|
+
async ( outputFile ) =>
|
|
92
|
+
await writeOutputAsset(
|
|
93
|
+
outputAssets[ outputFile ],
|
|
94
|
+
outputFile,
|
|
95
|
+
view
|
|
96
|
+
)
|
|
97
|
+
)
|
|
95
98
|
);
|
|
96
99
|
|
|
97
|
-
await
|
|
100
|
+
await initBlock( blockOutputTemplates, view );
|
|
101
|
+
|
|
98
102
|
await initPackageJSON( view );
|
|
99
103
|
|
|
100
104
|
if ( wpScripts ) {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* Registers all block assets so that they can be enqueued through the block editor
|
|
26
26
|
* in the corresponding context.
|
|
27
27
|
*
|
|
28
|
-
* @see https://developer.wordpress.org/block-editor/
|
|
28
|
+
* @see https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/applying-styles-with-stylesheets/
|
|
29
29
|
*/
|
|
30
30
|
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
|
|
31
31
|
$dir = __DIR__;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
* Behind the scenes, it registers also all assets so they can be enqueued
|
|
27
27
|
* through the block editor in the corresponding context.
|
|
28
28
|
*
|
|
29
|
-
* @see https://developer.wordpress.org/
|
|
29
|
+
* @see https://developer.wordpress.org/reference/functions/register_block_type/
|
|
30
30
|
*/
|
|
31
31
|
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
|
|
32
|
-
register_block_type( __DIR__ );
|
|
32
|
+
register_block_type( __DIR__ . '/build' );
|
|
33
33
|
}
|
|
34
34
|
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );
|
|
File without changes
|
package/lib/templates.js
CHANGED
|
@@ -19,7 +19,7 @@ const CLIError = require( './cli-error' );
|
|
|
19
19
|
const { info } = require( './log' );
|
|
20
20
|
const prompts = require( './prompts' );
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const predefinedPluginTemplates = {
|
|
23
23
|
es5: {
|
|
24
24
|
defaultValues: {
|
|
25
25
|
slug: 'es5-example',
|
|
@@ -44,13 +44,13 @@ const predefinedBlockTemplates = {
|
|
|
44
44
|
supports: {
|
|
45
45
|
html: false,
|
|
46
46
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
],
|
|
47
|
+
folderName: 'src',
|
|
48
|
+
editorScript: 'file:./index.js',
|
|
49
|
+
editorStyle: 'file:./index.css',
|
|
50
|
+
style: 'file:./style-index.css',
|
|
52
51
|
},
|
|
53
|
-
templatesPath: join( __dirname, 'templates', 'esnext' ),
|
|
52
|
+
templatesPath: join( __dirname, 'templates', 'esnext', 'plugin' ),
|
|
53
|
+
blockTemplatesPath: join( __dirname, 'templates', 'esnext', 'block' ),
|
|
54
54
|
},
|
|
55
55
|
};
|
|
56
56
|
|
|
@@ -104,6 +104,7 @@ const externalTemplateExists = async ( templateName ) => {
|
|
|
104
104
|
|
|
105
105
|
const configToTemplate = async ( {
|
|
106
106
|
assetsPath,
|
|
107
|
+
blockTemplatesPath,
|
|
107
108
|
defaultValues = {},
|
|
108
109
|
templatesPath,
|
|
109
110
|
} ) => {
|
|
@@ -112,16 +113,19 @@ const configToTemplate = async ( {
|
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
return {
|
|
116
|
+
blockOutputTemplates: blockTemplatesPath
|
|
117
|
+
? await getOutputTemplates( blockTemplatesPath )
|
|
118
|
+
: {},
|
|
115
119
|
defaultValues,
|
|
116
120
|
outputAssets: assetsPath ? await getOutputAssets( assetsPath ) : {},
|
|
117
121
|
outputTemplates: await getOutputTemplates( templatesPath ),
|
|
118
122
|
};
|
|
119
123
|
};
|
|
120
124
|
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
125
|
+
const getPluginTemplate = async ( templateName ) => {
|
|
126
|
+
if ( predefinedPluginTemplates[ templateName ] ) {
|
|
123
127
|
return await configToTemplate(
|
|
124
|
-
|
|
128
|
+
predefinedPluginTemplates[ templateName ]
|
|
125
129
|
);
|
|
126
130
|
}
|
|
127
131
|
|
|
@@ -142,8 +146,8 @@ const getBlockTemplate = async ( templateName ) => {
|
|
|
142
146
|
|
|
143
147
|
if ( ! ( await externalTemplateExists( templateName ) ) ) {
|
|
144
148
|
throw new CLIError(
|
|
145
|
-
`Invalid
|
|
146
|
-
Object.keys(
|
|
149
|
+
`Invalid plugin template type name: "${ templateName }". Allowed values: ` +
|
|
150
|
+
Object.keys( predefinedPluginTemplates )
|
|
147
151
|
.map( ( name ) => `"${ name }"` )
|
|
148
152
|
.join( ', ' ) +
|
|
149
153
|
', or an existing npm package name.'
|
|
@@ -173,7 +177,7 @@ const getBlockTemplate = async ( templateName ) => {
|
|
|
173
177
|
throw error;
|
|
174
178
|
} else {
|
|
175
179
|
throw new CLIError(
|
|
176
|
-
`Invalid
|
|
180
|
+
`Invalid plugin template downloaded. Error: ${ error.message }`
|
|
177
181
|
);
|
|
178
182
|
}
|
|
179
183
|
} finally {
|
|
@@ -183,8 +187,9 @@ const getBlockTemplate = async ( templateName ) => {
|
|
|
183
187
|
}
|
|
184
188
|
};
|
|
185
189
|
|
|
186
|
-
const getDefaultValues = (
|
|
190
|
+
const getDefaultValues = ( pluginTemplate ) => {
|
|
187
191
|
return {
|
|
192
|
+
$schema: 'https://schemas.wp.org/trunk/block.json',
|
|
188
193
|
apiVersion: 2,
|
|
189
194
|
namespace: 'create-block',
|
|
190
195
|
category: 'widgets',
|
|
@@ -193,17 +198,19 @@ const getDefaultValues = ( blockTemplate ) => {
|
|
|
193
198
|
licenseURI: 'https://www.gnu.org/licenses/gpl-2.0.html',
|
|
194
199
|
version: '0.1.0',
|
|
195
200
|
wpScripts: true,
|
|
201
|
+
customScripts: {},
|
|
196
202
|
wpEnv: false,
|
|
197
203
|
npmDependencies: [],
|
|
204
|
+
folderName: '.',
|
|
198
205
|
editorScript: 'file:./build/index.js',
|
|
199
206
|
editorStyle: 'file:./build/index.css',
|
|
200
207
|
style: 'file:./build/style-index.css',
|
|
201
|
-
...
|
|
208
|
+
...pluginTemplate.defaultValues,
|
|
202
209
|
};
|
|
203
210
|
};
|
|
204
211
|
|
|
205
|
-
const getPrompts = (
|
|
206
|
-
const defaultValues = getDefaultValues(
|
|
212
|
+
const getPrompts = ( pluginTemplate ) => {
|
|
213
|
+
const defaultValues = getDefaultValues( pluginTemplate );
|
|
207
214
|
return Object.keys( prompts ).map( ( promptName ) => {
|
|
208
215
|
return {
|
|
209
216
|
...prompts[ promptName ],
|
|
@@ -213,7 +220,7 @@ const getPrompts = ( blockTemplate ) => {
|
|
|
213
220
|
};
|
|
214
221
|
|
|
215
222
|
module.exports = {
|
|
216
|
-
|
|
223
|
+
getPluginTemplate,
|
|
217
224
|
getDefaultValues,
|
|
218
225
|
getPrompts,
|
|
219
226
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/create-block",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.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,22 +31,22 @@
|
|
|
31
31
|
"wp-create-block": "./index.js"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@wordpress/lazy-import": "^1.
|
|
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",
|
|
38
38
|
"execa": "^4.0.2",
|
|
39
|
-
"fast-glob": "^
|
|
39
|
+
"fast-glob": "^3.2.7",
|
|
40
40
|
"inquirer": "^7.1.0",
|
|
41
41
|
"lodash": "^4.17.21",
|
|
42
42
|
"make-dir": "^3.0.0",
|
|
43
43
|
"mustache": "^4.0.0",
|
|
44
|
-
"npm-package-arg": "^8.
|
|
44
|
+
"npm-package-arg": "^8.1.5",
|
|
45
45
|
"rimraf": "^3.0.2",
|
|
46
46
|
"write-pkg": "^4.0.0"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "2e4922861e49f5a090f9dc52056165092cfba163"
|
|
52
52
|
}
|