@wordpress/create-block 2.5.2 → 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 +30 -0
- package/LICENSE.md +1 -1
- package/README.md +32 -10
- package/lib/index.js +13 -10
- package/lib/{init-block-json.js → init-block.js} +26 -4
- package/lib/init-package-json.js +3 -2
- package/lib/output.js +28 -0
- package/lib/scaffold.js +29 -27
- 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 +29 -18
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
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))
|
|
17
|
+
|
|
18
|
+
### Internal
|
|
19
|
+
|
|
20
|
+
- 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)).
|
|
21
|
+
|
|
22
|
+
## 2.7.0 (2021-11-07)
|
|
23
|
+
|
|
24
|
+
### New Features
|
|
25
|
+
|
|
26
|
+
- Add $schema definition to generated `block.json` file.
|
|
27
|
+
|
|
28
|
+
## 2.6.0 (2021-10-22)
|
|
29
|
+
|
|
30
|
+
### New Features
|
|
31
|
+
|
|
32
|
+
- Add passing local directories to --template. ([#35645](https://github.com/WordPress/gutenberg/pull/35645))
|
|
33
|
+
- Add `slugPascalCase` to the list of variables that can be used in templates ([#35462](https://github.com/WordPress/gutenberg/pull/35462))
|
|
34
|
+
|
|
5
35
|
## 2.5.0 (2021-07-21)
|
|
6
36
|
|
|
7
37
|
### Enhancements
|
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
|
|
@@ -65,7 +65,13 @@ $ npx @wordpress/create-block
|
|
|
65
65
|
$ npx @wordpress/create-block --template es5
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
3.
|
|
68
|
+
3. Local template directory – it is also possible to pick a local directory as a template.
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
$ npx @wordpress/create-block --template ./path/to/template
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
4. Help – you need to use `npx` to output usage information.
|
|
69
75
|
|
|
70
76
|
```bash
|
|
71
77
|
$ npx @wordpress/create-block --help
|
|
@@ -125,7 +131,21 @@ It is mandatory to provide the main file (`index.js` by default) for the package
|
|
|
125
131
|
|
|
126
132
|
#### `templatesPath`
|
|
127
133
|
|
|
128
|
-
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
|
+
|
|
136
|
+
_Example:_
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
const { join } = require( 'path' );
|
|
140
|
+
|
|
141
|
+
module.exports = {
|
|
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.
|
|
129
149
|
|
|
130
150
|
_Example:_
|
|
131
151
|
|
|
@@ -133,13 +153,13 @@ _Example:_
|
|
|
133
153
|
const { join } = require( 'path' );
|
|
134
154
|
|
|
135
155
|
module.exports = {
|
|
136
|
-
|
|
156
|
+
blockTemplatesPath: join( __dirname, 'block-templates' ),
|
|
137
157
|
};
|
|
138
158
|
```
|
|
139
159
|
|
|
140
160
|
#### `assetsPath`
|
|
141
161
|
|
|
142
|
-
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.
|
|
143
163
|
|
|
144
164
|
_Example:_
|
|
145
165
|
|
|
@@ -147,7 +167,7 @@ _Example:_
|
|
|
147
167
|
const { join } = require( 'path' );
|
|
148
168
|
|
|
149
169
|
module.exports = {
|
|
150
|
-
assetsPath: join( __dirname, 'assets' ),
|
|
170
|
+
assetsPath: join( __dirname, 'plugin-assets' ),
|
|
151
171
|
};
|
|
152
172
|
```
|
|
153
173
|
|
|
@@ -171,6 +191,7 @@ module.exports = {
|
|
|
171
191
|
|
|
172
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:
|
|
173
193
|
|
|
194
|
+
- `$schema` (default: `https://schemas.wp.org/trunk/block.json`)
|
|
174
195
|
- `apiVersion` (default: `2`) - see https://make.wordpress.org/core/2020/11/18/block-api-version-2/.
|
|
175
196
|
- `slug` (no default)
|
|
176
197
|
- `namespace` (default: `'create-block'`)
|
|
@@ -186,7 +207,8 @@ The following configurable variables are used with the template files. Template
|
|
|
186
207
|
- `version` (default: `'0.1.0'`)
|
|
187
208
|
- `wpScripts` (default: `true`)
|
|
188
209
|
- `wpEnv` (default: `false`)
|
|
189
|
-
- `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.
|
|
190
212
|
- `editorScript` (default: `'file:./build/index.js'`)
|
|
191
213
|
- `editorStyle` (default: `'file:./build/index.css'`)
|
|
192
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,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
|
@@ -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,24 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
const {
|
|
5
|
-
const { snakeCase } = require( 'lodash' );
|
|
6
|
-
const makeDir = require( 'make-dir' );
|
|
7
|
-
const { render } = require( 'mustache' );
|
|
8
|
-
const { dirname, join } = require( 'path' );
|
|
4
|
+
const { snakeCase, camelCase, upperFirst } = require( 'lodash' );
|
|
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,7 @@ module.exports = async (
|
|
|
35
33
|
wpScripts,
|
|
36
34
|
wpEnv,
|
|
37
35
|
npmDependencies,
|
|
36
|
+
folderName,
|
|
38
37
|
editorScript,
|
|
39
38
|
editorStyle,
|
|
40
39
|
style,
|
|
@@ -44,15 +43,16 @@ module.exports = async (
|
|
|
44
43
|
namespace = namespace.toLowerCase();
|
|
45
44
|
|
|
46
45
|
info( '' );
|
|
47
|
-
info( `Creating a new WordPress
|
|
46
|
+
info( `Creating a new WordPress plugin in "${ slug }" folder.` );
|
|
48
47
|
|
|
49
|
-
const { outputTemplates, outputAssets } = blockTemplate;
|
|
50
48
|
const view = {
|
|
49
|
+
$schema,
|
|
51
50
|
apiVersion,
|
|
52
51
|
namespace,
|
|
53
52
|
namespaceSnakeCase: snakeCase( namespace ),
|
|
54
53
|
slug,
|
|
55
54
|
slugSnakeCase: snakeCase( slug ),
|
|
55
|
+
slugPascalCase: upperFirst( camelCase( slug ) ),
|
|
56
56
|
title,
|
|
57
57
|
description,
|
|
58
58
|
dashicon,
|
|
@@ -66,34 +66,36 @@ module.exports = async (
|
|
|
66
66
|
textdomain: slug,
|
|
67
67
|
wpScripts,
|
|
68
68
|
npmDependencies,
|
|
69
|
+
folderName,
|
|
69
70
|
editorScript,
|
|
70
71
|
editorStyle,
|
|
71
72
|
style,
|
|
72
73
|
};
|
|
74
|
+
|
|
73
75
|
await Promise.all(
|
|
74
|
-
Object.keys( outputTemplates ).map(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
outputFilePath,
|
|
83
|
-
render( outputTemplates[ outputFile ], view )
|
|
84
|
-
);
|
|
85
|
-
} )
|
|
76
|
+
Object.keys( outputTemplates ).map(
|
|
77
|
+
async ( outputFile ) =>
|
|
78
|
+
await writeOutputTemplate(
|
|
79
|
+
outputTemplates[ outputFile ],
|
|
80
|
+
outputFile,
|
|
81
|
+
view
|
|
82
|
+
)
|
|
83
|
+
)
|
|
86
84
|
);
|
|
87
85
|
|
|
88
86
|
await Promise.all(
|
|
89
|
-
Object.keys( outputAssets ).map(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
Object.keys( outputAssets ).map(
|
|
88
|
+
async ( outputFile ) =>
|
|
89
|
+
await writeOutputAsset(
|
|
90
|
+
outputAssets[ outputFile ],
|
|
91
|
+
outputFile,
|
|
92
|
+
view
|
|
93
|
+
)
|
|
94
|
+
)
|
|
94
95
|
);
|
|
95
96
|
|
|
96
|
-
await
|
|
97
|
+
await initBlock( blockOutputTemplates, view );
|
|
98
|
+
|
|
97
99
|
await initPackageJSON( view );
|
|
98
100
|
|
|
99
101
|
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
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
const { command } = require( 'execa' );
|
|
5
5
|
const glob = require( 'fast-glob' );
|
|
6
|
+
const { resolve } = require( 'path' );
|
|
7
|
+
const { existsSync } = require( 'fs' );
|
|
6
8
|
const { mkdtemp, readFile } = require( 'fs' ).promises;
|
|
7
9
|
const { fromPairs, isObject } = require( 'lodash' );
|
|
8
10
|
const npmPackageArg = require( 'npm-package-arg' );
|
|
@@ -17,7 +19,7 @@ const CLIError = require( './cli-error' );
|
|
|
17
19
|
const { info } = require( './log' );
|
|
18
20
|
const prompts = require( './prompts' );
|
|
19
21
|
|
|
20
|
-
const
|
|
22
|
+
const predefinedPluginTemplates = {
|
|
21
23
|
es5: {
|
|
22
24
|
defaultValues: {
|
|
23
25
|
slug: 'es5-example',
|
|
@@ -42,13 +44,13 @@ const predefinedBlockTemplates = {
|
|
|
42
44
|
supports: {
|
|
43
45
|
html: false,
|
|
44
46
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
],
|
|
47
|
+
folderName: 'src',
|
|
48
|
+
editorScript: 'file:./index.js',
|
|
49
|
+
editorStyle: 'file:./index.css',
|
|
50
|
+
style: 'file:./style-index.css',
|
|
50
51
|
},
|
|
51
|
-
templatesPath: join( __dirname, 'templates', 'esnext' ),
|
|
52
|
+
templatesPath: join( __dirname, 'templates', 'esnext', 'plugin' ),
|
|
53
|
+
blockTemplatesPath: join( __dirname, 'templates', 'esnext', 'block' ),
|
|
52
54
|
},
|
|
53
55
|
};
|
|
54
56
|
|
|
@@ -102,6 +104,7 @@ const externalTemplateExists = async ( templateName ) => {
|
|
|
102
104
|
|
|
103
105
|
const configToTemplate = async ( {
|
|
104
106
|
assetsPath,
|
|
107
|
+
blockTemplatesPath,
|
|
105
108
|
defaultValues = {},
|
|
106
109
|
templatesPath,
|
|
107
110
|
} ) => {
|
|
@@ -110,20 +113,26 @@ const configToTemplate = async ( {
|
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
return {
|
|
116
|
+
blockOutputTemplates: blockTemplatesPath
|
|
117
|
+
? await getOutputTemplates( blockTemplatesPath )
|
|
118
|
+
: {},
|
|
113
119
|
defaultValues,
|
|
114
120
|
outputAssets: assetsPath ? await getOutputAssets( assetsPath ) : {},
|
|
115
121
|
outputTemplates: await getOutputTemplates( templatesPath ),
|
|
116
122
|
};
|
|
117
123
|
};
|
|
118
124
|
|
|
119
|
-
const
|
|
120
|
-
if (
|
|
125
|
+
const getPluginTemplate = async ( templateName ) => {
|
|
126
|
+
if ( predefinedPluginTemplates[ templateName ] ) {
|
|
121
127
|
return await configToTemplate(
|
|
122
|
-
|
|
128
|
+
predefinedPluginTemplates[ templateName ]
|
|
123
129
|
);
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
try {
|
|
133
|
+
if ( existsSync( resolve( templateName ) ) ) {
|
|
134
|
+
return await configToTemplate( require( resolve( templateName ) ) );
|
|
135
|
+
}
|
|
127
136
|
return await configToTemplate( require( templateName ) );
|
|
128
137
|
} catch ( error ) {
|
|
129
138
|
if ( error instanceof CLIError ) {
|
|
@@ -137,8 +146,8 @@ const getBlockTemplate = async ( templateName ) => {
|
|
|
137
146
|
|
|
138
147
|
if ( ! ( await externalTemplateExists( templateName ) ) ) {
|
|
139
148
|
throw new CLIError(
|
|
140
|
-
`Invalid
|
|
141
|
-
Object.keys(
|
|
149
|
+
`Invalid plugin template type name: "${ templateName }". Allowed values: ` +
|
|
150
|
+
Object.keys( predefinedPluginTemplates )
|
|
142
151
|
.map( ( name ) => `"${ name }"` )
|
|
143
152
|
.join( ', ' ) +
|
|
144
153
|
', or an existing npm package name.'
|
|
@@ -168,7 +177,7 @@ const getBlockTemplate = async ( templateName ) => {
|
|
|
168
177
|
throw error;
|
|
169
178
|
} else {
|
|
170
179
|
throw new CLIError(
|
|
171
|
-
`Invalid
|
|
180
|
+
`Invalid plugin template downloaded. Error: ${ error.message }`
|
|
172
181
|
);
|
|
173
182
|
}
|
|
174
183
|
} finally {
|
|
@@ -178,8 +187,9 @@ const getBlockTemplate = async ( templateName ) => {
|
|
|
178
187
|
}
|
|
179
188
|
};
|
|
180
189
|
|
|
181
|
-
const getDefaultValues = (
|
|
190
|
+
const getDefaultValues = ( pluginTemplate ) => {
|
|
182
191
|
return {
|
|
192
|
+
$schema: 'https://schemas.wp.org/trunk/block.json',
|
|
183
193
|
apiVersion: 2,
|
|
184
194
|
namespace: 'create-block',
|
|
185
195
|
category: 'widgets',
|
|
@@ -190,15 +200,16 @@ const getDefaultValues = ( blockTemplate ) => {
|
|
|
190
200
|
wpScripts: true,
|
|
191
201
|
wpEnv: false,
|
|
192
202
|
npmDependencies: [],
|
|
203
|
+
folderName: '.',
|
|
193
204
|
editorScript: 'file:./build/index.js',
|
|
194
205
|
editorStyle: 'file:./build/index.css',
|
|
195
206
|
style: 'file:./build/style-index.css',
|
|
196
|
-
...
|
|
207
|
+
...pluginTemplate.defaultValues,
|
|
197
208
|
};
|
|
198
209
|
};
|
|
199
210
|
|
|
200
|
-
const getPrompts = (
|
|
201
|
-
const defaultValues = getDefaultValues(
|
|
211
|
+
const getPrompts = ( pluginTemplate ) => {
|
|
212
|
+
const defaultValues = getDefaultValues( pluginTemplate );
|
|
202
213
|
return Object.keys( prompts ).map( ( promptName ) => {
|
|
203
214
|
return {
|
|
204
215
|
...prompts[ promptName ],
|
|
@@ -208,7 +219,7 @@ const getPrompts = ( blockTemplate ) => {
|
|
|
208
219
|
};
|
|
209
220
|
|
|
210
221
|
module.exports = {
|
|
211
|
-
|
|
222
|
+
getPluginTemplate,
|
|
212
223
|
getDefaultValues,
|
|
213
224
|
getPrompts,
|
|
214
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,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.0",
|
|
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": "d95ccb9366e249133cdb1d7b25c382446b9ee502"
|
|
52
52
|
}
|