@wp-typia/project-tools 0.20.1 → 0.21.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.
Files changed (48) hide show
  1. package/dist/runtime/cli-add-block.js +1 -1
  2. package/dist/runtime/cli-add-shared.d.ts +73 -5
  3. package/dist/runtime/cli-add-shared.js +58 -11
  4. package/dist/runtime/cli-add-workspace-ability.js +11 -57
  5. package/dist/runtime/cli-add-workspace-admin-view.d.ts +23 -0
  6. package/dist/runtime/cli-add-workspace-admin-view.js +872 -0
  7. package/dist/runtime/cli-add-workspace-ai-anchors.js +2 -5
  8. package/dist/runtime/cli-add-workspace-ai-source-emitters.d.ts +0 -4
  9. package/dist/runtime/cli-add-workspace-ai-source-emitters.js +7 -17
  10. package/dist/runtime/cli-add-workspace-ai.js +4 -6
  11. package/dist/runtime/cli-add-workspace-assets.d.ts +13 -5
  12. package/dist/runtime/cli-add-workspace-assets.js +290 -106
  13. package/dist/runtime/cli-add-workspace-rest-anchors.js +2 -5
  14. package/dist/runtime/cli-add-workspace-rest-source-emitters.d.ts +0 -1
  15. package/dist/runtime/cli-add-workspace-rest-source-emitters.js +7 -14
  16. package/dist/runtime/cli-add-workspace-rest.js +4 -6
  17. package/dist/runtime/cli-add-workspace.d.ts +58 -1
  18. package/dist/runtime/cli-add-workspace.js +588 -18
  19. package/dist/runtime/cli-add.d.ts +1 -1
  20. package/dist/runtime/cli-add.js +1 -1
  21. package/dist/runtime/cli-core.d.ts +8 -5
  22. package/dist/runtime/cli-core.js +7 -4
  23. package/dist/runtime/cli-diagnostics.d.ts +84 -1
  24. package/dist/runtime/cli-diagnostics.js +90 -3
  25. package/dist/runtime/cli-doctor-workspace.js +552 -13
  26. package/dist/runtime/cli-doctor.d.ts +4 -2
  27. package/dist/runtime/cli-doctor.js +2 -1
  28. package/dist/runtime/cli-help.js +19 -9
  29. package/dist/runtime/cli-init.d.ts +67 -3
  30. package/dist/runtime/cli-init.js +603 -64
  31. package/dist/runtime/cli-validation.js +4 -3
  32. package/dist/runtime/index.d.ts +9 -4
  33. package/dist/runtime/index.js +7 -3
  34. package/dist/runtime/package-json-types.d.ts +12 -0
  35. package/dist/runtime/package-json-types.js +1 -0
  36. package/dist/runtime/package-versions.d.ts +17 -2
  37. package/dist/runtime/package-versions.js +46 -1
  38. package/dist/runtime/php-utils.d.ts +16 -0
  39. package/dist/runtime/php-utils.js +59 -0
  40. package/dist/runtime/scaffold-answer-resolution.js +35 -10
  41. package/dist/runtime/scaffold-apply-utils.d.ts +2 -3
  42. package/dist/runtime/scaffold-apply-utils.js +3 -43
  43. package/dist/runtime/template-source-cache.d.ts +112 -0
  44. package/dist/runtime/template-source-cache.js +434 -0
  45. package/dist/runtime/template-source-seeds.js +333 -53
  46. package/dist/runtime/workspace-inventory.d.ts +43 -2
  47. package/dist/runtime/workspace-inventory.js +138 -5
  48. package/package.json +2 -2
@@ -3,13 +3,17 @@ import path from "node:path";
3
3
  import { readFile, writeFile } from "node:fs/promises";
4
4
  import ts from "typescript";
5
5
  import { REST_RESOURCE_METHOD_IDS } from "./cli-add-shared.js";
6
+ import { escapeRegex } from "./php-utils.js";
6
7
  export const BLOCK_CONFIG_ENTRY_MARKER = "\t// wp-typia add block entries";
7
8
  export const VARIATION_CONFIG_ENTRY_MARKER = "\t// wp-typia add variation entries";
9
+ export const BLOCK_STYLE_CONFIG_ENTRY_MARKER = "\t// wp-typia add style entries";
10
+ export const BLOCK_TRANSFORM_CONFIG_ENTRY_MARKER = "\t// wp-typia add transform entries";
8
11
  export const PATTERN_CONFIG_ENTRY_MARKER = "\t// wp-typia add pattern entries";
9
12
  export const BINDING_SOURCE_CONFIG_ENTRY_MARKER = "\t// wp-typia add binding-source entries";
10
13
  export const REST_RESOURCE_CONFIG_ENTRY_MARKER = "\t// wp-typia add rest-resource entries";
11
14
  export const ABILITY_CONFIG_ENTRY_MARKER = "\t// wp-typia add ability entries";
12
15
  export const AI_FEATURE_CONFIG_ENTRY_MARKER = "\t// wp-typia add ai-feature entries";
16
+ export const ADMIN_VIEW_CONFIG_ENTRY_MARKER = "\t// wp-typia add admin-view entries";
13
17
  /**
14
18
  * Marker used to append generated editor-plugin entries into `EDITOR_PLUGINS`.
15
19
  */
@@ -28,6 +32,36 @@ export const VARIATIONS: WorkspaceVariationConfig[] = [
28
32
  \t// wp-typia add variation entries
29
33
  ];
30
34
  `;
35
+ const BLOCK_STYLES_INTERFACE_SECTION = `
36
+
37
+ export interface WorkspaceBlockStyleConfig {
38
+ \tblock: string;
39
+ \tfile: string;
40
+ \tslug: string;
41
+ }
42
+ `;
43
+ const BLOCK_STYLES_CONST_SECTION = `
44
+
45
+ export const BLOCK_STYLES: WorkspaceBlockStyleConfig[] = [
46
+ \t// wp-typia add style entries
47
+ ];
48
+ `;
49
+ const BLOCK_TRANSFORMS_INTERFACE_SECTION = `
50
+
51
+ export interface WorkspaceBlockTransformConfig {
52
+ \tblock: string;
53
+ \tfile: string;
54
+ \tfrom: string;
55
+ \tslug: string;
56
+ \tto: string;
57
+ }
58
+ `;
59
+ const BLOCK_TRANSFORMS_CONST_SECTION = `
60
+
61
+ export const BLOCK_TRANSFORMS: WorkspaceBlockTransformConfig[] = [
62
+ \t// wp-typia add transform entries
63
+ ];
64
+ `;
31
65
  const PATTERNS_INTERFACE_SECTION = `
32
66
 
33
67
  export interface WorkspacePatternConfig {
@@ -44,6 +78,8 @@ export const PATTERNS: WorkspacePatternConfig[] = [
44
78
  const BINDING_SOURCES_INTERFACE_SECTION = `
45
79
 
46
80
  export interface WorkspaceBindingSourceConfig {
81
+ \tattribute?: string;
82
+ \tblock?: string;
47
83
  \teditorFile: string;
48
84
  \tserverFile: string;
49
85
  \tslug: string;
@@ -135,6 +171,21 @@ export const AI_FEATURES: WorkspaceAiFeatureConfig[] = [
135
171
  \t// wp-typia add ai-feature entries
136
172
  ];
137
173
  `;
174
+ const ADMIN_VIEWS_INTERFACE_SECTION = `
175
+
176
+ export interface WorkspaceAdminViewConfig {
177
+ \tfile: string;
178
+ \tphpFile: string;
179
+ \tslug: string;
180
+ \tsource?: string;
181
+ }
182
+ `;
183
+ const ADMIN_VIEWS_CONST_SECTION = `
184
+
185
+ export const ADMIN_VIEWS: WorkspaceAdminViewConfig[] = [
186
+ \t// wp-typia add admin-view entries
187
+ ];
188
+ `;
138
189
  const EDITOR_PLUGINS_INTERFACE_SECTION = `
139
190
 
140
191
  export interface WorkspaceEditorPluginConfig {
@@ -254,6 +305,32 @@ function parseVariationEntries(arrayLiteral) {
254
305
  };
255
306
  });
256
307
  }
308
+ function parseBlockStyleEntries(arrayLiteral) {
309
+ return arrayLiteral.elements.map((element, elementIndex) => {
310
+ if (!ts.isObjectLiteralExpression(element)) {
311
+ throw new Error(`BLOCK_STYLES[${elementIndex}] must be an object literal in scripts/block-config.ts.`);
312
+ }
313
+ return {
314
+ block: getRequiredStringProperty("BLOCK_STYLES", elementIndex, element, "block"),
315
+ file: getRequiredStringProperty("BLOCK_STYLES", elementIndex, element, "file"),
316
+ slug: getRequiredStringProperty("BLOCK_STYLES", elementIndex, element, "slug"),
317
+ };
318
+ });
319
+ }
320
+ function parseBlockTransformEntries(arrayLiteral) {
321
+ return arrayLiteral.elements.map((element, elementIndex) => {
322
+ if (!ts.isObjectLiteralExpression(element)) {
323
+ throw new Error(`BLOCK_TRANSFORMS[${elementIndex}] must be an object literal in scripts/block-config.ts.`);
324
+ }
325
+ return {
326
+ block: getRequiredStringProperty("BLOCK_TRANSFORMS", elementIndex, element, "block"),
327
+ file: getRequiredStringProperty("BLOCK_TRANSFORMS", elementIndex, element, "file"),
328
+ from: getRequiredStringProperty("BLOCK_TRANSFORMS", elementIndex, element, "from"),
329
+ slug: getRequiredStringProperty("BLOCK_TRANSFORMS", elementIndex, element, "slug"),
330
+ to: getRequiredStringProperty("BLOCK_TRANSFORMS", elementIndex, element, "to"),
331
+ };
332
+ });
333
+ }
257
334
  function parsePatternEntries(arrayLiteral) {
258
335
  return arrayLiteral.elements.map((element, elementIndex) => {
259
336
  if (!ts.isObjectLiteralExpression(element)) {
@@ -271,6 +348,8 @@ function parseBindingSourceEntries(arrayLiteral) {
271
348
  throw new Error(`BINDING_SOURCES[${elementIndex}] must be an object literal in scripts/block-config.ts.`);
272
349
  }
273
350
  return {
351
+ attribute: getOptionalStringProperty("BINDING_SOURCES", elementIndex, element, "attribute"),
352
+ block: getOptionalStringProperty("BINDING_SOURCES", elementIndex, element, "block"),
274
353
  editorFile: getRequiredStringProperty("BINDING_SOURCES", elementIndex, element, "editorFile"),
275
354
  serverFile: getRequiredStringProperty("BINDING_SOURCES", elementIndex, element, "serverFile"),
276
355
  slug: getRequiredStringProperty("BINDING_SOURCES", elementIndex, element, "slug"),
@@ -351,6 +430,19 @@ function parseEditorPluginEntries(arrayLiteral) {
351
430
  };
352
431
  });
353
432
  }
433
+ function parseAdminViewEntries(arrayLiteral) {
434
+ return arrayLiteral.elements.map((element, elementIndex) => {
435
+ if (!ts.isObjectLiteralExpression(element)) {
436
+ throw new Error(`ADMIN_VIEWS[${elementIndex}] must be an object literal in scripts/block-config.ts.`);
437
+ }
438
+ return {
439
+ file: getRequiredStringProperty("ADMIN_VIEWS", elementIndex, element, "file"),
440
+ phpFile: getRequiredStringProperty("ADMIN_VIEWS", elementIndex, element, "phpFile"),
441
+ slug: getRequiredStringProperty("ADMIN_VIEWS", elementIndex, element, "slug"),
442
+ source: getOptionalStringProperty("ADMIN_VIEWS", elementIndex, element, "source"),
443
+ };
444
+ });
445
+ }
354
446
  /**
355
447
  * Parse workspace inventory entries from the source of `scripts/block-config.ts`.
356
448
  *
@@ -365,15 +457,24 @@ export function parseWorkspaceInventorySource(source) {
365
457
  throw new Error("scripts/block-config.ts must export a BLOCKS array.");
366
458
  }
367
459
  const variationArray = findExportedArrayLiteral(sourceFile, "VARIATIONS");
460
+ const blockStyleArray = findExportedArrayLiteral(sourceFile, "BLOCK_STYLES");
461
+ const blockTransformArray = findExportedArrayLiteral(sourceFile, "BLOCK_TRANSFORMS");
368
462
  const patternArray = findExportedArrayLiteral(sourceFile, "PATTERNS");
369
463
  const bindingSourceArray = findExportedArrayLiteral(sourceFile, "BINDING_SOURCES");
370
464
  const restResourceArray = findExportedArrayLiteral(sourceFile, "REST_RESOURCES");
371
465
  const abilityArray = findExportedArrayLiteral(sourceFile, "ABILITIES");
372
466
  const aiFeatureArray = findExportedArrayLiteral(sourceFile, "AI_FEATURES");
467
+ const adminViewArray = findExportedArrayLiteral(sourceFile, "ADMIN_VIEWS");
373
468
  const editorPluginArray = findExportedArrayLiteral(sourceFile, "EDITOR_PLUGINS");
374
469
  if (variationArray.found && !variationArray.array) {
375
470
  throw new Error("scripts/block-config.ts must export VARIATIONS as an array literal.");
376
471
  }
472
+ if (blockStyleArray.found && !blockStyleArray.array) {
473
+ throw new Error("scripts/block-config.ts must export BLOCK_STYLES as an array literal.");
474
+ }
475
+ if (blockTransformArray.found && !blockTransformArray.array) {
476
+ throw new Error("scripts/block-config.ts must export BLOCK_TRANSFORMS as an array literal.");
477
+ }
377
478
  if (patternArray.found && !patternArray.array) {
378
479
  throw new Error("scripts/block-config.ts must export PATTERNS as an array literal.");
379
480
  }
@@ -389,19 +490,30 @@ export function parseWorkspaceInventorySource(source) {
389
490
  if (aiFeatureArray.found && !aiFeatureArray.array) {
390
491
  throw new Error("scripts/block-config.ts must export AI_FEATURES as an array literal.");
391
492
  }
493
+ if (adminViewArray.found && !adminViewArray.array) {
494
+ throw new Error("scripts/block-config.ts must export ADMIN_VIEWS as an array literal.");
495
+ }
392
496
  if (editorPluginArray.found && !editorPluginArray.array) {
393
497
  throw new Error("scripts/block-config.ts must export EDITOR_PLUGINS as an array literal.");
394
498
  }
395
499
  return {
396
500
  abilities: abilityArray.array ? parseAbilityEntries(abilityArray.array) : [],
501
+ adminViews: adminViewArray.array ? parseAdminViewEntries(adminViewArray.array) : [],
397
502
  aiFeatures: aiFeatureArray.array ? parseAiFeatureEntries(aiFeatureArray.array) : [],
398
503
  bindingSources: bindingSourceArray.array
399
504
  ? parseBindingSourceEntries(bindingSourceArray.array)
400
505
  : [],
506
+ blockStyles: blockStyleArray.array ? parseBlockStyleEntries(blockStyleArray.array) : [],
507
+ blockTransforms: blockTransformArray.array
508
+ ? parseBlockTransformEntries(blockTransformArray.array)
509
+ : [],
401
510
  blocks: parseBlockEntries(blockArray.array),
402
511
  hasAbilitiesSection: abilityArray.found,
512
+ hasAdminViewsSection: adminViewArray.found,
403
513
  hasAiFeaturesSection: aiFeatureArray.found,
404
514
  hasBindingSourcesSection: bindingSourceArray.found,
515
+ hasBlockStylesSection: blockStyleArray.found,
516
+ hasBlockTransformsSection: blockTransformArray.found,
405
517
  hasEditorPluginsSection: editorPluginArray.found,
406
518
  hasPatternsSection: patternArray.found,
407
519
  hasRestResourcesSection: restResourceArray.found,
@@ -468,6 +580,18 @@ function ensureWorkspaceInventorySections(source) {
468
580
  if (!/export\s+const\s+VARIATIONS\b/u.test(nextSource)) {
469
581
  nextSource += VARIATIONS_CONST_SECTION;
470
582
  }
583
+ if (!/export\s+interface\s+WorkspaceBlockStyleConfig\b/u.test(nextSource)) {
584
+ nextSource += BLOCK_STYLES_INTERFACE_SECTION;
585
+ }
586
+ if (!/export\s+const\s+BLOCK_STYLES\b/u.test(nextSource)) {
587
+ nextSource += BLOCK_STYLES_CONST_SECTION;
588
+ }
589
+ if (!/export\s+interface\s+WorkspaceBlockTransformConfig\b/u.test(nextSource)) {
590
+ nextSource += BLOCK_TRANSFORMS_INTERFACE_SECTION;
591
+ }
592
+ if (!/export\s+const\s+BLOCK_TRANSFORMS\b/u.test(nextSource)) {
593
+ nextSource += BLOCK_TRANSFORMS_CONST_SECTION;
594
+ }
471
595
  if (!/export\s+interface\s+WorkspacePatternConfig\b/u.test(nextSource)) {
472
596
  nextSource += PATTERNS_INTERFACE_SECTION;
473
597
  }
@@ -498,6 +622,12 @@ function ensureWorkspaceInventorySections(source) {
498
622
  if (!/export\s+const\s+AI_FEATURES\b/u.test(nextSource)) {
499
623
  nextSource += AI_FEATURES_CONST_SECTION;
500
624
  }
625
+ if (!/export\s+interface\s+WorkspaceAdminViewConfig\b/u.test(nextSource)) {
626
+ nextSource += ADMIN_VIEWS_INTERFACE_SECTION;
627
+ }
628
+ if (!/export\s+const\s+ADMIN_VIEWS\b/u.test(nextSource)) {
629
+ nextSource += ADMIN_VIEWS_CONST_SECTION;
630
+ }
501
631
  if (!/export\s+interface\s+WorkspaceEditorPluginConfig\b/u.test(nextSource)) {
502
632
  nextSource += EDITOR_PLUGINS_INTERFACE_SECTION;
503
633
  }
@@ -515,9 +645,6 @@ function appendEntriesAtMarker(source, marker, entries) {
515
645
  }
516
646
  return source.replace(marker, `${entries.join("\n")}\n${marker}`);
517
647
  }
518
- function escapeRegex(value) {
519
- return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
520
- }
521
648
  function ensureInterfaceField(source, interfaceName, fieldName, fieldSource) {
522
649
  const interfacePattern = new RegExp(`(export\\s+interface\\s+${escapeRegex(interfaceName)}\\s*\\{\\r?\\n)([\\s\\S]*?)(\\r?\\n\\})`, "u");
523
650
  return source.replace(interfacePattern, (match, start, body, end) => {
@@ -547,7 +674,8 @@ function ensureInterfaceField(source, interfaceName, fieldName, fieldSource) {
547
674
  * Update `scripts/block-config.ts` source text with additional inventory entries.
548
675
  *
549
676
  * Missing inventory sections for variations, patterns, binding sources, REST
550
- * resources, workflow abilities, AI features, and editor plugins are created
677
+ * resources, workflow abilities, AI features, editor plugins, block styles, and
678
+ * block transforms are created
551
679
  * automatically before new entries are appended at their marker comments.
552
680
  * When provided, `transformSource` runs before any entries are inserted.
553
681
  *
@@ -555,18 +683,23 @@ function ensureInterfaceField(source, interfaceName, fieldName, fieldSource) {
555
683
  * @param options Entry lists plus an optional source transformer.
556
684
  * @returns Updated source text with all requested inventory entries appended.
557
685
  */
558
- export function updateWorkspaceInventorySource(source, { blockEntries = [], bindingSourceEntries = [], abilityEntries = [], aiFeatureEntries = [], editorPluginEntries = [], patternEntries = [], restResourceEntries = [], variationEntries = [], transformSource, } = {}) {
686
+ export function updateWorkspaceInventorySource(source, { blockEntries = [], blockStyleEntries = [], blockTransformEntries = [], bindingSourceEntries = [], abilityEntries = [], adminViewEntries = [], aiFeatureEntries = [], editorPluginEntries = [], patternEntries = [], restResourceEntries = [], variationEntries = [], transformSource, } = {}) {
559
687
  let nextSource = ensureWorkspaceInventorySections(source);
560
688
  if (transformSource) {
561
689
  nextSource = transformSource(nextSource);
562
690
  }
563
691
  nextSource = appendEntriesAtMarker(nextSource, BLOCK_CONFIG_ENTRY_MARKER, blockEntries);
564
692
  nextSource = appendEntriesAtMarker(nextSource, VARIATION_CONFIG_ENTRY_MARKER, variationEntries);
693
+ nextSource = appendEntriesAtMarker(nextSource, BLOCK_STYLE_CONFIG_ENTRY_MARKER, blockStyleEntries);
694
+ nextSource = appendEntriesAtMarker(nextSource, BLOCK_TRANSFORM_CONFIG_ENTRY_MARKER, blockTransformEntries);
565
695
  nextSource = appendEntriesAtMarker(nextSource, PATTERN_CONFIG_ENTRY_MARKER, patternEntries);
566
696
  nextSource = appendEntriesAtMarker(nextSource, BINDING_SOURCE_CONFIG_ENTRY_MARKER, bindingSourceEntries);
567
697
  nextSource = appendEntriesAtMarker(nextSource, REST_RESOURCE_CONFIG_ENTRY_MARKER, restResourceEntries);
568
698
  nextSource = appendEntriesAtMarker(nextSource, ABILITY_CONFIG_ENTRY_MARKER, abilityEntries);
569
699
  nextSource = appendEntriesAtMarker(nextSource, AI_FEATURE_CONFIG_ENTRY_MARKER, aiFeatureEntries);
700
+ nextSource = appendEntriesAtMarker(nextSource, ADMIN_VIEW_CONFIG_ENTRY_MARKER, adminViewEntries);
701
+ nextSource = ensureInterfaceField(nextSource, "WorkspaceBindingSourceConfig", "attribute", "\tattribute?: string;");
702
+ nextSource = ensureInterfaceField(nextSource, "WorkspaceBindingSourceConfig", "block", "\tblock?: string;");
570
703
  nextSource = ensureInterfaceField(nextSource, "WorkspaceAbilityConfig", "compatibility", WORKSPACE_COMPATIBILITY_CONFIG_FIELD);
571
704
  nextSource = ensureInterfaceField(nextSource, "WorkspaceAiFeatureConfig", "compatibility", WORKSPACE_COMPATIBILITY_CONFIG_FIELD);
572
705
  nextSource = appendEntriesAtMarker(nextSource, EDITOR_PLUGIN_CONFIG_ENTRY_MARKER, editorPluginEntries);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-typia/project-tools",
3
- "version": "0.20.1",
3
+ "version": "0.21.0",
4
4
  "description": "Project orchestration and programmatic tooling for wp-typia",
5
5
  "packageManager": "bun@1.3.11",
6
6
  "type": "module",
@@ -105,7 +105,7 @@
105
105
  "prepack": "bun run build && node ./scripts/publish-manifest.mjs prepare",
106
106
  "postpack": "node ./scripts/publish-manifest.mjs restore",
107
107
  "test": "bun run build && bun test tests/*.test.ts",
108
- "test:scaffold-core": "bun run build && bun test tests/block-generator-service.test.ts tests/built-in-block-artifacts.test.ts tests/scaffold-basic.test.ts tests/scaffold-persistence.test.ts tests/template-source.test.ts tests/init-command.test.ts tests/cli-entry.test.ts tests/cli-prompt.test.ts tests/import-policy.test.ts tests/wordpress-ai-spec.test.ts tests/typia-llm.test.ts",
108
+ "test:scaffold-core": "bun run build && bun test tests/block-generator-service.test.ts tests/built-in-block-artifacts.test.ts tests/scaffold-basic.test.ts tests/scaffold-persistence.test.ts tests/template-source.test.ts tests/init-command.test.ts tests/package-versions.test.ts tests/cli-entry.test.ts tests/cli-prompt.test.ts tests/import-policy.test.ts tests/wordpress-ai-spec.test.ts tests/typia-llm.test.ts",
109
109
  "test:workspace": "bun run build && bun test tests/workspace-add.test.ts tests/workspace-doctor.test.ts",
110
110
  "test:compound": "bun run build && bun test tests/scaffold-compound.test.ts",
111
111
  "test:migration-planning": "bun run build && bun test tests/migration-init.test.ts tests/migration-config.test.ts tests/migration-plan-wizard.test.ts",