@wordpress/create-block 4.80.2-next.ba3aee3a2.0 → 4.81.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/lib/index.js CHANGED
@@ -127,6 +127,7 @@ program
127
127
  // Transforms slug to title as a fallback.
128
128
  title: capitalCase( slug ),
129
129
  ...optionsValues,
130
+ variant,
130
131
  };
131
132
  await scaffold( projectTemplate, answers );
132
133
  } else {
package/lib/scaffold.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- const { pascalCase, snakeCase } = require( 'change-case' );
5
4
  const { join } = require( 'path' );
5
+ const { pascalCase, snakeCase } = require( 'change-case' );
6
6
 
7
7
  /**
8
8
  * Internal dependencies
@@ -16,7 +16,12 @@ const { writeOutputAsset, writeOutputTemplate } = require( './output' );
16
16
  const { getOutputTemplates, getOutputAssets } = require( './templates' );
17
17
 
18
18
  module.exports = async (
19
- { blockOutputTemplates, pluginOutputTemplates, outputAssets },
19
+ {
20
+ blockOutputTemplates,
21
+ pluginOutputTemplates,
22
+ outputAssets,
23
+ variantTemplates,
24
+ },
20
25
  {
21
26
  $schema,
22
27
  apiVersion,
@@ -59,6 +64,7 @@ module.exports = async (
59
64
  customBlockJSON,
60
65
  example,
61
66
  transformer,
67
+ variant,
62
68
  pluginTemplatesPath: variantPluginTemplatesPath,
63
69
  blockTemplatesPath: variantBlockTemplatesPath,
64
70
  assetsPath: variantAssetsPath,
@@ -118,29 +124,49 @@ module.exports = async (
118
124
  ...variantVars,
119
125
  };
120
126
 
121
- // Check for the pluginTemplates path in the variant
122
- if ( variantPluginTemplatesPath === null ) {
123
- pluginOutputTemplates = {};
124
- } else if ( variantPluginTemplatesPath ) {
125
- pluginOutputTemplates = await getOutputTemplates(
126
- variantPluginTemplatesPath
127
- );
128
- }
127
+ // Check for variant-specific templates
128
+ // If the variant has pre-processed templates, use them; otherwise fall back to path-based loading
129
+ if ( variant && variantTemplates && variantTemplates[ variant ] ) {
130
+ const variantTemplate = variantTemplates[ variant ];
129
131
 
130
- // Check for the blockTemplatesPath path in the variant
131
- if ( variantBlockTemplatesPath === null ) {
132
- blockOutputTemplates = {};
133
- } else if ( variantBlockTemplatesPath ) {
134
- blockOutputTemplates = await getOutputTemplates(
135
- variantBlockTemplatesPath
136
- );
137
- }
132
+ // null = use default from main template, {} or object = use variant's templates
133
+ if ( variantTemplate.pluginOutputTemplates !== null ) {
134
+ pluginOutputTemplates = variantTemplate.pluginOutputTemplates;
135
+ }
138
136
 
139
- // Check for the assetsPath
140
- if ( variantAssetsPath === null ) {
141
- outputAssets = {};
142
- } else if ( variantAssetsPath ) {
143
- outputAssets = await getOutputAssets( variantAssetsPath );
137
+ if ( variantTemplate.blockOutputTemplates !== null ) {
138
+ blockOutputTemplates = variantTemplate.blockOutputTemplates;
139
+ }
140
+
141
+ if ( variantTemplate.outputAssets !== null ) {
142
+ outputAssets = variantTemplate.outputAssets;
143
+ }
144
+ } else {
145
+ // Fallback: legacy path-based loading for backward compatibility
146
+ // Check for the pluginTemplates path in the variant
147
+ if ( variantPluginTemplatesPath === null ) {
148
+ pluginOutputTemplates = {};
149
+ } else if ( variantPluginTemplatesPath ) {
150
+ pluginOutputTemplates = await getOutputTemplates(
151
+ variantPluginTemplatesPath
152
+ );
153
+ }
154
+
155
+ // Check for the blockTemplatesPath path in the variant
156
+ if ( variantBlockTemplatesPath === null ) {
157
+ blockOutputTemplates = {};
158
+ } else if ( variantBlockTemplatesPath ) {
159
+ blockOutputTemplates = await getOutputTemplates(
160
+ variantBlockTemplatesPath
161
+ );
162
+ }
163
+
164
+ // Check for the assetsPath
165
+ if ( variantAssetsPath === null ) {
166
+ outputAssets = {};
167
+ } else if ( variantAssetsPath ) {
168
+ outputAssets = await getOutputAssets( variantAssetsPath );
169
+ }
144
170
  }
145
171
 
146
172
  if ( ! plugin && Object.keys( blockOutputTemplates ) < 1 ) {
package/lib/templates.js CHANGED
@@ -1,15 +1,14 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
+ const { existsSync } = require( 'fs' );
5
+ const { mkdtemp, readFile } = require( 'fs' ).promises;
6
+ const { tmpdir } = require( 'os' );
7
+ const { join, resolve } = require( 'path' );
4
8
  const inquirer = require( '@inquirer/prompts' );
5
9
  const { command } = require( 'execa' );
6
10
  const glob = require( 'fast-glob' );
7
- const { resolve } = require( 'path' );
8
- const { existsSync } = require( 'fs' );
9
- const { mkdtemp, readFile } = require( 'fs' ).promises;
10
11
  const npmPackageArg = require( 'npm-package-arg' );
11
- const { tmpdir } = require( 'os' );
12
- const { join } = require( 'path' );
13
12
  const rimraf = require( 'rimraf' ).sync;
14
13
 
15
14
  /**
@@ -153,6 +152,49 @@ const configToTemplate = async ( {
153
152
  blockTemplatesPath || join( __dirname, 'templates', 'block' );
154
153
  }
155
154
 
155
+ // Process variant-specific template paths
156
+ const variantTemplates = {};
157
+ for ( const [ variantName, variantConfig ] of Object.entries( variants ) ) {
158
+ if ( ! variantConfig ) {
159
+ continue;
160
+ }
161
+
162
+ const variantPluginTemplatesPath = variantConfig.pluginTemplatesPath;
163
+ const variantBlockTemplatesPath = variantConfig.blockTemplatesPath;
164
+ const variantAssetsPath = variantConfig.assetsPath;
165
+
166
+ let pluginOutputTemplates = null;
167
+ if ( variantPluginTemplatesPath === null ) {
168
+ pluginOutputTemplates = {};
169
+ } else if ( variantPluginTemplatesPath ) {
170
+ pluginOutputTemplates = await getOutputTemplates(
171
+ variantPluginTemplatesPath
172
+ );
173
+ }
174
+
175
+ let blockOutputTemplates = null;
176
+ if ( variantBlockTemplatesPath === null ) {
177
+ blockOutputTemplates = {};
178
+ } else if ( variantBlockTemplatesPath ) {
179
+ blockOutputTemplates = await getOutputTemplates(
180
+ variantBlockTemplatesPath
181
+ );
182
+ }
183
+
184
+ let outputAssets = null;
185
+ if ( variantAssetsPath === null ) {
186
+ outputAssets = {};
187
+ } else if ( variantAssetsPath ) {
188
+ outputAssets = await getOutputAssets( variantAssetsPath );
189
+ }
190
+
191
+ variantTemplates[ variantName ] = {
192
+ pluginOutputTemplates,
193
+ blockOutputTemplates,
194
+ outputAssets,
195
+ };
196
+ }
197
+
156
198
  return {
157
199
  blockOutputTemplates: blockTemplatesPath
158
200
  ? await getOutputTemplates( blockTemplatesPath )
@@ -161,6 +203,7 @@ const configToTemplate = async ( {
161
203
  outputAssets: assetsPath ? await getOutputAssets( assetsPath ) : {},
162
204
  defaultValues,
163
205
  variants,
206
+ variantTemplates,
164
207
  };
165
208
  };
166
209
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/create-block",
3
- "version": "4.80.2-next.ba3aee3a2.0",
3
+ "version": "4.81.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",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@inquirer/prompts": "^7.2.0",
41
- "@wordpress/lazy-import": "^2.37.1-next.ba3aee3a2.0",
41
+ "@wordpress/lazy-import": "^2.38.0",
42
42
  "chalk": "^4.0.0",
43
43
  "change-case": "^4.1.2",
44
44
  "check-node-version": "^4.1.0",
@@ -54,5 +54,5 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  },
57
- "gitHead": "67d2e486fcd40c753591cf911ca0659132f519ca"
57
+ "gitHead": "50c4c0f51e4797c217946ce42adfaa5eb026f33f"
58
58
  }