@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
@@ -1,9 +1,7 @@
1
1
  import path from "node:path";
2
2
  import { getWorkspaceBootstrapPath, patchFile, } from "./cli-add-shared.js";
3
+ import { hasPhpFunctionDefinition } from "./php-utils.js";
3
4
  const REST_RESOURCE_SERVER_GLOB = "/inc/rest/*.php";
4
- function escapeRegex(value) {
5
- return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
6
- }
7
5
  export async function ensureRestResourceBootstrapAnchors(workspace) {
8
6
  const bootstrapPath = getWorkspaceBootstrapPath(workspace);
9
7
  await patchFile(bootstrapPath, (source) => {
@@ -22,7 +20,6 @@ function ${registerFunctionName}() {
22
20
  /add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
23
21
  /\?>\s*$/u,
24
22
  ];
25
- const hasPhpFunctionDefinition = (functionName) => new RegExp(`function\\s+${escapeRegex(functionName)}\\s*\\(`, "u").test(nextSource);
26
23
  const insertPhpSnippet = (snippet) => {
27
24
  for (const anchor of insertionAnchors) {
28
25
  const candidate = nextSource.replace(anchor, (match) => `${snippet}\n${match}`);
@@ -41,7 +38,7 @@ function ${registerFunctionName}() {
41
38
  }
42
39
  nextSource = `${nextSource.trimEnd()}\n${snippet}\n`;
43
40
  };
44
- if (!hasPhpFunctionDefinition(registerFunctionName)) {
41
+ if (!hasPhpFunctionDefinition(nextSource, registerFunctionName)) {
45
42
  insertPhpSnippet(registerFunction);
46
43
  }
47
44
  else if (!nextSource.includes(REST_RESOURCE_SERVER_GLOB)) {
@@ -1,5 +1,4 @@
1
1
  import { type RestResourceMethodId } from "./cli-add-shared.js";
2
- export declare function toPascalCaseFromSlug(slug: string): string;
3
2
  export declare function buildRestResourceConfigEntry(restResourceSlug: string, namespace: string, methods: RestResourceMethodId[]): string;
4
3
  export declare function buildRestResourceTypesSource(restResourceSlug: string, methods: RestResourceMethodId[]): string;
5
4
  export declare function buildRestResourceValidatorsSource(restResourceSlug: string, methods: RestResourceMethodId[]): string;
@@ -1,13 +1,6 @@
1
- import { normalizeBlockSlug, quoteTsString, } from "./cli-add-shared.js";
1
+ import { quoteTsString, } from "./cli-add-shared.js";
2
2
  import { buildRestResourceEndpointManifest } from "./rest-resource-artifacts.js";
3
- import { toTitleCase } from "./string-case.js";
4
- export function toPascalCaseFromSlug(slug) {
5
- return normalizeBlockSlug(slug)
6
- .split("-")
7
- .filter(Boolean)
8
- .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
9
- .join("");
10
- }
3
+ import { toPascalCase, toTitleCase } from "./string-case.js";
11
4
  function indentMultiline(source, prefix) {
12
5
  return source
13
6
  .split("\n")
@@ -15,7 +8,7 @@ function indentMultiline(source, prefix) {
15
8
  .join("\n");
16
9
  }
17
10
  export function buildRestResourceConfigEntry(restResourceSlug, namespace, methods) {
18
- const pascalCase = toPascalCaseFromSlug(restResourceSlug);
11
+ const pascalCase = toPascalCase(restResourceSlug);
19
12
  const title = toTitleCase(restResourceSlug);
20
13
  const manifest = buildRestResourceEndpointManifest({
21
14
  namespace,
@@ -42,7 +35,7 @@ export function buildRestResourceConfigEntry(restResourceSlug, namespace, method
42
35
  ].join("\n");
43
36
  }
44
37
  export function buildRestResourceTypesSource(restResourceSlug, methods) {
45
- const pascalCase = toPascalCaseFromSlug(restResourceSlug);
38
+ const pascalCase = toPascalCase(restResourceSlug);
46
39
  const lines = [
47
40
  "import { tags } from 'typia';",
48
41
  "",
@@ -74,7 +67,7 @@ export function buildRestResourceTypesSource(restResourceSlug, methods) {
74
67
  return `${lines.join("\n")}\n`;
75
68
  }
76
69
  export function buildRestResourceValidatorsSource(restResourceSlug, methods) {
77
- const pascalCase = toPascalCaseFromSlug(restResourceSlug);
70
+ const pascalCase = toPascalCase(restResourceSlug);
78
71
  const importedTypes = new Set();
79
72
  const validatorDeclarations = [];
80
73
  const validatorEntries = [];
@@ -119,7 +112,7 @@ ${validatorEntries.join("\n")}
119
112
  `;
120
113
  }
121
114
  export function buildRestResourceApiSource(restResourceSlug, methods) {
122
- const pascalCase = toPascalCaseFromSlug(restResourceSlug);
115
+ const pascalCase = toPascalCase(restResourceSlug);
123
116
  const typeImports = new Set();
124
117
  const clientEndpointImports = [];
125
118
  const exportedBindings = [];
@@ -262,7 +255,7 @@ ${exportedBindings.join("\n\n")}
262
255
  `;
263
256
  }
264
257
  export function buildRestResourceDataSource(restResourceSlug, methods) {
265
- const pascalCase = toPascalCaseFromSlug(restResourceSlug);
258
+ const pascalCase = toPascalCase(restResourceSlug);
266
259
  const typeImports = new Set();
267
260
  const endpointImports = [];
268
261
  const exportedBindings = [];
@@ -3,14 +3,12 @@ import path from "node:path";
3
3
  import { ensureBlockConfigCanAddRestManifests } from "./cli-add-block-legacy-validator.js";
4
4
  import { assertRestResourceDoesNotExist, assertValidGeneratedSlug, assertValidRestResourceMethods, getWorkspaceBootstrapPath, normalizeBlockSlug, resolveRestResourceNamespace, rollbackWorkspaceMutation, snapshotWorkspaceFiles, } from "./cli-add-shared.js";
5
5
  import { ensureRestResourceBootstrapAnchors, ensureRestResourceSyncScriptAnchors, } from "./cli-add-workspace-rest-anchors.js";
6
- import { buildRestResourceApiSource, buildRestResourceConfigEntry, buildRestResourceDataSource, buildRestResourceTypesSource, buildRestResourceValidatorsSource, toPascalCaseFromSlug, } from "./cli-add-workspace-rest-source-emitters.js";
6
+ import { buildRestResourceApiSource, buildRestResourceConfigEntry, buildRestResourceDataSource, buildRestResourceTypesSource, buildRestResourceValidatorsSource, } from "./cli-add-workspace-rest-source-emitters.js";
7
+ import { quotePhpString } from "./php-utils.js";
7
8
  import { syncRestResourceArtifacts } from "./rest-resource-artifacts.js";
8
- import { toTitleCase } from "./string-case.js";
9
+ import { toPascalCase, toTitleCase } from "./string-case.js";
9
10
  import { appendWorkspaceInventoryEntries, readWorkspaceInventory, } from "./workspace-inventory.js";
10
11
  import { resolveWorkspaceProject } from "./workspace-project.js";
11
- function quotePhpString(value) {
12
- return `'${value.replace(/\\/gu, "\\\\").replace(/'/gu, "\\'")}'`;
13
- }
14
12
  function buildRestResourceRouteRegistrations(restResourceSlug, methods, functions) {
15
13
  const collectionRoutes = [];
16
14
  const itemRoutes = [];
@@ -475,7 +473,7 @@ export async function runAddRestResourceCommand({ cwd = process.cwd(), methods,
475
473
  validatorsFile: `src/rest/${restResourceSlug}/api-validators.ts`,
476
474
  variables: {
477
475
  namespace: resolvedNamespace,
478
- pascalCase: toPascalCaseFromSlug(restResourceSlug),
476
+ pascalCase: toPascalCase(restResourceSlug),
479
477
  slugKebabCase: restResourceSlug,
480
478
  title: toTitleCase(restResourceSlug),
481
479
  },
@@ -1,5 +1,10 @@
1
1
  import type { HookedBlockPositionId } from "./hooked-blocks.js";
2
- import { type RunAddHookedBlockCommandOptions, type RunAddVariationCommandOptions } from "./cli-add-shared.js";
2
+ import { type RunAddBlockStyleCommandOptions, type RunAddBlockTransformCommandOptions, type RunAddHookedBlockCommandOptions, type RunAddVariationCommandOptions } from "./cli-add-shared.js";
3
+ /**
4
+ * Re-export the DataViews admin screen scaffold workflow from the focused
5
+ * admin-view runtime helper module.
6
+ */
7
+ export { runAddAdminViewCommand, } from "./cli-add-workspace-admin-view.js";
3
8
  /**
4
9
  * Re-export focused workspace asset scaffold commands from the companion
5
10
  * `cli-add-workspace-assets` module.
@@ -41,6 +46,58 @@ export declare function runAddVariationCommand({ blockName, cwd, variationName,
41
46
  projectDir: string;
42
47
  variationSlug: string;
43
48
  }>;
49
+ /**
50
+ * Add one Block Styles registration to an existing workspace block.
51
+ *
52
+ * @param options Command options for the Block Styles scaffold workflow.
53
+ * @param options.blockName Target workspace block slug that will own the style.
54
+ * @param options.cwd Working directory used to resolve the nearest official workspace.
55
+ * Defaults to `process.cwd()`.
56
+ * @param options.styleName Human-entered style name that will be normalized and
57
+ * validated before files are written.
58
+ * @returns A promise that resolves with the normalized `blockSlug`, `styleSlug`,
59
+ * and owning `projectDir` after the style module, style registry, entrypoint
60
+ * hook, and inventory entry have been written successfully.
61
+ * @throws {Error} When the command is run outside an official workspace, when
62
+ * the target block is unknown, when the style slug is invalid, or when a
63
+ * conflicting file or inventory entry already exists.
64
+ */
65
+ export declare function runAddBlockStyleCommand({ blockName, cwd, styleName, }: RunAddBlockStyleCommandOptions): Promise<{
66
+ blockSlug: string;
67
+ projectDir: string;
68
+ styleSlug: string;
69
+ }>;
70
+ /**
71
+ * Add one block-to-block transform registration to an existing workspace block.
72
+ *
73
+ * @param options Command options for the block transform scaffold workflow.
74
+ * @param options.cwd Working directory used to resolve the nearest official workspace.
75
+ * Defaults to `process.cwd()`.
76
+ * @param options.fromBlockName Source block name for `--from`. This must be the
77
+ * full `namespace/block` form because transforms may originate from WordPress
78
+ * core or third-party blocks outside the workspace.
79
+ * @param options.toBlockName Target block for `--to`. A workspace block slug is
80
+ * resolved against the workspace namespace, while a full `namespace/block` name
81
+ * must still point at an existing workspace block.
82
+ * @param options.transformName Human-entered transform name that will be
83
+ * normalized and validated before files are written.
84
+ * @returns A promise that resolves with the normalized target `blockSlug`,
85
+ * resolved `fromBlockName`, resolved `toBlockName`, `transformSlug`, and owning
86
+ * `projectDir` after the transform module, transform registry, entrypoint hook,
87
+ * and inventory entry have been written successfully.
88
+ * @throws {Error} When the command is run outside an official workspace, when
89
+ * the target block is unknown, when `--from` is not a full block name, when
90
+ * `--to` uses a non-workspace namespace, when the target block entrypoint does
91
+ * not expose `registration.settings`, when the transform slug is invalid, or
92
+ * when a conflicting file or inventory entry already exists.
93
+ */
94
+ export declare function runAddBlockTransformCommand({ cwd, fromBlockName, toBlockName, transformName, }: RunAddBlockTransformCommandOptions): Promise<{
95
+ blockSlug: string;
96
+ fromBlockName: string;
97
+ projectDir: string;
98
+ toBlockName: string;
99
+ transformSlug: string;
100
+ }>;
44
101
  /**
45
102
  * Add one `blockHooks` entry to an existing official workspace block.
46
103
  *