@wp-typia/project-tools 0.22.10 → 0.23.1

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 (155) hide show
  1. package/dist/runtime/ai-feature-artifacts.js +4 -1
  2. package/dist/runtime/block-generator-service-spec.js +2 -1
  3. package/dist/runtime/cli-add-block-json.js +5 -1
  4. package/dist/runtime/cli-add-collision.d.ts +25 -0
  5. package/dist/runtime/cli-add-collision.js +76 -0
  6. package/dist/runtime/cli-add-help.js +12 -2
  7. package/dist/runtime/cli-add-kind-ids.d.ts +1 -1
  8. package/dist/runtime/cli-add-kind-ids.js +3 -0
  9. package/dist/runtime/cli-add-types.d.ts +129 -0
  10. package/dist/runtime/cli-add-types.js +26 -0
  11. package/dist/runtime/cli-add-validation.d.ts +97 -1
  12. package/dist/runtime/cli-add-validation.js +313 -1
  13. package/dist/runtime/cli-add-workspace-ability-scaffold.js +4 -1
  14. package/dist/runtime/cli-add-workspace-admin-view-scaffold.js +79 -20
  15. package/dist/runtime/cli-add-workspace-admin-view-source.js +11 -2
  16. package/dist/runtime/cli-add-workspace-admin-view-templates-core-data.d.ts +34 -0
  17. package/dist/runtime/cli-add-workspace-admin-view-templates-core-data.js +483 -0
  18. package/dist/runtime/cli-add-workspace-admin-view-templates-default.d.ts +30 -0
  19. package/dist/runtime/cli-add-workspace-admin-view-templates-default.js +310 -0
  20. package/dist/runtime/cli-add-workspace-admin-view-templates-rest.d.ts +25 -0
  21. package/dist/runtime/cli-add-workspace-admin-view-templates-rest.js +124 -0
  22. package/dist/runtime/cli-add-workspace-admin-view-templates-settings.d.ts +34 -0
  23. package/dist/runtime/cli-add-workspace-admin-view-templates-settings.js +370 -0
  24. package/dist/runtime/cli-add-workspace-admin-view-templates-shared.d.ts +49 -0
  25. package/dist/runtime/cli-add-workspace-admin-view-templates-shared.js +259 -0
  26. package/dist/runtime/cli-add-workspace-admin-view-templates.d.ts +19 -10
  27. package/dist/runtime/cli-add-workspace-admin-view-templates.js +31 -971
  28. package/dist/runtime/cli-add-workspace-admin-view-types.d.ts +21 -0
  29. package/dist/runtime/cli-add-workspace-admin-view-types.js +22 -0
  30. package/dist/runtime/cli-add-workspace-ai-anchors.js +125 -32
  31. package/dist/runtime/cli-add-workspace-ai-source-emitters.js +17 -1
  32. package/dist/runtime/cli-add-workspace-contract-source-emitters.d.ts +15 -0
  33. package/dist/runtime/cli-add-workspace-contract-source-emitters.js +42 -0
  34. package/dist/runtime/cli-add-workspace-contract.d.ts +15 -0
  35. package/dist/runtime/cli-add-workspace-contract.js +65 -0
  36. package/dist/runtime/cli-add-workspace-integration-env.d.ts +26 -0
  37. package/dist/runtime/cli-add-workspace-integration-env.js +428 -0
  38. package/dist/runtime/cli-add-workspace-post-meta-anchors.d.ts +23 -0
  39. package/dist/runtime/cli-add-workspace-post-meta-anchors.js +244 -0
  40. package/dist/runtime/cli-add-workspace-post-meta-source-emitters.d.ts +63 -0
  41. package/dist/runtime/cli-add-workspace-post-meta-source-emitters.js +179 -0
  42. package/dist/runtime/cli-add-workspace-post-meta.d.ts +15 -0
  43. package/dist/runtime/cli-add-workspace-post-meta.js +107 -0
  44. package/dist/runtime/cli-add-workspace-rest-anchors.d.ts +9 -0
  45. package/dist/runtime/cli-add-workspace-rest-anchors.js +326 -21
  46. package/dist/runtime/cli-add-workspace-rest-generated.d.ts +9 -0
  47. package/dist/runtime/cli-add-workspace-rest-generated.js +158 -0
  48. package/dist/runtime/cli-add-workspace-rest-manual.d.ts +8 -0
  49. package/dist/runtime/cli-add-workspace-rest-manual.js +279 -0
  50. package/dist/runtime/cli-add-workspace-rest-php-templates.d.ts +24 -0
  51. package/dist/runtime/cli-add-workspace-rest-php-templates.js +678 -0
  52. package/dist/runtime/cli-add-workspace-rest-source-emitters.d.ts +98 -2
  53. package/dist/runtime/cli-add-workspace-rest-source-emitters.js +323 -29
  54. package/dist/runtime/cli-add-workspace-rest-types.d.ts +108 -0
  55. package/dist/runtime/cli-add-workspace-rest-types.js +1 -0
  56. package/dist/runtime/cli-add-workspace-rest.d.ts +3 -7
  57. package/dist/runtime/cli-add-workspace-rest.js +34 -481
  58. package/dist/runtime/cli-add-workspace.d.ts +15 -0
  59. package/dist/runtime/cli-add-workspace.js +15 -0
  60. package/dist/runtime/cli-add.d.ts +1 -1
  61. package/dist/runtime/cli-add.js +1 -1
  62. package/dist/runtime/cli-core.d.ts +3 -2
  63. package/dist/runtime/cli-core.js +3 -2
  64. package/dist/runtime/cli-diagnostics.d.ts +3 -1
  65. package/dist/runtime/cli-diagnostics.js +17 -5
  66. package/dist/runtime/cli-doctor-environment.js +1 -3
  67. package/dist/runtime/cli-doctor-workspace-bindings.js +4 -1
  68. package/dist/runtime/cli-doctor-workspace-block-addons.d.ts +12 -0
  69. package/dist/runtime/cli-doctor-workspace-block-addons.js +134 -0
  70. package/dist/runtime/cli-doctor-workspace-block-iframe.d.ts +9 -0
  71. package/dist/runtime/cli-doctor-workspace-block-iframe.js +228 -0
  72. package/dist/runtime/cli-doctor-workspace-block-metadata.d.ts +11 -0
  73. package/dist/runtime/cli-doctor-workspace-block-metadata.js +111 -0
  74. package/dist/runtime/cli-doctor-workspace-blocks.js +6 -424
  75. package/dist/runtime/cli-doctor-workspace-features-abilities.d.ts +11 -0
  76. package/dist/runtime/cli-doctor-workspace-features-abilities.js +112 -0
  77. package/dist/runtime/cli-doctor-workspace-features-admin-views.d.ts +11 -0
  78. package/dist/runtime/cli-doctor-workspace-features-admin-views.js +128 -0
  79. package/dist/runtime/cli-doctor-workspace-features-ai.d.ts +11 -0
  80. package/dist/runtime/cli-doctor-workspace-features-ai.js +57 -0
  81. package/dist/runtime/cli-doctor-workspace-features-editor-plugins.d.ts +11 -0
  82. package/dist/runtime/cli-doctor-workspace-features-editor-plugins.js +80 -0
  83. package/dist/runtime/cli-doctor-workspace-features-post-meta.d.ts +11 -0
  84. package/dist/runtime/cli-doctor-workspace-features-post-meta.js +77 -0
  85. package/dist/runtime/cli-doctor-workspace-features-rest.d.ts +11 -0
  86. package/dist/runtime/cli-doctor-workspace-features-rest.js +120 -0
  87. package/dist/runtime/cli-doctor-workspace-features.js +14 -369
  88. package/dist/runtime/cli-doctor-workspace-package.d.ts +25 -3
  89. package/dist/runtime/cli-doctor-workspace-package.js +35 -13
  90. package/dist/runtime/cli-doctor-workspace-shared.d.ts +2 -0
  91. package/dist/runtime/cli-doctor-workspace-shared.js +2 -0
  92. package/dist/runtime/cli-doctor-workspace.js +8 -3
  93. package/dist/runtime/cli-doctor.d.ts +52 -3
  94. package/dist/runtime/cli-doctor.js +79 -8
  95. package/dist/runtime/cli-help.js +10 -0
  96. package/dist/runtime/cli-init-package-json.js +4 -2
  97. package/dist/runtime/cli-init-templates.js +11 -1
  98. package/dist/runtime/cli-prompt.d.ts +16 -2
  99. package/dist/runtime/cli-prompt.js +29 -12
  100. package/dist/runtime/cli-scaffold.d.ts +2 -1
  101. package/dist/runtime/cli-scaffold.js +19 -10
  102. package/dist/runtime/contract-artifacts.d.ts +14 -0
  103. package/dist/runtime/contract-artifacts.js +15 -0
  104. package/dist/runtime/external-template-guards.js +4 -6
  105. package/dist/runtime/index.d.ts +2 -2
  106. package/dist/runtime/index.js +1 -1
  107. package/dist/runtime/json-utils.d.ts +62 -4
  108. package/dist/runtime/json-utils.js +78 -4
  109. package/dist/runtime/local-dev-presets.js +4 -1
  110. package/dist/runtime/migration-ui-capability.js +4 -1
  111. package/dist/runtime/migration-utils.js +4 -1
  112. package/dist/runtime/package-managers.js +6 -1
  113. package/dist/runtime/package-versions.js +6 -1
  114. package/dist/runtime/rest-resource-artifacts.d.ts +57 -1
  115. package/dist/runtime/rest-resource-artifacts.js +97 -1
  116. package/dist/runtime/scaffold-bootstrap.js +7 -2
  117. package/dist/runtime/scaffold-package-manager-files.js +5 -1
  118. package/dist/runtime/scaffold-repository-reference.js +4 -2
  119. package/dist/runtime/scaffold-template-variables.js +2 -1
  120. package/dist/runtime/scaffold.d.ts +18 -1
  121. package/dist/runtime/scaffold.js +55 -2
  122. package/dist/runtime/temp-roots.js +4 -1
  123. package/dist/runtime/template-layers.js +4 -1
  124. package/dist/runtime/template-registry.js +9 -3
  125. package/dist/runtime/template-render.d.ts +1 -1
  126. package/dist/runtime/template-render.js +1 -1
  127. package/dist/runtime/template-source-cache-markers.d.ts +37 -0
  128. package/dist/runtime/template-source-cache-markers.js +125 -0
  129. package/dist/runtime/template-source-cache.d.ts +1 -4
  130. package/dist/runtime/template-source-cache.js +16 -122
  131. package/dist/runtime/template-source-contracts.d.ts +2 -0
  132. package/dist/runtime/template-source-external.d.ts +4 -2
  133. package/dist/runtime/template-source-external.js +4 -2
  134. package/dist/runtime/template-source-normalization.js +2 -1
  135. package/dist/runtime/template-source-remote.d.ts +8 -4
  136. package/dist/runtime/template-source-remote.js +26 -9
  137. package/dist/runtime/template-source-seeds.js +10 -3
  138. package/dist/runtime/workspace-inventory-mutations.js +54 -4
  139. package/dist/runtime/workspace-inventory-parser-entries.d.ts +17 -0
  140. package/dist/runtime/workspace-inventory-parser-entries.js +157 -0
  141. package/dist/runtime/workspace-inventory-parser-validation.d.ts +104 -0
  142. package/dist/runtime/workspace-inventory-parser-validation.js +34 -0
  143. package/dist/runtime/workspace-inventory-parser.d.ts +3 -44
  144. package/dist/runtime/workspace-inventory-parser.js +7 -464
  145. package/dist/runtime/workspace-inventory-read.d.ts +9 -2
  146. package/dist/runtime/workspace-inventory-read.js +9 -2
  147. package/dist/runtime/workspace-inventory-section-descriptors.d.ts +19 -0
  148. package/dist/runtime/workspace-inventory-section-descriptors.js +435 -0
  149. package/dist/runtime/workspace-inventory-templates.d.ts +16 -1
  150. package/dist/runtime/workspace-inventory-templates.js +75 -4
  151. package/dist/runtime/workspace-inventory-types.d.ts +52 -2
  152. package/dist/runtime/workspace-inventory.d.ts +2 -2
  153. package/dist/runtime/workspace-inventory.js +1 -1
  154. package/dist/runtime/workspace-project.js +4 -6
  155. package/package.json +2 -2
@@ -1,7 +1,65 @@
1
1
  /**
2
- * Re-exports JSON cloning helpers from `@wp-typia/block-runtime`.
3
- * This adapter keeps the existing project-tools module path stable while the
4
- * runtime implementation now lives in block-runtime.
2
+ * JSON helpers shared by project-tools runtime modules.
3
+ *
4
+ * File-backed runtime JSON readers should use `safeJsonParse`,
5
+ * `readJsonFileSync`, or `readJsonFile` so malformed JSON reports the file path
6
+ * and operation context. Raw `JSON.parse` remains intentional for trusted
7
+ * in-memory clones, subprocess output, test fixtures, generated workspace
8
+ * script templates that embed their own path-aware parse handling,
9
+ * package-version manifest cache probes with colocated path-aware wrappers,
10
+ * and cache/discovery probes that immediately catch malformed documents to
11
+ * continue with fallback behavior.
12
+ *
13
+ * This module keeps `cloneJsonValue` local instead of re-exporting the
14
+ * block-runtime helper so Bunli CLI bundles that only need project-tools JSON
15
+ * readers do not need to resolve the block-runtime subpath at runtime.
16
+ *
5
17
  * @module
6
18
  */
7
- export * from "@wp-typia/block-runtime/json-utils";
19
+ /**
20
+ * Create a deep clone of a JSON-serializable value.
21
+ *
22
+ * @remarks
23
+ * Values that are not JSON-serializable, such as functions, `undefined`,
24
+ * `BigInt`, class instances, and `Date` objects, are not preserved faithfully.
25
+ *
26
+ * @param value JSON-compatible data to clone.
27
+ * @returns A deep-cloned copy created with `JSON.parse(JSON.stringify(...))`.
28
+ */
29
+ export declare function cloneJsonValue<T>(value: T): T;
30
+ /**
31
+ * Optional metadata used to enrich JSON parse errors.
32
+ */
33
+ export interface SafeJsonParseOptions {
34
+ /** Human-readable operation label included in parse failures. */
35
+ context?: string;
36
+ /** Source file path included in parse failures when available. */
37
+ filePath?: string;
38
+ }
39
+ /**
40
+ * Parse JSON and include operation/file context when decoding fails.
41
+ *
42
+ * @param source Raw JSON source text.
43
+ * @param options Optional file path and human-readable operation context.
44
+ * @returns Parsed JSON value cast to the caller-specified type.
45
+ * @throws {Error} When the source is malformed JSON.
46
+ */
47
+ export declare function safeJsonParse<T = unknown>(source: string, options?: SafeJsonParseOptions): T;
48
+ /**
49
+ * Read and parse a JSON file synchronously with path-aware parse errors.
50
+ *
51
+ * @param filePath JSON file path to read.
52
+ * @param options Optional parse context. `filePath` is always set from the
53
+ * reader argument.
54
+ * @returns Parsed JSON value cast to the caller-specified type.
55
+ */
56
+ export declare function readJsonFileSync<T = unknown>(filePath: string, options?: Omit<SafeJsonParseOptions, "filePath">): T;
57
+ /**
58
+ * Read and parse a JSON file asynchronously with path-aware parse errors.
59
+ *
60
+ * @param filePath JSON file path to read.
61
+ * @param options Optional parse context. `filePath` is always set from the
62
+ * reader argument.
63
+ * @returns Parsed JSON value cast to the caller-specified type.
64
+ */
65
+ export declare function readJsonFile<T = unknown>(filePath: string, options?: Omit<SafeJsonParseOptions, "filePath">): Promise<T>;
@@ -1,7 +1,81 @@
1
+ import fs from "node:fs";
2
+ import { promises as fsp } from "node:fs";
1
3
  /**
2
- * Re-exports JSON cloning helpers from `@wp-typia/block-runtime`.
3
- * This adapter keeps the existing project-tools module path stable while the
4
- * runtime implementation now lives in block-runtime.
4
+ * JSON helpers shared by project-tools runtime modules.
5
+ *
6
+ * File-backed runtime JSON readers should use `safeJsonParse`,
7
+ * `readJsonFileSync`, or `readJsonFile` so malformed JSON reports the file path
8
+ * and operation context. Raw `JSON.parse` remains intentional for trusted
9
+ * in-memory clones, subprocess output, test fixtures, generated workspace
10
+ * script templates that embed their own path-aware parse handling,
11
+ * package-version manifest cache probes with colocated path-aware wrappers,
12
+ * and cache/discovery probes that immediately catch malformed documents to
13
+ * continue with fallback behavior.
14
+ *
15
+ * This module keeps `cloneJsonValue` local instead of re-exporting the
16
+ * block-runtime helper so Bunli CLI bundles that only need project-tools JSON
17
+ * readers do not need to resolve the block-runtime subpath at runtime.
18
+ *
5
19
  * @module
6
20
  */
7
- export * from "@wp-typia/block-runtime/json-utils";
21
+ /**
22
+ * Create a deep clone of a JSON-serializable value.
23
+ *
24
+ * @remarks
25
+ * Values that are not JSON-serializable, such as functions, `undefined`,
26
+ * `BigInt`, class instances, and `Date` objects, are not preserved faithfully.
27
+ *
28
+ * @param value JSON-compatible data to clone.
29
+ * @returns A deep-cloned copy created with `JSON.parse(JSON.stringify(...))`.
30
+ */
31
+ export function cloneJsonValue(value) {
32
+ return JSON.parse(JSON.stringify(value));
33
+ }
34
+ function formatJsonParseTarget({ context, filePath }) {
35
+ const operation = context?.trim() || "JSON";
36
+ return filePath ? `${operation} at ${filePath}` : operation;
37
+ }
38
+ /**
39
+ * Parse JSON and include operation/file context when decoding fails.
40
+ *
41
+ * @param source Raw JSON source text.
42
+ * @param options Optional file path and human-readable operation context.
43
+ * @returns Parsed JSON value cast to the caller-specified type.
44
+ * @throws {Error} When the source is malformed JSON.
45
+ */
46
+ export function safeJsonParse(source, options = {}) {
47
+ try {
48
+ return JSON.parse(source);
49
+ }
50
+ catch (error) {
51
+ throw new Error(`Failed to parse ${formatJsonParseTarget(options)}: ${error instanceof Error ? error.message : String(error)}`);
52
+ }
53
+ }
54
+ /**
55
+ * Read and parse a JSON file synchronously with path-aware parse errors.
56
+ *
57
+ * @param filePath JSON file path to read.
58
+ * @param options Optional parse context. `filePath` is always set from the
59
+ * reader argument.
60
+ * @returns Parsed JSON value cast to the caller-specified type.
61
+ */
62
+ export function readJsonFileSync(filePath, options = {}) {
63
+ return safeJsonParse(fs.readFileSync(filePath, "utf8"), {
64
+ ...options,
65
+ filePath,
66
+ });
67
+ }
68
+ /**
69
+ * Read and parse a JSON file asynchronously with path-aware parse errors.
70
+ *
71
+ * @param filePath JSON file path to read.
72
+ * @param options Optional parse context. `filePath` is always set from the
73
+ * reader argument.
74
+ * @returns Parsed JSON value cast to the caller-specified type.
75
+ */
76
+ export async function readJsonFile(filePath, options = {}) {
77
+ return safeJsonParse(await fsp.readFile(filePath, "utf8"), {
78
+ ...options,
79
+ filePath,
80
+ });
81
+ }
@@ -8,6 +8,7 @@ import fs from "node:fs";
8
8
  import { promises as fsp } from "node:fs";
9
9
  import path from "node:path";
10
10
  import { formatRunScript, } from "./package-managers.js";
11
+ import { readJsonFile } from "./json-utils.js";
11
12
  import { OFFICIAL_WORKSPACE_TEMPLATE_PACKAGE, SHARED_TEST_PRESET_TEMPLATE_ROOT, SHARED_WP_ENV_PRESET_TEMPLATE_ROOT, } from "./template-registry.js";
12
13
  import { copyInterpolatedDirectory } from "./template-render.js";
13
14
  function templateHasPersistenceSync(templateId, compoundPersistenceEnabled) {
@@ -54,7 +55,9 @@ function getDevScript(packageManager, compoundPersistenceEnabled, templateId) {
54
55
  }
55
56
  async function mutatePackageJson(projectDir, mutate) {
56
57
  const packageJsonPath = path.join(projectDir, "package.json");
57
- const packageJson = JSON.parse(await fsp.readFile(packageJsonPath, "utf8"));
58
+ const packageJson = await readJsonFile(packageJsonPath, {
59
+ context: "local dev package manifest",
60
+ });
58
61
  mutate(packageJson);
59
62
  await fsp.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, "\t")}\n`, "utf8");
60
63
  }
@@ -2,6 +2,7 @@ import { promises as fsp } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { getPackageVersions } from "./package-versions.js";
4
4
  import { formatPackageExecCommand } from "./package-managers.js";
5
+ import { readJsonFile } from "./json-utils.js";
5
6
  import { seedProjectMigrations } from "./migrations.js";
6
7
  import { copyInterpolatedDirectory } from "./template-render.js";
7
8
  import { SHARED_MIGRATION_UI_TEMPLATE_ROOT, } from "./template-registry.js";
@@ -10,7 +11,9 @@ const BLOCK_METADATA_IMPORT_LINE = "import metadata from './block-metadata';";
10
11
  const LEGACY_BLOCK_JSON_IMPORT_LINE = "import metadata from './block.json';";
11
12
  async function mutatePackageJson(projectDir, mutate) {
12
13
  const packageJsonPath = path.join(projectDir, "package.json");
13
- const packageJson = JSON.parse(await fsp.readFile(packageJsonPath, "utf8"));
14
+ const packageJson = await readJsonFile(packageJsonPath, {
15
+ context: "migration UI package manifest",
16
+ });
14
17
  mutate(packageJson);
15
18
  await fsp.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, "\t")}\n`, "utf8");
16
19
  }
@@ -3,6 +3,7 @@ import path from 'node:path';
3
3
  import { execSync } from 'node:child_process';
4
4
  import { formatRunScript, inferPackageManagerId, parsePackageManagerField, } from './package-managers.js';
5
5
  import { isPlainObject } from './object-utils.js';
6
+ import { readJsonFileSync } from './json-utils.js';
6
7
  export { cloneJsonValue } from './json-utils.js';
7
8
  const MIGRATION_VERSION_LABEL_PATTERN = /^v([1-9]\d*)$/;
8
9
  const LEGACY_SEMVER_MIGRATION_VERSION_PATTERN = /^\d+\.\d+\.\d+$/;
@@ -66,7 +67,9 @@ export function createTransformFixtureValue(attribute, pathLabel) {
66
67
  }
67
68
  }
68
69
  export function readJson(filePath) {
69
- return JSON.parse(fs.readFileSync(filePath, 'utf8'));
70
+ return readJsonFileSync(filePath, {
71
+ context: 'migration JSON file',
72
+ });
70
73
  }
71
74
  export function renderPhpValue(value, indentLevel) {
72
75
  const indent = '\t'.repeat(indentLevel);
@@ -1,5 +1,6 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
+ import { readJsonFileSync } from "./json-utils.js";
3
4
  const PACKAGE_MANAGER_DATA = [
4
5
  {
5
6
  id: "bun",
@@ -73,12 +74,16 @@ function readPackageManagerField(projectDir) {
73
74
  if (!fs.existsSync(packageJsonPath)) {
74
75
  return undefined;
75
76
  }
76
- const manifest = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
77
+ const manifest = readJsonFileSync(packageJsonPath, {
78
+ context: "package manager manifest",
79
+ });
77
80
  return typeof manifest.packageManager === "string"
78
81
  ? manifest.packageManager
79
82
  : undefined;
80
83
  }
81
84
  catch {
85
+ // Package manager inference intentionally falls back to lockfile signals
86
+ // when package.json is absent or malformed.
82
87
  return undefined;
83
88
  }
84
89
  }
@@ -92,7 +92,12 @@ function readPackageManifest(location) {
92
92
  if (!location.packageJsonPath || location.source === null) {
93
93
  return null;
94
94
  }
95
- return JSON.parse(location.source);
95
+ try {
96
+ return JSON.parse(location.source);
97
+ }
98
+ catch (error) {
99
+ throw new Error(`Failed to parse package version manifest at ${location.packageJsonPath}: ${error instanceof Error ? error.message : String(error)}`);
100
+ }
96
101
  }
97
102
  function tryReadPackageManifest(location) {
98
103
  if (!location) {
@@ -1,7 +1,8 @@
1
- import type { RestResourceMethodId } from "./cli-add-shared.js";
1
+ import type { ManualRestContractAuthId, ManualRestContractHttpMethodId, RestResourceMethodId } from "./cli-add-shared.js";
2
2
  interface RestResourceTemplateVariablesLike {
3
3
  namespace: string;
4
4
  pascalCase: string;
5
+ routePattern?: string;
5
6
  slugKebabCase: string;
6
7
  title: string;
7
8
  }
@@ -14,6 +15,26 @@ interface SyncRestResourceArtifactsOptions {
14
15
  validatorsFile: string;
15
16
  variables: RestResourceTemplateVariablesLike;
16
17
  }
18
+ interface ManualRestContractTemplateVariablesLike {
19
+ auth: ManualRestContractAuthId;
20
+ bodyTypeName?: string;
21
+ method: ManualRestContractHttpMethodId;
22
+ namespace: string;
23
+ pascalCase: string;
24
+ pathPattern: string;
25
+ queryTypeName: string;
26
+ responseTypeName: string;
27
+ slugKebabCase: string;
28
+ title: string;
29
+ }
30
+ interface SyncManualRestContractArtifactsOptions {
31
+ clientFile: string;
32
+ outputDir: string;
33
+ projectDir: string;
34
+ typesFile: string;
35
+ validatorsFile: string;
36
+ variables: ManualRestContractTemplateVariablesLike;
37
+ }
17
38
  /**
18
39
  * Build the endpoint manifest for a workspace-level REST resource scaffold.
19
40
  *
@@ -24,6 +45,33 @@ interface SyncRestResourceArtifactsOptions {
24
45
  export declare function buildRestResourceEndpointManifest(variables: RestResourceTemplateVariablesLike, methods: RestResourceMethodId[]): import("@wp-typia/block-runtime/metadata-core").EndpointManifestDefinition<Record<string, {
25
46
  sourceTypeName: string;
26
47
  }>, import("@wp-typia/block-runtime/schema-core").EndpointOpenApiEndpointDefinition[]>;
48
+ /**
49
+ * Build the endpoint manifest for a type-only manual REST contract. Manual
50
+ * contracts describe routes owned by another integration without generating PHP
51
+ * route glue in the workspace.
52
+ *
53
+ * @param variables Template naming data used for contract names, route path,
54
+ * and OpenAPI info.
55
+ * @returns Endpoint manifest consumed by schema, OpenAPI, and client generators.
56
+ */
57
+ export declare function buildManualRestContractEndpointManifest(variables: ManualRestContractTemplateVariablesLike): import("@wp-typia/block-runtime/metadata-core").EndpointManifestDefinition<Record<string, {
58
+ sourceTypeName: string;
59
+ }>, readonly [{
60
+ readonly wordpressAuth?: {
61
+ mechanism: "rest-nonce";
62
+ } | {
63
+ mechanism: "public-signed-token";
64
+ } | undefined;
65
+ readonly method: "DELETE" | "GET" | "PATCH" | "POST" | "PUT";
66
+ readonly operationId: `call${string}ManualRestContract`;
67
+ readonly path: `/${string}${string}`;
68
+ readonly queryContract: "query";
69
+ readonly responseContract: "response";
70
+ readonly summary: `Call external ${string} REST route.`;
71
+ readonly tags: readonly [string];
72
+ readonly bodyContract?: string | undefined;
73
+ readonly auth: "authenticated" | "public" | "public-write-protected";
74
+ }]>;
27
75
  /**
28
76
  * Synchronize generated schemas, OpenAPI output, and endpoint client code for
29
77
  * a workspace-level REST resource scaffold.
@@ -32,4 +80,12 @@ export declare function buildRestResourceEndpointManifest(variables: RestResourc
32
80
  * @returns A promise that resolves after every generated REST artifact has been refreshed.
33
81
  */
34
82
  export declare function syncRestResourceArtifacts({ clientFile, methods, outputDir, projectDir, typesFile, validatorsFile, variables, }: SyncRestResourceArtifactsOptions): Promise<void>;
83
+ /**
84
+ * Synchronize generated schemas, OpenAPI output, and endpoint client code for a
85
+ * type-only manual REST contract.
86
+ *
87
+ * @param options Contract file paths and naming variables.
88
+ * @returns A promise that resolves after every generated artifact has refreshed.
89
+ */
90
+ export declare function syncManualRestContractArtifacts({ clientFile, outputDir, projectDir, typesFile, validatorsFile, variables, }: SyncManualRestContractArtifactsOptions): Promise<void>;
35
91
  export {};
@@ -1,5 +1,18 @@
1
1
  import path from "node:path";
2
2
  import { defineEndpointManifest, syncEndpointClient, syncRestOpenApi, syncTypeSchemas, } from "@wp-typia/block-runtime/metadata-core";
3
+ function resolveManualRestContractWordPressAuth(auth) {
4
+ if (auth === "authenticated") {
5
+ return {
6
+ mechanism: "rest-nonce",
7
+ };
8
+ }
9
+ if (auth === "public-write-protected") {
10
+ return {
11
+ mechanism: "public-signed-token",
12
+ };
13
+ }
14
+ return undefined;
15
+ }
3
16
  /**
4
17
  * Build the endpoint manifest for a workspace-level REST resource scaffold.
5
18
  *
@@ -9,7 +22,12 @@ import { defineEndpointManifest, syncEndpointClient, syncRestOpenApi, syncTypeSc
9
22
  */
10
23
  export function buildRestResourceEndpointManifest(variables, methods) {
11
24
  const basePath = `/${variables.namespace}/${variables.slugKebabCase}`;
12
- const itemPath = `${basePath}/item`;
25
+ const routePattern = variables.routePattern == null
26
+ ? `/${variables.slugKebabCase}/item`
27
+ : variables.routePattern.startsWith("/")
28
+ ? variables.routePattern
29
+ : `/${variables.routePattern}`;
30
+ const itemPath = `/${variables.namespace}${routePattern}`;
13
31
  const contracts = {};
14
32
  const endpoints = [];
15
33
  if (methods.includes("list")) {
@@ -124,6 +142,52 @@ export function buildRestResourceEndpointManifest(variables, methods) {
124
142
  },
125
143
  });
126
144
  }
145
+ /**
146
+ * Build the endpoint manifest for a type-only manual REST contract. Manual
147
+ * contracts describe routes owned by another integration without generating PHP
148
+ * route glue in the workspace.
149
+ *
150
+ * @param variables Template naming data used for contract names, route path,
151
+ * and OpenAPI info.
152
+ * @returns Endpoint manifest consumed by schema, OpenAPI, and client generators.
153
+ */
154
+ export function buildManualRestContractEndpointManifest(variables) {
155
+ const contracts = {
156
+ query: {
157
+ sourceTypeName: variables.queryTypeName,
158
+ },
159
+ response: {
160
+ sourceTypeName: variables.responseTypeName,
161
+ },
162
+ };
163
+ if (variables.bodyTypeName) {
164
+ contracts.request = {
165
+ sourceTypeName: variables.bodyTypeName,
166
+ };
167
+ }
168
+ const wordpressAuth = resolveManualRestContractWordPressAuth(variables.auth);
169
+ return defineEndpointManifest({
170
+ contracts,
171
+ endpoints: [
172
+ {
173
+ auth: variables.auth,
174
+ ...(variables.bodyTypeName ? { bodyContract: "request" } : {}),
175
+ method: variables.method,
176
+ operationId: `call${variables.pascalCase}ManualRestContract`,
177
+ path: `/${variables.namespace}${variables.pathPattern}`,
178
+ queryContract: "query",
179
+ responseContract: "response",
180
+ summary: `Call external ${variables.title} REST route.`,
181
+ tags: [variables.title],
182
+ ...(wordpressAuth ? { wordpressAuth } : {}),
183
+ },
184
+ ],
185
+ info: {
186
+ title: `${variables.title} Manual REST Contract`,
187
+ version: "1.0.0",
188
+ },
189
+ });
190
+ }
127
191
  /**
128
192
  * Synchronize generated schemas, OpenAPI output, and endpoint client code for
129
193
  * a workspace-level REST resource scaffold.
@@ -156,3 +220,35 @@ export async function syncRestResourceArtifacts({ clientFile, methods, outputDir
156
220
  validatorsFile,
157
221
  });
158
222
  }
223
+ /**
224
+ * Synchronize generated schemas, OpenAPI output, and endpoint client code for a
225
+ * type-only manual REST contract.
226
+ *
227
+ * @param options Contract file paths and naming variables.
228
+ * @returns A promise that resolves after every generated artifact has refreshed.
229
+ */
230
+ export async function syncManualRestContractArtifacts({ clientFile, outputDir, projectDir, typesFile, validatorsFile, variables, }) {
231
+ const manifest = buildManualRestContractEndpointManifest(variables);
232
+ for (const [baseName, contract] of Object.entries(manifest.contracts)) {
233
+ await syncTypeSchemas({
234
+ jsonSchemaFile: path.join(outputDir, "api-schemas", `${baseName}.schema.json`),
235
+ openApiFile: path.join(outputDir, "api-schemas", `${baseName}.openapi.json`),
236
+ projectRoot: projectDir,
237
+ sourceTypeName: contract.sourceTypeName,
238
+ typesFile,
239
+ });
240
+ }
241
+ await syncRestOpenApi({
242
+ manifest,
243
+ openApiFile: path.join(outputDir, "api.openapi.json"),
244
+ projectRoot: projectDir,
245
+ typesFile,
246
+ });
247
+ await syncEndpointClient({
248
+ clientFile,
249
+ manifest,
250
+ projectRoot: projectDir,
251
+ typesFile,
252
+ validatorsFile,
253
+ });
254
+ }
@@ -9,6 +9,7 @@ import { getStarterManifestFiles, stringifyStarterManifest } from "./starter-man
9
9
  import { OFFICIAL_WORKSPACE_TEMPLATE_PACKAGE, PROJECT_TOOLS_PACKAGE_ROOT, } from "./template-registry.js";
10
10
  import { getScaffoldTemplateVariableGroups } from "./scaffold-template-variable-groups.js";
11
11
  import { pathExists } from "./fs-async.js";
12
+ import { readJsonFile, readJsonFileSync } from "./json-utils.js";
12
13
  const EPHEMERAL_NODE_MODULES_LINK_TYPE = process.platform === "win32" ? "junction" : "dir";
13
14
  /**
14
15
  * Ensures the scaffold target directory exists and is empty unless explicitly allowed.
@@ -32,7 +33,9 @@ function readGeneratedPackageJson(projectDir) {
32
33
  if (!fs.existsSync(packageJsonPath)) {
33
34
  return null;
34
35
  }
35
- return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
36
+ return readJsonFileSync(packageJsonPath, {
37
+ context: "generated package manifest",
38
+ });
36
39
  }
37
40
  /**
38
41
  * Format the actionable error message used when a scaffold target directory
@@ -125,7 +128,9 @@ export function isOfficialWorkspaceProject(projectDir) {
125
128
  */
126
129
  export async function applyWorkspaceMigrationCapability(projectDir, packageManager) {
127
130
  const packageJsonPath = path.join(projectDir, "package.json");
128
- const packageJson = JSON.parse(await fsp.readFile(packageJsonPath, "utf8"));
131
+ const packageJson = await readJsonFile(packageJsonPath, {
132
+ context: "workspace package manifest",
133
+ });
129
134
  const wpTypiaPackageVersion = getPackageVersions().wpTypiaPackageVersion;
130
135
  const canonicalCliSpecifier = wpTypiaPackageVersion === "^0.0.0"
131
136
  ? "wp-typia"
@@ -3,6 +3,7 @@ import { execSync } from "node:child_process";
3
3
  import path from "node:path";
4
4
  import { formatInstallCommand, getPackageManager, transformPackageManagerText, } from "./package-managers.js";
5
5
  import { readOptionalUtf8File } from "./fs-async.js";
6
+ import { safeJsonParse } from "./json-utils.js";
6
7
  const LOCKFILES = {
7
8
  bun: ["bun.lock", "bun.lockb"],
8
9
  npm: ["package-lock.json"],
@@ -38,7 +39,10 @@ export async function normalizePackageJson(targetDir, packageManagerId) {
38
39
  return;
39
40
  }
40
41
  const packageManager = getPackageManager(packageManagerId);
41
- const packageJson = JSON.parse(packageJsonSource);
42
+ const packageJson = safeJsonParse(packageJsonSource, {
43
+ context: "generated package manifest",
44
+ filePath: packageJsonPath,
45
+ });
42
46
  if (packageManagerId === "npm") {
43
47
  delete packageJson.packageManager;
44
48
  }
@@ -1,7 +1,7 @@
1
- import fs from "node:fs";
2
1
  import { createRequire } from "node:module";
3
2
  import path from "node:path";
4
3
  import { getOptionalNodeErrorCode } from "./fs-async.js";
4
+ import { readJsonFileSync } from "./json-utils.js";
5
5
  import { PROJECT_TOOLS_PACKAGE_ROOT } from "./template-registry.js";
6
6
  const require = createRequire(import.meta.url);
7
7
  /**
@@ -11,7 +11,9 @@ const require = createRequire(import.meta.url);
11
11
  export const DEFAULT_SCAFFOLD_REPOSITORY_REFERENCE = "imjlk/wp-typia";
12
12
  function readRepositoryPackageManifest(packageJsonPath) {
13
13
  try {
14
- return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
14
+ return readJsonFileSync(packageJsonPath, {
15
+ context: "repository package manifest",
16
+ });
15
17
  }
16
18
  catch (error) {
17
19
  if (getOptionalNodeErrorCode(error) === "ENOENT") {
@@ -23,7 +23,7 @@ export function getTemplateVariables(templateId, answers) {
23
23
  templateId,
24
24
  }));
25
25
  }
26
- const { apiClientPackageVersion, blockRuntimePackageVersion, blockTypesPackageVersion, projectToolsPackageVersion, restPackageVersion, } = getPackageVersions();
26
+ const { apiClientPackageVersion, blockRuntimePackageVersion, blockTypesPackageVersion, projectToolsPackageVersion, restPackageVersion, wpTypiaPackageVersion, } = getPackageVersions();
27
27
  const template = isBuiltInTemplateId(templateId) ? getTemplateById(templateId) : null;
28
28
  const metadataDefaults = isBuiltInTemplateId(templateId)
29
29
  ? getBuiltInTemplateMetadataDefaults(templateId)
@@ -94,6 +94,7 @@ export function getTemplateVariables(templateId, answers) {
94
94
  hasAlternatePlainTextRenderTarget: 'false',
95
95
  hasAlternateRenderTargets: 'false',
96
96
  projectToolsPackageVersion,
97
+ wpTypiaPackageVersion,
97
98
  requiresAtLeast: compatibility.pluginHeader.requiresAtLeast,
98
99
  requiresPhp: compatibility.pluginHeader.requiresPhp,
99
100
  cssClassName,
@@ -27,6 +27,10 @@ export declare const DATA_STORAGE_MODES: readonly ["post-meta", "custom-table"];
27
27
  export type DataStorageMode = (typeof DATA_STORAGE_MODES)[number];
28
28
  export declare const PERSISTENCE_POLICIES: readonly ["authenticated", "public"];
29
29
  export type PersistencePolicy = (typeof PERSISTENCE_POLICIES)[number];
30
+ /** Supported create profile ids for opt-in workspace scaffold presets. */
31
+ export declare const CREATE_PROFILE_IDS: readonly ["plugin-qa"];
32
+ /** Union of supported `wp-typia create --profile` id strings. */
33
+ export type CreateProfileId = (typeof CREATE_PROFILE_IDS)[number];
30
34
  /**
31
35
  * Normalized template variables shared by built-in and remote scaffold flows.
32
36
  */
@@ -58,6 +62,7 @@ export interface FlatScaffoldTemplateVariables extends Record<string, string> {
58
62
  hasAlternatePlainTextRenderTarget: "false" | "true";
59
63
  hasAlternateRenderTargets: "false" | "true";
60
64
  projectToolsPackageVersion: string;
65
+ wpTypiaPackageVersion: string;
61
66
  requiresAtLeast: string;
62
67
  requiresPhp: string;
63
68
  cssClassName: string;
@@ -163,6 +168,7 @@ interface ScaffoldProjectOptions {
163
168
  onProgress?: ((event: ScaffoldProgressEvent) => void | Promise<void>) | undefined;
164
169
  packageManager: PackageManagerId;
165
170
  persistencePolicy?: PersistencePolicy;
171
+ profile?: CreateProfileId;
166
172
  projectDir: string;
167
173
  repositoryReference?: string;
168
174
  templateId: string;
@@ -185,4 +191,15 @@ export { getTemplateVariables } from "./scaffold-template-variables.js";
185
191
  export { getScaffoldTemplateVariableGroups, type BasicScaffoldTemplateVariableGroups, type CompoundScaffoldTemplateVariableGroups, type ExternalScaffoldTemplateVariableGroups, type InteractivityScaffoldTemplateVariableGroups, type PersistenceScaffoldTemplateVariableGroups, type QueryLoopScaffoldTemplateVariableGroups, type ScaffoldTemplateFamily, type ScaffoldTemplateVariableGroups, type ScaffoldTemplateVariableGroupsCarrier, } from "./scaffold-template-variable-groups.js";
186
192
  export declare function isDataStorageMode(value: string): value is DataStorageMode;
187
193
  export declare function isPersistencePolicy(value: string): value is PersistencePolicy;
188
- export declare function scaffoldProject({ projectDir, templateId, answers, alternateRenderTargets, dataStorageMode, persistencePolicy, packageManager, externalLayerId, externalLayerSource, externalLayerSourceLabel, repositoryReference, cwd, allowExistingDir, noInstall, installDependencies, onProgress, variant, withMigrationUi, withTestPreset, withWpEnv, }: ScaffoldProjectOptions): Promise<ScaffoldProjectResult>;
194
+ /**
195
+ * Return whether a raw string is a supported create profile id.
196
+ */
197
+ export declare function isCreateProfileId(value: string): value is CreateProfileId;
198
+ /**
199
+ * Resolve an optional create profile flag into a validated profile id.
200
+ *
201
+ * Empty input disables profile application; unknown ids throw with the allowed
202
+ * profile list for CLI diagnostics.
203
+ */
204
+ export declare function resolveCreateProfileId(profile?: string): CreateProfileId | undefined;
205
+ export declare function scaffoldProject({ projectDir, templateId, answers, alternateRenderTargets, dataStorageMode, persistencePolicy, packageManager, externalLayerId, externalLayerSource, externalLayerSourceLabel, profile, repositoryReference, cwd, allowExistingDir, noInstall, installDependencies, onProgress, variant, withMigrationUi, withTestPreset, withWpEnv, }: ScaffoldProjectOptions): Promise<ScaffoldProjectResult>;