@wp-typia/project-tools 0.22.3 → 0.22.5

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 (43) hide show
  1. package/dist/runtime/cli-add-block-json.d.ts +31 -0
  2. package/dist/runtime/cli-add-block-json.js +65 -0
  3. package/dist/runtime/cli-add-collision.d.ts +129 -0
  4. package/dist/runtime/cli-add-collision.js +293 -0
  5. package/dist/runtime/cli-add-filesystem.d.ts +29 -0
  6. package/dist/runtime/cli-add-filesystem.js +77 -0
  7. package/dist/runtime/cli-add-help.d.ts +4 -0
  8. package/dist/runtime/cli-add-help.js +41 -0
  9. package/dist/runtime/cli-add-shared.d.ts +6 -304
  10. package/dist/runtime/cli-add-shared.js +6 -524
  11. package/dist/runtime/cli-add-types.d.ts +247 -0
  12. package/dist/runtime/cli-add-types.js +64 -0
  13. package/dist/runtime/cli-add-validation.d.ts +87 -0
  14. package/dist/runtime/cli-add-validation.js +147 -0
  15. package/dist/runtime/cli-add-workspace-ability-scaffold.js +46 -72
  16. package/dist/runtime/cli-add-workspace-admin-view-scaffold.js +35 -61
  17. package/dist/runtime/cli-add-workspace-ai-anchors.js +3 -24
  18. package/dist/runtime/cli-add-workspace-ai-scaffold.js +53 -57
  19. package/dist/runtime/cli-add-workspace-ai-templates.js +2 -0
  20. package/dist/runtime/cli-add-workspace-assets.js +7 -50
  21. package/dist/runtime/cli-add-workspace-mutation.d.ts +30 -0
  22. package/dist/runtime/cli-add-workspace-mutation.js +60 -0
  23. package/dist/runtime/cli-add-workspace-rest-anchors.js +3 -24
  24. package/dist/runtime/cli-add-workspace.js +1 -79
  25. package/dist/runtime/cli-add.d.ts +2 -2
  26. package/dist/runtime/cli-add.js +2 -2
  27. package/dist/runtime/cli-doctor-workspace-blocks.js +1 -66
  28. package/dist/runtime/index.d.ts +2 -0
  29. package/dist/runtime/index.js +1 -0
  30. package/dist/runtime/migration-utils.d.ts +2 -1
  31. package/dist/runtime/migration-utils.js +3 -11
  32. package/dist/runtime/package-managers.d.ts +19 -0
  33. package/dist/runtime/package-managers.js +62 -0
  34. package/dist/runtime/template-source-cache.d.ts +59 -0
  35. package/dist/runtime/template-source-cache.js +160 -0
  36. package/dist/runtime/ts-source-masking.d.ts +28 -0
  37. package/dist/runtime/ts-source-masking.js +104 -0
  38. package/dist/runtime/typia-llm.d.ts +9 -1
  39. package/dist/runtime/typia-llm.js +20 -5
  40. package/dist/runtime/workspace-inventory.js +368 -284
  41. package/dist/runtime/workspace-project.d.ts +1 -1
  42. package/dist/runtime/workspace-project.js +2 -10
  43. package/package.json +2 -2
@@ -0,0 +1,31 @@
1
+ import type { WorkspaceInventory } from "./workspace-inventory.js";
2
+ /**
3
+ * Resolve an existing workspace block inventory entry by slug.
4
+ *
5
+ * @param inventory Parsed workspace inventory that owns available blocks.
6
+ * @param blockSlug Workspace block slug to locate.
7
+ * @returns The matching workspace block inventory entry.
8
+ * @throws {Error} When the block slug is not present in the inventory.
9
+ */
10
+ export declare function resolveWorkspaceBlock(inventory: WorkspaceInventory, blockSlug: string): WorkspaceInventory["blocks"][number];
11
+ /**
12
+ * Read and validate a workspace block's `block.json` metadata from disk.
13
+ *
14
+ * @param projectDir Absolute workspace root directory.
15
+ * @param blockSlug Workspace block slug whose metadata should be read.
16
+ * @returns Parsed block metadata and the absolute `block.json` path.
17
+ * @throws {Error} When the file is missing or cannot be parsed as scaffold metadata.
18
+ */
19
+ export declare function readWorkspaceBlockJson(projectDir: string, blockSlug: string): {
20
+ blockJson: Record<string, unknown>;
21
+ blockJsonPath: string;
22
+ };
23
+ /**
24
+ * Return a mutable `blockHooks` object for a parsed block metadata document.
25
+ *
26
+ * @param blockJson Parsed block metadata object that may be mutated.
27
+ * @param blockJsonRelativePath Relative path used in validation error messages.
28
+ * @returns The existing or newly created mutable `blockHooks` map.
29
+ * @throws {Error} When `blockHooks` exists but is not an object.
30
+ */
31
+ export declare function getMutableBlockHooks(blockJson: Record<string, unknown>, blockJsonRelativePath: string): Record<string, string>;
@@ -0,0 +1,65 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { parseScaffoldBlockMetadata } from "@wp-typia/block-runtime/blocks";
4
+ /**
5
+ * Resolve an existing workspace block inventory entry by slug.
6
+ *
7
+ * @param inventory Parsed workspace inventory that owns available blocks.
8
+ * @param blockSlug Workspace block slug to locate.
9
+ * @returns The matching workspace block inventory entry.
10
+ * @throws {Error} When the block slug is not present in the inventory.
11
+ */
12
+ export function resolveWorkspaceBlock(inventory, blockSlug) {
13
+ const block = inventory.blocks.find((entry) => entry.slug === blockSlug);
14
+ if (!block) {
15
+ throw new Error(`Unknown workspace block "${blockSlug}". Choose one of: ${inventory.blocks.map((entry) => entry.slug).join(", ")}`);
16
+ }
17
+ return block;
18
+ }
19
+ /**
20
+ * Read and validate a workspace block's `block.json` metadata from disk.
21
+ *
22
+ * @param projectDir Absolute workspace root directory.
23
+ * @param blockSlug Workspace block slug whose metadata should be read.
24
+ * @returns Parsed block metadata and the absolute `block.json` path.
25
+ * @throws {Error} When the file is missing or cannot be parsed as scaffold metadata.
26
+ */
27
+ export function readWorkspaceBlockJson(projectDir, blockSlug) {
28
+ const blockJsonPath = path.join(projectDir, "src", "blocks", blockSlug, "block.json");
29
+ if (!fs.existsSync(blockJsonPath)) {
30
+ throw new Error(`Missing ${path.relative(projectDir, blockJsonPath)} for workspace block "${blockSlug}".`);
31
+ }
32
+ let blockJson;
33
+ try {
34
+ blockJson = parseScaffoldBlockMetadata(JSON.parse(fs.readFileSync(blockJsonPath, "utf8")));
35
+ }
36
+ catch (error) {
37
+ throw new Error(error instanceof Error
38
+ ? `Failed to parse ${path.relative(projectDir, blockJsonPath)}: ${error.message}`
39
+ : `Failed to parse ${path.relative(projectDir, blockJsonPath)}.`);
40
+ }
41
+ return {
42
+ blockJson,
43
+ blockJsonPath,
44
+ };
45
+ }
46
+ /**
47
+ * Return a mutable `blockHooks` object for a parsed block metadata document.
48
+ *
49
+ * @param blockJson Parsed block metadata object that may be mutated.
50
+ * @param blockJsonRelativePath Relative path used in validation error messages.
51
+ * @returns The existing or newly created mutable `blockHooks` map.
52
+ * @throws {Error} When `blockHooks` exists but is not an object.
53
+ */
54
+ export function getMutableBlockHooks(blockJson, blockJsonRelativePath) {
55
+ const blockHooks = blockJson.blockHooks;
56
+ if (blockHooks === undefined) {
57
+ const nextHooks = {};
58
+ blockJson.blockHooks = nextHooks;
59
+ return nextHooks;
60
+ }
61
+ if (!blockHooks || typeof blockHooks !== "object" || Array.isArray(blockHooks)) {
62
+ throw new Error(`${blockJsonRelativePath} must define blockHooks as an object when present.`);
63
+ }
64
+ return blockHooks;
65
+ }
@@ -0,0 +1,129 @@
1
+ import type { WorkspaceInventory } from "./workspace-inventory.js";
2
+ type ScaffoldFilesystemCollision = {
3
+ label: string;
4
+ relativePath: string;
5
+ };
6
+ type ScaffoldInventoryCollision<TEntry> = {
7
+ entries: readonly TEntry[];
8
+ exists: (entry: TEntry) => boolean;
9
+ message: string;
10
+ };
11
+ /**
12
+ * Ensure scaffold targets do not already exist on disk or in workspace inventory.
13
+ *
14
+ * @param options Collision checks to run before writing scaffold files.
15
+ * @throws {Error} When a filesystem path or inventory entry already exists.
16
+ */
17
+ export declare function assertScaffoldDoesNotExist<TEntry>(options: {
18
+ projectDir: string;
19
+ filesystemCollisions: readonly ScaffoldFilesystemCollision[];
20
+ inventoryCollision?: ScaffoldInventoryCollision<TEntry>;
21
+ }): void;
22
+ /**
23
+ * Ensure a block variation scaffold does not already exist.
24
+ *
25
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
26
+ * @param blockSlug Existing workspace block slug that owns the variation.
27
+ * @param variationSlug Normalized variation slug that would be created.
28
+ * @param inventory Current workspace inventory used for duplicate detection.
29
+ * @throws {Error} When the variation file or inventory entry already exists.
30
+ */
31
+ export declare function assertVariationDoesNotExist(projectDir: string, blockSlug: string, variationSlug: string, inventory: WorkspaceInventory): void;
32
+ /**
33
+ * Ensure a block style scaffold does not already exist.
34
+ *
35
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
36
+ * @param blockSlug Existing workspace block slug that owns the style.
37
+ * @param styleSlug Normalized style slug that would be created.
38
+ * @param inventory Current workspace inventory used for duplicate detection.
39
+ * @throws {Error} When the style file or inventory entry already exists.
40
+ */
41
+ export declare function assertBlockStyleDoesNotExist(projectDir: string, blockSlug: string, styleSlug: string, inventory: WorkspaceInventory): void;
42
+ /**
43
+ * Ensure a block transform scaffold does not already exist.
44
+ *
45
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
46
+ * @param blockSlug Existing workspace block slug that owns the transform.
47
+ * @param transformSlug Normalized transform slug that would be created.
48
+ * @param inventory Current workspace inventory used for duplicate detection.
49
+ * @throws {Error} When the transform file or inventory entry already exists.
50
+ */
51
+ export declare function assertBlockTransformDoesNotExist(projectDir: string, blockSlug: string, transformSlug: string, inventory: WorkspaceInventory): void;
52
+ /**
53
+ * Ensure a pattern scaffold does not already exist on disk or in inventory.
54
+ *
55
+ * Delegates filesystem and inventory checks to `assertScaffoldDoesNotExist`.
56
+ *
57
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
58
+ * @param patternSlug Normalized pattern slug that would be created.
59
+ * @param inventory Current workspace inventory used for duplicate detection.
60
+ * @throws {Error} When the pattern file or inventory entry already exists.
61
+ */
62
+ export declare function assertPatternDoesNotExist(projectDir: string, patternSlug: string, inventory: WorkspaceInventory): void;
63
+ /**
64
+ * Ensure a binding source scaffold does not already exist on disk or in inventory.
65
+ *
66
+ * Delegates filesystem and inventory checks to `assertScaffoldDoesNotExist`.
67
+ *
68
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
69
+ * @param bindingSourceSlug Normalized binding source slug that would be created.
70
+ * @param inventory Current workspace inventory used for duplicate detection.
71
+ * @throws {Error} When the binding directory or inventory entry already exists.
72
+ */
73
+ export declare function assertBindingSourceDoesNotExist(projectDir: string, bindingSourceSlug: string, inventory: WorkspaceInventory): void;
74
+ /**
75
+ * Ensure a REST resource scaffold does not already exist on disk or in inventory.
76
+ *
77
+ * Delegates filesystem and inventory checks to `assertScaffoldDoesNotExist`.
78
+ *
79
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
80
+ * @param restResourceSlug Normalized REST resource slug that would be created.
81
+ * @param inventory Current workspace inventory used for duplicate detection.
82
+ * @throws {Error} When REST resource files or inventory entry already exist.
83
+ */
84
+ export declare function assertRestResourceDoesNotExist(projectDir: string, restResourceSlug: string, inventory: WorkspaceInventory): void;
85
+ /**
86
+ * Ensure a DataViews admin screen scaffold does not already exist on disk or in
87
+ * the workspace inventory.
88
+ *
89
+ * @param projectDir Workspace root directory.
90
+ * @param adminViewSlug Normalized admin screen slug.
91
+ * @param inventory Parsed workspace inventory.
92
+ * @throws {Error} When the directory, PHP bootstrap, or inventory entry already exists.
93
+ */
94
+ export declare function assertAdminViewDoesNotExist(projectDir: string, adminViewSlug: string, inventory: WorkspaceInventory): void;
95
+ /**
96
+ * Ensure a workflow ability scaffold does not already exist on disk or in the
97
+ * workspace inventory.
98
+ *
99
+ * The check covers the generated `src/abilities/<slug>` directory,
100
+ * `inc/abilities/<slug>.php`, and any matching `inventory.abilities` entry.
101
+ *
102
+ * @param projectDir Workspace root directory.
103
+ * @param abilitySlug Normalized workflow ability slug.
104
+ * @param inventory Parsed workspace inventory.
105
+ * @throws {Error} When the ability directory, PHP bootstrap, or inventory entry already exists.
106
+ */
107
+ export declare function assertAbilityDoesNotExist(projectDir: string, abilitySlug: string, inventory: WorkspaceInventory): void;
108
+ /**
109
+ * Ensure an AI feature scaffold does not already exist on disk or in inventory.
110
+ *
111
+ * Delegates filesystem and inventory checks to `assertScaffoldDoesNotExist`.
112
+ *
113
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
114
+ * @param aiFeatureSlug Normalized AI feature slug that would be created.
115
+ * @param inventory Current workspace inventory used for duplicate detection.
116
+ * @throws {Error} When AI feature files or inventory entry already exist.
117
+ */
118
+ export declare function assertAiFeatureDoesNotExist(projectDir: string, aiFeatureSlug: string, inventory: WorkspaceInventory): void;
119
+ /**
120
+ * Ensure an editor plugin scaffold does not already exist on disk or in the
121
+ * workspace inventory.
122
+ *
123
+ * @param projectDir Workspace root directory.
124
+ * @param editorPluginSlug Normalized editor plugin slug.
125
+ * @param inventory Parsed workspace inventory.
126
+ * @throws {Error} When the directory or inventory entry already exists.
127
+ */
128
+ export declare function assertEditorPluginDoesNotExist(projectDir: string, editorPluginSlug: string, inventory: WorkspaceInventory): void;
129
+ export {};
@@ -0,0 +1,293 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ /**
4
+ * Ensure scaffold targets do not already exist on disk or in workspace inventory.
5
+ *
6
+ * @param options Collision checks to run before writing scaffold files.
7
+ * @throws {Error} When a filesystem path or inventory entry already exists.
8
+ */
9
+ export function assertScaffoldDoesNotExist(options) {
10
+ for (const collision of options.filesystemCollisions) {
11
+ const targetPath = path.join(options.projectDir, collision.relativePath);
12
+ if (fs.existsSync(targetPath)) {
13
+ throw new Error(`${collision.label} already exists at ${path.relative(options.projectDir, targetPath)}. Choose a different name.`);
14
+ }
15
+ }
16
+ if (options.inventoryCollision &&
17
+ options.inventoryCollision.entries.some(options.inventoryCollision.exists)) {
18
+ throw new Error(options.inventoryCollision.message);
19
+ }
20
+ }
21
+ /**
22
+ * Ensure a block variation scaffold does not already exist.
23
+ *
24
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
25
+ * @param blockSlug Existing workspace block slug that owns the variation.
26
+ * @param variationSlug Normalized variation slug that would be created.
27
+ * @param inventory Current workspace inventory used for duplicate detection.
28
+ * @throws {Error} When the variation file or inventory entry already exists.
29
+ */
30
+ export function assertVariationDoesNotExist(projectDir, blockSlug, variationSlug, inventory) {
31
+ assertScaffoldDoesNotExist({
32
+ filesystemCollisions: [
33
+ {
34
+ label: "A variation",
35
+ relativePath: path.join("src", "blocks", blockSlug, "variations", `${variationSlug}.ts`),
36
+ },
37
+ ],
38
+ inventoryCollision: {
39
+ entries: inventory.variations,
40
+ exists: (entry) => entry.block === blockSlug && entry.slug === variationSlug,
41
+ message: `A variation inventory entry already exists for ${blockSlug}/${variationSlug}. Choose a different name.`,
42
+ },
43
+ projectDir,
44
+ });
45
+ }
46
+ /**
47
+ * Ensure a block style scaffold does not already exist.
48
+ *
49
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
50
+ * @param blockSlug Existing workspace block slug that owns the style.
51
+ * @param styleSlug Normalized style slug that would be created.
52
+ * @param inventory Current workspace inventory used for duplicate detection.
53
+ * @throws {Error} When the style file or inventory entry already exists.
54
+ */
55
+ export function assertBlockStyleDoesNotExist(projectDir, blockSlug, styleSlug, inventory) {
56
+ assertScaffoldDoesNotExist({
57
+ filesystemCollisions: [
58
+ {
59
+ label: "A block style",
60
+ relativePath: path.join("src", "blocks", blockSlug, "styles", `${styleSlug}.ts`),
61
+ },
62
+ ],
63
+ inventoryCollision: {
64
+ entries: inventory.blockStyles,
65
+ exists: (entry) => entry.block === blockSlug && entry.slug === styleSlug,
66
+ message: `A block style inventory entry already exists for ${blockSlug}/${styleSlug}. Choose a different name.`,
67
+ },
68
+ projectDir,
69
+ });
70
+ }
71
+ /**
72
+ * Ensure a block transform scaffold does not already exist.
73
+ *
74
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
75
+ * @param blockSlug Existing workspace block slug that owns the transform.
76
+ * @param transformSlug Normalized transform slug that would be created.
77
+ * @param inventory Current workspace inventory used for duplicate detection.
78
+ * @throws {Error} When the transform file or inventory entry already exists.
79
+ */
80
+ export function assertBlockTransformDoesNotExist(projectDir, blockSlug, transformSlug, inventory) {
81
+ assertScaffoldDoesNotExist({
82
+ filesystemCollisions: [
83
+ {
84
+ label: "A block transform",
85
+ relativePath: path.join("src", "blocks", blockSlug, "transforms", `${transformSlug}.ts`),
86
+ },
87
+ ],
88
+ inventoryCollision: {
89
+ entries: inventory.blockTransforms,
90
+ exists: (entry) => entry.block === blockSlug && entry.slug === transformSlug,
91
+ message: `A block transform inventory entry already exists for ${blockSlug}/${transformSlug}. Choose a different name.`,
92
+ },
93
+ projectDir,
94
+ });
95
+ }
96
+ /**
97
+ * Ensure a pattern scaffold does not already exist on disk or in inventory.
98
+ *
99
+ * Delegates filesystem and inventory checks to `assertScaffoldDoesNotExist`.
100
+ *
101
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
102
+ * @param patternSlug Normalized pattern slug that would be created.
103
+ * @param inventory Current workspace inventory used for duplicate detection.
104
+ * @throws {Error} When the pattern file or inventory entry already exists.
105
+ */
106
+ export function assertPatternDoesNotExist(projectDir, patternSlug, inventory) {
107
+ assertScaffoldDoesNotExist({
108
+ filesystemCollisions: [
109
+ {
110
+ label: "A pattern",
111
+ relativePath: path.join("src", "patterns", `${patternSlug}.php`),
112
+ },
113
+ ],
114
+ inventoryCollision: {
115
+ entries: inventory.patterns,
116
+ exists: (entry) => entry.slug === patternSlug,
117
+ message: `A pattern inventory entry already exists for ${patternSlug}. Choose a different name.`,
118
+ },
119
+ projectDir,
120
+ });
121
+ }
122
+ /**
123
+ * Ensure a binding source scaffold does not already exist on disk or in inventory.
124
+ *
125
+ * Delegates filesystem and inventory checks to `assertScaffoldDoesNotExist`.
126
+ *
127
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
128
+ * @param bindingSourceSlug Normalized binding source slug that would be created.
129
+ * @param inventory Current workspace inventory used for duplicate detection.
130
+ * @throws {Error} When the binding directory or inventory entry already exists.
131
+ */
132
+ export function assertBindingSourceDoesNotExist(projectDir, bindingSourceSlug, inventory) {
133
+ assertScaffoldDoesNotExist({
134
+ filesystemCollisions: [
135
+ {
136
+ label: "A binding source",
137
+ relativePath: path.join("src", "bindings", bindingSourceSlug),
138
+ },
139
+ ],
140
+ inventoryCollision: {
141
+ entries: inventory.bindingSources,
142
+ exists: (entry) => entry.slug === bindingSourceSlug,
143
+ message: `A binding source inventory entry already exists for ${bindingSourceSlug}. Choose a different name.`,
144
+ },
145
+ projectDir,
146
+ });
147
+ }
148
+ /**
149
+ * Ensure a REST resource scaffold does not already exist on disk or in inventory.
150
+ *
151
+ * Delegates filesystem and inventory checks to `assertScaffoldDoesNotExist`.
152
+ *
153
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
154
+ * @param restResourceSlug Normalized REST resource slug that would be created.
155
+ * @param inventory Current workspace inventory used for duplicate detection.
156
+ * @throws {Error} When REST resource files or inventory entry already exist.
157
+ */
158
+ export function assertRestResourceDoesNotExist(projectDir, restResourceSlug, inventory) {
159
+ assertScaffoldDoesNotExist({
160
+ filesystemCollisions: [
161
+ {
162
+ label: "A REST resource",
163
+ relativePath: path.join("src", "rest", restResourceSlug),
164
+ },
165
+ {
166
+ label: "A REST resource bootstrap",
167
+ relativePath: path.join("inc", "rest", `${restResourceSlug}.php`),
168
+ },
169
+ ],
170
+ inventoryCollision: {
171
+ entries: inventory.restResources,
172
+ exists: (entry) => entry.slug === restResourceSlug,
173
+ message: `A REST resource inventory entry already exists for ${restResourceSlug}. Choose a different name.`,
174
+ },
175
+ projectDir,
176
+ });
177
+ }
178
+ /**
179
+ * Ensure a DataViews admin screen scaffold does not already exist on disk or in
180
+ * the workspace inventory.
181
+ *
182
+ * @param projectDir Workspace root directory.
183
+ * @param adminViewSlug Normalized admin screen slug.
184
+ * @param inventory Parsed workspace inventory.
185
+ * @throws {Error} When the directory, PHP bootstrap, or inventory entry already exists.
186
+ */
187
+ export function assertAdminViewDoesNotExist(projectDir, adminViewSlug, inventory) {
188
+ assertScaffoldDoesNotExist({
189
+ filesystemCollisions: [
190
+ {
191
+ label: "An admin view",
192
+ relativePath: path.join("src", "admin-views", adminViewSlug),
193
+ },
194
+ {
195
+ label: "An admin view bootstrap",
196
+ relativePath: path.join("inc", "admin-views", `${adminViewSlug}.php`),
197
+ },
198
+ ],
199
+ inventoryCollision: {
200
+ entries: inventory.adminViews,
201
+ exists: (entry) => entry.slug === adminViewSlug,
202
+ message: `An admin view inventory entry already exists for ${adminViewSlug}. Choose a different name.`,
203
+ },
204
+ projectDir,
205
+ });
206
+ }
207
+ /**
208
+ * Ensure a workflow ability scaffold does not already exist on disk or in the
209
+ * workspace inventory.
210
+ *
211
+ * The check covers the generated `src/abilities/<slug>` directory,
212
+ * `inc/abilities/<slug>.php`, and any matching `inventory.abilities` entry.
213
+ *
214
+ * @param projectDir Workspace root directory.
215
+ * @param abilitySlug Normalized workflow ability slug.
216
+ * @param inventory Parsed workspace inventory.
217
+ * @throws {Error} When the ability directory, PHP bootstrap, or inventory entry already exists.
218
+ */
219
+ export function assertAbilityDoesNotExist(projectDir, abilitySlug, inventory) {
220
+ assertScaffoldDoesNotExist({
221
+ filesystemCollisions: [
222
+ {
223
+ label: "An ability scaffold",
224
+ relativePath: path.join("src", "abilities", abilitySlug),
225
+ },
226
+ {
227
+ label: "An ability bootstrap",
228
+ relativePath: path.join("inc", "abilities", `${abilitySlug}.php`),
229
+ },
230
+ ],
231
+ inventoryCollision: {
232
+ entries: inventory.abilities,
233
+ exists: (entry) => entry.slug === abilitySlug,
234
+ message: `An ability inventory entry already exists for ${abilitySlug}. Choose a different name.`,
235
+ },
236
+ projectDir,
237
+ });
238
+ }
239
+ /**
240
+ * Ensure an AI feature scaffold does not already exist on disk or in inventory.
241
+ *
242
+ * Delegates filesystem and inventory checks to `assertScaffoldDoesNotExist`.
243
+ *
244
+ * @param projectDir Absolute workspace root used to resolve scaffold paths.
245
+ * @param aiFeatureSlug Normalized AI feature slug that would be created.
246
+ * @param inventory Current workspace inventory used for duplicate detection.
247
+ * @throws {Error} When AI feature files or inventory entry already exist.
248
+ */
249
+ export function assertAiFeatureDoesNotExist(projectDir, aiFeatureSlug, inventory) {
250
+ assertScaffoldDoesNotExist({
251
+ filesystemCollisions: [
252
+ {
253
+ label: "An AI feature",
254
+ relativePath: path.join("src", "ai-features", aiFeatureSlug),
255
+ },
256
+ {
257
+ label: "An AI feature bootstrap",
258
+ relativePath: path.join("inc", "ai-features", `${aiFeatureSlug}.php`),
259
+ },
260
+ ],
261
+ inventoryCollision: {
262
+ entries: inventory.aiFeatures,
263
+ exists: (entry) => entry.slug === aiFeatureSlug,
264
+ message: `An AI feature inventory entry already exists for ${aiFeatureSlug}. Choose a different name.`,
265
+ },
266
+ projectDir,
267
+ });
268
+ }
269
+ /**
270
+ * Ensure an editor plugin scaffold does not already exist on disk or in the
271
+ * workspace inventory.
272
+ *
273
+ * @param projectDir Workspace root directory.
274
+ * @param editorPluginSlug Normalized editor plugin slug.
275
+ * @param inventory Parsed workspace inventory.
276
+ * @throws {Error} When the directory or inventory entry already exists.
277
+ */
278
+ export function assertEditorPluginDoesNotExist(projectDir, editorPluginSlug, inventory) {
279
+ assertScaffoldDoesNotExist({
280
+ filesystemCollisions: [
281
+ {
282
+ label: "An editor plugin",
283
+ relativePath: path.join("src", "editor-plugins", editorPluginSlug),
284
+ },
285
+ ],
286
+ inventoryCollision: {
287
+ entries: inventory.editorPlugins,
288
+ exists: (entry) => entry.slug === editorPluginSlug,
289
+ message: `An editor plugin inventory entry already exists for ${editorPluginSlug}. Choose a different name.`,
290
+ },
291
+ projectDir,
292
+ });
293
+ }
@@ -0,0 +1,29 @@
1
+ import type { WorkspaceMutationSnapshot } from "./cli-add-types.js";
2
+ import type { WorkspaceProject } from "./workspace-project.js";
3
+ /**
4
+ * Resolve the primary PHP bootstrap file for an official workspace.
5
+ *
6
+ * @param workspace Workspace metadata that provides `packageName` and `projectDir`.
7
+ * @returns Absolute path to `<packageBase>.php` in the workspace root.
8
+ */
9
+ export declare function getWorkspaceBootstrapPath(workspace: WorkspaceProject): string;
10
+ /**
11
+ * Apply a text transform to an existing file only when the contents change.
12
+ */
13
+ export declare function patchFile(filePath: string, transform: (source: string) => string): Promise<void>;
14
+ /**
15
+ * Read a file when it exists and otherwise return `null`.
16
+ */
17
+ export declare function readOptionalFile(filePath: string): Promise<string | null>;
18
+ /**
19
+ * Restore a file to its captured source, deleting it when the snapshot was `null`.
20
+ */
21
+ export declare function restoreOptionalFile(filePath: string, source: string | null): Promise<void>;
22
+ /**
23
+ * Capture the current contents of a set of workspace files for rollback.
24
+ */
25
+ export declare function snapshotWorkspaceFiles(filePaths: string[]): Promise<WorkspaceMutationSnapshot["fileSources"]>;
26
+ /**
27
+ * Undo a partially applied workspace mutation from a captured snapshot.
28
+ */
29
+ export declare function rollbackWorkspaceMutation(snapshot: WorkspaceMutationSnapshot): Promise<void>;
@@ -0,0 +1,77 @@
1
+ import { promises as fsp } from "node:fs";
2
+ import path from "node:path";
3
+ /**
4
+ * Resolve the primary PHP bootstrap file for an official workspace.
5
+ *
6
+ * @param workspace Workspace metadata that provides `packageName` and `projectDir`.
7
+ * @returns Absolute path to `<packageBase>.php` in the workspace root.
8
+ */
9
+ export function getWorkspaceBootstrapPath(workspace) {
10
+ const workspaceBaseName = workspace.packageName.split("/").pop() ?? workspace.packageName;
11
+ return path.join(workspace.projectDir, `${workspaceBaseName}.php`);
12
+ }
13
+ /**
14
+ * Apply a text transform to an existing file only when the contents change.
15
+ */
16
+ export async function patchFile(filePath, transform) {
17
+ const currentSource = await fsp.readFile(filePath, "utf8");
18
+ const nextSource = transform(currentSource);
19
+ if (nextSource !== currentSource) {
20
+ await fsp.writeFile(filePath, nextSource, "utf8");
21
+ }
22
+ }
23
+ /**
24
+ * Read a file when it exists and otherwise return `null`.
25
+ */
26
+ export async function readOptionalFile(filePath) {
27
+ try {
28
+ return await fsp.readFile(filePath, "utf8");
29
+ }
30
+ catch (error) {
31
+ if (isFileNotFoundError(error)) {
32
+ return null;
33
+ }
34
+ throw error;
35
+ }
36
+ }
37
+ /**
38
+ * Restore a file to its captured source, deleting it when the snapshot was `null`.
39
+ */
40
+ export async function restoreOptionalFile(filePath, source) {
41
+ if (source === null) {
42
+ await fsp.rm(filePath, { force: true });
43
+ return;
44
+ }
45
+ await fsp.mkdir(path.dirname(filePath), { recursive: true });
46
+ await fsp.writeFile(filePath, source, "utf8");
47
+ }
48
+ /**
49
+ * Capture the current contents of a set of workspace files for rollback.
50
+ */
51
+ export async function snapshotWorkspaceFiles(filePaths) {
52
+ const uniquePaths = Array.from(new Set(filePaths));
53
+ return Promise.all(uniquePaths.map(async (filePath) => ({
54
+ filePath,
55
+ source: await readOptionalFile(filePath),
56
+ })));
57
+ }
58
+ /**
59
+ * Undo a partially applied workspace mutation from a captured snapshot.
60
+ */
61
+ export async function rollbackWorkspaceMutation(snapshot) {
62
+ for (const targetPath of snapshot.targetPaths) {
63
+ await fsp.rm(targetPath, { force: true, recursive: true });
64
+ }
65
+ for (const snapshotDir of snapshot.snapshotDirs) {
66
+ await fsp.rm(snapshotDir, { force: true, recursive: true });
67
+ }
68
+ for (const { filePath, source } of snapshot.fileSources) {
69
+ await restoreOptionalFile(filePath, source);
70
+ }
71
+ }
72
+ function isFileNotFoundError(error) {
73
+ return (typeof error === "object" &&
74
+ error !== null &&
75
+ "code" in error &&
76
+ error.code === "ENOENT");
77
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Returns help text for the canonical `wp-typia add` subcommands.
3
+ */
4
+ export declare function formatAddHelpText(): string;
@@ -0,0 +1,41 @@
1
+ import { HOOKED_BLOCK_POSITION_IDS, } from "./hooked-blocks.js";
2
+ import { ADD_BLOCK_TEMPLATE_IDS, EDITOR_PLUGIN_SLOT_IDS, REST_RESOURCE_METHOD_IDS, } from "./cli-add-types.js";
3
+ import { WORKSPACE_TEMPLATE_PACKAGE, } from "./workspace-project.js";
4
+ /**
5
+ * Returns help text for the canonical `wp-typia add` subcommands.
6
+ */
7
+ export function formatAddHelpText() {
8
+ return `Usage:
9
+ wp-typia add admin-view <name> [--source <rest-resource:slug|core-data:kind/name>] [--dry-run]
10
+ wp-typia add block <name> [--template <${ADD_BLOCK_TEMPLATE_IDS.join("|")}>] [--external-layer-source <./path|github:owner/repo/path[#ref]|npm-package>] [--external-layer-id <layer-id>] [--inner-blocks-preset <freeform|ordered|horizontal|locked-structure>] [--alternate-render-targets <email,mjml,plain-text>] [--data-storage <post-meta|custom-table>] [--persistence-policy <authenticated|public>] [--dry-run]
11
+ wp-typia add variation <name> --block <block-slug> [--dry-run]
12
+ wp-typia add style <name> --block <block-slug> [--dry-run]
13
+ wp-typia add transform <name> --from <namespace/block> --to <block-slug|namespace/block-slug> [--dry-run]
14
+ wp-typia add pattern <name> [--dry-run]
15
+ wp-typia add binding-source <name> [--block <block-slug|namespace/block-slug> --attribute <attribute>] [--dry-run]
16
+ wp-typia add rest-resource <name> [--namespace <vendor/v1>] [--methods <${REST_RESOURCE_METHOD_IDS.join(",")}>] [--dry-run]
17
+ wp-typia add ability <name> [--dry-run]
18
+ wp-typia add ai-feature <name> [--namespace <vendor/v1>] [--dry-run]
19
+ wp-typia add hooked-block <block-slug> --anchor <anchor-block-name> --position <${HOOKED_BLOCK_POSITION_IDS.join("|")}> [--dry-run]
20
+ wp-typia add editor-plugin <name> [--slot <${EDITOR_PLUGIN_SLOT_IDS.join("|")}>] [--dry-run]
21
+
22
+ Notes:
23
+ \`wp-typia add\` runs only inside official ${WORKSPACE_TEMPLATE_PACKAGE} workspaces scaffolded via \`wp-typia create <project-dir> --template workspace\`.
24
+ Pass \`--dry-run\` to preview the workspace files that would change without writing them.
25
+ Interactive add flows let you choose a template when \`--template\` is omitted; non-interactive runs default to \`basic\`.
26
+ \`add admin-view\` scaffolds an opt-in DataViews-powered WordPress admin screen under \`src/admin-views/\`.
27
+ Pass \`--source rest-resource:<slug>\` to reuse a list-capable REST resource.
28
+ Pass \`--source core-data:postType/post\` or \`--source core-data:taxonomy/category\` to bind a WordPress-owned entity collection.
29
+ Public installs currently gate this workflow until \`@wp-typia/dataviews\` is published to npm.
30
+ \`query-loop\` is a create-time scaffold family. Use \`wp-typia create <project-dir> --template query-loop\` instead of \`wp-typia add block\`.
31
+ \`add variation\` targets an existing block slug from \`scripts/block-config.ts\`.
32
+ \`add style\` registers a Block Styles option for an existing generated block.
33
+ \`add transform\` adds a block-to-block transform into an existing generated block.
34
+ \`add pattern\` scaffolds a namespaced PHP pattern shell under \`src/patterns/\`.
35
+ \`add binding-source\` scaffolds shared PHP and editor registration under \`src/bindings/\`; pass \`--block\` and \`--attribute\` together to declare an end-to-end bindable attribute on an existing generated block.
36
+ \`add rest-resource\` scaffolds plugin-level TypeScript REST contracts under \`src/rest/\` and PHP route glue under \`inc/rest/\`.
37
+ \`add ability\` scaffolds typed workflow abilities under \`src/abilities/\` and server registration under \`inc/abilities/\`.
38
+ \`add ai-feature\` scaffolds server-owned AI feature endpoints under \`src/ai-features/\` and PHP route glue under \`inc/ai-features/\`.
39
+ \`add hooked-block\` patches an existing workspace block's \`block.json\` \`blockHooks\` metadata.
40
+ \`add editor-plugin\` scaffolds a document-level editor extension under \`src/editor-plugins/\`; legacy aliases \`PluginSidebar\` and \`PluginDocumentSettingPanel\` resolve to \`sidebar\` and \`document-setting-panel\`.`;
41
+ }