@wordpress/create-block 2.7.2-next.33ec3857e2.0 → 2.8.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 +12 -1
- package/LICENSE.md +1 -1
- package/README.md +24 -9
- package/lib/index.js +13 -10
- package/lib/{init-block-json.js → init-block.js} +24 -4
- package/lib/init-package-json.js +3 -2
- package/lib/output.js +28 -0
- package/lib/scaffold.js +25 -26
- 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 +23 -18
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
-
## 2.
|
|
5
|
+
## 2.8.0 (2022-01-27)
|
|
6
|
+
|
|
7
|
+
### New Features
|
|
8
|
+
|
|
9
|
+
- Integrated a new `plugin-zip` command to create a zip file for a WordPress plugin ([#37687](https://github.com/WordPress/gutenberg/pull/37687)).
|
|
10
|
+
- Add support for handling block templates with the `blockTemplatesPath` field in the external template configuration ([#37612](https://github.com/WordPress/gutenberg/pull/37612)).
|
|
11
|
+
- 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)).
|
|
12
|
+
|
|
13
|
+
### Enhancement
|
|
14
|
+
|
|
15
|
+
- Speed up scaffolding process by omitting WordPress dependencies in the template ([#37639](https://github.com/WordPress/gutenberg/pull/37639)).
|
|
16
|
+
- Update link to block registration reference ([#37674](https://github.com/WordPress/gutenberg/pull/37674))
|
|
6
17
|
|
|
7
18
|
### Internal
|
|
8
19
|
|
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
|
|
@@ -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
|
|
|
@@ -193,7 +207,8 @@ The following configurable variables are used with the template files. Template
|
|
|
193
207
|
- `version` (default: `'0.1.0'`)
|
|
194
208
|
- `wpScripts` (default: `true`)
|
|
195
209
|
- `wpEnv` (default: `false`)
|
|
196
|
-
- `npmDependencies` (default: `[]`) – the list of remote npm packages to be installed in the project with [`npm install`](https://docs.npmjs.com/cli/
|
|
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
|
+
- `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.
|
|
197
212
|
- `editorScript` (default: `'file:./build/index.js'`)
|
|
198
213
|
- `editorStyle` (default: `'file:./build/index.css'`)
|
|
199
214
|
- `style` (default: `'file:./build/style-index.css'`)
|
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,17 @@
|
|
|
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( {
|
|
14
16
|
$schema,
|
|
15
17
|
apiVersion,
|
|
16
18
|
slug,
|
|
@@ -23,13 +25,16 @@ module.exports = async ( {
|
|
|
23
25
|
supports,
|
|
24
26
|
dashicon,
|
|
25
27
|
textdomain,
|
|
28
|
+
folderName,
|
|
26
29
|
editorScript,
|
|
27
30
|
editorStyle,
|
|
28
31
|
style,
|
|
29
|
-
} )
|
|
30
|
-
const outputFile = join( process.cwd(), slug, 'block.json' );
|
|
32
|
+
} ) {
|
|
31
33
|
info( '' );
|
|
32
34
|
info( 'Creating a "block.json" file.' );
|
|
35
|
+
|
|
36
|
+
const outputFile = join( process.cwd(), slug, folderName, 'block.json' );
|
|
37
|
+
await makeDir( dirname( outputFile ) );
|
|
33
38
|
await writeFile(
|
|
34
39
|
outputFile,
|
|
35
40
|
JSON.stringify(
|
|
@@ -56,4 +61,19 @@ module.exports = async ( {
|
|
|
56
61
|
'\t'
|
|
57
62
|
)
|
|
58
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 );
|
|
59
79
|
};
|
package/lib/init-package-json.js
CHANGED
|
@@ -40,15 +40,16 @@ module.exports = async ( {
|
|
|
40
40
|
format: 'wp-scripts format',
|
|
41
41
|
'lint:css': 'wp-scripts lint-style',
|
|
42
42
|
'lint:js': 'wp-scripts lint-js',
|
|
43
|
-
start: 'wp-scripts start',
|
|
44
43
|
'packages-update': 'wp-scripts packages-update',
|
|
44
|
+
'plugin-zip': 'wp-scripts plugin-zip',
|
|
45
|
+
start: 'wp-scripts start',
|
|
45
46
|
},
|
|
46
47
|
},
|
|
47
48
|
isEmpty
|
|
48
49
|
)
|
|
49
50
|
);
|
|
50
51
|
|
|
51
|
-
if ( size( npmDependencies ) ) {
|
|
52
|
+
if ( wpScripts && size( npmDependencies ) ) {
|
|
52
53
|
info( '' );
|
|
53
54
|
info(
|
|
54
55
|
'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,23 +1,20 @@
|
|
|
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
|
{
|
|
22
19
|
$schema,
|
|
23
20
|
apiVersion,
|
|
@@ -36,6 +33,7 @@ module.exports = async (
|
|
|
36
33
|
wpScripts,
|
|
37
34
|
wpEnv,
|
|
38
35
|
npmDependencies,
|
|
36
|
+
folderName,
|
|
39
37
|
editorScript,
|
|
40
38
|
editorStyle,
|
|
41
39
|
style,
|
|
@@ -45,9 +43,8 @@ module.exports = async (
|
|
|
45
43
|
namespace = namespace.toLowerCase();
|
|
46
44
|
|
|
47
45
|
info( '' );
|
|
48
|
-
info( `Creating a new WordPress
|
|
46
|
+
info( `Creating a new WordPress plugin in "${ slug }" folder.` );
|
|
49
47
|
|
|
50
|
-
const { outputTemplates, outputAssets } = blockTemplate;
|
|
51
48
|
const view = {
|
|
52
49
|
$schema,
|
|
53
50
|
apiVersion,
|
|
@@ -69,34 +66,36 @@ module.exports = async (
|
|
|
69
66
|
textdomain: slug,
|
|
70
67
|
wpScripts,
|
|
71
68
|
npmDependencies,
|
|
69
|
+
folderName,
|
|
72
70
|
editorScript,
|
|
73
71
|
editorStyle,
|
|
74
72
|
style,
|
|
75
73
|
};
|
|
74
|
+
|
|
76
75
|
await Promise.all(
|
|
77
|
-
Object.keys( outputTemplates ).map(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
outputFilePath,
|
|
86
|
-
render( outputTemplates[ outputFile ], view )
|
|
87
|
-
);
|
|
88
|
-
} )
|
|
76
|
+
Object.keys( outputTemplates ).map(
|
|
77
|
+
async ( outputFile ) =>
|
|
78
|
+
await writeOutputTemplate(
|
|
79
|
+
outputTemplates[ outputFile ],
|
|
80
|
+
outputFile,
|
|
81
|
+
view
|
|
82
|
+
)
|
|
83
|
+
)
|
|
89
84
|
);
|
|
90
85
|
|
|
91
86
|
await Promise.all(
|
|
92
|
-
Object.keys( outputAssets ).map(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
Object.keys( outputAssets ).map(
|
|
88
|
+
async ( outputFile ) =>
|
|
89
|
+
await writeOutputAsset(
|
|
90
|
+
outputAssets[ outputFile ],
|
|
91
|
+
outputFile,
|
|
92
|
+
view
|
|
93
|
+
)
|
|
94
|
+
)
|
|
97
95
|
);
|
|
98
96
|
|
|
99
|
-
await
|
|
97
|
+
await initBlock( blockOutputTemplates, view );
|
|
98
|
+
|
|
100
99
|
await initPackageJSON( view );
|
|
101
100
|
|
|
102
101
|
if ( wpScripts ) {
|
|
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,7 +187,7 @@ const getBlockTemplate = async ( templateName ) => {
|
|
|
183
187
|
}
|
|
184
188
|
};
|
|
185
189
|
|
|
186
|
-
const getDefaultValues = (
|
|
190
|
+
const getDefaultValues = ( pluginTemplate ) => {
|
|
187
191
|
return {
|
|
188
192
|
$schema: 'https://schemas.wp.org/trunk/block.json',
|
|
189
193
|
apiVersion: 2,
|
|
@@ -196,15 +200,16 @@ const getDefaultValues = ( blockTemplate ) => {
|
|
|
196
200
|
wpScripts: true,
|
|
197
201
|
wpEnv: false,
|
|
198
202
|
npmDependencies: [],
|
|
203
|
+
folderName: '.',
|
|
199
204
|
editorScript: 'file:./build/index.js',
|
|
200
205
|
editorStyle: 'file:./build/index.css',
|
|
201
206
|
style: 'file:./build/style-index.css',
|
|
202
|
-
...
|
|
207
|
+
...pluginTemplate.defaultValues,
|
|
203
208
|
};
|
|
204
209
|
};
|
|
205
210
|
|
|
206
|
-
const getPrompts = (
|
|
207
|
-
const defaultValues = getDefaultValues(
|
|
211
|
+
const getPrompts = ( pluginTemplate ) => {
|
|
212
|
+
const defaultValues = getDefaultValues( pluginTemplate );
|
|
208
213
|
return Object.keys( prompts ).map( ( promptName ) => {
|
|
209
214
|
return {
|
|
210
215
|
...prompts[ promptName ],
|
|
@@ -214,7 +219,7 @@ const getPrompts = ( blockTemplate ) => {
|
|
|
214
219
|
};
|
|
215
220
|
|
|
216
221
|
module.exports = {
|
|
217
|
-
|
|
222
|
+
getPluginTemplate,
|
|
218
223
|
getDefaultValues,
|
|
219
224
|
getPrompts,
|
|
220
225
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/create-block",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.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.
|
|
34
|
+
"@wordpress/lazy-import": "^1.4.0",
|
|
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": "d95ccb9366e249133cdb1d7b25c382446b9ee502"
|
|
52
52
|
}
|