@wp-typia/create-workspace-template 0.14.0 → 0.15.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.
@@ -25,6 +25,7 @@ Variations and patterns can also be added after the first block exists:
25
25
  ```bash
26
26
  wp-typia add variation hero-card --block counter-card
27
27
  wp-typia add pattern hero-layout
28
+ wp-typia add rest-resource snapshots --namespace {{namespace}}/v1 --methods list,read,create
28
29
  ```
29
30
 
30
31
  ## Development
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-typia/create-workspace-template",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Official empty wp-typia workspace template package",
5
5
  "packageManager": "bun@1.3.11",
6
6
  "type": "module",
@@ -47,8 +47,10 @@
47
47
  "@wordpress/block-editor": "^15.2.0",
48
48
  "@wordpress/blocks": "^15.2.0",
49
49
  "@wordpress/components": "^30.2.0",
50
+ "@wordpress/editor": "^14.44.0",
50
51
  "@wordpress/element": "^6.29.0",
51
52
  "@wordpress/i18n": "^6.2.0",
52
- "@wordpress/interactivity": "^6.29.0"
53
+ "@wordpress/interactivity": "^6.29.0",
54
+ "@wordpress/plugins": "^7.44.0"
53
55
  }
54
56
  }
@@ -26,6 +26,28 @@ export interface WorkspaceBindingSourceConfig {
26
26
  slug: string;
27
27
  }
28
28
 
29
+ export interface WorkspaceRestResourceConfig {
30
+ apiFile: string;
31
+ clientFile: string;
32
+ dataFile: string;
33
+ methods: Array< 'list' | 'read' | 'create' | 'update' | 'delete' >;
34
+ namespace: string;
35
+ openApiFile: string;
36
+ phpFile: string;
37
+ restManifest?: ReturnType<
38
+ typeof import( '@wp-typia/block-runtime/metadata-core' ).defineEndpointManifest
39
+ >;
40
+ slug: string;
41
+ typesFile: string;
42
+ validatorsFile: string;
43
+ }
44
+
45
+ export interface WorkspaceEditorPluginConfig {
46
+ file: string;
47
+ slug: string;
48
+ slot: string;
49
+ }
50
+
29
51
  export const BLOCKS: WorkspaceBlockConfig[] = [
30
52
  // wp-typia add block entries
31
53
  ];
@@ -41,3 +63,11 @@ export const PATTERNS: WorkspacePatternConfig[] = [
41
63
  export const BINDING_SOURCES: WorkspaceBindingSourceConfig[] = [
42
64
  // wp-typia add binding-source entries
43
65
  ];
66
+
67
+ export const REST_RESOURCES: WorkspaceRestResourceConfig[] = [
68
+ // wp-typia add rest-resource entries
69
+ ];
70
+
71
+ export const EDITOR_PLUGINS: WorkspaceEditorPluginConfig[] = [
72
+ // wp-typia add editor-plugin entries
73
+ ];
@@ -22,7 +22,12 @@ function getBlockSlugs() {
22
22
  }
23
23
 
24
24
  function hasSharedEditorEntries() {
25
- for ( const relativePath of [ 'src/bindings/index.ts', 'src/bindings/index.js' ] ) {
25
+ for ( const relativePath of [
26
+ 'src/bindings/index.ts',
27
+ 'src/bindings/index.js',
28
+ 'src/editor-plugins/index.ts',
29
+ 'src/editor-plugins/index.js',
30
+ ] ) {
26
31
  if ( fs.existsSync( path.join( process.cwd(), relativePath ) ) ) {
27
32
  return true;
28
33
  }
@@ -8,7 +8,12 @@ import {
8
8
  syncTypeSchemas,
9
9
  } from '@wp-typia/block-runtime/metadata-core';
10
10
 
11
- import { BLOCKS, type WorkspaceBlockConfig } from './block-config';
11
+ import {
12
+ BLOCKS,
13
+ REST_RESOURCES,
14
+ type WorkspaceBlockConfig,
15
+ type WorkspaceRestResourceConfig,
16
+ } from './block-config';
12
17
 
13
18
  function parseCliOptions( argv: string[] ) {
14
19
  const options = {
@@ -42,6 +47,25 @@ function isRestEnabledBlock(
42
47
  );
43
48
  }
44
49
 
50
+ function isWorkspaceRestResource(
51
+ resource: WorkspaceRestResourceConfig
52
+ ): resource is WorkspaceRestResourceConfig & {
53
+ clientFile: string;
54
+ openApiFile: string;
55
+ restManifest: NonNullable< WorkspaceRestResourceConfig[ 'restManifest' ] >;
56
+ typesFile: string;
57
+ validatorsFile: string;
58
+ } {
59
+ return (
60
+ typeof resource.clientFile === 'string' &&
61
+ typeof resource.openApiFile === 'string' &&
62
+ typeof resource.typesFile === 'string' &&
63
+ typeof resource.validatorsFile === 'string' &&
64
+ typeof resource.restManifest === 'object' &&
65
+ resource.restManifest !== null
66
+ );
67
+ }
68
+
45
69
  async function assertTypeArtifactsCurrent( block: WorkspaceBlockConfig ) {
46
70
  const report = await runSyncBlockMetadata(
47
71
  {
@@ -73,12 +97,13 @@ async function assertTypeArtifactsCurrent( block: WorkspaceBlockConfig ) {
73
97
  async function main() {
74
98
  const options = parseCliOptions( process.argv.slice( 2 ) );
75
99
  const restBlocks = BLOCKS.filter( isRestEnabledBlock );
100
+ const restResources = REST_RESOURCES.filter( isWorkspaceRestResource );
76
101
 
77
- if ( restBlocks.length === 0 ) {
102
+ if ( restBlocks.length === 0 && restResources.length === 0 ) {
78
103
  console.log(
79
104
  options.check
80
- ? 'ℹ️ No REST-enabled workspace blocks are registered yet. `sync-rest --check` is already clean.'
81
- : 'ℹ️ No REST-enabled workspace blocks are registered yet.'
105
+ ? 'ℹ️ No REST-enabled workspace blocks or plugin-level REST resources are registered yet. `sync-rest --check` is already clean.'
106
+ : 'ℹ️ No REST-enabled workspace blocks or plugin-level REST resources are registered yet.'
82
107
  );
83
108
  return;
84
109
  }
@@ -142,10 +167,59 @@ async function main() {
142
167
  );
143
168
  }
144
169
 
170
+ for ( const resource of restResources ) {
171
+ const contracts = resource.restManifest.contracts;
172
+
173
+ for ( const [ baseName, contract ] of Object.entries( contracts ) ) {
174
+ await syncTypeSchemas(
175
+ {
176
+ jsonSchemaFile: path.join(
177
+ path.dirname( resource.typesFile ),
178
+ 'api-schemas',
179
+ `${ baseName }.schema.json`
180
+ ),
181
+ openApiFile: path.join(
182
+ path.dirname( resource.typesFile ),
183
+ 'api-schemas',
184
+ `${ baseName }.openapi.json`
185
+ ),
186
+ sourceTypeName: contract.sourceTypeName,
187
+ typesFile: resource.typesFile,
188
+ },
189
+ {
190
+ check: options.check,
191
+ }
192
+ );
193
+ }
194
+
195
+ await syncRestOpenApi(
196
+ {
197
+ manifest: resource.restManifest,
198
+ openApiFile: resource.openApiFile,
199
+ typesFile: resource.typesFile,
200
+ },
201
+ {
202
+ check: options.check,
203
+ }
204
+ );
205
+
206
+ await syncEndpointClient(
207
+ {
208
+ clientFile: resource.clientFile,
209
+ manifest: resource.restManifest,
210
+ typesFile: resource.typesFile,
211
+ validatorsFile: resource.validatorsFile,
212
+ },
213
+ {
214
+ check: options.check,
215
+ }
216
+ );
217
+ }
218
+
145
219
  console.log(
146
220
  options.check
147
- ? '✅ REST contract schemas, portable API clients, and endpoint-aware OpenAPI documents are already up to date with the TypeScript types!'
148
- : '✅ REST contract schemas, portable API clients, and endpoint-aware OpenAPI documents generated from TypeScript types!'
221
+ ? '✅ REST contract schemas, portable API clients, and endpoint-aware OpenAPI documents are already up to date for workspace blocks and plugin-level resources!'
222
+ : '✅ REST contract schemas, portable API clients, and endpoint-aware OpenAPI documents generated for workspace blocks and plugin-level resources!'
149
223
  );
150
224
  }
151
225
 
@@ -0,0 +1 @@
1
+
@@ -189,14 +189,25 @@ function getEditorEntries() {
189
189
  function getSharedEditorEntries() {
190
190
  const entries = [];
191
191
 
192
- for ( const relativePath of [ 'src/bindings/index.ts', 'src/bindings/index.js' ] ) {
193
- const entryPath = path.resolve( process.cwd(), relativePath );
194
- if ( ! fs.existsSync( entryPath ) ) {
195
- continue;
196
- }
192
+ for ( const [ entryName, candidates ] of [
193
+ [
194
+ 'bindings/index',
195
+ [ 'src/bindings/index.ts', 'src/bindings/index.js' ],
196
+ ],
197
+ [
198
+ 'editor-plugins/index',
199
+ [ 'src/editor-plugins/index.ts', 'src/editor-plugins/index.js' ],
200
+ ],
201
+ ] ) {
202
+ for ( const relativePath of candidates ) {
203
+ const entryPath = path.resolve( process.cwd(), relativePath );
204
+ if ( ! fs.existsSync( entryPath ) ) {
205
+ continue;
206
+ }
197
207
 
198
- entries.push( [ 'bindings/index', entryPath ] );
199
- break;
208
+ entries.push( [ entryName, entryPath ] );
209
+ break;
210
+ }
200
211
  }
201
212
 
202
213
  return Object.fromEntries( entries );
@@ -117,6 +117,42 @@ function {{phpPrefix}}_enqueue_binding_sources_editor() {
117
117
  );
118
118
  }
119
119
 
120
+ function {{phpPrefix}}_enqueue_editor_plugins_editor() {
121
+ $script_path = __DIR__ . '/build/editor-plugins/index.js';
122
+ $asset_path = __DIR__ . '/build/editor-plugins/index.asset.php';
123
+ $style_path = __DIR__ . '/build/editor-plugins/style-index.css';
124
+ $style_rtl_path = __DIR__ . '/build/editor-plugins/style-index-rtl.css';
125
+
126
+ if ( ! file_exists( $script_path ) || ! file_exists( $asset_path ) ) {
127
+ return;
128
+ }
129
+
130
+ $asset = require $asset_path;
131
+ if ( ! is_array( $asset ) ) {
132
+ $asset = array();
133
+ }
134
+
135
+ wp_enqueue_script(
136
+ '{{slugKebabCase}}-editor-plugins',
137
+ plugins_url( 'build/editor-plugins/index.js', __FILE__ ),
138
+ isset( $asset['dependencies'] ) && is_array( $asset['dependencies'] ) ? $asset['dependencies'] : array(),
139
+ isset( $asset['version'] ) ? $asset['version'] : filemtime( $script_path ),
140
+ true
141
+ );
142
+
143
+ if ( file_exists( $style_path ) ) {
144
+ wp_enqueue_style(
145
+ '{{slugKebabCase}}-editor-plugins',
146
+ plugins_url( 'build/editor-plugins/style-index.css', __FILE__ ),
147
+ array(),
148
+ isset( $asset['version'] ) ? $asset['version'] : filemtime( $style_path )
149
+ );
150
+ if ( file_exists( $style_rtl_path ) ) {
151
+ wp_style_add_data( '{{slugKebabCase}}-editor-plugins', 'rtl', 'replace' );
152
+ }
153
+ }
154
+ }
155
+
120
156
  function {{phpPrefix}}_register_pattern_category() {
121
157
  if ( function_exists( 'register_block_pattern_category' ) ) {
122
158
  register_block_pattern_category(
@@ -143,3 +179,4 @@ add_action( 'init', '{{phpPrefix}}_register_binding_sources', 20 );
143
179
  add_action( 'init', '{{phpPrefix}}_register_pattern_category' );
144
180
  add_action( 'init', '{{phpPrefix}}_register_patterns', 20 );
145
181
  add_action( 'enqueue_block_editor_assets', '{{phpPrefix}}_enqueue_binding_sources_editor' );
182
+ add_action( 'enqueue_block_editor_assets', '{{phpPrefix}}_enqueue_editor_plugins_editor' );