@wordpress/create-block 4.27.0 → 4.28.1-next.f8d8eceb.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/README.md CHANGED
@@ -28,7 +28,7 @@ $ cd todo-list
28
28
  $ npm start
29
29
  ```
30
30
 
31
- The `slug` provided (`todo-list` in the example) defines the folder name for the scaffolded plugin and the internal block name. The WordPress plugin generated must [be installed manually](https://wordpress.org/documentation/article/manage-plugins/#manual-plugin-installation).
31
+ The `slug` provided (`todo-list` in the example) defines the folder name for the scaffolded plugin and the internal block name. The WordPress plugin generated must [be installed manually](https://wordpress.org/documentation/article/manage-plugins/#manual-plugin-installation-1).
32
32
 
33
33
 
34
34
  _(requires `node` version `14.0.0` or above, and `npm` version `6.14.4` or above)_
package/lib/scaffold.js CHANGED
@@ -49,52 +49,31 @@ module.exports = async (
49
49
  customPackageJSON,
50
50
  customBlockJSON,
51
51
  example,
52
+ transformer,
52
53
  }
53
54
  ) => {
54
55
  slug = slug.toLowerCase();
55
56
  namespace = namespace.toLowerCase();
56
- /**
57
- * --no-plugin relies on the used template supporting the [blockTemplatesPath property](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/#blocktemplatespath).
58
- * If the blockOutputTemplates object has no properties, we can assume that there was a custom --template passed that
59
- * doesn't support it.
60
- */
61
- if ( ! plugin && Object.keys( blockOutputTemplates ) < 1 ) {
62
- error(
63
- 'No block files found in the template. Please ensure that the template supports the blockTemplatesPath property.'
64
- );
65
- return;
66
- }
67
57
 
68
- info( '' );
69
- info(
70
- plugin
71
- ? `Creating a new WordPress plugin in the ${ slug } directory.`
72
- : `Creating a new block in the ${ slug } directory.`
73
- );
74
-
75
- const view = {
58
+ const transformedValues = transformer( {
76
59
  $schema,
77
60
  apiVersion,
78
61
  plugin,
79
62
  namespace,
80
- namespaceSnakeCase: snakeCase( namespace ),
81
63
  slug,
82
- slugSnakeCase: snakeCase( slug ),
83
- slugPascalCase: pascalCase( slug ),
84
64
  title,
85
65
  description,
86
66
  dashicon,
87
67
  category,
88
68
  attributes,
89
69
  supports,
90
- version,
91
70
  author,
92
71
  pluginURI,
93
72
  license,
94
73
  licenseURI,
95
- textdomain: slug,
96
74
  domainPath,
97
75
  updateURI,
76
+ version,
98
77
  wpScripts,
99
78
  wpEnv,
100
79
  npmDependencies,
@@ -106,12 +85,40 @@ module.exports = async (
106
85
  style,
107
86
  render,
108
87
  viewScript,
88
+ variantVars,
109
89
  customPackageJSON,
110
90
  customBlockJSON,
111
91
  example,
92
+ textdomain: slug,
93
+ } );
94
+
95
+ const view = {
96
+ ...transformedValues,
97
+ namespaceSnakeCase: snakeCase( transformedValues.slug ),
98
+ slugSnakeCase: snakeCase( transformedValues.slug ),
99
+ slugPascalCase: pascalCase( transformedValues.slug ),
112
100
  ...variantVars,
113
101
  };
114
102
 
103
+ /**
104
+ * --no-plugin relies on the used template supporting the [blockTemplatesPath property](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/#blocktemplatespath).
105
+ * If the blockOutputTemplates object has no properties, we can assume that there was a custom --template passed that
106
+ * doesn't support it.
107
+ */
108
+ if ( ! plugin && Object.keys( blockOutputTemplates ) < 1 ) {
109
+ error(
110
+ 'No block files found in the template. Please ensure that the template supports the blockTemplatesPath property.'
111
+ );
112
+ return;
113
+ }
114
+
115
+ info( '' );
116
+ info(
117
+ plugin
118
+ ? `Creating a new WordPress plugin in the ${ view.slug } directory.`
119
+ : `Creating a new block in the ${ view.slug } directory.`
120
+ );
121
+
115
122
  if ( plugin ) {
116
123
  await Promise.all(
117
124
  Object.keys( pluginOutputTemplates ).map(
@@ -30,6 +30,10 @@
30
30
  * @package {{namespace}}
31
31
  */
32
32
 
33
+ if ( ! defined( 'ABSPATH' ) ) {
34
+ exit; // Exit if accessed directly.
35
+ }
36
+
33
37
  /**
34
38
  * Registers all block assets so that they can be enqueued through the block editor
35
39
  * in the corresponding context.
@@ -30,6 +30,10 @@
30
30
  * @package {{namespace}}
31
31
  */
32
32
 
33
+ if ( ! defined( 'ABSPATH' ) ) {
34
+ exit; // Exit if accessed directly.
35
+ }
36
+
33
37
  /**
34
38
  * Registers the block using the metadata loaded from the `block.json` file.
35
39
  * Behind the scenes, it registers also all assets so they can be enqueued
package/lib/templates.js CHANGED
@@ -241,6 +241,7 @@ const getDefaultValues = ( pluginTemplate, variant ) => {
241
241
  editorScript: 'file:./index.js',
242
242
  editorStyle: 'file:./index.css',
243
243
  style: 'file:./style-index.css',
244
+ transformer: ( view ) => view,
244
245
  ...pluginTemplate.defaultValues,
245
246
  ...pluginTemplate.variants?.[ variant ],
246
247
  variantVars: getVariantVars( pluginTemplate.variants, variant ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/create-block",
3
- "version": "4.27.0",
3
+ "version": "4.28.1-next.f8d8eceb.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.30.0",
34
+ "@wordpress/lazy-import": "^1.31.1-next.f8d8eceb.0",
35
35
  "chalk": "^4.0.0",
36
36
  "change-case": "^4.1.2",
37
37
  "check-node-version": "^4.1.0",
@@ -48,5 +48,5 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "9b8e598c5418d38fe72197c24ef1d3dd6c712151"
51
+ "gitHead": "8d8fd197e202b8104ffb1cb83048efd0a6c3faf4"
52
52
  }