wp-typia 0.24.4 → 0.24.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.
- package/README.md +7 -5
- package/bin/wp-typia.js +24 -103
- package/{dist-bunli/node-cli.js → dist/cli.js} +5013 -3687
- package/package.json +9 -36
- package/bin/routing-metadata.generated.d.ts +0 -8
- package/bin/routing-metadata.generated.js +0 -93
- package/bin/runtime-routing.d.ts +0 -34
- package/bin/runtime-routing.js +0 -124
- package/dist-bunli/.bunli/commands.gen.js +0 -304441
- package/dist-bunli/.bunli/highlights-eq9cgrbb.scm +0 -604
- package/dist-bunli/.bunli/highlights-ghv9g403.scm +0 -205
- package/dist-bunli/.bunli/highlights-hk7bwhj4.scm +0 -284
- package/dist-bunli/.bunli/highlights-r812a2qc.scm +0 -150
- package/dist-bunli/.bunli/highlights-x6tmsnaa.scm +0 -115
- package/dist-bunli/.bunli/injections-73j83es3.scm +0 -27
- package/dist-bunli/.bunli/tree-sitter-javascript-nd0q4pe9.wasm +0 -0
- package/dist-bunli/.bunli/tree-sitter-markdown-411r6y9b.wasm +0 -0
- package/dist-bunli/.bunli/tree-sitter-markdown_inline-j5349f42.wasm +0 -0
- package/dist-bunli/.bunli/tree-sitter-typescript-zxjzwt75.wasm +0 -0
- package/dist-bunli/.bunli/tree-sitter-zig-e78zbjpm.wasm +0 -0
- package/dist-bunli/agents-91fpdyyt.js +0 -12
- package/dist-bunli/chunk-bdqvmfwv-f5qmzmxg.js +0 -16825
- package/dist-bunli/cli-03j0axbt.js +0 -163
- package/dist-bunli/cli-1170yyve.js +0 -106
- package/dist-bunli/cli-368d4cgy.js +0 -1235
- package/dist-bunli/cli-377p86mf.js +0 -191
- package/dist-bunli/cli-6v0pcxw6.js +0 -314
- package/dist-bunli/cli-84c7wff4.js +0 -198
- package/dist-bunli/cli-8hxf9qw6.js +0 -198
- package/dist-bunli/cli-9fx0qgb7.js +0 -3680
- package/dist-bunli/cli-ac2ebaf8.js +0 -3
- package/dist-bunli/cli-add-qjd3ba8j.js +0 -10671
- package/dist-bunli/cli-am5x7tb4.js +0 -192
- package/dist-bunli/cli-bajwv85z.js +0 -24
- package/dist-bunli/cli-ccax7s0s.js +0 -34
- package/dist-bunli/cli-cvxvcw7c.js +0 -46
- package/dist-bunli/cli-diagnostics-10drxh34.js +0 -34
- package/dist-bunli/cli-doctor-6fyxq940.js +0 -1446
- package/dist-bunli/cli-e4bwd81c.js +0 -1260
- package/dist-bunli/cli-fv4h3ydt.js +0 -173823
- package/dist-bunli/cli-hv2yedw2.js +0 -74591
- package/dist-bunli/cli-init-7avk42dh.js +0 -880
- package/dist-bunli/cli-kfm9mm68.js +0 -14679
- package/dist-bunli/cli-prompt-ncyg68rn.js +0 -12
- package/dist-bunli/cli-rdcga1bd.js +0 -135
- package/dist-bunli/cli-scaffold-0bb6pr3w.js +0 -538
- package/dist-bunli/cli-t73q5aqz.js +0 -103
- package/dist-bunli/cli-templates-g8t4fm11.js +0 -167
- package/dist-bunli/cli-tj7ajdvf.js +0 -2612
- package/dist-bunli/cli-tq730sqt.js +0 -344
- package/dist-bunli/cli-xnn9xjcy.js +0 -68
- package/dist-bunli/cli-z48frc8t.js +0 -229
- package/dist-bunli/cli.js +0 -2523
- package/dist-bunli/command-list-y3g7e9rb.js +0 -4013
- package/dist-bunli/create-template-validation-4fr851vg.js +0 -16
- package/dist-bunli/migrations-3vngdy51.js +0 -47
- package/dist-bunli/sync-k2k8svyc.js +0 -13
- package/dist-bunli/workspace-project-gmv2a71z.js +0 -22
|
@@ -1,4013 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import {
|
|
3
|
-
ADD_OPTION_METADATA,
|
|
4
|
-
CREATE_OPTION_METADATA,
|
|
5
|
-
DOCTOR_OPTION_METADATA,
|
|
6
|
-
INIT_OPTION_METADATA,
|
|
7
|
-
MCP_OPTION_METADATA,
|
|
8
|
-
MIGRATE_OPTION_METADATA,
|
|
9
|
-
SYNC_OPTION_METADATA,
|
|
10
|
-
TEMPLATES_OPTION_METADATA,
|
|
11
|
-
WP_TYPIA_TOP_LEVEL_COMMAND_NAMES,
|
|
12
|
-
buildCommandOptions,
|
|
13
|
-
emitCliDiagnosticFailure,
|
|
14
|
-
formatAddKindList,
|
|
15
|
-
formatAddKindUsagePlaceholder,
|
|
16
|
-
getAddBlockDefaults,
|
|
17
|
-
getCreateDefaults,
|
|
18
|
-
getMcpSchemaSources,
|
|
19
|
-
package_default,
|
|
20
|
-
prefersStructuredCliOutput,
|
|
21
|
-
resolveCommandOptionValues
|
|
22
|
-
} from "./cli-368d4cgy.js";
|
|
23
|
-
import {
|
|
24
|
-
Result,
|
|
25
|
-
TaggedError,
|
|
26
|
-
createKeyMatcher,
|
|
27
|
-
defineCommand,
|
|
28
|
-
exports_external,
|
|
29
|
-
option,
|
|
30
|
-
require_jsx_dev_runtime,
|
|
31
|
-
require_react,
|
|
32
|
-
useKeyboard,
|
|
33
|
-
useRuntime
|
|
34
|
-
} from "./cli-hv2yedw2.js";
|
|
35
|
-
import"./cli-ac2ebaf8.js";
|
|
36
|
-
import {
|
|
37
|
-
createManagedTempRoot
|
|
38
|
-
} from "./cli-t73q5aqz.js";
|
|
39
|
-
import {
|
|
40
|
-
ADD_KIND_IDS
|
|
41
|
-
} from "./cli-bajwv85z.js";
|
|
42
|
-
import {
|
|
43
|
-
CLI_DIAGNOSTIC_CODES,
|
|
44
|
-
createCliDiagnosticCodeError
|
|
45
|
-
} from "./cli-tq730sqt.js";
|
|
46
|
-
import {
|
|
47
|
-
PACKAGE_MANAGER_IDS,
|
|
48
|
-
formatInstallCommand,
|
|
49
|
-
formatPackageExecCommand,
|
|
50
|
-
formatRunScript,
|
|
51
|
-
inferPackageManagerId,
|
|
52
|
-
parsePackageManagerField
|
|
53
|
-
} from "./cli-am5x7tb4.js";
|
|
54
|
-
import"./cli-ccax7s0s.js";
|
|
55
|
-
import {
|
|
56
|
-
__require,
|
|
57
|
-
__toESM
|
|
58
|
-
} from "./cli-xnn9xjcy.js";
|
|
59
|
-
|
|
60
|
-
// src/commands/add.ts
|
|
61
|
-
var import_react34 = __toESM(require_react(), 1);
|
|
62
|
-
|
|
63
|
-
// src/commands/output-adapters.ts
|
|
64
|
-
var defaultPrintLine = (line) => {
|
|
65
|
-
process.stdout.write(`${line}
|
|
66
|
-
`);
|
|
67
|
-
};
|
|
68
|
-
var defaultWarnLine = (line) => {
|
|
69
|
-
process.stderr.write(`${line}
|
|
70
|
-
`);
|
|
71
|
-
};
|
|
72
|
-
function resolveCommandPrintLine(args) {
|
|
73
|
-
return args.printLine ?? defaultPrintLine;
|
|
74
|
-
}
|
|
75
|
-
function resolveCommandOutputAdapters(args) {
|
|
76
|
-
const adapters = args;
|
|
77
|
-
return {
|
|
78
|
-
printLine: adapters.printLine ?? defaultPrintLine,
|
|
79
|
-
warnLine: adapters.warnLine ?? defaultWarnLine
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// src/render-loader.ts
|
|
84
|
-
import fs from "fs";
|
|
85
|
-
import { fileURLToPath } from "url";
|
|
86
|
-
function resolveBundledModuleHref(baseUrl, candidates, options = {}) {
|
|
87
|
-
for (const candidate of candidates) {
|
|
88
|
-
const url = new URL(candidate, baseUrl);
|
|
89
|
-
if (fs.existsSync(fileURLToPath(url))) {
|
|
90
|
-
return url.href;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
const missingCandidates = candidates.map((candidate) => fileURLToPath(new URL(candidate, baseUrl)));
|
|
94
|
-
const label = options.moduleLabel ?? "bundled wp-typia runtime module";
|
|
95
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_BUILD_ARTIFACT, [
|
|
96
|
-
`Missing bundled build artifacts for ${label}.`,
|
|
97
|
-
"None of the expected files were found:",
|
|
98
|
-
...missingCandidates.map((candidatePath) => `- ${candidatePath}`),
|
|
99
|
-
"Run `bun run --filter wp-typia build` in a source checkout, or reinstall the published package/standalone binary if its bundled files are missing."
|
|
100
|
-
].join(`
|
|
101
|
-
`));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// src/add-kind-registry-shared.ts
|
|
105
|
-
var BLOCK_VISIBLE_FIELD_ORDER = [
|
|
106
|
-
"kind",
|
|
107
|
-
"name",
|
|
108
|
-
"template",
|
|
109
|
-
"alternate-render-targets",
|
|
110
|
-
"inner-blocks-preset",
|
|
111
|
-
"data-storage",
|
|
112
|
-
"persistence-policy"
|
|
113
|
-
];
|
|
114
|
-
var NAME_ONLY_VISIBLE_FIELDS = [
|
|
115
|
-
"kind",
|
|
116
|
-
"name"
|
|
117
|
-
];
|
|
118
|
-
var PATTERN_CATALOG_VISIBLE_FIELDS = [
|
|
119
|
-
"kind",
|
|
120
|
-
"name",
|
|
121
|
-
"scope",
|
|
122
|
-
"section-role",
|
|
123
|
-
"catalog-title",
|
|
124
|
-
"tags",
|
|
125
|
-
"thumbnail-url"
|
|
126
|
-
];
|
|
127
|
-
var NAME_SOURCE_VISIBLE_FIELDS = [
|
|
128
|
-
"kind",
|
|
129
|
-
"name",
|
|
130
|
-
"source"
|
|
131
|
-
];
|
|
132
|
-
var NAME_TYPE_VISIBLE_FIELDS = [
|
|
133
|
-
"kind",
|
|
134
|
-
"name",
|
|
135
|
-
"type"
|
|
136
|
-
];
|
|
137
|
-
var NAME_BLOCK_ATTRIBUTE_POST_META_VISIBLE_FIELDS = [
|
|
138
|
-
"kind",
|
|
139
|
-
"name",
|
|
140
|
-
"block",
|
|
141
|
-
"attribute",
|
|
142
|
-
"post-meta",
|
|
143
|
-
"meta-path"
|
|
144
|
-
];
|
|
145
|
-
var NAME_BLOCK_VISIBLE_FIELDS = [
|
|
146
|
-
"kind",
|
|
147
|
-
"name",
|
|
148
|
-
"block"
|
|
149
|
-
];
|
|
150
|
-
var NAME_SLOT_VISIBLE_FIELDS = [
|
|
151
|
-
"kind",
|
|
152
|
-
"name",
|
|
153
|
-
"slot"
|
|
154
|
-
];
|
|
155
|
-
var NAME_ANCHOR_POSITION_VISIBLE_FIELDS = [
|
|
156
|
-
"kind",
|
|
157
|
-
"name",
|
|
158
|
-
"anchor",
|
|
159
|
-
"position"
|
|
160
|
-
];
|
|
161
|
-
var NAME_FROM_TO_VISIBLE_FIELDS = [
|
|
162
|
-
"kind",
|
|
163
|
-
"name",
|
|
164
|
-
"from",
|
|
165
|
-
"to"
|
|
166
|
-
];
|
|
167
|
-
var NAME_NAMESPACE_METHODS_VISIBLE_FIELDS = [
|
|
168
|
-
"kind",
|
|
169
|
-
"name",
|
|
170
|
-
"namespace",
|
|
171
|
-
"methods"
|
|
172
|
-
];
|
|
173
|
-
var NAME_NAMESPACE_VISIBLE_FIELDS = [
|
|
174
|
-
"kind",
|
|
175
|
-
"name",
|
|
176
|
-
"namespace"
|
|
177
|
-
];
|
|
178
|
-
var NAME_POST_TYPE_TYPE_VISIBLE_FIELDS = [
|
|
179
|
-
"kind",
|
|
180
|
-
"name",
|
|
181
|
-
"post-type",
|
|
182
|
-
"type"
|
|
183
|
-
];
|
|
184
|
-
function requireAddKindName(context, message) {
|
|
185
|
-
if (!context.name) {
|
|
186
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, message);
|
|
187
|
-
}
|
|
188
|
-
return context.name;
|
|
189
|
-
}
|
|
190
|
-
function defineAddKindRegistryEntry(entry) {
|
|
191
|
-
return entry;
|
|
192
|
-
}
|
|
193
|
-
function createNamedExecutionPlan(context, options) {
|
|
194
|
-
const name = options.name ?? requireAddKindName(context, options.missingNameMessage);
|
|
195
|
-
return {
|
|
196
|
-
execute: (cwd) => options.execute({ cwd, name }),
|
|
197
|
-
getValues: options.getValues,
|
|
198
|
-
...options.getWarnings ? { getWarnings: options.getWarnings } : {},
|
|
199
|
-
...options.warnLine ? { warnLine: options.warnLine } : {}
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
function isAddPersistenceTemplate(template) {
|
|
203
|
-
return template === "persistence" || template === "compound";
|
|
204
|
-
}
|
|
205
|
-
function formatAddBlockTemplateIds(addRuntime) {
|
|
206
|
-
return addRuntime.ADD_BLOCK_TEMPLATE_IDS.join(", ");
|
|
207
|
-
}
|
|
208
|
-
function getMistypedAddBlockTemplateMessage(addRuntime, templateId) {
|
|
209
|
-
const suggestion = addRuntime.suggestAddBlockTemplateId(templateId);
|
|
210
|
-
if (!suggestion) {
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
return `Unknown add-block template "${templateId}". Did you mean "${suggestion}"? Use \`--template ${suggestion}\`, or run \`wp-typia templates list\` to inspect available templates.`;
|
|
214
|
-
}
|
|
215
|
-
function assertAddBlockTemplateId(context, templateId) {
|
|
216
|
-
if (templateId === "query-loop") {
|
|
217
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, "`wp-typia add block --template query-loop` is not supported. Query Loop is a create-time `core/query` variation scaffold, so use `wp-typia create <project-dir> --template query-loop` instead.");
|
|
218
|
-
}
|
|
219
|
-
if (context.addRuntime.isAddBlockTemplateId(templateId)) {
|
|
220
|
-
return templateId;
|
|
221
|
-
}
|
|
222
|
-
const mistypedAddBlockTemplateMessage = getMistypedAddBlockTemplateMessage(context.addRuntime, templateId);
|
|
223
|
-
if (mistypedAddBlockTemplateMessage) {
|
|
224
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.UNKNOWN_TEMPLATE, mistypedAddBlockTemplateMessage);
|
|
225
|
-
}
|
|
226
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.UNKNOWN_TEMPLATE, `Unknown add-block template "${templateId}". Expected one of: ${formatAddBlockTemplateIds(context.addRuntime)}. Run \`wp-typia templates list\` to inspect available templates.`);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// src/add-kinds/ability.ts
|
|
230
|
-
var ABILITY_MISSING_NAME_MESSAGE = "`wp-typia add ability` requires <name>. Usage: wp-typia add ability <name>.";
|
|
231
|
-
var abilityAddKindEntry = defineAddKindRegistryEntry({
|
|
232
|
-
completion: {
|
|
233
|
-
nextSteps: (values) => [
|
|
234
|
-
`Review src/abilities/${values.abilitySlug}/ and inc/abilities/${values.abilitySlug}.php.`,
|
|
235
|
-
"Run `wp-typia sync` or `npm run sync-abilities -- --check` and then your workspace build/dev command to verify the generated workflow ability."
|
|
236
|
-
],
|
|
237
|
-
summaryLines: (values, projectDir) => [
|
|
238
|
-
`Ability: ${values.abilitySlug}`,
|
|
239
|
-
`Project directory: ${projectDir}`
|
|
240
|
-
],
|
|
241
|
-
title: "Added workflow ability"
|
|
242
|
-
},
|
|
243
|
-
description: "Add a typed server/client workflow ability scaffold",
|
|
244
|
-
nameLabel: "Ability name",
|
|
245
|
-
async prepareExecution(context) {
|
|
246
|
-
return createNamedExecutionPlan(context, {
|
|
247
|
-
execute: ({ cwd, name }) => context.addRuntime.runAddAbilityCommand({
|
|
248
|
-
abilityName: name,
|
|
249
|
-
cwd
|
|
250
|
-
}),
|
|
251
|
-
getValues: (result) => ({
|
|
252
|
-
abilitySlug: result.abilitySlug
|
|
253
|
-
}),
|
|
254
|
-
getWarnings: (result) => result.warnings,
|
|
255
|
-
missingNameMessage: ABILITY_MISSING_NAME_MESSAGE,
|
|
256
|
-
warnLine: context.warnLine
|
|
257
|
-
});
|
|
258
|
-
},
|
|
259
|
-
sortOrder: 90,
|
|
260
|
-
supportsDryRun: true,
|
|
261
|
-
usage: "wp-typia add ability <name> [--dry-run]",
|
|
262
|
-
visibleFieldNames: () => NAME_ONLY_VISIBLE_FIELDS
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
// src/cli-string-flags.ts
|
|
266
|
-
function readOptionalCliStringFlagValue(flags, name, mode) {
|
|
267
|
-
const value = flags[name];
|
|
268
|
-
if (value === undefined || value === null) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
if (typeof value !== "string") {
|
|
272
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, `\`--${name}\` requires a value.`);
|
|
273
|
-
}
|
|
274
|
-
const trimmed = value.trim();
|
|
275
|
-
if (trimmed.length === 0) {
|
|
276
|
-
if (mode === "strict") {
|
|
277
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, `\`--${name}\` requires a value.`);
|
|
278
|
-
}
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
return mode === "strict" ? value : trimmed;
|
|
282
|
-
}
|
|
283
|
-
function readOptionalLooseStringFlag(flags, name) {
|
|
284
|
-
return readOptionalCliStringFlagValue(flags, name, "loose");
|
|
285
|
-
}
|
|
286
|
-
function readOptionalStrictStringFlag(flags, name) {
|
|
287
|
-
return readOptionalCliStringFlagValue(flags, name, "strict");
|
|
288
|
-
}
|
|
289
|
-
function readOptionalDashedOrCamelStringFlag(flags, dashedName, camelName) {
|
|
290
|
-
return readOptionalStrictStringFlag(flags, dashedName) ?? readOptionalStrictStringFlag(flags, camelName);
|
|
291
|
-
}
|
|
292
|
-
function requireStrictStringFlag(flags, name, message) {
|
|
293
|
-
const value = readOptionalStrictStringFlag(flags, name);
|
|
294
|
-
if (!value) {
|
|
295
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, message);
|
|
296
|
-
}
|
|
297
|
-
return value;
|
|
298
|
-
}
|
|
299
|
-
function readOptionalPairedStrictStringFlags(flags, leftName, rightName, message) {
|
|
300
|
-
const leftValue = readOptionalStrictStringFlag(flags, leftName);
|
|
301
|
-
const rightValue = readOptionalStrictStringFlag(flags, rightName);
|
|
302
|
-
if (Boolean(leftValue) !== Boolean(rightValue)) {
|
|
303
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, message);
|
|
304
|
-
}
|
|
305
|
-
return [leftValue, rightValue];
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// src/add-kinds/admin-view.ts
|
|
309
|
-
var ADMIN_VIEW_MISSING_NAME_MESSAGE = "`wp-typia add admin-view` requires <name>. Usage: wp-typia add admin-view <name> [--source <rest-resource:slug|core-data:kind/name>].";
|
|
310
|
-
var adminViewAddKindEntry = defineAddKindRegistryEntry({
|
|
311
|
-
completion: {
|
|
312
|
-
nextSteps: (values) => [
|
|
313
|
-
`Review src/admin-views/${values.adminViewSlug}/ and inc/admin-views/${values.adminViewSlug}.php.`,
|
|
314
|
-
"Run your workspace build or dev command to verify the generated DataViews admin screen."
|
|
315
|
-
],
|
|
316
|
-
summaryLines: (values, projectDir) => [
|
|
317
|
-
`Admin view: ${values.adminViewSlug}`,
|
|
318
|
-
...values.source ? [`Source: ${values.source}`] : [],
|
|
319
|
-
`Project directory: ${projectDir}`
|
|
320
|
-
],
|
|
321
|
-
title: "Added DataViews admin screen"
|
|
322
|
-
},
|
|
323
|
-
description: "Add an opt-in DataViews-powered admin screen",
|
|
324
|
-
nameLabel: "Admin view name",
|
|
325
|
-
async prepareExecution(context) {
|
|
326
|
-
const name = requireAddKindName(context, ADMIN_VIEW_MISSING_NAME_MESSAGE);
|
|
327
|
-
const source = readOptionalStrictStringFlag(context.flags, "source");
|
|
328
|
-
return createNamedExecutionPlan(context, {
|
|
329
|
-
execute: ({ cwd, name: name2 }) => context.addRuntime.runAddAdminViewCommand({
|
|
330
|
-
adminViewName: name2,
|
|
331
|
-
cwd,
|
|
332
|
-
source
|
|
333
|
-
}),
|
|
334
|
-
getValues: (result) => ({
|
|
335
|
-
adminViewSlug: result.adminViewSlug,
|
|
336
|
-
...result.source ? { source: result.source } : {}
|
|
337
|
-
}),
|
|
338
|
-
missingNameMessage: ADMIN_VIEW_MISSING_NAME_MESSAGE,
|
|
339
|
-
name,
|
|
340
|
-
warnLine: context.warnLine
|
|
341
|
-
});
|
|
342
|
-
},
|
|
343
|
-
sortOrder: 10,
|
|
344
|
-
supportsDryRun: true,
|
|
345
|
-
usage: "wp-typia add admin-view <name> [--source <rest-resource:slug|core-data:kind/name>] [--dry-run]",
|
|
346
|
-
visibleFieldNames: () => NAME_SOURCE_VISIBLE_FIELDS
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
// src/add-kinds/ai-feature.ts
|
|
350
|
-
var AI_FEATURE_MISSING_NAME_MESSAGE = "`wp-typia add ai-feature` requires <name>. Usage: wp-typia add ai-feature <name> [--namespace <vendor/v1>].";
|
|
351
|
-
var aiFeatureAddKindEntry = defineAddKindRegistryEntry({
|
|
352
|
-
completion: {
|
|
353
|
-
nextSteps: (values) => [
|
|
354
|
-
`Review src/ai-features/${values.aiFeatureSlug}/ and inc/ai-features/${values.aiFeatureSlug}.php.`,
|
|
355
|
-
"Run `wp-typia sync-rest` and `wp-typia sync ai` or your workspace build/dev command to verify the generated REST artifacts and AI schema."
|
|
356
|
-
],
|
|
357
|
-
summaryLines: (values, projectDir) => [
|
|
358
|
-
`AI feature: ${values.aiFeatureSlug}`,
|
|
359
|
-
`Namespace: ${values.namespace}`,
|
|
360
|
-
`Project directory: ${projectDir}`
|
|
361
|
-
],
|
|
362
|
-
title: "Added server-only AI feature"
|
|
363
|
-
},
|
|
364
|
-
description: "Add a server-owned WordPress AI feature endpoint",
|
|
365
|
-
nameLabel: "AI feature name",
|
|
366
|
-
async prepareExecution(context) {
|
|
367
|
-
const name = requireAddKindName(context, AI_FEATURE_MISSING_NAME_MESSAGE);
|
|
368
|
-
const namespace = readOptionalStrictStringFlag(context.flags, "namespace");
|
|
369
|
-
return createNamedExecutionPlan(context, {
|
|
370
|
-
execute: ({ cwd, name: name2 }) => context.addRuntime.runAddAiFeatureCommand({
|
|
371
|
-
aiFeatureName: name2,
|
|
372
|
-
cwd,
|
|
373
|
-
namespace
|
|
374
|
-
}),
|
|
375
|
-
getValues: (result) => ({
|
|
376
|
-
aiFeatureSlug: result.aiFeatureSlug,
|
|
377
|
-
namespace: result.namespace
|
|
378
|
-
}),
|
|
379
|
-
getWarnings: (result) => result.warnings,
|
|
380
|
-
missingNameMessage: AI_FEATURE_MISSING_NAME_MESSAGE,
|
|
381
|
-
name,
|
|
382
|
-
warnLine: context.warnLine
|
|
383
|
-
});
|
|
384
|
-
},
|
|
385
|
-
sortOrder: 100,
|
|
386
|
-
supportsDryRun: true,
|
|
387
|
-
usage: "wp-typia add ai-feature <name> [--namespace <vendor/v1>] [--dry-run]",
|
|
388
|
-
visibleFieldNames: () => NAME_NAMESPACE_VISIBLE_FIELDS
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
// src/add-kinds/binding-source.ts
|
|
392
|
-
var BINDING_SOURCE_MISSING_NAME_MESSAGE = "`wp-typia add binding-source` requires <name>. Usage: wp-typia add binding-source <name> [--block <block-slug|namespace/block-slug> --attribute <attribute>] [--from-post-meta <post-meta> --meta-path <field>].";
|
|
393
|
-
var bindingSourceAddKindEntry = defineAddKindRegistryEntry({
|
|
394
|
-
completion: {
|
|
395
|
-
nextSteps: (values) => [
|
|
396
|
-
`Review src/bindings/${values.bindingSourceSlug}/server.php and src/bindings/${values.bindingSourceSlug}/editor.ts.`,
|
|
397
|
-
...values.blockSlug && values.attributeName ? [
|
|
398
|
-
`Review src/blocks/${values.blockSlug}/block.json for the ${values.attributeName} bindable attribute.`
|
|
399
|
-
] : [],
|
|
400
|
-
...values.postMetaSlug ? [
|
|
401
|
-
`Run wp-typia sync-rest --check after editing ${values.schemaFile}.`
|
|
402
|
-
] : [],
|
|
403
|
-
"Run your workspace build or dev command to verify the binding source hooks and editor registration."
|
|
404
|
-
],
|
|
405
|
-
summaryLines: (values, projectDir) => [
|
|
406
|
-
`Binding source: ${values.bindingSourceSlug}`,
|
|
407
|
-
...values.blockSlug && values.attributeName ? [`Target: ${values.blockSlug}.${values.attributeName}`] : [],
|
|
408
|
-
...values.postMetaSlug ? [
|
|
409
|
-
`Post meta: ${values.postMetaSlug}`,
|
|
410
|
-
`Meta field: ${values.metaPath}`
|
|
411
|
-
] : [],
|
|
412
|
-
`Project directory: ${projectDir}`
|
|
413
|
-
],
|
|
414
|
-
title: "Added binding source"
|
|
415
|
-
},
|
|
416
|
-
description: "Add a shared block bindings source",
|
|
417
|
-
nameLabel: "Binding source name",
|
|
418
|
-
async prepareExecution(context) {
|
|
419
|
-
const name = requireAddKindName(context, BINDING_SOURCE_MISSING_NAME_MESSAGE);
|
|
420
|
-
const [blockName, attributeName] = readOptionalPairedStrictStringFlags(context.flags, "block", "attribute", "`wp-typia add binding-source` requires --block and --attribute to be provided together.");
|
|
421
|
-
const postMetaName = readOptionalDashedOrCamelStringFlag(context.flags, "from-post-meta", "fromPostMeta") ?? readOptionalDashedOrCamelStringFlag(context.flags, "post-meta", "postMeta");
|
|
422
|
-
const metaPath = readOptionalDashedOrCamelStringFlag(context.flags, "meta-path", "metaPath");
|
|
423
|
-
return createNamedExecutionPlan(context, {
|
|
424
|
-
execute: ({ cwd, name: name2 }) => context.addRuntime.runAddBindingSourceCommand({
|
|
425
|
-
attributeName,
|
|
426
|
-
bindingSourceName: name2,
|
|
427
|
-
blockName,
|
|
428
|
-
cwd,
|
|
429
|
-
metaPath,
|
|
430
|
-
postMetaName
|
|
431
|
-
}),
|
|
432
|
-
getValues: (result) => ({
|
|
433
|
-
...result.attributeName ? { attributeName: result.attributeName } : {},
|
|
434
|
-
...result.blockSlug ? { blockSlug: result.blockSlug } : {},
|
|
435
|
-
bindingSourceSlug: result.bindingSourceSlug,
|
|
436
|
-
...result.metaKey ? { metaKey: result.metaKey } : {},
|
|
437
|
-
...result.metaPath ? { metaPath: result.metaPath } : {},
|
|
438
|
-
...result.postMetaSlug ? { postMetaSlug: result.postMetaSlug } : {},
|
|
439
|
-
...result.postType ? { postType: result.postType } : {},
|
|
440
|
-
...result.schemaFile ? { schemaFile: result.schemaFile } : {}
|
|
441
|
-
}),
|
|
442
|
-
missingNameMessage: BINDING_SOURCE_MISSING_NAME_MESSAGE,
|
|
443
|
-
name,
|
|
444
|
-
warnLine: context.warnLine
|
|
445
|
-
});
|
|
446
|
-
},
|
|
447
|
-
sortOrder: 70,
|
|
448
|
-
supportsDryRun: true,
|
|
449
|
-
usage: "wp-typia add binding-source <name> [--block <block-slug|namespace/block-slug> --attribute <attribute>] [--from-post-meta|--post-meta <post-meta> [--meta-path <field>]] [--dry-run]",
|
|
450
|
-
visibleFieldNames: () => NAME_BLOCK_ATTRIBUTE_POST_META_VISIBLE_FIELDS
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
// src/external-layer-prompt-options.ts
|
|
454
|
-
function formatExternalLayerSelectHint(option2) {
|
|
455
|
-
const details = [
|
|
456
|
-
option2.description,
|
|
457
|
-
option2.extends.length > 0 ? `extends ${option2.extends.join(", ")}` : undefined
|
|
458
|
-
].filter((value) => typeof value === "string" && value.length > 0);
|
|
459
|
-
return details.length > 0 ? details.join(" \xB7 ") : undefined;
|
|
460
|
-
}
|
|
461
|
-
function toExternalLayerPromptOptions(options) {
|
|
462
|
-
return options.map((option2) => ({
|
|
463
|
-
hint: formatExternalLayerSelectHint(option2),
|
|
464
|
-
label: option2.id,
|
|
465
|
-
value: option2.id
|
|
466
|
-
}));
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// src/add-kinds/block.ts
|
|
470
|
-
var BLOCK_MISSING_NAME_MESSAGE = "`wp-typia add block` requires <name>. Usage: wp-typia add block <name> [--template <basic|interactivity|persistence|compound>]";
|
|
471
|
-
var blockAddKindEntry = defineAddKindRegistryEntry({
|
|
472
|
-
completion: {
|
|
473
|
-
nextSteps: () => [
|
|
474
|
-
"Review the generated sources under src/blocks/ and the updated scripts/block-config.ts entry.",
|
|
475
|
-
"Run your workspace build or dev command to verify the new scaffolded block family."
|
|
476
|
-
],
|
|
477
|
-
summaryLines: (values, projectDir) => [
|
|
478
|
-
`Blocks: ${values.blockSlugs}`,
|
|
479
|
-
`Template family: ${values.templateId}`,
|
|
480
|
-
`Project directory: ${projectDir}`
|
|
481
|
-
],
|
|
482
|
-
title: "Added workspace block"
|
|
483
|
-
},
|
|
484
|
-
description: "Add a real block slice",
|
|
485
|
-
hiddenStringSubmitFields: ["external-layer-id", "external-layer-source"],
|
|
486
|
-
nameLabel: "Block name",
|
|
487
|
-
async prepareExecution(context) {
|
|
488
|
-
const name = requireAddKindName(context, BLOCK_MISSING_NAME_MESSAGE);
|
|
489
|
-
const externalLayerId = readOptionalStrictStringFlag(context.flags, "external-layer-id");
|
|
490
|
-
const externalLayerSource = readOptionalStrictStringFlag(context.flags, "external-layer-source");
|
|
491
|
-
const shouldPromptForLayerSelection = Boolean(externalLayerSource) && !Boolean(externalLayerId) && context.isInteractiveSession;
|
|
492
|
-
const selectPrompt = shouldPromptForLayerSelection ? await context.getOrCreatePrompt() : undefined;
|
|
493
|
-
const alternateRenderTargets = readOptionalStrictStringFlag(context.flags, "alternate-render-targets");
|
|
494
|
-
const dataStorageMode = readOptionalStrictStringFlag(context.flags, "data-storage");
|
|
495
|
-
const innerBlocksPreset = readOptionalStrictStringFlag(context.flags, "inner-blocks-preset");
|
|
496
|
-
const persistencePolicy = readOptionalStrictStringFlag(context.flags, "persistence-policy");
|
|
497
|
-
const requestedTemplateId = readOptionalStrictStringFlag(context.flags, "template");
|
|
498
|
-
let resolvedTemplateId = requestedTemplateId ? assertAddBlockTemplateId(context, requestedTemplateId) : undefined;
|
|
499
|
-
if (!resolvedTemplateId && context.isInteractiveSession) {
|
|
500
|
-
const templatePrompt = await context.getOrCreatePrompt();
|
|
501
|
-
resolvedTemplateId = await templatePrompt.select("Select a block template", context.addRuntime.ADD_BLOCK_TEMPLATE_IDS.map((templateId) => ({
|
|
502
|
-
hint: `Scaffold the ${templateId} block family`,
|
|
503
|
-
label: templateId,
|
|
504
|
-
value: templateId
|
|
505
|
-
})), 1);
|
|
506
|
-
}
|
|
507
|
-
resolvedTemplateId ??= "basic";
|
|
508
|
-
return createNamedExecutionPlan(context, {
|
|
509
|
-
execute: ({ cwd, name: name2 }) => context.addRuntime.runAddBlockCommand({
|
|
510
|
-
alternateRenderTargets,
|
|
511
|
-
blockName: name2,
|
|
512
|
-
cwd,
|
|
513
|
-
dataStorageMode,
|
|
514
|
-
externalLayerId,
|
|
515
|
-
externalLayerSource,
|
|
516
|
-
innerBlocksPreset,
|
|
517
|
-
persistencePolicy,
|
|
518
|
-
selectExternalLayerId: selectPrompt ? (options) => selectPrompt.select("Select an external layer", toExternalLayerPromptOptions(options), 1) : undefined,
|
|
519
|
-
templateId: resolvedTemplateId
|
|
520
|
-
}),
|
|
521
|
-
getValues: (result) => ({
|
|
522
|
-
blockSlugs: result.blockSlugs.join(", "),
|
|
523
|
-
templateId: result.templateId
|
|
524
|
-
}),
|
|
525
|
-
getWarnings: (result) => result.warnings,
|
|
526
|
-
missingNameMessage: BLOCK_MISSING_NAME_MESSAGE,
|
|
527
|
-
name,
|
|
528
|
-
warnLine: context.warnLine
|
|
529
|
-
});
|
|
530
|
-
},
|
|
531
|
-
sortOrder: 20,
|
|
532
|
-
supportsDryRun: true,
|
|
533
|
-
usage: "wp-typia add block <name> [--template <basic|interactivity|persistence|compound>] [--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]",
|
|
534
|
-
visibleFieldNames: ({ template }) => BLOCK_VISIBLE_FIELD_ORDER.filter((fieldName) => {
|
|
535
|
-
if (fieldName === "alternate-render-targets") {
|
|
536
|
-
return isAddPersistenceTemplate(template);
|
|
537
|
-
}
|
|
538
|
-
if (fieldName === "inner-blocks-preset") {
|
|
539
|
-
return template === "compound";
|
|
540
|
-
}
|
|
541
|
-
if (fieldName === "data-storage" || fieldName === "persistence-policy") {
|
|
542
|
-
return isAddPersistenceTemplate(template);
|
|
543
|
-
}
|
|
544
|
-
return true;
|
|
545
|
-
})
|
|
546
|
-
});
|
|
547
|
-
|
|
548
|
-
// src/add-kinds/contract.ts
|
|
549
|
-
var CONTRACT_MISSING_NAME_MESSAGE = "`wp-typia add contract` requires <name>. Usage: wp-typia add contract <name> [--type <ExportedTypeName>].";
|
|
550
|
-
var contractAddKindEntry = defineAddKindRegistryEntry({
|
|
551
|
-
completion: {
|
|
552
|
-
nextSteps: (values) => [
|
|
553
|
-
`Edit ${values.typesFile} when the standalone wire shape changes.`,
|
|
554
|
-
"Run `wp-typia sync-rest` or `wp-typia sync` to refresh the generated schema artifact."
|
|
555
|
-
],
|
|
556
|
-
summaryLines: (values, projectDir) => [
|
|
557
|
-
`Contract: ${values.contractSlug}`,
|
|
558
|
-
`Source type: ${values.sourceTypeName}`,
|
|
559
|
-
`Schema: ${values.schemaFile}`,
|
|
560
|
-
`Project directory: ${projectDir}`
|
|
561
|
-
],
|
|
562
|
-
title: "Added standalone contract"
|
|
563
|
-
},
|
|
564
|
-
description: "Add a standalone TypeScript schema contract",
|
|
565
|
-
nameLabel: "Contract name",
|
|
566
|
-
async prepareExecution(context) {
|
|
567
|
-
const name = requireAddKindName(context, CONTRACT_MISSING_NAME_MESSAGE);
|
|
568
|
-
const typeName = readOptionalStrictStringFlag(context.flags, "type");
|
|
569
|
-
return createNamedExecutionPlan(context, {
|
|
570
|
-
execute: ({ cwd, name: name2 }) => context.addRuntime.runAddContractCommand({
|
|
571
|
-
contractName: name2,
|
|
572
|
-
cwd,
|
|
573
|
-
typeName
|
|
574
|
-
}),
|
|
575
|
-
getValues: (result) => ({
|
|
576
|
-
contractSlug: result.contractSlug,
|
|
577
|
-
schemaFile: result.schemaFile,
|
|
578
|
-
sourceTypeName: result.sourceTypeName,
|
|
579
|
-
typesFile: result.typesFile
|
|
580
|
-
}),
|
|
581
|
-
missingNameMessage: CONTRACT_MISSING_NAME_MESSAGE,
|
|
582
|
-
name,
|
|
583
|
-
warnLine: context.warnLine
|
|
584
|
-
});
|
|
585
|
-
},
|
|
586
|
-
sortOrder: 75,
|
|
587
|
-
supportsDryRun: true,
|
|
588
|
-
usage: "wp-typia add contract <name> [--type <ExportedTypeName>] [--dry-run]",
|
|
589
|
-
visibleFieldNames: () => NAME_TYPE_VISIBLE_FIELDS
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
// src/add-kinds/core-variation.ts
|
|
593
|
-
var CORE_VARIATION_MISSING_NAME_MESSAGE = "`wp-typia add core-variation` requires <name>. Usage: wp-typia add core-variation <block-name> <name> or wp-typia add core-variation <name> --block <namespace/block>.";
|
|
594
|
-
var CORE_VARIATION_MISSING_BLOCK_MESSAGE = "`wp-typia add core-variation` requires <block-name>. Usage: wp-typia add core-variation <block-name> <name> or wp-typia add core-variation <name> --block <namespace/block>.";
|
|
595
|
-
var CORE_VARIATION_BLOCK_NAME_PATTERN = /^[^/\s]+\/[^/\s]+$/u;
|
|
596
|
-
var CORE_VARIATION_POSITIONAL_TARGET_DIAGNOSTICS = {
|
|
597
|
-
empty: () => "The first positional argument (target block name) requires a block name.",
|
|
598
|
-
invalidFormat: () => "The first positional argument (target block name) must use <namespace/block-slug> format."
|
|
599
|
-
};
|
|
600
|
-
function formatCoreVariationMissingPositionalNameMessage(blockName) {
|
|
601
|
-
return [
|
|
602
|
-
`\`wp-typia add core-variation ${blockName}\` is missing <name>.`,
|
|
603
|
-
"Usage: wp-typia add core-variation <block-name> <name>",
|
|
604
|
-
"Alternative: wp-typia add core-variation <name> --block <namespace/block>"
|
|
605
|
-
].join(`
|
|
606
|
-
`);
|
|
607
|
-
}
|
|
608
|
-
function resolveCoreVariationInputs(context) {
|
|
609
|
-
const positionalTargetBlockName = context.positionalArgs?.[1];
|
|
610
|
-
const positionalVariationName = context.positionalArgs?.[2];
|
|
611
|
-
if (positionalVariationName) {
|
|
612
|
-
if (!positionalTargetBlockName) {
|
|
613
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, CORE_VARIATION_MISSING_BLOCK_MESSAGE);
|
|
614
|
-
}
|
|
615
|
-
return {
|
|
616
|
-
targetBlockName: positionalTargetBlockName,
|
|
617
|
-
targetBlockNameDiagnostics: CORE_VARIATION_POSITIONAL_TARGET_DIAGNOSTICS,
|
|
618
|
-
variationName: positionalVariationName
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
const targetBlockFlag = readOptionalStrictStringFlag(context.flags, "block");
|
|
622
|
-
const missingPositionalNameTarget = context.name !== undefined && positionalTargetBlockName === context.name && CORE_VARIATION_BLOCK_NAME_PATTERN.test(context.name) ? context.name : undefined;
|
|
623
|
-
if (missingPositionalNameTarget && !targetBlockFlag) {
|
|
624
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, formatCoreVariationMissingPositionalNameMessage(missingPositionalNameTarget));
|
|
625
|
-
}
|
|
626
|
-
const variationName = requireAddKindName(context, CORE_VARIATION_MISSING_NAME_MESSAGE);
|
|
627
|
-
if (!targetBlockFlag) {
|
|
628
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, CORE_VARIATION_MISSING_BLOCK_MESSAGE);
|
|
629
|
-
}
|
|
630
|
-
return {
|
|
631
|
-
targetBlockName: targetBlockFlag,
|
|
632
|
-
targetBlockNameDiagnostics: "--block",
|
|
633
|
-
variationName
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
var coreVariationAddKindEntry = defineAddKindRegistryEntry({
|
|
637
|
-
completion: {
|
|
638
|
-
nextSteps: (values) => [
|
|
639
|
-
`Review ${values.variationFile}.`,
|
|
640
|
-
"Run your workspace build or dev command to verify the editor-side variation registration."
|
|
641
|
-
],
|
|
642
|
-
summaryLines: (values, projectDir) => [
|
|
643
|
-
`Core variation: ${values.variationSlug}`,
|
|
644
|
-
`Target block: ${values.targetBlockName}`,
|
|
645
|
-
`Project directory: ${projectDir}`
|
|
646
|
-
],
|
|
647
|
-
title: "Added core block variation"
|
|
648
|
-
},
|
|
649
|
-
description: "Add an editor-side variation for an existing core or external block",
|
|
650
|
-
nameLabel: "Variation name",
|
|
651
|
-
async prepareExecution(context) {
|
|
652
|
-
const { targetBlockName, targetBlockNameDiagnostics, variationName } = resolveCoreVariationInputs(context);
|
|
653
|
-
return createNamedExecutionPlan(context, {
|
|
654
|
-
execute: ({ cwd, name }) => context.addRuntime.runAddCoreVariationCommand({
|
|
655
|
-
cwd,
|
|
656
|
-
targetBlockName,
|
|
657
|
-
targetBlockNameDiagnostics,
|
|
658
|
-
variationName: name
|
|
659
|
-
}),
|
|
660
|
-
getValues: (result) => ({
|
|
661
|
-
targetBlockName: result.targetBlockName,
|
|
662
|
-
variationFile: result.variationFile,
|
|
663
|
-
variationSlug: result.variationSlug
|
|
664
|
-
}),
|
|
665
|
-
getWarnings: (result) => result.warnings,
|
|
666
|
-
missingNameMessage: CORE_VARIATION_MISSING_NAME_MESSAGE,
|
|
667
|
-
name: variationName,
|
|
668
|
-
warnLine: context.warnLine
|
|
669
|
-
});
|
|
670
|
-
},
|
|
671
|
-
sortOrder: 25,
|
|
672
|
-
supportsDryRun: true,
|
|
673
|
-
usage: `wp-typia add core-variation <block-name> <name> [--dry-run]
|
|
674
|
-
Alias: wp-typia add core-variation <name> --block <namespace/block> [--dry-run]`,
|
|
675
|
-
visibleFieldNames: () => NAME_BLOCK_VISIBLE_FIELDS
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
// src/add-kinds/editor-plugin.ts
|
|
679
|
-
var EDITOR_PLUGIN_MISSING_NAME_MESSAGE = "`wp-typia add editor-plugin` requires <name>. Usage: wp-typia add editor-plugin <name> [--slot <sidebar|document-setting-panel>].";
|
|
680
|
-
var editorPluginAddKindEntry = defineAddKindRegistryEntry({
|
|
681
|
-
completion: {
|
|
682
|
-
nextSteps: (values) => [
|
|
683
|
-
`Review src/editor-plugins/${values.editorPluginSlug}/.`,
|
|
684
|
-
"Run your workspace build or dev command to verify the new editor plugin registration."
|
|
685
|
-
],
|
|
686
|
-
summaryLines: (values, projectDir) => [
|
|
687
|
-
`Editor plugin: ${values.editorPluginSlug}`,
|
|
688
|
-
`Slot: ${values.slot}`,
|
|
689
|
-
`Project directory: ${projectDir}`
|
|
690
|
-
],
|
|
691
|
-
title: "Added editor plugin"
|
|
692
|
-
},
|
|
693
|
-
description: "Add a slot-aware document editor extension shell",
|
|
694
|
-
nameLabel: "Editor plugin name",
|
|
695
|
-
async prepareExecution(context) {
|
|
696
|
-
const name = requireAddKindName(context, EDITOR_PLUGIN_MISSING_NAME_MESSAGE);
|
|
697
|
-
const slot = readOptionalStrictStringFlag(context.flags, "slot");
|
|
698
|
-
return createNamedExecutionPlan(context, {
|
|
699
|
-
execute: ({ cwd, name: name2 }) => context.addRuntime.runAddEditorPluginCommand({
|
|
700
|
-
cwd,
|
|
701
|
-
editorPluginName: name2,
|
|
702
|
-
slot
|
|
703
|
-
}),
|
|
704
|
-
getValues: (result) => ({
|
|
705
|
-
editorPluginSlug: result.editorPluginSlug,
|
|
706
|
-
slot: result.slot
|
|
707
|
-
}),
|
|
708
|
-
missingNameMessage: EDITOR_PLUGIN_MISSING_NAME_MESSAGE,
|
|
709
|
-
name,
|
|
710
|
-
warnLine: context.warnLine
|
|
711
|
-
});
|
|
712
|
-
},
|
|
713
|
-
sortOrder: 120,
|
|
714
|
-
supportsDryRun: true,
|
|
715
|
-
usage: "wp-typia add editor-plugin <name> [--slot <sidebar|document-setting-panel>] [--dry-run]",
|
|
716
|
-
visibleFieldNames: () => NAME_SLOT_VISIBLE_FIELDS
|
|
717
|
-
});
|
|
718
|
-
|
|
719
|
-
// src/add-kinds/hooked-block.ts
|
|
720
|
-
var HOOKED_BLOCK_MISSING_NAME_MESSAGE = "`wp-typia add hooked-block` requires <block-slug>. Usage: wp-typia add hooked-block <block-slug> --anchor <anchor-block-name> --position <before|after|firstChild|lastChild>.";
|
|
721
|
-
var hookedBlockAddKindEntry = defineAddKindRegistryEntry({
|
|
722
|
-
completion: {
|
|
723
|
-
nextSteps: (values) => [
|
|
724
|
-
`Review src/blocks/${values.blockSlug}/block.json for the new blockHooks entry.`,
|
|
725
|
-
"Run your workspace build or dev command to verify the updated hooked-block metadata."
|
|
726
|
-
],
|
|
727
|
-
summaryLines: (values, projectDir) => [
|
|
728
|
-
`Block: ${values.blockSlug}`,
|
|
729
|
-
`Anchor: ${values.anchorBlockName}`,
|
|
730
|
-
`Position: ${values.position}`,
|
|
731
|
-
`Project directory: ${projectDir}`
|
|
732
|
-
],
|
|
733
|
-
title: "Added blockHooks metadata"
|
|
734
|
-
},
|
|
735
|
-
description: "Add block.json hook metadata to an existing block",
|
|
736
|
-
nameLabel: "Target block",
|
|
737
|
-
async prepareExecution(context) {
|
|
738
|
-
const name = requireAddKindName(context, HOOKED_BLOCK_MISSING_NAME_MESSAGE);
|
|
739
|
-
const anchorBlockName = requireStrictStringFlag(context.flags, "anchor", "`wp-typia add hooked-block` requires --anchor <anchor-block-name>.");
|
|
740
|
-
const position = requireStrictStringFlag(context.flags, "position", "`wp-typia add hooked-block` requires --position <before|after|firstChild|lastChild>.");
|
|
741
|
-
return createNamedExecutionPlan(context, {
|
|
742
|
-
execute: ({ cwd, name: name2 }) => context.addRuntime.runAddHookedBlockCommand({
|
|
743
|
-
anchorBlockName,
|
|
744
|
-
blockName: name2,
|
|
745
|
-
cwd,
|
|
746
|
-
position
|
|
747
|
-
}),
|
|
748
|
-
getValues: (result) => ({
|
|
749
|
-
anchorBlockName: result.anchorBlockName,
|
|
750
|
-
blockSlug: result.blockSlug,
|
|
751
|
-
position: result.position
|
|
752
|
-
}),
|
|
753
|
-
missingNameMessage: HOOKED_BLOCK_MISSING_NAME_MESSAGE,
|
|
754
|
-
name,
|
|
755
|
-
warnLine: context.warnLine
|
|
756
|
-
});
|
|
757
|
-
},
|
|
758
|
-
sortOrder: 110,
|
|
759
|
-
supportsDryRun: true,
|
|
760
|
-
usage: "wp-typia add hooked-block <block-slug> --anchor <anchor-block-name> --position <before|after|firstChild|lastChild> [--dry-run]",
|
|
761
|
-
visibleFieldNames: () => NAME_ANCHOR_POSITION_VISIBLE_FIELDS
|
|
762
|
-
});
|
|
763
|
-
|
|
764
|
-
// src/add-kinds/integration-env.ts
|
|
765
|
-
var INTEGRATION_ENV_MISSING_NAME_MESSAGE = "`wp-typia add integration-env` requires <name>. Usage: wp-typia add integration-env <name> [--wp-env] [--release-zip] [--service <none|docker-compose>].";
|
|
766
|
-
var integrationEnvAddKindEntry = defineAddKindRegistryEntry({
|
|
767
|
-
completion: {
|
|
768
|
-
nextSteps: (values) => [
|
|
769
|
-
`Review scripts/integration-smoke/${values.integrationEnvSlug}.mjs and docs/integration-env/${values.integrationEnvSlug}.md.`,
|
|
770
|
-
"Copy `.env.example` to `.env`, adjust local URLs or credentials, then run the generated smoke script.",
|
|
771
|
-
...values.withWpEnv === "true" ? ["Run `npm run wp-env:start` before the smoke check when using the generated wp-env preset."] : [],
|
|
772
|
-
...values.withReleaseZip === "true" ? ["Run `npm run release:zip` after smoke checks pass to build a distributable plugin zip."] : []
|
|
773
|
-
],
|
|
774
|
-
summaryLines: (values, projectDir) => [
|
|
775
|
-
`Integration env: ${values.integrationEnvSlug}`,
|
|
776
|
-
`wp-env preset: ${values.withWpEnv}`,
|
|
777
|
-
`Release zip scripts: ${values.withReleaseZip}`,
|
|
778
|
-
`Service starter: ${values.service}`,
|
|
779
|
-
`Project directory: ${projectDir}`
|
|
780
|
-
],
|
|
781
|
-
title: "Added integration environment starter"
|
|
782
|
-
},
|
|
783
|
-
description: "Add an opt-in local WordPress integration smoke environment starter",
|
|
784
|
-
nameLabel: "Integration env name",
|
|
785
|
-
async prepareExecution(context) {
|
|
786
|
-
const service = readOptionalStrictStringFlag(context.flags, "service");
|
|
787
|
-
const withReleaseZip = Boolean(context.flags["release-zip"]);
|
|
788
|
-
const withWpEnv = Boolean(context.flags["wp-env"]);
|
|
789
|
-
return createNamedExecutionPlan(context, {
|
|
790
|
-
execute: ({ cwd, name }) => context.addRuntime.runAddIntegrationEnvCommand({
|
|
791
|
-
cwd,
|
|
792
|
-
integrationEnvName: name,
|
|
793
|
-
service,
|
|
794
|
-
withReleaseZip,
|
|
795
|
-
withWpEnv
|
|
796
|
-
}),
|
|
797
|
-
getValues: (result) => ({
|
|
798
|
-
integrationEnvSlug: result.integrationEnvSlug,
|
|
799
|
-
service: result.service,
|
|
800
|
-
withReleaseZip: String(result.withReleaseZip),
|
|
801
|
-
withWpEnv: String(result.withWpEnv)
|
|
802
|
-
}),
|
|
803
|
-
getWarnings: (result) => result.warnings,
|
|
804
|
-
missingNameMessage: INTEGRATION_ENV_MISSING_NAME_MESSAGE,
|
|
805
|
-
warnLine: context.warnLine
|
|
806
|
-
});
|
|
807
|
-
},
|
|
808
|
-
sortOrder: 25,
|
|
809
|
-
supportsDryRun: true,
|
|
810
|
-
usage: "wp-typia add integration-env <name> [--wp-env] [--release-zip] [--service <none|docker-compose>] [--dry-run]",
|
|
811
|
-
visibleFieldNames: () => NAME_ONLY_VISIBLE_FIELDS,
|
|
812
|
-
hiddenBooleanSubmitFields: ["wp-env", "release-zip"],
|
|
813
|
-
hiddenStringSubmitFields: ["service"]
|
|
814
|
-
});
|
|
815
|
-
|
|
816
|
-
// src/add-kinds/pattern.ts
|
|
817
|
-
var PATTERN_MISSING_NAME_MESSAGE = "`wp-typia add pattern` requires <name>. Usage: wp-typia add pattern <name>.";
|
|
818
|
-
var patternAddKindEntry = defineAddKindRegistryEntry({
|
|
819
|
-
completion: {
|
|
820
|
-
nextSteps: (values) => [
|
|
821
|
-
`Review ${values.contentFile}.`,
|
|
822
|
-
"Run your workspace build or dev command to verify the new pattern registration."
|
|
823
|
-
],
|
|
824
|
-
summaryLines: (values, projectDir) => [
|
|
825
|
-
`Pattern: ${values.patternSlug}`,
|
|
826
|
-
`Content file: ${values.contentFile}`,
|
|
827
|
-
`Project directory: ${projectDir}`
|
|
828
|
-
],
|
|
829
|
-
title: "Added workspace pattern"
|
|
830
|
-
},
|
|
831
|
-
description: "Add a PHP block pattern shell",
|
|
832
|
-
hiddenStringSubmitFields: ["tag"],
|
|
833
|
-
nameLabel: "Pattern name",
|
|
834
|
-
async prepareExecution(context) {
|
|
835
|
-
const name = requireAddKindName(context, PATTERN_MISSING_NAME_MESSAGE);
|
|
836
|
-
const rawScope = typeof context.flags.scope === "string" ? context.flags.scope : undefined;
|
|
837
|
-
const rawSectionRole = typeof context.flags["section-role"] === "string" ? context.flags["section-role"] : undefined;
|
|
838
|
-
const rawCatalogTitle = typeof context.flags["catalog-title"] === "string" ? context.flags["catalog-title"] : undefined;
|
|
839
|
-
const rawThumbnailUrl = typeof context.flags["thumbnail-url"] === "string" ? context.flags["thumbnail-url"] : undefined;
|
|
840
|
-
const scope = resolvePatternScopeFlag(context);
|
|
841
|
-
const sectionRole = resolvePatternSectionRoleFlag(context, scope);
|
|
842
|
-
const catalogTitle = rawCatalogTitle;
|
|
843
|
-
const tags = normalizePatternTagFlags(context.flags.tags, context.flags.tag);
|
|
844
|
-
const thumbnailUrl = rawThumbnailUrl;
|
|
845
|
-
return {
|
|
846
|
-
execute: (cwd) => context.addRuntime.runAddPatternCommand({
|
|
847
|
-
catalogTitle,
|
|
848
|
-
cwd,
|
|
849
|
-
patternScope: scope,
|
|
850
|
-
patternName: name,
|
|
851
|
-
sectionRole,
|
|
852
|
-
tags,
|
|
853
|
-
thumbnailUrl
|
|
854
|
-
}),
|
|
855
|
-
getDryRunSummaryLines: (result) => buildPatternCatalogDryRunSummaryLines(result, {
|
|
856
|
-
rawCatalogTitle,
|
|
857
|
-
rawScope,
|
|
858
|
-
rawSectionRole,
|
|
859
|
-
rawTags: tags,
|
|
860
|
-
rawThumbnailUrl
|
|
861
|
-
}),
|
|
862
|
-
getValues: (result) => ({
|
|
863
|
-
contentFile: result.contentFile,
|
|
864
|
-
patternSlug: result.patternSlug,
|
|
865
|
-
patternScope: result.patternScope,
|
|
866
|
-
...result.sectionRole ? { sectionRole: result.sectionRole } : {}
|
|
867
|
-
}),
|
|
868
|
-
warnLine: context.warnLine
|
|
869
|
-
};
|
|
870
|
-
},
|
|
871
|
-
sortOrder: 60,
|
|
872
|
-
supportsDryRun: true,
|
|
873
|
-
usage: "wp-typia add pattern <name> [--scope <full|section>] [--section-role <role>] [--catalog-title <title>] [--tags <tag,...>] [--tag <tag>...] [--thumbnail-url <url>] [--dry-run]",
|
|
874
|
-
visibleFieldNames: () => PATTERN_CATALOG_VISIBLE_FIELDS
|
|
875
|
-
});
|
|
876
|
-
function createInvalidPatternArgumentError(message) {
|
|
877
|
-
return createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, message);
|
|
878
|
-
}
|
|
879
|
-
function createMissingPatternArgumentError(message) {
|
|
880
|
-
return createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, message);
|
|
881
|
-
}
|
|
882
|
-
function resolvePatternScopeFlag(context) {
|
|
883
|
-
const scope = readOptionalLooseStringFlag(context.flags, "scope");
|
|
884
|
-
if (!scope) {
|
|
885
|
-
return;
|
|
886
|
-
}
|
|
887
|
-
if (context.addRuntime.PATTERN_CATALOG_SCOPE_IDS.includes(scope)) {
|
|
888
|
-
return scope;
|
|
889
|
-
}
|
|
890
|
-
throw createInvalidPatternArgumentError(`\`--scope\` must be one of: ${context.addRuntime.PATTERN_CATALOG_SCOPE_IDS.join(", ")}. Usage: wp-typia add pattern <name> --scope <full|section>.`);
|
|
891
|
-
}
|
|
892
|
-
function resolvePatternSectionRoleFlag(context, scope) {
|
|
893
|
-
const sectionRole = readOptionalLooseStringFlag(context.flags, "section-role");
|
|
894
|
-
if (scope === "section" && sectionRole === undefined) {
|
|
895
|
-
throw createMissingPatternArgumentError("`wp-typia add pattern --scope section` requires --section-role <role> because section-scoped patterns need a typed catalog section role.");
|
|
896
|
-
}
|
|
897
|
-
if (scope !== "section" && sectionRole !== undefined) {
|
|
898
|
-
throw createInvalidPatternArgumentError("`--section-role` only applies with `--scope section`. Use `--scope section --section-role <role>` or omit `--section-role` for full patterns.");
|
|
899
|
-
}
|
|
900
|
-
const normalizedSectionRole = sectionRole === undefined ? undefined : context.addRuntime.normalizeBlockSlug(sectionRole);
|
|
901
|
-
if (normalizedSectionRole && !context.addRuntime.PATTERN_SECTION_ROLE_PATTERN.test(normalizedSectionRole)) {
|
|
902
|
-
throw createInvalidPatternArgumentError("`--section-role` must start with a lowercase letter and contain only lowercase letters, numbers, and hyphens. Section roles apply only with `--scope section`.");
|
|
903
|
-
}
|
|
904
|
-
if (sectionRole !== undefined && !normalizedSectionRole) {
|
|
905
|
-
throw createInvalidPatternArgumentError("`--section-role` must start with a lowercase letter and contain only lowercase letters, numbers, and hyphens. Section roles apply only with `--scope section`.");
|
|
906
|
-
}
|
|
907
|
-
return normalizedSectionRole;
|
|
908
|
-
}
|
|
909
|
-
function collectStringFlagValues(value) {
|
|
910
|
-
if (typeof value === "string") {
|
|
911
|
-
return [value];
|
|
912
|
-
}
|
|
913
|
-
if (Array.isArray(value)) {
|
|
914
|
-
return value.filter((item) => typeof item === "string");
|
|
915
|
-
}
|
|
916
|
-
return [];
|
|
917
|
-
}
|
|
918
|
-
function normalizePatternTagFlags(tagsFlag, tagFlag) {
|
|
919
|
-
const tags = [
|
|
920
|
-
...collectStringFlagValues(tagsFlag),
|
|
921
|
-
...collectStringFlagValues(tagFlag)
|
|
922
|
-
];
|
|
923
|
-
return tags.length > 0 ? tags : undefined;
|
|
924
|
-
}
|
|
925
|
-
function quoteValue(value) {
|
|
926
|
-
return `"${value}"`;
|
|
927
|
-
}
|
|
928
|
-
function formatTags(tags) {
|
|
929
|
-
return tags.length > 0 ? tags.join(", ") : "no tags";
|
|
930
|
-
}
|
|
931
|
-
function collectPatternTagTokens(tags) {
|
|
932
|
-
return (tags ?? []).flatMap((tag) => tag.split(",")).map((tag) => tag.trim()).filter((tag) => tag.length > 0);
|
|
933
|
-
}
|
|
934
|
-
function valuesMatch(left, right) {
|
|
935
|
-
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
936
|
-
}
|
|
937
|
-
function createNormalizationNote(options) {
|
|
938
|
-
const rawValue = options.rawValue;
|
|
939
|
-
if (rawValue === undefined || rawValue.trim().length === 0 || !options.resolvedValue || rawValue === options.resolvedValue) {
|
|
940
|
-
return;
|
|
941
|
-
}
|
|
942
|
-
return `${options.fieldLabel} normalized from ${quoteValue(rawValue)} to ${quoteValue(options.resolvedValue)}.`;
|
|
943
|
-
}
|
|
944
|
-
function collectPatternCatalogNormalizationNotes(result, options) {
|
|
945
|
-
const notes = [
|
|
946
|
-
createNormalizationNote({
|
|
947
|
-
fieldLabel: "Scope",
|
|
948
|
-
rawValue: options.rawScope,
|
|
949
|
-
resolvedValue: result.patternScope
|
|
950
|
-
}),
|
|
951
|
-
createNormalizationNote({
|
|
952
|
-
fieldLabel: "Section role",
|
|
953
|
-
rawValue: options.rawSectionRole,
|
|
954
|
-
resolvedValue: result.sectionRole
|
|
955
|
-
}),
|
|
956
|
-
createNormalizationNote({
|
|
957
|
-
fieldLabel: "Title",
|
|
958
|
-
rawValue: options.rawCatalogTitle,
|
|
959
|
-
resolvedValue: result.title
|
|
960
|
-
}),
|
|
961
|
-
createNormalizationNote({
|
|
962
|
-
fieldLabel: "Thumbnail URL",
|
|
963
|
-
rawValue: options.rawThumbnailUrl,
|
|
964
|
-
resolvedValue: result.thumbnailUrl
|
|
965
|
-
})
|
|
966
|
-
].filter((note) => typeof note === "string");
|
|
967
|
-
const rawTags = collectPatternTagTokens(options.rawTags);
|
|
968
|
-
if (rawTags.length > 0 && !valuesMatch(rawTags, result.tags)) {
|
|
969
|
-
notes.push(`Tags normalized from ${quoteValue(formatTags(rawTags))} to ${quoteValue(formatTags(result.tags))}.`);
|
|
970
|
-
}
|
|
971
|
-
return notes;
|
|
972
|
-
}
|
|
973
|
-
function buildPatternCatalogDryRunSummaryLines(result, options) {
|
|
974
|
-
const catalogLines = [
|
|
975
|
-
"",
|
|
976
|
-
"Catalog metadata:",
|
|
977
|
-
` Scope: ${result.patternScope}`,
|
|
978
|
-
...result.sectionRole ? [` Section role: ${result.sectionRole}`] : [],
|
|
979
|
-
` Title: ${result.title}`,
|
|
980
|
-
...result.tags.length > 0 ? [` Tags: ${formatTags(result.tags)}`] : [],
|
|
981
|
-
...result.thumbnailUrl ? [` Thumbnail URL: ${result.thumbnailUrl}`] : []
|
|
982
|
-
];
|
|
983
|
-
const normalizationNotes = collectPatternCatalogNormalizationNotes(result, options);
|
|
984
|
-
if (normalizationNotes.length === 0) {
|
|
985
|
-
return catalogLines;
|
|
986
|
-
}
|
|
987
|
-
return [
|
|
988
|
-
...catalogLines,
|
|
989
|
-
"",
|
|
990
|
-
"Normalization notes:",
|
|
991
|
-
...normalizationNotes.map((note) => ` ${note}`)
|
|
992
|
-
];
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
// src/add-kinds/post-meta.ts
|
|
996
|
-
var POST_META_MISSING_NAME_MESSAGE = "`wp-typia add post-meta` requires <name>. Usage: wp-typia add post-meta <name> --post-type <post-type> [--type <ExportedTypeName>] [--meta-key <meta-key>].";
|
|
997
|
-
var POST_META_MISSING_POST_TYPE_MESSAGE = "`wp-typia add post-meta` requires --post-type <post-type>. Usage: wp-typia add post-meta <name> --post-type <post-type>.";
|
|
998
|
-
var postMetaAddKindEntry = defineAddKindRegistryEntry({
|
|
999
|
-
completion: {
|
|
1000
|
-
nextSteps: (values) => [
|
|
1001
|
-
`Edit ${values.typesFile} when the post meta shape changes.`,
|
|
1002
|
-
"Run `wp-typia sync-rest --check` to verify the generated meta schema is current.",
|
|
1003
|
-
`Smoke test ${values.metaKey} on the ${values.postType} post type in WordPress.`
|
|
1004
|
-
],
|
|
1005
|
-
summaryLines: (values, projectDir) => [
|
|
1006
|
-
`Post meta contract: ${values.postMetaSlug}`,
|
|
1007
|
-
`Post type: ${values.postType}`,
|
|
1008
|
-
`Meta key: ${values.metaKey}`,
|
|
1009
|
-
`REST/editor exposure: ${values.showInRest}`,
|
|
1010
|
-
`Schema: ${values.schemaFile}`,
|
|
1011
|
-
`PHP: ${values.phpFile}`,
|
|
1012
|
-
`Project directory: ${projectDir}`
|
|
1013
|
-
],
|
|
1014
|
-
title: "Added post meta contract"
|
|
1015
|
-
},
|
|
1016
|
-
description: "Add a typed WordPress post meta contract",
|
|
1017
|
-
hiddenBooleanSubmitFields: ["hide-from-rest"],
|
|
1018
|
-
hiddenStringSubmitFields: ["meta-key"],
|
|
1019
|
-
nameLabel: "Post meta name",
|
|
1020
|
-
async prepareExecution(context) {
|
|
1021
|
-
const name = requireAddKindName(context, POST_META_MISSING_NAME_MESSAGE);
|
|
1022
|
-
const hideFromRest = Boolean(context.flags["hide-from-rest"] ?? context.flags.hideFromRest);
|
|
1023
|
-
const metaKey = readOptionalDashedOrCamelStringFlag(context.flags, "meta-key", "metaKey");
|
|
1024
|
-
const postType = readOptionalDashedOrCamelStringFlag(context.flags, "post-type", "postType") ?? requireStrictStringFlag(context.flags, "post-type", POST_META_MISSING_POST_TYPE_MESSAGE);
|
|
1025
|
-
const typeName = readOptionalStrictStringFlag(context.flags, "type");
|
|
1026
|
-
return createNamedExecutionPlan(context, {
|
|
1027
|
-
execute: ({ cwd, name: name2 }) => context.addRuntime.runAddPostMetaCommand({
|
|
1028
|
-
cwd,
|
|
1029
|
-
hideFromRest,
|
|
1030
|
-
metaKey,
|
|
1031
|
-
postMetaName: name2,
|
|
1032
|
-
postType,
|
|
1033
|
-
typeName
|
|
1034
|
-
}),
|
|
1035
|
-
getValues: (result) => ({
|
|
1036
|
-
metaKey: result.metaKey,
|
|
1037
|
-
phpFile: result.phpFile,
|
|
1038
|
-
postMetaSlug: result.postMetaSlug,
|
|
1039
|
-
postType: result.postType,
|
|
1040
|
-
schemaFile: result.schemaFile,
|
|
1041
|
-
showInRest: result.showInRest ? "enabled" : "disabled",
|
|
1042
|
-
sourceTypeName: result.sourceTypeName,
|
|
1043
|
-
typesFile: result.typesFile
|
|
1044
|
-
}),
|
|
1045
|
-
missingNameMessage: POST_META_MISSING_NAME_MESSAGE,
|
|
1046
|
-
name,
|
|
1047
|
-
warnLine: context.warnLine
|
|
1048
|
-
});
|
|
1049
|
-
},
|
|
1050
|
-
sortOrder: 85,
|
|
1051
|
-
supportsDryRun: true,
|
|
1052
|
-
usage: "wp-typia add post-meta <name> --post-type <post-type> [--type <ExportedTypeName>] [--meta-key <meta-key>] [--hide-from-rest] [--dry-run]",
|
|
1053
|
-
visibleFieldNames: () => NAME_POST_TYPE_TYPE_VISIBLE_FIELDS
|
|
1054
|
-
});
|
|
1055
|
-
|
|
1056
|
-
// src/add-kinds/rest-resource.ts
|
|
1057
|
-
var REST_RESOURCE_GENERATED_USAGE = "Generated: wp-typia add rest-resource <name> [--namespace <vendor/v1>] [--methods <list,read,create,update,delete>] [--route-pattern <route-pattern>] [--permission-callback <callback>] [--controller-class <ClassName>] [--controller-extends <BaseClass>] [--dry-run]";
|
|
1058
|
-
var REST_RESOURCE_MANUAL_USAGE = "Manual: wp-typia add rest-resource <name> --manual [--namespace <vendor/v1>] [--method <GET|POST|PUT|PATCH|DELETE>] [--auth <public|authenticated|public-write-protected>] [--path <route-pattern>|--route-pattern <route-pattern>] [--permission-callback <callback>] [--controller-class <ClassName>] [--controller-extends <BaseClass>] [--query-type <Type>] [--body-type <Type>] [--response-type <Type>] [--secret-field <field>] [--secret-state-field|--secret-has-value-field <field>] [--secret-preserve-on-empty <true|false>] [--dry-run]";
|
|
1059
|
-
var REST_RESOURCE_USAGE = `${REST_RESOURCE_GENERATED_USAGE}
|
|
1060
|
-
${REST_RESOURCE_MANUAL_USAGE}`;
|
|
1061
|
-
var REST_RESOURCE_MISSING_NAME_MESSAGE = [
|
|
1062
|
-
"`wp-typia add rest-resource` requires <name>. Usage:",
|
|
1063
|
-
` ${REST_RESOURCE_GENERATED_USAGE}`,
|
|
1064
|
-
` ${REST_RESOURCE_MANUAL_USAGE}`
|
|
1065
|
-
].join(`
|
|
1066
|
-
`);
|
|
1067
|
-
var SECRET_PRESERVE_ON_EMPTY_TRUE_VALUES = new Set(["1", "true", "yes"]);
|
|
1068
|
-
var SECRET_PRESERVE_ON_EMPTY_FALSE_VALUES = new Set(["0", "false", "no"]);
|
|
1069
|
-
function readOptionalSecretPreserveOnEmptyFlag(flags) {
|
|
1070
|
-
const value = flags["secret-preserve-on-empty"] ?? flags.secretPreserveOnEmpty;
|
|
1071
|
-
if (value === undefined || value === null) {
|
|
1072
|
-
return;
|
|
1073
|
-
}
|
|
1074
|
-
if (typeof value === "boolean") {
|
|
1075
|
-
return value;
|
|
1076
|
-
}
|
|
1077
|
-
if (typeof value !== "string") {
|
|
1078
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, "`--secret-preserve-on-empty` requires a value.");
|
|
1079
|
-
}
|
|
1080
|
-
const normalized = value.trim().toLowerCase();
|
|
1081
|
-
if (normalized.length === 0) {
|
|
1082
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, "`--secret-preserve-on-empty` requires a value.");
|
|
1083
|
-
}
|
|
1084
|
-
if (SECRET_PRESERVE_ON_EMPTY_TRUE_VALUES.has(normalized)) {
|
|
1085
|
-
return true;
|
|
1086
|
-
}
|
|
1087
|
-
if (SECRET_PRESERVE_ON_EMPTY_FALSE_VALUES.has(normalized)) {
|
|
1088
|
-
return false;
|
|
1089
|
-
}
|
|
1090
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, "Manual REST contract --secret-preserve-on-empty must be true or false.");
|
|
1091
|
-
}
|
|
1092
|
-
var restResourceAddKindEntry = defineAddKindRegistryEntry({
|
|
1093
|
-
completion: {
|
|
1094
|
-
nextSteps: (values) => values.mode === "manual" ? [
|
|
1095
|
-
`Review src/rest/${values.restResourceSlug}/ and edit the manual contract types to match the external route owner.`,
|
|
1096
|
-
"Run sync-rest --check after changing the contract types to verify schemas, OpenAPI, and client artifacts."
|
|
1097
|
-
] : [
|
|
1098
|
-
`Review src/rest/${values.restResourceSlug}/ and inc/rest/${values.restResourceSlug}.php.`,
|
|
1099
|
-
"Run your workspace build or dev command to verify the generated REST resource contract."
|
|
1100
|
-
],
|
|
1101
|
-
summaryLines: (values, projectDir) => [
|
|
1102
|
-
`REST resource: ${values.restResourceSlug}`,
|
|
1103
|
-
`Mode: ${values.mode}`,
|
|
1104
|
-
`Namespace: ${values.namespace}`,
|
|
1105
|
-
...values.mode === "manual" ? [
|
|
1106
|
-
`Route: ${values.method} /${values.namespace}${values.pathPattern}`,
|
|
1107
|
-
`Auth: ${values.auth}`,
|
|
1108
|
-
...values.secretFieldName ? [
|
|
1109
|
-
`Secret field: ${values.secretFieldName} -> ${values.secretStateFieldName}`,
|
|
1110
|
-
`Secret preserve on empty: ${values.secretPreserveOnEmpty}`
|
|
1111
|
-
] : [],
|
|
1112
|
-
...values.permissionCallback ? [`Declared permission callback: ${values.permissionCallback}`] : [],
|
|
1113
|
-
...values.controllerClass ? [`Declared controller class: ${values.controllerClass}`] : [],
|
|
1114
|
-
...values.controllerExtends ? [`Declared controller base: ${values.controllerExtends}`] : []
|
|
1115
|
-
] : [
|
|
1116
|
-
`Methods: ${values.methods}`,
|
|
1117
|
-
...values.routePattern ? [`Item route: /${values.namespace}${values.routePattern}`] : [],
|
|
1118
|
-
...values.permissionCallback ? [`Permission callback: ${values.permissionCallback}`] : [],
|
|
1119
|
-
...values.controllerClass ? [`Controller class: ${values.controllerClass}`] : []
|
|
1120
|
-
],
|
|
1121
|
-
`Project directory: ${projectDir}`
|
|
1122
|
-
],
|
|
1123
|
-
title: "Added REST resource contract"
|
|
1124
|
-
},
|
|
1125
|
-
description: "Add a generated or type-only REST resource contract",
|
|
1126
|
-
hiddenBooleanSubmitFields: ["manual"],
|
|
1127
|
-
hiddenStringSubmitFields: [
|
|
1128
|
-
"auth",
|
|
1129
|
-
"body-type",
|
|
1130
|
-
"controller-class",
|
|
1131
|
-
"controller-extends",
|
|
1132
|
-
"method",
|
|
1133
|
-
"path",
|
|
1134
|
-
"permission-callback",
|
|
1135
|
-
"query-type",
|
|
1136
|
-
"response-type",
|
|
1137
|
-
"route-pattern",
|
|
1138
|
-
"secret-field",
|
|
1139
|
-
"secret-has-value-field",
|
|
1140
|
-
"secret-masked-response-field",
|
|
1141
|
-
"secret-preserve-on-empty",
|
|
1142
|
-
"secret-state-field"
|
|
1143
|
-
],
|
|
1144
|
-
nameLabel: "REST resource name",
|
|
1145
|
-
async prepareExecution(context) {
|
|
1146
|
-
const name = requireAddKindName(context, REST_RESOURCE_MISSING_NAME_MESSAGE);
|
|
1147
|
-
const auth = readOptionalStrictStringFlag(context.flags, "auth");
|
|
1148
|
-
const bodyTypeName = readOptionalStrictStringFlag(context.flags, "body-type");
|
|
1149
|
-
const controllerClass = readOptionalDashedOrCamelStringFlag(context.flags, "controller-class", "controllerClass");
|
|
1150
|
-
const controllerExtends = readOptionalDashedOrCamelStringFlag(context.flags, "controller-extends", "controllerExtends");
|
|
1151
|
-
const manual = Boolean(context.flags.manual);
|
|
1152
|
-
const method = readOptionalStrictStringFlag(context.flags, "method");
|
|
1153
|
-
const methods = readOptionalStrictStringFlag(context.flags, "methods");
|
|
1154
|
-
const namespace = readOptionalStrictStringFlag(context.flags, "namespace");
|
|
1155
|
-
const permissionCallback = readOptionalDashedOrCamelStringFlag(context.flags, "permission-callback", "permissionCallback");
|
|
1156
|
-
const pathPattern = readOptionalStrictStringFlag(context.flags, "path");
|
|
1157
|
-
const queryTypeName = readOptionalStrictStringFlag(context.flags, "query-type");
|
|
1158
|
-
const responseTypeName = readOptionalStrictStringFlag(context.flags, "response-type");
|
|
1159
|
-
const routePattern = readOptionalDashedOrCamelStringFlag(context.flags, "route-pattern", "routePattern");
|
|
1160
|
-
const secretFieldName = readOptionalDashedOrCamelStringFlag(context.flags, "secret-field", "secretField");
|
|
1161
|
-
const secretHasValueFieldName = readOptionalDashedOrCamelStringFlag(context.flags, "secret-has-value-field", "secretHasValueField");
|
|
1162
|
-
const secretMaskedResponseFieldName = readOptionalDashedOrCamelStringFlag(context.flags, "secret-masked-response-field", "secretMaskedResponseField");
|
|
1163
|
-
const secretPreserveOnEmpty = readOptionalSecretPreserveOnEmptyFlag(context.flags);
|
|
1164
|
-
const secretStateFieldName = readOptionalDashedOrCamelStringFlag(context.flags, "secret-state-field", "secretStateField");
|
|
1165
|
-
return createNamedExecutionPlan(context, {
|
|
1166
|
-
execute: ({ cwd, name: name2 }) => context.addRuntime.runAddRestResourceCommand({
|
|
1167
|
-
auth,
|
|
1168
|
-
bodyTypeName,
|
|
1169
|
-
controllerClass,
|
|
1170
|
-
controllerExtends,
|
|
1171
|
-
cwd,
|
|
1172
|
-
manual,
|
|
1173
|
-
method,
|
|
1174
|
-
methods,
|
|
1175
|
-
namespace,
|
|
1176
|
-
permissionCallback,
|
|
1177
|
-
pathPattern,
|
|
1178
|
-
queryTypeName,
|
|
1179
|
-
restResourceName: name2,
|
|
1180
|
-
responseTypeName,
|
|
1181
|
-
routePattern,
|
|
1182
|
-
secretFieldName,
|
|
1183
|
-
secretHasValueFieldName,
|
|
1184
|
-
secretMaskedResponseFieldName,
|
|
1185
|
-
secretPreserveOnEmpty,
|
|
1186
|
-
secretStateFieldName
|
|
1187
|
-
}),
|
|
1188
|
-
getValues: (result) => ({
|
|
1189
|
-
auth: result.auth ?? "",
|
|
1190
|
-
controllerClass: result.controllerClass ?? "",
|
|
1191
|
-
controllerExtends: result.controllerExtends ?? "",
|
|
1192
|
-
method: result.method ?? "",
|
|
1193
|
-
methods: result.methods.join(", "),
|
|
1194
|
-
mode: result.mode,
|
|
1195
|
-
namespace: result.namespace,
|
|
1196
|
-
pathPattern: result.pathPattern ?? "",
|
|
1197
|
-
permissionCallback: result.permissionCallback ?? "",
|
|
1198
|
-
restResourceSlug: result.restResourceSlug,
|
|
1199
|
-
routePattern: result.routePattern ?? "",
|
|
1200
|
-
secretFieldName: result.secretFieldName ?? "",
|
|
1201
|
-
secretPreserveOnEmpty: result.secretPreserveOnEmpty === undefined ? "" : String(result.secretPreserveOnEmpty),
|
|
1202
|
-
secretStateFieldName: result.secretStateFieldName ?? ""
|
|
1203
|
-
}),
|
|
1204
|
-
missingNameMessage: REST_RESOURCE_MISSING_NAME_MESSAGE,
|
|
1205
|
-
name,
|
|
1206
|
-
warnLine: context.warnLine
|
|
1207
|
-
});
|
|
1208
|
-
},
|
|
1209
|
-
sortOrder: 80,
|
|
1210
|
-
supportsDryRun: true,
|
|
1211
|
-
usage: REST_RESOURCE_USAGE,
|
|
1212
|
-
visibleFieldNames: () => NAME_NAMESPACE_METHODS_VISIBLE_FIELDS
|
|
1213
|
-
});
|
|
1214
|
-
|
|
1215
|
-
// src/add-kinds/style.ts
|
|
1216
|
-
var STYLE_MISSING_NAME_MESSAGE = "`wp-typia add style` requires <name>. Usage: wp-typia add style <name> --block <block-slug>.";
|
|
1217
|
-
var styleAddKindEntry = defineAddKindRegistryEntry({
|
|
1218
|
-
completion: {
|
|
1219
|
-
nextSteps: (values) => [
|
|
1220
|
-
`Review src/blocks/${values.blockSlug}/styles/${values.styleSlug}.ts.`,
|
|
1221
|
-
"Run your workspace build or dev command to verify the new block style registration."
|
|
1222
|
-
],
|
|
1223
|
-
summaryLines: (values, projectDir) => [
|
|
1224
|
-
`Block style: ${values.styleSlug}`,
|
|
1225
|
-
`Target block: ${values.blockSlug}`,
|
|
1226
|
-
`Project directory: ${projectDir}`
|
|
1227
|
-
],
|
|
1228
|
-
title: "Added block style"
|
|
1229
|
-
},
|
|
1230
|
-
description: "Add a Block Styles registration to an existing block",
|
|
1231
|
-
nameLabel: "Style name",
|
|
1232
|
-
async prepareExecution(context) {
|
|
1233
|
-
const name = requireAddKindName(context, STYLE_MISSING_NAME_MESSAGE);
|
|
1234
|
-
const blockSlug = requireStrictStringFlag(context.flags, "block", "`wp-typia add style` requires --block <block-slug>.");
|
|
1235
|
-
return createNamedExecutionPlan(context, {
|
|
1236
|
-
execute: ({ cwd, name: name2 }) => context.addRuntime.runAddBlockStyleCommand({
|
|
1237
|
-
blockName: blockSlug,
|
|
1238
|
-
cwd,
|
|
1239
|
-
styleName: name2
|
|
1240
|
-
}),
|
|
1241
|
-
getValues: (result) => ({
|
|
1242
|
-
blockSlug: result.blockSlug,
|
|
1243
|
-
styleSlug: result.styleSlug
|
|
1244
|
-
}),
|
|
1245
|
-
missingNameMessage: STYLE_MISSING_NAME_MESSAGE,
|
|
1246
|
-
name,
|
|
1247
|
-
warnLine: context.warnLine
|
|
1248
|
-
});
|
|
1249
|
-
},
|
|
1250
|
-
sortOrder: 40,
|
|
1251
|
-
supportsDryRun: true,
|
|
1252
|
-
usage: "wp-typia add style <name> --block <block-slug> [--dry-run]",
|
|
1253
|
-
visibleFieldNames: () => NAME_BLOCK_VISIBLE_FIELDS
|
|
1254
|
-
});
|
|
1255
|
-
|
|
1256
|
-
// src/add-kinds/transform.ts
|
|
1257
|
-
var TRANSFORM_MISSING_NAME_MESSAGE = "`wp-typia add transform` requires <name>. Usage: wp-typia add transform <name> --from <namespace/block> --to <block-slug|namespace/block-slug>.";
|
|
1258
|
-
var transformAddKindEntry = defineAddKindRegistryEntry({
|
|
1259
|
-
completion: {
|
|
1260
|
-
nextSteps: (values) => [
|
|
1261
|
-
`Review src/blocks/${values.blockSlug}/transforms/${values.transformSlug}.ts.`,
|
|
1262
|
-
"Run your workspace build or dev command to verify the new block transform registration."
|
|
1263
|
-
],
|
|
1264
|
-
summaryLines: (values, projectDir) => [
|
|
1265
|
-
`Block transform: ${values.transformSlug}`,
|
|
1266
|
-
`From: ${values.fromBlockName}`,
|
|
1267
|
-
`To: ${values.toBlockName}`,
|
|
1268
|
-
`Project directory: ${projectDir}`
|
|
1269
|
-
],
|
|
1270
|
-
title: "Added block transform"
|
|
1271
|
-
},
|
|
1272
|
-
description: "Add a block-to-block transform into a workspace block",
|
|
1273
|
-
nameLabel: "Transform name",
|
|
1274
|
-
async prepareExecution(context) {
|
|
1275
|
-
const name = requireAddKindName(context, TRANSFORM_MISSING_NAME_MESSAGE);
|
|
1276
|
-
const fromBlockName = requireStrictStringFlag(context.flags, "from", "`wp-typia add transform` requires --from <namespace/block>.");
|
|
1277
|
-
const toBlockName = requireStrictStringFlag(context.flags, "to", "`wp-typia add transform` requires --to <block-slug|namespace/block-slug>.");
|
|
1278
|
-
return createNamedExecutionPlan(context, {
|
|
1279
|
-
execute: ({ cwd, name: name2 }) => context.addRuntime.runAddBlockTransformCommand({
|
|
1280
|
-
cwd,
|
|
1281
|
-
fromBlockName,
|
|
1282
|
-
toBlockName,
|
|
1283
|
-
transformName: name2
|
|
1284
|
-
}),
|
|
1285
|
-
getValues: (result) => ({
|
|
1286
|
-
blockSlug: result.blockSlug,
|
|
1287
|
-
fromBlockName: result.fromBlockName,
|
|
1288
|
-
toBlockName: result.toBlockName,
|
|
1289
|
-
transformSlug: result.transformSlug
|
|
1290
|
-
}),
|
|
1291
|
-
missingNameMessage: TRANSFORM_MISSING_NAME_MESSAGE,
|
|
1292
|
-
name,
|
|
1293
|
-
warnLine: context.warnLine
|
|
1294
|
-
});
|
|
1295
|
-
},
|
|
1296
|
-
sortOrder: 50,
|
|
1297
|
-
supportsDryRun: true,
|
|
1298
|
-
usage: "wp-typia add transform <name> --from <namespace/block> --to <block-slug|namespace/block-slug> [--dry-run]",
|
|
1299
|
-
visibleFieldNames: () => NAME_FROM_TO_VISIBLE_FIELDS
|
|
1300
|
-
});
|
|
1301
|
-
|
|
1302
|
-
// src/add-kinds/variation.ts
|
|
1303
|
-
var VARIATION_MISSING_NAME_MESSAGE = "`wp-typia add variation` requires <name>. Usage: wp-typia add variation <name> --block <block-slug>";
|
|
1304
|
-
var variationAddKindEntry = defineAddKindRegistryEntry({
|
|
1305
|
-
completion: {
|
|
1306
|
-
nextSteps: (values) => [
|
|
1307
|
-
`Review src/blocks/${values.blockSlug}/variations/${values.variationSlug}.ts.`,
|
|
1308
|
-
"Run your workspace build or dev command to pick up the new variation."
|
|
1309
|
-
],
|
|
1310
|
-
summaryLines: (values, projectDir) => [
|
|
1311
|
-
`Variation: ${values.variationSlug}`,
|
|
1312
|
-
`Target block: ${values.blockSlug}`,
|
|
1313
|
-
`Project directory: ${projectDir}`
|
|
1314
|
-
],
|
|
1315
|
-
title: "Added workspace variation"
|
|
1316
|
-
},
|
|
1317
|
-
description: "Add a variation to an existing block",
|
|
1318
|
-
nameLabel: "Variation name",
|
|
1319
|
-
async prepareExecution(context) {
|
|
1320
|
-
const name = requireAddKindName(context, VARIATION_MISSING_NAME_MESSAGE);
|
|
1321
|
-
const blockSlug = requireStrictStringFlag(context.flags, "block", "`wp-typia add variation` requires --block <block-slug>.");
|
|
1322
|
-
return createNamedExecutionPlan(context, {
|
|
1323
|
-
execute: ({ cwd, name: name2 }) => context.addRuntime.runAddVariationCommand({
|
|
1324
|
-
blockName: blockSlug,
|
|
1325
|
-
cwd,
|
|
1326
|
-
variationName: name2
|
|
1327
|
-
}),
|
|
1328
|
-
getValues: (result) => ({
|
|
1329
|
-
blockSlug: result.blockSlug,
|
|
1330
|
-
variationSlug: result.variationSlug
|
|
1331
|
-
}),
|
|
1332
|
-
missingNameMessage: VARIATION_MISSING_NAME_MESSAGE,
|
|
1333
|
-
name,
|
|
1334
|
-
warnLine: context.warnLine
|
|
1335
|
-
});
|
|
1336
|
-
},
|
|
1337
|
-
sortOrder: 30,
|
|
1338
|
-
supportsDryRun: true,
|
|
1339
|
-
usage: "wp-typia add variation <name> --block <block-slug> [--dry-run]",
|
|
1340
|
-
visibleFieldNames: () => NAME_BLOCK_VISIBLE_FIELDS
|
|
1341
|
-
});
|
|
1342
|
-
|
|
1343
|
-
// src/add-kind-registry.ts
|
|
1344
|
-
var ADD_KIND_REGISTRY = {
|
|
1345
|
-
"admin-view": adminViewAddKindEntry,
|
|
1346
|
-
block: blockAddKindEntry,
|
|
1347
|
-
"integration-env": integrationEnvAddKindEntry,
|
|
1348
|
-
"core-variation": coreVariationAddKindEntry,
|
|
1349
|
-
variation: variationAddKindEntry,
|
|
1350
|
-
style: styleAddKindEntry,
|
|
1351
|
-
transform: transformAddKindEntry,
|
|
1352
|
-
pattern: patternAddKindEntry,
|
|
1353
|
-
"binding-source": bindingSourceAddKindEntry,
|
|
1354
|
-
contract: contractAddKindEntry,
|
|
1355
|
-
"rest-resource": restResourceAddKindEntry,
|
|
1356
|
-
"post-meta": postMetaAddKindEntry,
|
|
1357
|
-
ability: abilityAddKindEntry,
|
|
1358
|
-
"ai-feature": aiFeatureAddKindEntry,
|
|
1359
|
-
"hooked-block": hookedBlockAddKindEntry,
|
|
1360
|
-
"editor-plugin": editorPluginAddKindEntry
|
|
1361
|
-
};
|
|
1362
|
-
function isAddKindId(value) {
|
|
1363
|
-
return typeof value === "string" && ADD_KIND_IDS.includes(value);
|
|
1364
|
-
}
|
|
1365
|
-
async function getAddKindExecutionPlan(kind, context) {
|
|
1366
|
-
return ADD_KIND_REGISTRY[kind].prepareExecution(context);
|
|
1367
|
-
}
|
|
1368
|
-
function buildAddKindCompletionDetails(kind, options) {
|
|
1369
|
-
const descriptor = ADD_KIND_REGISTRY[kind].completion;
|
|
1370
|
-
return {
|
|
1371
|
-
nextSteps: descriptor.nextSteps(options.values),
|
|
1372
|
-
summaryLines: descriptor.summaryLines(options.values, options.projectDir),
|
|
1373
|
-
title: descriptor.title
|
|
1374
|
-
};
|
|
1375
|
-
}
|
|
1376
|
-
function supportsAddKindDryRun(kind) {
|
|
1377
|
-
return ADD_KIND_REGISTRY[kind].supportsDryRun;
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
// src/cli-error-messages.ts
|
|
1381
|
-
var MISSING_CREATE_PROJECT_DIR_DETAIL_LINES = [
|
|
1382
|
-
"`wp-typia create` requires <project-dir>.",
|
|
1383
|
-
"`--dry-run` still needs a logical project directory name because wp-typia derives slugs, package names, and planned file paths from it."
|
|
1384
|
-
];
|
|
1385
|
-
function formatMissingAddKindDetailLine() {
|
|
1386
|
-
return `\`wp-typia add\` requires <kind>. Usage: wp-typia add ${formatAddKindUsagePlaceholder()} ...`;
|
|
1387
|
-
}
|
|
1388
|
-
function shouldPrintMissingAddKindHelp(options) {
|
|
1389
|
-
if (typeof options.emitOutput === "boolean") {
|
|
1390
|
-
return options.emitOutput;
|
|
1391
|
-
}
|
|
1392
|
-
return options.format !== "json";
|
|
1393
|
-
}
|
|
1394
|
-
function buildMissingCreateProjectDirDetailLines() {
|
|
1395
|
-
return [...MISSING_CREATE_PROJECT_DIR_DETAIL_LINES];
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
// src/runtime-bridge-add-dry-run.ts
|
|
1399
|
-
import fs2 from "fs";
|
|
1400
|
-
import { promises as fsp } from "fs";
|
|
1401
|
-
import path from "path";
|
|
1402
|
-
var SKIPPED_COPY_ROOT_ENTRIES = new Set([".git", "node_modules"]);
|
|
1403
|
-
var SKIPPED_COMPARE_ROOT_ENTRIES = new Set([
|
|
1404
|
-
".git",
|
|
1405
|
-
".pnp.cjs",
|
|
1406
|
-
".pnp.loader.mjs",
|
|
1407
|
-
"node_modules"
|
|
1408
|
-
]);
|
|
1409
|
-
async function copyWorkspaceProject(sourceDir, targetDir) {
|
|
1410
|
-
await fsp.cp(sourceDir, targetDir, {
|
|
1411
|
-
filter: (sourcePath) => {
|
|
1412
|
-
const relativePath = path.relative(sourceDir, sourcePath);
|
|
1413
|
-
if (relativePath === "") {
|
|
1414
|
-
return true;
|
|
1415
|
-
}
|
|
1416
|
-
const [rootEntry] = relativePath.split(path.sep);
|
|
1417
|
-
return !SKIPPED_COPY_ROOT_ENTRIES.has(rootEntry ?? "");
|
|
1418
|
-
},
|
|
1419
|
-
recursive: true
|
|
1420
|
-
});
|
|
1421
|
-
}
|
|
1422
|
-
function formatInstallMarkerError(error) {
|
|
1423
|
-
if (error instanceof Error) {
|
|
1424
|
-
return error.message;
|
|
1425
|
-
}
|
|
1426
|
-
return String(error);
|
|
1427
|
-
}
|
|
1428
|
-
function formatInstallMarkerFailures(failures) {
|
|
1429
|
-
return failures.map((failure) => `${failure.operation}: ${failure.reason}`).join("; ");
|
|
1430
|
-
}
|
|
1431
|
-
function ensureWorkspaceInstallMarker({
|
|
1432
|
-
fsAdapter = fs2,
|
|
1433
|
-
sourceMarker,
|
|
1434
|
-
targetMarker
|
|
1435
|
-
}) {
|
|
1436
|
-
const failures = [];
|
|
1437
|
-
try {
|
|
1438
|
-
fsAdapter.symlinkSync(sourceMarker, targetMarker);
|
|
1439
|
-
return;
|
|
1440
|
-
} catch (error) {
|
|
1441
|
-
failures.push({
|
|
1442
|
-
operation: "symlink",
|
|
1443
|
-
reason: formatInstallMarkerError(error)
|
|
1444
|
-
});
|
|
1445
|
-
}
|
|
1446
|
-
try {
|
|
1447
|
-
fsAdapter.linkSync(sourceMarker, targetMarker);
|
|
1448
|
-
return;
|
|
1449
|
-
} catch (error) {
|
|
1450
|
-
failures.push({
|
|
1451
|
-
operation: "hard link",
|
|
1452
|
-
reason: formatInstallMarkerError(error)
|
|
1453
|
-
});
|
|
1454
|
-
}
|
|
1455
|
-
try {
|
|
1456
|
-
fsAdapter.copyFileSync(sourceMarker, targetMarker);
|
|
1457
|
-
return;
|
|
1458
|
-
} catch (error) {
|
|
1459
|
-
failures.push({
|
|
1460
|
-
operation: "copy",
|
|
1461
|
-
reason: formatInstallMarkerError(error)
|
|
1462
|
-
});
|
|
1463
|
-
}
|
|
1464
|
-
throw new Error([
|
|
1465
|
-
"Failed to prepare dry-run install marker.",
|
|
1466
|
-
`Source: ${sourceMarker}`,
|
|
1467
|
-
`Target: ${targetMarker}`,
|
|
1468
|
-
`Fallback failures: ${formatInstallMarkerFailures(failures)}`
|
|
1469
|
-
].join(" "));
|
|
1470
|
-
}
|
|
1471
|
-
function ensureWorkspaceInstallMarkers(sourceDir, targetDir) {
|
|
1472
|
-
const sourceNodeModules = path.join(sourceDir, "node_modules");
|
|
1473
|
-
if (fs2.existsSync(sourceNodeModules)) {
|
|
1474
|
-
fs2.symlinkSync(sourceNodeModules, path.join(targetDir, "node_modules"), "junction");
|
|
1475
|
-
}
|
|
1476
|
-
for (const marker of [".pnp.cjs", ".pnp.loader.mjs"]) {
|
|
1477
|
-
const sourceMarker = path.join(sourceDir, marker);
|
|
1478
|
-
if (!fs2.existsSync(sourceMarker)) {
|
|
1479
|
-
continue;
|
|
1480
|
-
}
|
|
1481
|
-
const targetMarker = path.join(targetDir, marker);
|
|
1482
|
-
ensureWorkspaceInstallMarker({ sourceMarker, targetMarker });
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
async function listWorkspaceFiles(rootDir) {
|
|
1486
|
-
const files = new Map;
|
|
1487
|
-
async function visit(currentDir) {
|
|
1488
|
-
const entries = await fsp.readdir(currentDir, { withFileTypes: true });
|
|
1489
|
-
for (const entry of entries) {
|
|
1490
|
-
const absolutePath = path.join(currentDir, entry.name);
|
|
1491
|
-
const relativePath = path.relative(rootDir, absolutePath);
|
|
1492
|
-
const [rootEntry] = relativePath.split(path.sep);
|
|
1493
|
-
if (SKIPPED_COMPARE_ROOT_ENTRIES.has(rootEntry ?? "")) {
|
|
1494
|
-
continue;
|
|
1495
|
-
}
|
|
1496
|
-
if (entry.isDirectory()) {
|
|
1497
|
-
await visit(absolutePath);
|
|
1498
|
-
continue;
|
|
1499
|
-
}
|
|
1500
|
-
if (!entry.isFile()) {
|
|
1501
|
-
continue;
|
|
1502
|
-
}
|
|
1503
|
-
files.set(relativePath.replace(path.sep === "\\" ? /\\/gu : /\//gu, "/"), await fsp.readFile(absolutePath));
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
await visit(rootDir);
|
|
1507
|
-
return files;
|
|
1508
|
-
}
|
|
1509
|
-
function compareStrings(left, right) {
|
|
1510
|
-
if (left < right) {
|
|
1511
|
-
return -1;
|
|
1512
|
-
}
|
|
1513
|
-
if (left > right) {
|
|
1514
|
-
return 1;
|
|
1515
|
-
}
|
|
1516
|
-
return 0;
|
|
1517
|
-
}
|
|
1518
|
-
async function collectWorkspaceFileOperations(sourceDir, simulatedDir) {
|
|
1519
|
-
const [sourceFiles, simulatedFiles] = await Promise.all([
|
|
1520
|
-
listWorkspaceFiles(sourceDir),
|
|
1521
|
-
listWorkspaceFiles(simulatedDir)
|
|
1522
|
-
]);
|
|
1523
|
-
const operations = [];
|
|
1524
|
-
for (const [relativePath, simulatedSource] of simulatedFiles) {
|
|
1525
|
-
const originalSource = sourceFiles.get(relativePath);
|
|
1526
|
-
if (originalSource === undefined) {
|
|
1527
|
-
operations.push(`write ${relativePath}`);
|
|
1528
|
-
continue;
|
|
1529
|
-
}
|
|
1530
|
-
if (!originalSource.equals(simulatedSource)) {
|
|
1531
|
-
operations.push(`update ${relativePath}`);
|
|
1532
|
-
}
|
|
1533
|
-
}
|
|
1534
|
-
for (const relativePath of sourceFiles.keys()) {
|
|
1535
|
-
if (!simulatedFiles.has(relativePath)) {
|
|
1536
|
-
operations.push(`delete ${relativePath}`);
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
return operations.sort(compareStrings);
|
|
1540
|
-
}
|
|
1541
|
-
async function simulateWorkspaceAddDryRun({
|
|
1542
|
-
cwd,
|
|
1543
|
-
execute
|
|
1544
|
-
}) {
|
|
1545
|
-
const { resolveWorkspaceProject } = await import("./workspace-project-gmv2a71z.js");
|
|
1546
|
-
const workspace = resolveWorkspaceProject(cwd);
|
|
1547
|
-
const relativeCwd = path.relative(workspace.projectDir, path.resolve(cwd));
|
|
1548
|
-
const { path: tempRoot, cleanup } = await createManagedTempRoot("wp-typia-add-plan-");
|
|
1549
|
-
const simulatedProjectDir = path.join(tempRoot, "workspace");
|
|
1550
|
-
try {
|
|
1551
|
-
await copyWorkspaceProject(workspace.projectDir, simulatedProjectDir);
|
|
1552
|
-
ensureWorkspaceInstallMarkers(workspace.projectDir, simulatedProjectDir);
|
|
1553
|
-
const simulatedCwd = relativeCwd.length > 0 ? path.join(simulatedProjectDir, relativeCwd) : simulatedProjectDir;
|
|
1554
|
-
const result = await execute(simulatedCwd);
|
|
1555
|
-
const fileOperations = await collectWorkspaceFileOperations(workspace.projectDir, simulatedProjectDir);
|
|
1556
|
-
return {
|
|
1557
|
-
fileOperations,
|
|
1558
|
-
result
|
|
1559
|
-
};
|
|
1560
|
-
} finally {
|
|
1561
|
-
await cleanup();
|
|
1562
|
-
}
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
// src/string-utils.ts
|
|
1566
|
-
function escapeRegExp(source) {
|
|
1567
|
-
return source.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
// src/output-markers.ts
|
|
1571
|
-
var UNICODE_OUTPUT_MARKERS = {
|
|
1572
|
-
dryRun: "\uD83E\uDDEA",
|
|
1573
|
-
progress: "\u23F3",
|
|
1574
|
-
success: "\u2705",
|
|
1575
|
-
warning: "\u26A0\uFE0F"
|
|
1576
|
-
};
|
|
1577
|
-
var ASCII_OUTPUT_MARKERS = {
|
|
1578
|
-
dryRun: "[dry-run]",
|
|
1579
|
-
progress: "[...]",
|
|
1580
|
-
success: "[ok]",
|
|
1581
|
-
warning: "[!]"
|
|
1582
|
-
};
|
|
1583
|
-
var ASCII_ENV_TRUTHY_VALUES = new Set(["1", "on", "true", "yes"]);
|
|
1584
|
-
var ASCII_ENV_FALSY_VALUES = new Set(["0", "off", "false", "no"]);
|
|
1585
|
-
function readAsciiPreferenceFromEnv(env) {
|
|
1586
|
-
const rawValue = env.WP_TYPIA_ASCII;
|
|
1587
|
-
if (typeof rawValue !== "string") {
|
|
1588
|
-
return;
|
|
1589
|
-
}
|
|
1590
|
-
const normalizedValue = rawValue.trim().toLowerCase();
|
|
1591
|
-
if (ASCII_ENV_TRUTHY_VALUES.has(normalizedValue)) {
|
|
1592
|
-
return true;
|
|
1593
|
-
}
|
|
1594
|
-
if (ASCII_ENV_FALSY_VALUES.has(normalizedValue)) {
|
|
1595
|
-
return false;
|
|
1596
|
-
}
|
|
1597
|
-
return;
|
|
1598
|
-
}
|
|
1599
|
-
function hasNoColorPreference(env) {
|
|
1600
|
-
return typeof env.NO_COLOR === "string" && env.NO_COLOR.length > 0;
|
|
1601
|
-
}
|
|
1602
|
-
function prefersAsciiOutput(options = {}) {
|
|
1603
|
-
if (options.forceAscii) {
|
|
1604
|
-
return true;
|
|
1605
|
-
}
|
|
1606
|
-
const env = options.env ?? process.env;
|
|
1607
|
-
const envPreference = readAsciiPreferenceFromEnv(env);
|
|
1608
|
-
if (envPreference !== undefined) {
|
|
1609
|
-
return envPreference;
|
|
1610
|
-
}
|
|
1611
|
-
if (hasNoColorPreference(env)) {
|
|
1612
|
-
return true;
|
|
1613
|
-
}
|
|
1614
|
-
const term = options.term ?? env.TERM;
|
|
1615
|
-
if (term === "dumb") {
|
|
1616
|
-
return true;
|
|
1617
|
-
}
|
|
1618
|
-
const locale = (env.LC_ALL ?? env.LC_CTYPE ?? env.LANG ?? "").toUpperCase();
|
|
1619
|
-
if (locale.includes("UTF-8") || locale.includes("UTF8")) {
|
|
1620
|
-
return false;
|
|
1621
|
-
}
|
|
1622
|
-
if (locale === "C" || locale === "POSIX") {
|
|
1623
|
-
return true;
|
|
1624
|
-
}
|
|
1625
|
-
if (locale.includes("ASCII") || locale.includes("ANSI_X3") || locale.includes("8859")) {
|
|
1626
|
-
return true;
|
|
1627
|
-
}
|
|
1628
|
-
return false;
|
|
1629
|
-
}
|
|
1630
|
-
function getOutputMarker(kind, options = {}) {
|
|
1631
|
-
return prefersAsciiOutput(options) ? ASCII_OUTPUT_MARKERS[kind] : UNICODE_OUTPUT_MARKERS[kind];
|
|
1632
|
-
}
|
|
1633
|
-
function formatOutputMarker(kind, text, options = {}) {
|
|
1634
|
-
return `${getOutputMarker(kind, options)} ${text}`;
|
|
1635
|
-
}
|
|
1636
|
-
function stripLeadingOutputMarker(text, kind) {
|
|
1637
|
-
const markers = kind ? [UNICODE_OUTPUT_MARKERS[kind], ASCII_OUTPUT_MARKERS[kind]] : Array.from(new Set([
|
|
1638
|
-
...Object.values(UNICODE_OUTPUT_MARKERS),
|
|
1639
|
-
...Object.values(ASCII_OUTPUT_MARKERS)
|
|
1640
|
-
]));
|
|
1641
|
-
const markerPattern = markers.map((marker) => escapeRegExp(marker)).join("|");
|
|
1642
|
-
return text.replace(new RegExp(`^(?:${markerPattern})\\s*`, "u"), "");
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
// src/runtime-output/init.ts
|
|
1646
|
-
function buildInitCompletionPayload(plan, markerOptions) {
|
|
1647
|
-
const changeLines = [
|
|
1648
|
-
...plan.packageChanges.addDevDependencies.map((dependency) => `devDependency ${dependency.action} ${dependency.name} -> ${dependency.requiredValue}`),
|
|
1649
|
-
...plan.packageChanges.packageManagerField ? [
|
|
1650
|
-
`packageManager ${plan.packageChanges.packageManagerField.action} -> ${plan.packageChanges.packageManagerField.requiredValue}`
|
|
1651
|
-
] : [],
|
|
1652
|
-
...plan.packageChanges.scripts.map((script) => `script ${script.action} ${script.name} -> ${script.requiredValue}`),
|
|
1653
|
-
...plan.plannedFiles.map((filePlan) => `file ${filePlan.action} ${filePlan.path} (${filePlan.purpose})`),
|
|
1654
|
-
...plan.commandMode === "preview-only" ? plan.generatedArtifacts.map((artifactPath) => `generated artifact ${artifactPath}`) : []
|
|
1655
|
-
];
|
|
1656
|
-
const modeLine = plan.commandMode === "apply" ? plan.status === "already-initialized" ? "Mode: apply requested; no files were written because the retrofit surface already existed." : "Mode: apply; package.json and retrofit helper files were written." : "Mode: preview only; no files were written.";
|
|
1657
|
-
const optionalTitle = plan.commandMode === "apply" ? `Applied adoption changes (${changeLines.length}):` : `Planned adoption changes (${changeLines.length}):`;
|
|
1658
|
-
const title = plan.status === "already-initialized" ? formatOutputMarker("success", `wp-typia init: ${plan.projectName} is already initialized`, markerOptions) : plan.commandMode === "apply" ? formatOutputMarker("success", `Applied retrofit init for ${plan.projectName}`, markerOptions) : formatOutputMarker("dryRun", `Retrofit init plan for ${plan.projectName}`, markerOptions);
|
|
1659
|
-
return {
|
|
1660
|
-
nextSteps: plan.nextSteps,
|
|
1661
|
-
optionalLines: changeLines,
|
|
1662
|
-
optionalNote: plan.summary,
|
|
1663
|
-
optionalTitle,
|
|
1664
|
-
summaryLines: [
|
|
1665
|
-
`Project directory: ${plan.projectDir}`,
|
|
1666
|
-
`Detected layout: ${plan.detectedLayout.description}`,
|
|
1667
|
-
...plan.detectedLayout.blockNames.length > 0 ? [`Block targets: ${plan.detectedLayout.blockNames.join(", ")}`] : [],
|
|
1668
|
-
`Package manager: ${plan.packageManager}`,
|
|
1669
|
-
modeLine
|
|
1670
|
-
],
|
|
1671
|
-
title,
|
|
1672
|
-
warningLines: plan.notes
|
|
1673
|
-
};
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
|
-
// src/runtime-output/structured.ts
|
|
1677
|
-
function toNonEmptyArray(values) {
|
|
1678
|
-
return values && values.length > 0 ? values : undefined;
|
|
1679
|
-
}
|
|
1680
|
-
function extractPlannedFiles(payload) {
|
|
1681
|
-
const files = payload.optionalLines?.map((line) => line.match(/^(?:delete|update|write)\s+(.+)$/u)?.[1]).filter((value) => typeof value === "string" && value.length > 0);
|
|
1682
|
-
return toNonEmptyArray(files);
|
|
1683
|
-
}
|
|
1684
|
-
var PROJECT_DIRECTORY_SUMMARY_PREFIX = "Project directory: ";
|
|
1685
|
-
function extractCompletionProjectDir(completion) {
|
|
1686
|
-
const projectDir = completion?.summaryLines?.find((line) => line.startsWith(PROJECT_DIRECTORY_SUMMARY_PREFIX))?.slice(PROJECT_DIRECTORY_SUMMARY_PREFIX.length).trim();
|
|
1687
|
-
return projectDir && projectDir.length > 0 ? projectDir : undefined;
|
|
1688
|
-
}
|
|
1689
|
-
function serializeCompletionPayload(payload) {
|
|
1690
|
-
return {
|
|
1691
|
-
nextSteps: toNonEmptyArray(payload.nextSteps),
|
|
1692
|
-
optionalLines: toNonEmptyArray(payload.optionalLines),
|
|
1693
|
-
optionalNote: payload.optionalNote,
|
|
1694
|
-
optionalTitle: payload.optionalTitle,
|
|
1695
|
-
preambleLines: toNonEmptyArray(payload.preambleLines),
|
|
1696
|
-
summaryLines: toNonEmptyArray(payload.summaryLines),
|
|
1697
|
-
title: stripLeadingOutputMarker(payload.title),
|
|
1698
|
-
warningLines: toNonEmptyArray(payload.warningLines)
|
|
1699
|
-
};
|
|
1700
|
-
}
|
|
1701
|
-
function buildStructuredCompletionSuccessPayload(command, completion, metadata = {}) {
|
|
1702
|
-
const serializedCompletion = completion ? serializeCompletionPayload(completion) : undefined;
|
|
1703
|
-
return {
|
|
1704
|
-
ok: true,
|
|
1705
|
-
data: {
|
|
1706
|
-
...metadata,
|
|
1707
|
-
command,
|
|
1708
|
-
...serializedCompletion ? {
|
|
1709
|
-
completion: serializedCompletion,
|
|
1710
|
-
files: extractPlannedFiles(serializedCompletion)
|
|
1711
|
-
} : {}
|
|
1712
|
-
}
|
|
1713
|
-
};
|
|
1714
|
-
}
|
|
1715
|
-
function buildStructuredInitSuccessPayload(plan) {
|
|
1716
|
-
const completion = serializeCompletionPayload(buildInitCompletionPayload(plan));
|
|
1717
|
-
const files = Array.from(new Set([
|
|
1718
|
-
...plan.plannedFiles.map((filePlan) => filePlan.path),
|
|
1719
|
-
...plan.commandMode === "preview-only" ? plan.generatedArtifacts : []
|
|
1720
|
-
]));
|
|
1721
|
-
return {
|
|
1722
|
-
ok: true,
|
|
1723
|
-
data: {
|
|
1724
|
-
command: "init",
|
|
1725
|
-
completion,
|
|
1726
|
-
detectedLayout: plan.detectedLayout,
|
|
1727
|
-
files: toNonEmptyArray(files),
|
|
1728
|
-
mode: plan.commandMode === "apply" ? "apply" : "preview",
|
|
1729
|
-
packageManager: plan.packageManager,
|
|
1730
|
-
plan,
|
|
1731
|
-
projectDir: plan.projectDir,
|
|
1732
|
-
status: plan.status,
|
|
1733
|
-
summary: plan.summary
|
|
1734
|
-
}
|
|
1735
|
-
};
|
|
1736
|
-
}
|
|
1737
|
-
// src/runtime-output/create.ts
|
|
1738
|
-
var LOOSE_CREATE_COMPLETION_PACKAGE_MANAGER_PATTERN = new RegExp(`^(?:corepack\\s+)?(${PACKAGE_MANAGER_IDS.map(escapeRegExp).join("|")})(?=$|[@:/+\\s])`, "iu");
|
|
1739
|
-
function parseCreateCompletionPackageManager(packageManager) {
|
|
1740
|
-
const normalizedPackageManager = packageManager.trim();
|
|
1741
|
-
const parsedPackageManager = parsePackageManagerField(normalizedPackageManager);
|
|
1742
|
-
if (parsedPackageManager) {
|
|
1743
|
-
return parsedPackageManager;
|
|
1744
|
-
}
|
|
1745
|
-
const looseMatch = LOOSE_CREATE_COMPLETION_PACKAGE_MANAGER_PATTERN.exec(normalizedPackageManager);
|
|
1746
|
-
const loosePackageManager = looseMatch?.[1]?.toLowerCase();
|
|
1747
|
-
return PACKAGE_MANAGER_IDS.includes(loosePackageManager) ? loosePackageManager : null;
|
|
1748
|
-
}
|
|
1749
|
-
function resolveCreateCompletionPackageManager(packageManager) {
|
|
1750
|
-
const parsedPackageManager = parseCreateCompletionPackageManager(packageManager);
|
|
1751
|
-
if (parsedPackageManager) {
|
|
1752
|
-
return parsedPackageManager;
|
|
1753
|
-
}
|
|
1754
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `Unsupported package manager "${packageManager}" in create completion payload. Expected one of: ${PACKAGE_MANAGER_IDS.join(", ")}.`);
|
|
1755
|
-
}
|
|
1756
|
-
function formatCreateProgressLine(payload, markerOptions) {
|
|
1757
|
-
return formatOutputMarker("progress", `${payload.title}: ${payload.detail}`, markerOptions);
|
|
1758
|
-
}
|
|
1759
|
-
function buildCreateCompletionPayload(flow, markerOptions) {
|
|
1760
|
-
const packageManager = resolveCreateCompletionPackageManager(flow.packageManager);
|
|
1761
|
-
const verificationSteps = [
|
|
1762
|
-
formatPackageExecCommand(packageManager, `wp-typia@${package_default.version}`, "doctor"),
|
|
1763
|
-
...flow.optionalOnboarding.steps
|
|
1764
|
-
];
|
|
1765
|
-
return {
|
|
1766
|
-
nextSteps: flow.nextSteps,
|
|
1767
|
-
optionalLines: verificationSteps,
|
|
1768
|
-
optionalNote: flow.optionalOnboarding.shortNote ?? flow.optionalOnboarding.note,
|
|
1769
|
-
optionalTitle: "Verify and sync (optional):",
|
|
1770
|
-
preambleLines: flow.result.selectedVariant ? [`Template variant: ${flow.result.selectedVariant}`] : undefined,
|
|
1771
|
-
summaryLines: [`Project directory: ${flow.projectDir}`],
|
|
1772
|
-
title: formatOutputMarker("success", `Created ${flow.result.variables.title} in ${flow.projectDir}`, markerOptions),
|
|
1773
|
-
warningLines: flow.result.warnings
|
|
1774
|
-
};
|
|
1775
|
-
}
|
|
1776
|
-
function buildCreateDryRunPayload(flow, markerOptions) {
|
|
1777
|
-
let dependencyInstallLine;
|
|
1778
|
-
switch (flow.plan.dependencyInstall) {
|
|
1779
|
-
case "skipped-by-flag":
|
|
1780
|
-
dependencyInstallLine = "Dependency install: already skipped via --no-install";
|
|
1781
|
-
break;
|
|
1782
|
-
case "would-install":
|
|
1783
|
-
dependencyInstallLine = "Dependency install: would run during a real scaffold";
|
|
1784
|
-
break;
|
|
1785
|
-
}
|
|
1786
|
-
return {
|
|
1787
|
-
optionalLines: flow.plan.files.map((relativePath) => `write ${relativePath}`),
|
|
1788
|
-
optionalNote: "No files were written because --dry-run was enabled. Re-run without --dry-run to materialize this scaffold.",
|
|
1789
|
-
optionalTitle: `Planned files (${flow.plan.files.length}):`,
|
|
1790
|
-
preambleLines: flow.result.selectedVariant ? [`Template variant: ${flow.result.selectedVariant}`] : undefined,
|
|
1791
|
-
summaryLines: [
|
|
1792
|
-
`Project directory: ${flow.projectDir}`,
|
|
1793
|
-
`Template: ${flow.result.templateId}`,
|
|
1794
|
-
`Package manager: ${flow.packageManager}`,
|
|
1795
|
-
dependencyInstallLine
|
|
1796
|
-
],
|
|
1797
|
-
title: formatOutputMarker("dryRun", `Dry run for ${flow.result.variables.title} at ${flow.projectDir}`, markerOptions),
|
|
1798
|
-
warningLines: flow.result.warnings
|
|
1799
|
-
};
|
|
1800
|
-
}
|
|
1801
|
-
// src/runtime-output/add.ts
|
|
1802
|
-
function buildAddCompletionPayload(options, markerOptions) {
|
|
1803
|
-
const verificationLines = [
|
|
1804
|
-
formatPackageExecCommand(options.packageManager ?? inferPackageManagerId(options.projectDir), `wp-typia@${package_default.version}`, "doctor")
|
|
1805
|
-
];
|
|
1806
|
-
const verificationNote = "Run doctor via your package manager for a quick inventory and generated-artifact check after the add workflow.";
|
|
1807
|
-
const completion = buildAddKindCompletionDetails(options.kind, {
|
|
1808
|
-
projectDir: options.projectDir,
|
|
1809
|
-
values: options.values
|
|
1810
|
-
});
|
|
1811
|
-
return {
|
|
1812
|
-
nextSteps: completion.nextSteps,
|
|
1813
|
-
optionalLines: verificationLines,
|
|
1814
|
-
optionalNote: verificationNote,
|
|
1815
|
-
optionalTitle: "Verify workspace health (optional):",
|
|
1816
|
-
summaryLines: completion.summaryLines,
|
|
1817
|
-
title: formatOutputMarker("success", completion.title, markerOptions),
|
|
1818
|
-
warningLines: options.warnings
|
|
1819
|
-
};
|
|
1820
|
-
}
|
|
1821
|
-
function buildAddDryRunPayload(options, markerOptions) {
|
|
1822
|
-
const normalizedTitle = stripLeadingOutputMarker(options.completion.title, "success").replace(/^Added\s*/u, "");
|
|
1823
|
-
const summaryLines = [
|
|
1824
|
-
...options.completion.summaryLines ?? [],
|
|
1825
|
-
...options.summaryLines ?? []
|
|
1826
|
-
];
|
|
1827
|
-
return {
|
|
1828
|
-
optionalLines: options.fileOperations,
|
|
1829
|
-
optionalNote: "No workspace files were changed because --dry-run was enabled. Re-run without --dry-run to apply this add command.",
|
|
1830
|
-
optionalTitle: `Planned workspace updates (${options.fileOperations.length}):`,
|
|
1831
|
-
preambleLines: options.completion.preambleLines,
|
|
1832
|
-
summaryLines: summaryLines.length > 0 ? summaryLines : undefined,
|
|
1833
|
-
title: formatOutputMarker("dryRun", `Dry run for ${normalizedTitle || "workspace add command"}`, markerOptions),
|
|
1834
|
-
warningLines: options.completion.warningLines
|
|
1835
|
-
};
|
|
1836
|
-
}
|
|
1837
|
-
// src/runtime-output/migrate.ts
|
|
1838
|
-
function buildMigrationCompletionPayload(options, markerOptions) {
|
|
1839
|
-
const summaryLines = options.lines.filter((line) => line.trim().length > 0);
|
|
1840
|
-
return {
|
|
1841
|
-
summaryLines,
|
|
1842
|
-
title: formatOutputMarker("success", `Completed wp-typia migrate ${options.command}`, markerOptions)
|
|
1843
|
-
};
|
|
1844
|
-
}
|
|
1845
|
-
// src/runtime-output/sync.ts
|
|
1846
|
-
function buildSyncDryRunPayload(options, markerOptions) {
|
|
1847
|
-
const targetSuffix = options.target === "ai" ? " ai" : "";
|
|
1848
|
-
const targetSummary = options.target === "ai" ? "Sync target: AI artifacts only." : options.target === "default" ? "Sync target: generated project defaults." : undefined;
|
|
1849
|
-
return {
|
|
1850
|
-
optionalLines: options.plannedCommands.map((command) => command.displayCommand),
|
|
1851
|
-
optionalNote: options.check ? `No sync scripts were executed because --dry-run was enabled. Re-run \`wp-typia sync${targetSuffix} --check\` to verify generated artifacts without rewriting them.` : `No sync scripts were executed because --dry-run was enabled. Re-run \`wp-typia sync${targetSuffix}\` without --dry-run to apply generated-file updates, or add --check to verify without rewriting.`,
|
|
1852
|
-
optionalTitle: `Planned sync commands (${options.plannedCommands.length}):`,
|
|
1853
|
-
summaryLines: [
|
|
1854
|
-
`Project directory: ${options.projectDir}`,
|
|
1855
|
-
`Package manager: ${options.packageManager}`,
|
|
1856
|
-
...targetSummary ? [targetSummary] : [],
|
|
1857
|
-
options.check ? "Execution mode: would run generated sync scripts in verification mode." : "Execution mode: would run generated sync scripts in apply mode."
|
|
1858
|
-
],
|
|
1859
|
-
title: formatOutputMarker("dryRun", `Dry run for wp-typia sync${targetSuffix}`, markerOptions)
|
|
1860
|
-
};
|
|
1861
|
-
}
|
|
1862
|
-
// src/print-block.ts
|
|
1863
|
-
function printBlock(printLine, lines) {
|
|
1864
|
-
for (const line of lines) {
|
|
1865
|
-
printLine(line);
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
// src/runtime-output/print.ts
|
|
1870
|
-
function printCompletionPayload(payload, options = {}) {
|
|
1871
|
-
const printLine = options.printLine ?? console.log;
|
|
1872
|
-
const warnLine = options.warnLine ?? printLine;
|
|
1873
|
-
for (const line of payload.preambleLines ?? []) {
|
|
1874
|
-
printLine(line);
|
|
1875
|
-
}
|
|
1876
|
-
for (const warning of payload.warningLines ?? []) {
|
|
1877
|
-
warnLine(formatOutputMarker("warning", warning, options.markerOptions));
|
|
1878
|
-
}
|
|
1879
|
-
const hasDetails = (payload.summaryLines?.length ?? 0) > 0 || (payload.nextSteps?.length ?? 0) > 0 || (payload.optionalLines?.length ?? 0) > 0 || Boolean(payload.optionalNote);
|
|
1880
|
-
const hasLeadingContext = (payload.preambleLines?.length ?? 0) > 0 || (payload.warningLines?.length ?? 0) > 0;
|
|
1881
|
-
printLine(hasLeadingContext && hasDetails ? `
|
|
1882
|
-
${payload.title}` : payload.title);
|
|
1883
|
-
for (const line of payload.summaryLines ?? []) {
|
|
1884
|
-
printLine(line);
|
|
1885
|
-
}
|
|
1886
|
-
if ((payload.nextSteps?.length ?? 0) > 0) {
|
|
1887
|
-
printLine("Next steps:");
|
|
1888
|
-
for (const step of payload.nextSteps ?? []) {
|
|
1889
|
-
printLine(` ${step}`);
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
if ((payload.optionalLines?.length ?? 0) > 0) {
|
|
1893
|
-
printLine(`
|
|
1894
|
-
${payload.optionalTitle ?? "Optional:"}`);
|
|
1895
|
-
for (const step of payload.optionalLines ?? []) {
|
|
1896
|
-
printLine(` ${step}`);
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
if (payload.optionalNote) {
|
|
1900
|
-
printLine(`Note: ${payload.optionalNote}`);
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
// src/runtime-capabilities.ts
|
|
1904
|
-
function isInteractiveTerminal({
|
|
1905
|
-
stdin = process.stdin,
|
|
1906
|
-
stdout = process.stdout,
|
|
1907
|
-
term = process.env.TERM
|
|
1908
|
-
} = {}) {
|
|
1909
|
-
return Boolean(stdin?.isTTY) && Boolean(stdout?.isTTY) && term !== "dumb";
|
|
1910
|
-
}
|
|
1911
|
-
function supportsInteractiveTui(options = {}) {
|
|
1912
|
-
const hasBunRuntime = options.hasBunRuntime ?? typeof Bun !== "undefined";
|
|
1913
|
-
return hasBunRuntime && isInteractiveTerminal(options);
|
|
1914
|
-
}
|
|
1915
|
-
|
|
1916
|
-
// src/runtime-bridge-shared.ts
|
|
1917
|
-
var loadCliDiagnosticsRuntime = () => import("./cli-diagnostics-10drxh34.js");
|
|
1918
|
-
async function wrapCliCommandError(command, error) {
|
|
1919
|
-
const { createCliCommandError } = await loadCliDiagnosticsRuntime();
|
|
1920
|
-
return createCliCommandError({ command, error });
|
|
1921
|
-
}
|
|
1922
|
-
function shouldWrapCliCommandError(options) {
|
|
1923
|
-
if (options.emitOutput === false) {
|
|
1924
|
-
return false;
|
|
1925
|
-
}
|
|
1926
|
-
if (options.renderLine) {
|
|
1927
|
-
return false;
|
|
1928
|
-
}
|
|
1929
|
-
return true;
|
|
1930
|
-
}
|
|
1931
|
-
function emitCompletion(payload, options) {
|
|
1932
|
-
if (options.emitOutput) {
|
|
1933
|
-
printCompletionPayload(payload, {
|
|
1934
|
-
printLine: options.printLine,
|
|
1935
|
-
warnLine: options.warnLine
|
|
1936
|
-
});
|
|
1937
|
-
}
|
|
1938
|
-
return payload;
|
|
1939
|
-
}
|
|
1940
|
-
function pushFlag(argv, name, value) {
|
|
1941
|
-
if (value === undefined || value === null || value === false) {
|
|
1942
|
-
return;
|
|
1943
|
-
}
|
|
1944
|
-
if (value === true) {
|
|
1945
|
-
argv.push(`--${name}`);
|
|
1946
|
-
return;
|
|
1947
|
-
}
|
|
1948
|
-
argv.push(`--${name}`, String(value));
|
|
1949
|
-
}
|
|
1950
|
-
|
|
1951
|
-
// src/runtime-bridge-add.ts
|
|
1952
|
-
var loadCliAddRuntime = () => import("./cli-add-qjd3ba8j.js");
|
|
1953
|
-
var loadCliPromptRuntime = () => import("./cli-prompt-ncyg68rn.js");
|
|
1954
|
-
async function executeWorkspaceAddWithOptionalDryRun(options) {
|
|
1955
|
-
const simulated = options.dryRun ? await simulateWorkspaceAddDryRun({
|
|
1956
|
-
cwd: options.cwd,
|
|
1957
|
-
execute: options.execute
|
|
1958
|
-
}) : null;
|
|
1959
|
-
const result = simulated?.result ?? await options.execute(options.cwd);
|
|
1960
|
-
const completion = options.buildCompletion(result);
|
|
1961
|
-
if (!options.dryRun) {
|
|
1962
|
-
return emitCompletion(completion, {
|
|
1963
|
-
emitOutput: options.emitOutput ?? true,
|
|
1964
|
-
printLine: options.printLine,
|
|
1965
|
-
warnLine: options.warnLine
|
|
1966
|
-
});
|
|
1967
|
-
}
|
|
1968
|
-
return emitCompletion(buildAddDryRunPayload({
|
|
1969
|
-
completion,
|
|
1970
|
-
fileOperations: simulated.fileOperations,
|
|
1971
|
-
summaryLines: options.buildDryRunSummaryLines?.(result)
|
|
1972
|
-
}), {
|
|
1973
|
-
emitOutput: options.emitOutput ?? true,
|
|
1974
|
-
printLine: options.printLine,
|
|
1975
|
-
warnLine: options.warnLine
|
|
1976
|
-
});
|
|
1977
|
-
}
|
|
1978
|
-
function executePreparedAddKind(kind, context, plan) {
|
|
1979
|
-
return executeWorkspaceAddWithOptionalDryRun({
|
|
1980
|
-
buildCompletion: (result) => buildAddCompletionPayload({
|
|
1981
|
-
kind,
|
|
1982
|
-
projectDir: result.projectDir,
|
|
1983
|
-
values: plan.getValues(result),
|
|
1984
|
-
warnings: plan.getWarnings?.(result)
|
|
1985
|
-
}),
|
|
1986
|
-
buildDryRunSummaryLines: (result) => plan.getDryRunSummaryLines?.(result),
|
|
1987
|
-
cwd: context.cwd,
|
|
1988
|
-
dryRun: context.dryRun,
|
|
1989
|
-
emitOutput: context.emitOutput,
|
|
1990
|
-
execute: plan.execute,
|
|
1991
|
-
printLine: context.printLine,
|
|
1992
|
-
warnLine: plan.warnLine
|
|
1993
|
-
});
|
|
1994
|
-
}
|
|
1995
|
-
async function executePlannedAddKind(kind, executionContext, context) {
|
|
1996
|
-
const plan = await getAddKindExecutionPlan(kind, executionContext);
|
|
1997
|
-
return executePreparedAddKind(kind, context, plan);
|
|
1998
|
-
}
|
|
1999
|
-
async function executeAddCommand({
|
|
2000
|
-
cwd,
|
|
2001
|
-
emitOutput = true,
|
|
2002
|
-
flags,
|
|
2003
|
-
interactive,
|
|
2004
|
-
kind,
|
|
2005
|
-
name,
|
|
2006
|
-
positionalArgs,
|
|
2007
|
-
printLine = console.log,
|
|
2008
|
-
prompt,
|
|
2009
|
-
warnLine = console.warn
|
|
2010
|
-
}) {
|
|
2011
|
-
let activePrompt;
|
|
2012
|
-
const dryRun = Boolean(flags["dry-run"]);
|
|
2013
|
-
try {
|
|
2014
|
-
const addRuntime = await loadCliAddRuntime();
|
|
2015
|
-
const isInteractiveSession = interactive ?? isInteractiveTerminal();
|
|
2016
|
-
if (!kind) {
|
|
2017
|
-
if (shouldPrintMissingAddKindHelp({ emitOutput })) {
|
|
2018
|
-
printLine(addRuntime.formatAddHelpText());
|
|
2019
|
-
}
|
|
2020
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, formatMissingAddKindDetailLine());
|
|
2021
|
-
}
|
|
2022
|
-
if (!isAddKindId(kind)) {
|
|
2023
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_COMMAND, `Unknown add kind "${kind}". Expected one of: ${formatAddKindList()}.`);
|
|
2024
|
-
}
|
|
2025
|
-
if (dryRun && !supportsAddKindDryRun(kind)) {
|
|
2026
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `\`wp-typia add ${kind}\` does not support \`--dry-run\` yet.`);
|
|
2027
|
-
}
|
|
2028
|
-
const executionContext = {
|
|
2029
|
-
addRuntime,
|
|
2030
|
-
cwd,
|
|
2031
|
-
flags,
|
|
2032
|
-
getOrCreatePrompt: async () => {
|
|
2033
|
-
if (activePrompt) {
|
|
2034
|
-
return activePrompt;
|
|
2035
|
-
}
|
|
2036
|
-
const { createReadlinePrompt } = await loadCliPromptRuntime();
|
|
2037
|
-
activePrompt = prompt ?? createReadlinePrompt();
|
|
2038
|
-
return activePrompt;
|
|
2039
|
-
},
|
|
2040
|
-
isInteractiveSession,
|
|
2041
|
-
name,
|
|
2042
|
-
positionalArgs,
|
|
2043
|
-
warnLine
|
|
2044
|
-
};
|
|
2045
|
-
return await executePlannedAddKind(kind, executionContext, {
|
|
2046
|
-
cwd,
|
|
2047
|
-
dryRun,
|
|
2048
|
-
emitOutput,
|
|
2049
|
-
printLine
|
|
2050
|
-
});
|
|
2051
|
-
} catch (error) {
|
|
2052
|
-
if (!shouldWrapCliCommandError({ emitOutput })) {
|
|
2053
|
-
throw error;
|
|
2054
|
-
}
|
|
2055
|
-
throw await wrapCliCommandError("add", error);
|
|
2056
|
-
} finally {
|
|
2057
|
-
if (activePrompt && activePrompt !== prompt) {
|
|
2058
|
-
activePrompt.close();
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
}
|
|
2062
|
-
// src/runtime-bridge-create.ts
|
|
2063
|
-
var loadCliPromptRuntime2 = () => import("./cli-prompt-ncyg68rn.js");
|
|
2064
|
-
var loadCliScaffoldRuntime = () => import("./cli-scaffold-0bb6pr3w.js");
|
|
2065
|
-
var loadCliTemplatesRuntime = () => import("./cli-templates-g8t4fm11.js");
|
|
2066
|
-
var loadCreateTemplateValidationRuntime = () => import("./create-template-validation-4fr851vg.js");
|
|
2067
|
-
var PACKAGE_MANAGER_PROMPT_OPTIONS = [
|
|
2068
|
-
{ label: "npm", value: "npm", hint: "Use npm" },
|
|
2069
|
-
{ label: "pnpm", value: "pnpm", hint: "Use pnpm" },
|
|
2070
|
-
{ label: "yarn", value: "yarn", hint: "Use yarn" },
|
|
2071
|
-
{ label: "bun", value: "bun", hint: "Use bun" }
|
|
2072
|
-
];
|
|
2073
|
-
var DATA_STORAGE_PROMPT_OPTIONS = [
|
|
2074
|
-
{
|
|
2075
|
-
label: "custom-table",
|
|
2076
|
-
value: "custom-table",
|
|
2077
|
-
hint: "Dedicated custom table storage"
|
|
2078
|
-
},
|
|
2079
|
-
{ label: "post-meta", value: "post-meta", hint: "Persist through post meta" }
|
|
2080
|
-
];
|
|
2081
|
-
var PERSISTENCE_POLICY_PROMPT_OPTIONS = [
|
|
2082
|
-
{
|
|
2083
|
-
label: "authenticated",
|
|
2084
|
-
value: "authenticated",
|
|
2085
|
-
hint: "Authenticated write policy"
|
|
2086
|
-
},
|
|
2087
|
-
{ label: "public", value: "public", hint: "Public token policy" }
|
|
2088
|
-
];
|
|
2089
|
-
var BOOLEAN_PROMPT_OPTIONS = [
|
|
2090
|
-
{ label: "Yes", value: "yes", hint: "Enable this option" },
|
|
2091
|
-
{ label: "No", value: "no", hint: "Keep the default disabled state" }
|
|
2092
|
-
];
|
|
2093
|
-
async function executeCreateCommand({
|
|
2094
|
-
projectDir,
|
|
2095
|
-
cwd,
|
|
2096
|
-
emitOutput = true,
|
|
2097
|
-
flags,
|
|
2098
|
-
interactive,
|
|
2099
|
-
onProgress,
|
|
2100
|
-
printLine = console.log,
|
|
2101
|
-
prompt,
|
|
2102
|
-
warnLine = console.warn
|
|
2103
|
-
}) {
|
|
2104
|
-
let activePrompt;
|
|
2105
|
-
try {
|
|
2106
|
-
const requestedTemplateId = readOptionalLooseStringFlag(flags, "template");
|
|
2107
|
-
const resolvedTemplateId = requestedTemplateId ? (await loadCreateTemplateValidationRuntime()).validateExplicitCreateTemplateId(requestedTemplateId) : undefined;
|
|
2108
|
-
const [
|
|
2109
|
-
{ createReadlinePrompt },
|
|
2110
|
-
{ runScaffoldFlow },
|
|
2111
|
-
{ getTemplateSelectOptions }
|
|
2112
|
-
] = await Promise.all([
|
|
2113
|
-
loadCliPromptRuntime2(),
|
|
2114
|
-
loadCliScaffoldRuntime(),
|
|
2115
|
-
loadCliTemplatesRuntime()
|
|
2116
|
-
]);
|
|
2117
|
-
const shouldPrompt = interactive ?? (!Boolean(flags.yes) && isInteractiveTerminal());
|
|
2118
|
-
activePrompt = shouldPrompt ? prompt ?? createReadlinePrompt() : undefined;
|
|
2119
|
-
const scaffoldPrompt = activePrompt;
|
|
2120
|
-
const shouldPromptForExternalLayerSelection = Boolean(scaffoldPrompt) && scaffoldPrompt !== prompt;
|
|
2121
|
-
const effectiveYes = Boolean(flags.yes) || Boolean(flags["dry-run"]) && !Boolean(scaffoldPrompt);
|
|
2122
|
-
const flow = await runScaffoldFlow({
|
|
2123
|
-
alternateRenderTargets: readOptionalLooseStringFlag(flags, "alternate-render-targets"),
|
|
2124
|
-
cwd,
|
|
2125
|
-
dataStorageMode: readOptionalLooseStringFlag(flags, "data-storage"),
|
|
2126
|
-
dryRun: Boolean(flags["dry-run"]),
|
|
2127
|
-
externalLayerId: readOptionalLooseStringFlag(flags, "external-layer-id"),
|
|
2128
|
-
externalLayerSource: readOptionalLooseStringFlag(flags, "external-layer-source"),
|
|
2129
|
-
innerBlocksPreset: readOptionalLooseStringFlag(flags, "inner-blocks-preset"),
|
|
2130
|
-
isInteractive: Boolean(scaffoldPrompt),
|
|
2131
|
-
namespace: readOptionalLooseStringFlag(flags, "namespace"),
|
|
2132
|
-
noInstall: Boolean(flags["no-install"]),
|
|
2133
|
-
packageManager: readOptionalLooseStringFlag(flags, "package-manager"),
|
|
2134
|
-
persistencePolicy: readOptionalLooseStringFlag(flags, "persistence-policy"),
|
|
2135
|
-
phpPrefix: readOptionalLooseStringFlag(flags, "php-prefix"),
|
|
2136
|
-
profile: readOptionalLooseStringFlag(flags, "profile"),
|
|
2137
|
-
projectInput: projectDir,
|
|
2138
|
-
onProgress: async (progress) => {
|
|
2139
|
-
const payload2 = {
|
|
2140
|
-
detail: progress.detail,
|
|
2141
|
-
title: progress.title
|
|
2142
|
-
};
|
|
2143
|
-
onProgress?.(payload2);
|
|
2144
|
-
if (emitOutput) {
|
|
2145
|
-
printLine(formatCreateProgressLine(payload2));
|
|
2146
|
-
}
|
|
2147
|
-
},
|
|
2148
|
-
promptText: scaffoldPrompt ? (message, defaultValue, validate) => scaffoldPrompt.text(message, defaultValue, validate) : undefined,
|
|
2149
|
-
queryPostType: readOptionalLooseStringFlag(flags, "query-post-type"),
|
|
2150
|
-
selectDataStorage: scaffoldPrompt ? () => scaffoldPrompt.select("Select a data storage mode", [...DATA_STORAGE_PROMPT_OPTIONS], 1) : undefined,
|
|
2151
|
-
selectExternalLayerId: shouldPromptForExternalLayerSelection && scaffoldPrompt ? (options) => scaffoldPrompt.select("Select an external layer", toExternalLayerPromptOptions(options), 1) : undefined,
|
|
2152
|
-
selectPackageManager: scaffoldPrompt ? () => scaffoldPrompt.select("Select a package manager", [...PACKAGE_MANAGER_PROMPT_OPTIONS], 1) : undefined,
|
|
2153
|
-
selectPersistencePolicy: scaffoldPrompt ? () => scaffoldPrompt.select("Select a persistence policy", [...PERSISTENCE_POLICY_PROMPT_OPTIONS], 1) : undefined,
|
|
2154
|
-
selectTemplate: scaffoldPrompt ? () => scaffoldPrompt.select("Select a template", getTemplateSelectOptions(), 1) : undefined,
|
|
2155
|
-
selectWithMigrationUi: scaffoldPrompt ? async () => await scaffoldPrompt.select("Enable migration UI support?", [...BOOLEAN_PROMPT_OPTIONS], 2) === "yes" : undefined,
|
|
2156
|
-
selectWithTestPreset: scaffoldPrompt ? async () => await scaffoldPrompt.select("Include the Playwright test preset?", [...BOOLEAN_PROMPT_OPTIONS], 2) === "yes" : undefined,
|
|
2157
|
-
selectWithWpEnv: scaffoldPrompt ? async () => await scaffoldPrompt.select("Include a local wp-env preset?", [...BOOLEAN_PROMPT_OPTIONS], 2) === "yes" : undefined,
|
|
2158
|
-
templateId: resolvedTemplateId,
|
|
2159
|
-
textDomain: readOptionalLooseStringFlag(flags, "text-domain"),
|
|
2160
|
-
variant: readOptionalLooseStringFlag(flags, "variant"),
|
|
2161
|
-
withMigrationUi: flags["with-migration-ui"],
|
|
2162
|
-
withTestPreset: flags["with-test-preset"],
|
|
2163
|
-
withWpEnv: flags["with-wp-env"],
|
|
2164
|
-
yes: effectiveYes
|
|
2165
|
-
});
|
|
2166
|
-
const payload = flow.dryRun && flow.plan ? buildCreateDryRunPayload({
|
|
2167
|
-
packageManager: flow.packageManager,
|
|
2168
|
-
plan: flow.plan,
|
|
2169
|
-
projectDir: flow.projectDir,
|
|
2170
|
-
result: flow.result
|
|
2171
|
-
}) : buildCreateCompletionPayload(flow);
|
|
2172
|
-
return emitCompletion(payload, { emitOutput, printLine, warnLine });
|
|
2173
|
-
} catch (error) {
|
|
2174
|
-
if (!shouldWrapCliCommandError({ emitOutput })) {
|
|
2175
|
-
throw error;
|
|
2176
|
-
}
|
|
2177
|
-
throw await wrapCliCommandError("create", error);
|
|
2178
|
-
} finally {
|
|
2179
|
-
if (activePrompt && activePrompt !== prompt) {
|
|
2180
|
-
activePrompt.close();
|
|
2181
|
-
}
|
|
2182
|
-
}
|
|
2183
|
-
}
|
|
2184
|
-
// src/runtime-bridge-doctor.ts
|
|
2185
|
-
var loadCliDoctorRuntime = () => import("./cli-doctor-6fyxq940.js");
|
|
2186
|
-
async function executeDoctorCommand(cwd, options = {}) {
|
|
2187
|
-
try {
|
|
2188
|
-
const { runDoctor } = await loadCliDoctorRuntime();
|
|
2189
|
-
await runDoctor(cwd, { exitPolicy: options.exitPolicy });
|
|
2190
|
-
} catch (error) {
|
|
2191
|
-
throw await wrapCliCommandError("doctor", error);
|
|
2192
|
-
}
|
|
2193
|
-
}
|
|
2194
|
-
// src/runtime-bridge-init.ts
|
|
2195
|
-
import path2 from "path";
|
|
2196
|
-
var loadCliInitRuntime = () => import("./cli-init-7avk42dh.js");
|
|
2197
|
-
async function executeInitCommand({ apply, cwd, packageManager, projectDir }, options = {}) {
|
|
2198
|
-
try {
|
|
2199
|
-
const { runInitCommand } = await loadCliInitRuntime();
|
|
2200
|
-
const resolvedProjectDir = projectDir ? path2.resolve(cwd, projectDir) : cwd;
|
|
2201
|
-
const plan = await runInitCommand({
|
|
2202
|
-
apply,
|
|
2203
|
-
packageManager,
|
|
2204
|
-
projectDir: resolvedProjectDir
|
|
2205
|
-
});
|
|
2206
|
-
const completion = buildInitCompletionPayload(plan);
|
|
2207
|
-
if (options.emitOutput ?? true) {
|
|
2208
|
-
printCompletionPayload(completion, {
|
|
2209
|
-
printLine: options.printLine,
|
|
2210
|
-
warnLine: options.warnLine
|
|
2211
|
-
});
|
|
2212
|
-
}
|
|
2213
|
-
return plan;
|
|
2214
|
-
} catch (error) {
|
|
2215
|
-
if (!shouldWrapCliCommandError({ emitOutput: options.emitOutput })) {
|
|
2216
|
-
throw error;
|
|
2217
|
-
}
|
|
2218
|
-
throw await wrapCliCommandError("init", error);
|
|
2219
|
-
}
|
|
2220
|
-
}
|
|
2221
|
-
// src/runtime-bridge-migrate.ts
|
|
2222
|
-
var loadMigrationsRuntime = () => import("./migrations-3vngdy51.js");
|
|
2223
|
-
var defaultPrintLine2 = (line) => {
|
|
2224
|
-
process.stdout.write(`${line}
|
|
2225
|
-
`);
|
|
2226
|
-
};
|
|
2227
|
-
async function executeMigrateCommand({
|
|
2228
|
-
command,
|
|
2229
|
-
cwd,
|
|
2230
|
-
flags,
|
|
2231
|
-
printLine = defaultPrintLine2,
|
|
2232
|
-
prompt,
|
|
2233
|
-
renderLine
|
|
2234
|
-
}) {
|
|
2235
|
-
try {
|
|
2236
|
-
const { formatMigrationHelpText, parseMigrationArgs, runMigrationCommand } = await loadMigrationsRuntime();
|
|
2237
|
-
const outputLine = renderLine ?? printLine;
|
|
2238
|
-
if (!command) {
|
|
2239
|
-
const helpText = formatMigrationHelpText();
|
|
2240
|
-
outputLine(helpText);
|
|
2241
|
-
return;
|
|
2242
|
-
}
|
|
2243
|
-
const argv = [command];
|
|
2244
|
-
pushFlag(argv, "all", flags.all);
|
|
2245
|
-
pushFlag(argv, "force", flags.force);
|
|
2246
|
-
pushFlag(argv, "current-migration-version", readOptionalLooseStringFlag(flags, "current-migration-version"));
|
|
2247
|
-
pushFlag(argv, "migration-version", readOptionalLooseStringFlag(flags, "migration-version"));
|
|
2248
|
-
pushFlag(argv, "from-migration-version", readOptionalLooseStringFlag(flags, "from-migration-version"));
|
|
2249
|
-
pushFlag(argv, "to-migration-version", readOptionalLooseStringFlag(flags, "to-migration-version"));
|
|
2250
|
-
pushFlag(argv, "iterations", readOptionalLooseStringFlag(flags, "iterations"));
|
|
2251
|
-
pushFlag(argv, "seed", readOptionalLooseStringFlag(flags, "seed"));
|
|
2252
|
-
const parsed = parseMigrationArgs(argv);
|
|
2253
|
-
const lines = renderLine ? [] : null;
|
|
2254
|
-
const captureLine = (line) => {
|
|
2255
|
-
lines?.push(line);
|
|
2256
|
-
outputLine(line);
|
|
2257
|
-
};
|
|
2258
|
-
const result = await runMigrationCommand(parsed, cwd, {
|
|
2259
|
-
prompt,
|
|
2260
|
-
renderLine: captureLine
|
|
2261
|
-
});
|
|
2262
|
-
if (renderLine) {
|
|
2263
|
-
return result && typeof result === "object" && "cancelled" in result && result.cancelled === true ? undefined : buildMigrationCompletionPayload({
|
|
2264
|
-
command: parsed.command ?? "plan",
|
|
2265
|
-
lines: lines ?? []
|
|
2266
|
-
});
|
|
2267
|
-
}
|
|
2268
|
-
if (result && typeof result === "object" && "cancelled" in result && result.cancelled === true) {
|
|
2269
|
-
return;
|
|
2270
|
-
}
|
|
2271
|
-
} catch (error) {
|
|
2272
|
-
if (!shouldWrapCliCommandError({ renderLine })) {
|
|
2273
|
-
throw error;
|
|
2274
|
-
}
|
|
2275
|
-
throw await wrapCliCommandError("migrate", error);
|
|
2276
|
-
}
|
|
2277
|
-
}
|
|
2278
|
-
// src/runtime-bridge-templates.ts
|
|
2279
|
-
var loadCliTemplatesRuntime2 = () => import("./cli-templates-g8t4fm11.js");
|
|
2280
|
-
async function executeTemplatesCommand({ flags }, printLine = console.log) {
|
|
2281
|
-
const {
|
|
2282
|
-
formatTemplateDetails,
|
|
2283
|
-
formatTemplateFeatures,
|
|
2284
|
-
formatTemplateSummary,
|
|
2285
|
-
getTemplateById,
|
|
2286
|
-
listTemplates
|
|
2287
|
-
} = await loadCliTemplatesRuntime2();
|
|
2288
|
-
const subcommand = flags.subcommand ?? "list";
|
|
2289
|
-
if (subcommand === "list") {
|
|
2290
|
-
for (const template of listTemplates()) {
|
|
2291
|
-
printBlock(printLine, [formatTemplateSummary(template), formatTemplateFeatures(template)]);
|
|
2292
|
-
}
|
|
2293
|
-
return;
|
|
2294
|
-
}
|
|
2295
|
-
if (subcommand === "inspect") {
|
|
2296
|
-
if (!flags.id) {
|
|
2297
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, "`wp-typia templates inspect` requires <template-id>.");
|
|
2298
|
-
}
|
|
2299
|
-
const template = getTemplateById(flags.id);
|
|
2300
|
-
if (!template) {
|
|
2301
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `Unknown template "${flags.id}".`);
|
|
2302
|
-
}
|
|
2303
|
-
printBlock(printLine, [formatTemplateDetails(template)]);
|
|
2304
|
-
return;
|
|
2305
|
-
}
|
|
2306
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_COMMAND, `Unknown templates subcommand "${subcommand}". Expected list or inspect.`);
|
|
2307
|
-
}
|
|
2308
|
-
async function listTemplatesForRuntime() {
|
|
2309
|
-
const { listTemplates } = await loadCliTemplatesRuntime2();
|
|
2310
|
-
return listTemplates();
|
|
2311
|
-
}
|
|
2312
|
-
// src/runtime-bridge-sync.ts
|
|
2313
|
-
import { spawnSync } from "child_process";
|
|
2314
|
-
import fs3 from "fs";
|
|
2315
|
-
import path3 from "path";
|
|
2316
|
-
var SYNC_INSTALL_MARKERS = [
|
|
2317
|
-
"node_modules",
|
|
2318
|
-
".pnp.cjs",
|
|
2319
|
-
".pnp.loader.mjs"
|
|
2320
|
-
];
|
|
2321
|
-
var LOCAL_SYNC_TOOL_PATTERN = /(^|[\s;&|()])(?:tsx|wp-scripts)(?=($|[\s;&|()]))/u;
|
|
2322
|
-
var CAPTURED_SYNC_OUTPUT_MAX_BUFFER = 16 * 1024 * 1024;
|
|
2323
|
-
function resolveSyncExecutionTarget(subcommand) {
|
|
2324
|
-
if (!subcommand) {
|
|
2325
|
-
return "default";
|
|
2326
|
-
}
|
|
2327
|
-
if (subcommand === "ai") {
|
|
2328
|
-
return "ai";
|
|
2329
|
-
}
|
|
2330
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_COMMAND, `Unknown sync subcommand "${subcommand}". Expected one of: "ai".`);
|
|
2331
|
-
}
|
|
2332
|
-
function getSyncRootError(cwd) {
|
|
2333
|
-
return createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.OUTSIDE_PROJECT_ROOT, `No generated wp-typia project root was found at ${cwd}. Run \`wp-typia sync\` from a scaffolded project or official workspace root that already contains generated sync scripts. If you expected this directory to work, cd into the scaffold root first or rerun the scaffold before syncing.`);
|
|
2334
|
-
}
|
|
2335
|
-
function readSyncPackageJson(packageJsonPath) {
|
|
2336
|
-
const source = fs3.readFileSync(packageJsonPath, "utf8");
|
|
2337
|
-
try {
|
|
2338
|
-
return JSON.parse(source);
|
|
2339
|
-
} catch (error) {
|
|
2340
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2341
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `Unable to parse ${packageJsonPath}: ${message}`, error instanceof Error ? { cause: error } : undefined);
|
|
2342
|
-
}
|
|
2343
|
-
}
|
|
2344
|
-
function resolveSyncProjectContext(cwd) {
|
|
2345
|
-
const packageJsonPath = path3.join(cwd, "package.json");
|
|
2346
|
-
if (!fs3.existsSync(packageJsonPath)) {
|
|
2347
|
-
throw getSyncRootError(cwd);
|
|
2348
|
-
}
|
|
2349
|
-
const packageJson = readSyncPackageJson(packageJsonPath);
|
|
2350
|
-
const scripts = packageJson.scripts ?? {};
|
|
2351
|
-
const syncScripts = {
|
|
2352
|
-
sync: typeof scripts.sync === "string" ? {
|
|
2353
|
-
command: scripts.sync,
|
|
2354
|
-
scriptName: "sync"
|
|
2355
|
-
} : undefined,
|
|
2356
|
-
"sync-ai": typeof scripts["sync-ai"] === "string" ? {
|
|
2357
|
-
command: scripts["sync-ai"],
|
|
2358
|
-
scriptName: "sync-ai"
|
|
2359
|
-
} : typeof scripts["sync-wordpress-ai"] === "string" ? {
|
|
2360
|
-
command: scripts["sync-wordpress-ai"],
|
|
2361
|
-
scriptName: "sync-wordpress-ai"
|
|
2362
|
-
} : undefined,
|
|
2363
|
-
"sync-rest": typeof scripts["sync-rest"] === "string" ? {
|
|
2364
|
-
command: scripts["sync-rest"],
|
|
2365
|
-
scriptName: "sync-rest"
|
|
2366
|
-
} : undefined,
|
|
2367
|
-
"sync-types": typeof scripts["sync-types"] === "string" ? {
|
|
2368
|
-
command: scripts["sync-types"],
|
|
2369
|
-
scriptName: "sync-types"
|
|
2370
|
-
} : undefined
|
|
2371
|
-
};
|
|
2372
|
-
return {
|
|
2373
|
-
cwd,
|
|
2374
|
-
packageJsonPath,
|
|
2375
|
-
packageManager: inferPackageManagerId(cwd, packageJson.packageManager),
|
|
2376
|
-
scripts: syncScripts
|
|
2377
|
-
};
|
|
2378
|
-
}
|
|
2379
|
-
function findInstalledDependencyMarkerDir(projectDir) {
|
|
2380
|
-
let currentDir = path3.resolve(projectDir);
|
|
2381
|
-
while (true) {
|
|
2382
|
-
if (SYNC_INSTALL_MARKERS.some((marker) => fs3.existsSync(path3.join(currentDir, marker)))) {
|
|
2383
|
-
return currentDir;
|
|
2384
|
-
}
|
|
2385
|
-
const parentDir = path3.dirname(currentDir);
|
|
2386
|
-
if (parentDir === currentDir) {
|
|
2387
|
-
return null;
|
|
2388
|
-
}
|
|
2389
|
-
currentDir = parentDir;
|
|
2390
|
-
}
|
|
2391
|
-
}
|
|
2392
|
-
function scriptsLikelyNeedInstalledDependencies(project, target) {
|
|
2393
|
-
const candidateScripts = target === "ai" ? [project.scripts["sync-ai"]] : project.scripts.sync ? [project.scripts.sync] : [
|
|
2394
|
-
project.scripts["sync-types"],
|
|
2395
|
-
project.scripts["sync-rest"],
|
|
2396
|
-
project.scripts["sync-ai"]
|
|
2397
|
-
];
|
|
2398
|
-
return candidateScripts.some((script) => script !== undefined && LOCAL_SYNC_TOOL_PATTERN.test(script.command));
|
|
2399
|
-
}
|
|
2400
|
-
function assertSyncDependenciesInstalled(project, target) {
|
|
2401
|
-
if (!scriptsLikelyNeedInstalledDependencies(project, target)) {
|
|
2402
|
-
return;
|
|
2403
|
-
}
|
|
2404
|
-
const markerDir = findInstalledDependencyMarkerDir(project.cwd);
|
|
2405
|
-
if (markerDir) {
|
|
2406
|
-
return;
|
|
2407
|
-
}
|
|
2408
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.DEPENDENCIES_NOT_INSTALLED, `Project dependencies have not been installed yet. Run \`${formatInstallCommand(project.packageManager)}\` from the project root before \`wp-typia sync\`. The generated sync scripts rely on local tools such as \`tsx\`.`);
|
|
2409
|
-
}
|
|
2410
|
-
function getPackageManagerRunInvocation(packageManager, scriptName, extraArgs) {
|
|
2411
|
-
switch (packageManager) {
|
|
2412
|
-
case "bun":
|
|
2413
|
-
return { args: ["run", scriptName, ...extraArgs], command: "bun" };
|
|
2414
|
-
case "npm":
|
|
2415
|
-
return {
|
|
2416
|
-
args: [
|
|
2417
|
-
"run",
|
|
2418
|
-
scriptName,
|
|
2419
|
-
...extraArgs.length > 0 ? ["--", ...extraArgs] : []
|
|
2420
|
-
],
|
|
2421
|
-
command: "npm"
|
|
2422
|
-
};
|
|
2423
|
-
case "pnpm":
|
|
2424
|
-
return { args: ["run", scriptName, ...extraArgs], command: "pnpm" };
|
|
2425
|
-
case "yarn":
|
|
2426
|
-
return { args: ["run", scriptName, ...extraArgs], command: "yarn" };
|
|
2427
|
-
}
|
|
2428
|
-
}
|
|
2429
|
-
function createSyncPlannedCommand(project, scriptName, extraArgs) {
|
|
2430
|
-
const script = project.scripts[scriptName];
|
|
2431
|
-
if (!script) {
|
|
2432
|
-
return null;
|
|
2433
|
-
}
|
|
2434
|
-
const invocation = getPackageManagerRunInvocation(project.packageManager, script.scriptName, extraArgs);
|
|
2435
|
-
return {
|
|
2436
|
-
args: invocation.args,
|
|
2437
|
-
command: invocation.command,
|
|
2438
|
-
displayCommand: formatRunScript(project.packageManager, script.scriptName, extraArgs.join(" ")),
|
|
2439
|
-
scriptName: script.scriptName
|
|
2440
|
-
};
|
|
2441
|
-
}
|
|
2442
|
-
function buildSyncPlannedCommands(project, extraArgs, target) {
|
|
2443
|
-
if (target === "ai") {
|
|
2444
|
-
const syncAiCommand2 = createSyncPlannedCommand(project, "sync-ai", extraArgs);
|
|
2445
|
-
if (!syncAiCommand2) {
|
|
2446
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.CONFIGURATION_MISSING, `Expected ${project.packageJsonPath} to define a \`sync-ai\` script for \`wp-typia sync ai\`.`);
|
|
2447
|
-
}
|
|
2448
|
-
return [syncAiCommand2];
|
|
2449
|
-
}
|
|
2450
|
-
if (project.scripts.sync) {
|
|
2451
|
-
return [createSyncPlannedCommand(project, "sync", extraArgs)];
|
|
2452
|
-
}
|
|
2453
|
-
const syncTypesCommand = createSyncPlannedCommand(project, "sync-types", extraArgs);
|
|
2454
|
-
if (!syncTypesCommand) {
|
|
2455
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.CONFIGURATION_MISSING, `Expected ${project.packageJsonPath} to define either a \`sync\` or \`sync-types\` script.`);
|
|
2456
|
-
}
|
|
2457
|
-
const plannedCommands = [syncTypesCommand];
|
|
2458
|
-
const syncRestCommand = createSyncPlannedCommand(project, "sync-rest", extraArgs);
|
|
2459
|
-
if (syncRestCommand) {
|
|
2460
|
-
plannedCommands.push(syncRestCommand);
|
|
2461
|
-
}
|
|
2462
|
-
const syncAiCommand = createSyncPlannedCommand(project, "sync-ai", extraArgs);
|
|
2463
|
-
if (syncAiCommand) {
|
|
2464
|
-
plannedCommands.push(syncAiCommand);
|
|
2465
|
-
}
|
|
2466
|
-
return plannedCommands;
|
|
2467
|
-
}
|
|
2468
|
-
function runProjectScript(project, plannedCommand, options) {
|
|
2469
|
-
const result = spawnSync(plannedCommand.command, plannedCommand.args, {
|
|
2470
|
-
cwd: project.cwd,
|
|
2471
|
-
encoding: options.captureOutput ? "utf8" : undefined,
|
|
2472
|
-
...options.captureOutput ? { maxBuffer: CAPTURED_SYNC_OUTPUT_MAX_BUFFER } : {},
|
|
2473
|
-
shell: process.platform === "win32",
|
|
2474
|
-
stdio: options.captureOutput ? "pipe" : "inherit"
|
|
2475
|
-
});
|
|
2476
|
-
const stderr = options.captureOutput && typeof result.stderr === "string" ? result.stderr : undefined;
|
|
2477
|
-
const stdout = options.captureOutput && typeof result.stdout === "string" ? result.stdout : undefined;
|
|
2478
|
-
if (result.error || result.status !== 0) {
|
|
2479
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.COMMAND_EXECUTION, `\`${plannedCommand.displayCommand}\` failed.`, {
|
|
2480
|
-
cause: result.error ?? (stderr ? new Error(stderr.trim()) : undefined)
|
|
2481
|
-
});
|
|
2482
|
-
}
|
|
2483
|
-
return {
|
|
2484
|
-
...plannedCommand,
|
|
2485
|
-
exitCode: result.status ?? 0,
|
|
2486
|
-
...stderr !== undefined ? { stderr } : {},
|
|
2487
|
-
...stdout !== undefined ? { stdout } : {}
|
|
2488
|
-
};
|
|
2489
|
-
}
|
|
2490
|
-
async function executeSyncCommand({
|
|
2491
|
-
captureOutput = false,
|
|
2492
|
-
check = false,
|
|
2493
|
-
cwd,
|
|
2494
|
-
dryRun = false,
|
|
2495
|
-
target = "default"
|
|
2496
|
-
}) {
|
|
2497
|
-
const project = resolveSyncProjectContext(cwd);
|
|
2498
|
-
const extraArgs = check ? ["--check"] : [];
|
|
2499
|
-
const plannedCommands = buildSyncPlannedCommands(project, extraArgs, target);
|
|
2500
|
-
const result = {
|
|
2501
|
-
check,
|
|
2502
|
-
dryRun,
|
|
2503
|
-
packageJsonPath: project.packageJsonPath,
|
|
2504
|
-
packageManager: project.packageManager,
|
|
2505
|
-
plannedCommands,
|
|
2506
|
-
projectDir: project.cwd,
|
|
2507
|
-
target
|
|
2508
|
-
};
|
|
2509
|
-
if (dryRun) {
|
|
2510
|
-
return result;
|
|
2511
|
-
}
|
|
2512
|
-
assertSyncDependenciesInstalled(project, target);
|
|
2513
|
-
result.executedCommands = plannedCommands.map((plannedCommand) => runProjectScript(project, plannedCommand, {
|
|
2514
|
-
captureOutput
|
|
2515
|
-
}));
|
|
2516
|
-
return result;
|
|
2517
|
-
}
|
|
2518
|
-
// src/ui/lazy-flow.tsx
|
|
2519
|
-
var import_react33 = __toESM(require_react(), 1);
|
|
2520
|
-
|
|
2521
|
-
// src/ui/alternate-buffer-lifecycle.ts
|
|
2522
|
-
var import_react32 = __toESM(require_react(), 1);
|
|
2523
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/utils/format.ts
|
|
2524
|
-
var KEYWORDS = new Set([
|
|
2525
|
-
"const",
|
|
2526
|
-
"let",
|
|
2527
|
-
"var",
|
|
2528
|
-
"function",
|
|
2529
|
-
"class",
|
|
2530
|
-
"return",
|
|
2531
|
-
"if",
|
|
2532
|
-
"else",
|
|
2533
|
-
"for",
|
|
2534
|
-
"while",
|
|
2535
|
-
"import",
|
|
2536
|
-
"export",
|
|
2537
|
-
"from",
|
|
2538
|
-
"async",
|
|
2539
|
-
"await",
|
|
2540
|
-
"try",
|
|
2541
|
-
"catch",
|
|
2542
|
-
"throw",
|
|
2543
|
-
"new",
|
|
2544
|
-
"typeof",
|
|
2545
|
-
"interface",
|
|
2546
|
-
"type",
|
|
2547
|
-
"enum",
|
|
2548
|
-
"extends",
|
|
2549
|
-
"implements",
|
|
2550
|
-
"public",
|
|
2551
|
-
"private",
|
|
2552
|
-
"protected",
|
|
2553
|
-
"def",
|
|
2554
|
-
"fn",
|
|
2555
|
-
"pub",
|
|
2556
|
-
"use",
|
|
2557
|
-
"mod",
|
|
2558
|
-
"struct",
|
|
2559
|
-
"impl",
|
|
2560
|
-
"trait"
|
|
2561
|
-
]);
|
|
2562
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/form.tsx
|
|
2563
|
-
var import_react2 = __toESM(require_react(), 1);
|
|
2564
|
-
|
|
2565
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/form-context.tsx
|
|
2566
|
-
var import_react = __toESM(require_react(), 1);
|
|
2567
|
-
var FormContext = import_react.createContext(null);
|
|
2568
|
-
|
|
2569
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/form.tsx
|
|
2570
|
-
var jsx_dev_runtime = __toESM(require_jsx_dev_runtime(), 1);
|
|
2571
|
-
var formKeymap = createKeyMatcher({
|
|
2572
|
-
cancel: ["escape"],
|
|
2573
|
-
nextField: ["tab"],
|
|
2574
|
-
previousField: ["shift+tab"],
|
|
2575
|
-
submitShortcut: ["ctrl+s"],
|
|
2576
|
-
resetShortcut: ["ctrl+r"],
|
|
2577
|
-
nextError: ["f8"],
|
|
2578
|
-
previousError: ["shift+f8"],
|
|
2579
|
-
submit: ["enter"]
|
|
2580
|
-
});
|
|
2581
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/form-field.tsx
|
|
2582
|
-
var import_react3 = __toESM(require_react(), 1);
|
|
2583
|
-
var jsx_dev_runtime2 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2584
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/select-field.tsx
|
|
2585
|
-
var import_react4 = __toESM(require_react(), 1);
|
|
2586
|
-
var jsx_dev_runtime3 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2587
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/multi-select-field.tsx
|
|
2588
|
-
var import_react5 = __toESM(require_react(), 1);
|
|
2589
|
-
var jsx_dev_runtime4 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2590
|
-
var multiSelectKeymap = createKeyMatcher({
|
|
2591
|
-
up: ["up", "k"],
|
|
2592
|
-
down: ["down", "j"],
|
|
2593
|
-
toggle: ["space"],
|
|
2594
|
-
submit: ["enter"]
|
|
2595
|
-
});
|
|
2596
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/number-field.tsx
|
|
2597
|
-
var import_react6 = __toESM(require_react(), 1);
|
|
2598
|
-
var jsx_dev_runtime5 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2599
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/password-field.tsx
|
|
2600
|
-
var import_react7 = __toESM(require_react(), 1);
|
|
2601
|
-
var jsx_dev_runtime6 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2602
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/textarea-field.tsx
|
|
2603
|
-
var import_react8 = __toESM(require_react(), 1);
|
|
2604
|
-
var jsx_dev_runtime7 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2605
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/checkbox-field.tsx
|
|
2606
|
-
var import_react9 = __toESM(require_react(), 1);
|
|
2607
|
-
var jsx_dev_runtime8 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2608
|
-
var checkboxKeymap = createKeyMatcher({
|
|
2609
|
-
toggle: ["space", "enter"]
|
|
2610
|
-
});
|
|
2611
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/schema-form.tsx
|
|
2612
|
-
var import_react10 = __toESM(require_react(), 1);
|
|
2613
|
-
var jsx_dev_runtime9 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2614
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/progress-bar.tsx
|
|
2615
|
-
var jsx_dev_runtime10 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2616
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/stack.tsx
|
|
2617
|
-
var jsx_dev_runtime11 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2618
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/panel.tsx
|
|
2619
|
-
var jsx_dev_runtime12 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2620
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/scroll-panel.tsx
|
|
2621
|
-
var jsx_dev_runtime13 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2622
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/card.tsx
|
|
2623
|
-
var jsx_dev_runtime14 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2624
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/alert.tsx
|
|
2625
|
-
var jsx_dev_runtime15 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2626
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/badge.tsx
|
|
2627
|
-
var jsx_dev_runtime16 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2628
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/divider.tsx
|
|
2629
|
-
var jsx_dev_runtime17 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2630
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/key-value-list.tsx
|
|
2631
|
-
var import_react11 = __toESM(require_react(), 1);
|
|
2632
|
-
var jsx_dev_runtime18 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2633
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/stat.tsx
|
|
2634
|
-
var jsx_dev_runtime19 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2635
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/container.tsx
|
|
2636
|
-
var jsx_dev_runtime20 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2637
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/grid.tsx
|
|
2638
|
-
var import_react12 = __toESM(require_react(), 1);
|
|
2639
|
-
var jsx_dev_runtime21 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2640
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/section-header.tsx
|
|
2641
|
-
var jsx_dev_runtime22 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2642
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/empty-state.tsx
|
|
2643
|
-
var jsx_dev_runtime23 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2644
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/toast.tsx
|
|
2645
|
-
var jsx_dev_runtime24 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2646
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/modal.tsx
|
|
2647
|
-
var import_react13 = __toESM(require_react(), 1);
|
|
2648
|
-
var jsx_dev_runtime25 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2649
|
-
var modalKeymap = createKeyMatcher({
|
|
2650
|
-
close: ["escape", "ctrl+c"],
|
|
2651
|
-
trap: ["tab", "shift+tab"]
|
|
2652
|
-
});
|
|
2653
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/tabs.tsx
|
|
2654
|
-
var import_react15 = __toESM(require_react(), 1);
|
|
2655
|
-
var jsx_dev_runtime26 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2656
|
-
var tabsKeymap = createKeyMatcher({
|
|
2657
|
-
previous: ["left", "h"],
|
|
2658
|
-
next: ["right", "l"]
|
|
2659
|
-
});
|
|
2660
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/confirm.tsx
|
|
2661
|
-
var import_react16 = __toESM(require_react(), 1);
|
|
2662
|
-
var jsx_dev_runtime27 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2663
|
-
var confirmKeymap = createKeyMatcher({
|
|
2664
|
-
toggle: ["left", "right", "h", "l", "tab"],
|
|
2665
|
-
affirm: ["y"],
|
|
2666
|
-
negate: ["n", "q"],
|
|
2667
|
-
submit: ["enter"],
|
|
2668
|
-
abort: ["escape"]
|
|
2669
|
-
});
|
|
2670
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/menu.tsx
|
|
2671
|
-
var import_react17 = __toESM(require_react(), 1);
|
|
2672
|
-
var jsx_dev_runtime28 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2673
|
-
var menuKeymap = createKeyMatcher({
|
|
2674
|
-
up: ["up", "k"],
|
|
2675
|
-
down: ["down", "j"],
|
|
2676
|
-
select: ["enter"]
|
|
2677
|
-
});
|
|
2678
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/nav-list.tsx
|
|
2679
|
-
var import_react18 = __toESM(require_react(), 1);
|
|
2680
|
-
var jsx_dev_runtime29 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2681
|
-
var navKeymap = createKeyMatcher({
|
|
2682
|
-
up: ["up", "k"],
|
|
2683
|
-
down: ["down", "j"],
|
|
2684
|
-
select: ["enter"]
|
|
2685
|
-
});
|
|
2686
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/command-palette.tsx
|
|
2687
|
-
var import_react19 = __toESM(require_react(), 1);
|
|
2688
|
-
var jsx_dev_runtime30 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2689
|
-
var paletteKeymap = createKeyMatcher({
|
|
2690
|
-
up: ["up", "k"],
|
|
2691
|
-
down: ["down", "j"],
|
|
2692
|
-
select: ["enter"]
|
|
2693
|
-
});
|
|
2694
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/filter.tsx
|
|
2695
|
-
var import_react20 = __toESM(require_react(), 1);
|
|
2696
|
-
var jsx_dev_runtime31 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2697
|
-
var filterKeymap = createKeyMatcher({
|
|
2698
|
-
up: ["up"],
|
|
2699
|
-
down: ["down"],
|
|
2700
|
-
toggle: ["tab"],
|
|
2701
|
-
selectAll: ["ctrl+a"],
|
|
2702
|
-
submit: ["enter"],
|
|
2703
|
-
abort: ["escape"]
|
|
2704
|
-
});
|
|
2705
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/data-table.tsx
|
|
2706
|
-
var import_react21 = __toESM(require_react(), 1);
|
|
2707
|
-
var jsx_dev_runtime32 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2708
|
-
var dataTableKeymap = createKeyMatcher({
|
|
2709
|
-
sortPrevious: ["left", "h"],
|
|
2710
|
-
sortNext: ["right", "l"],
|
|
2711
|
-
rowPrevious: ["up", "k"],
|
|
2712
|
-
rowNext: ["down", "j"],
|
|
2713
|
-
select: ["enter"]
|
|
2714
|
-
});
|
|
2715
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/sidebar-layout.tsx
|
|
2716
|
-
var import_react22 = __toESM(require_react(), 1);
|
|
2717
|
-
var jsx_dev_runtime33 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2718
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/spinner.tsx
|
|
2719
|
-
var import_react24 = __toESM(require_react(), 1);
|
|
2720
|
-
var jsx_dev_runtime34 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2721
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/pager.tsx
|
|
2722
|
-
var import_react25 = __toESM(require_react(), 1);
|
|
2723
|
-
var jsx_dev_runtime35 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2724
|
-
var pagerKeymap = createKeyMatcher({
|
|
2725
|
-
scrollDown: ["down", "j"],
|
|
2726
|
-
scrollUp: ["up", "k"],
|
|
2727
|
-
halfPageDown: ["d"],
|
|
2728
|
-
halfPageUp: ["u"],
|
|
2729
|
-
top: ["g", "home"],
|
|
2730
|
-
bottom: ["end"],
|
|
2731
|
-
search: ["/"],
|
|
2732
|
-
nextMatch: ["n"],
|
|
2733
|
-
prevMatch: ["shift+n"],
|
|
2734
|
-
quit: ["q", "escape"]
|
|
2735
|
-
});
|
|
2736
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/choose.tsx
|
|
2737
|
-
var import_react26 = __toESM(require_react(), 1);
|
|
2738
|
-
var jsx_dev_runtime36 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2739
|
-
var chooseKeymap = createKeyMatcher({
|
|
2740
|
-
up: ["up", "k"],
|
|
2741
|
-
down: ["down", "j"],
|
|
2742
|
-
pageUp: ["left", "h"],
|
|
2743
|
-
pageDown: ["right", "l"],
|
|
2744
|
-
home: ["g", "home"],
|
|
2745
|
-
end: ["end", "G"],
|
|
2746
|
-
toggle: ["space", "tab", "x"],
|
|
2747
|
-
selectAll: ["a"],
|
|
2748
|
-
submit: ["enter"],
|
|
2749
|
-
abort: ["escape"]
|
|
2750
|
-
});
|
|
2751
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/components/file-picker.tsx
|
|
2752
|
-
var import_react27 = __toESM(require_react(), 1);
|
|
2753
|
-
var jsx_dev_runtime37 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2754
|
-
var filePickerKeymap = createKeyMatcher({
|
|
2755
|
-
up: ["up", "k"],
|
|
2756
|
-
down: ["down", "j"],
|
|
2757
|
-
enter: ["enter", "right", "l"],
|
|
2758
|
-
back: ["backspace", "left", "h"],
|
|
2759
|
-
toggleHidden: ["."],
|
|
2760
|
-
quit: ["q", "escape"]
|
|
2761
|
-
});
|
|
2762
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/interactive/index.tsx
|
|
2763
|
-
var jsx_dev_runtime38 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2764
|
-
// ../../node_modules/.bun/@bunli+tui@0.6.0+df522c502ed1ba91/node_modules/@bunli/tui/src/charts/index.tsx
|
|
2765
|
-
var import_react30 = __toESM(require_react(), 1);
|
|
2766
|
-
var jsx_dev_runtime39 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2767
|
-
// src/ui/alternate-buffer-lifecycle.ts
|
|
2768
|
-
function describeAlternateBufferFailure(context, error) {
|
|
2769
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2770
|
-
return `${context}: ${message}`;
|
|
2771
|
-
}
|
|
2772
|
-
function isAlternateBufferExitKey(key) {
|
|
2773
|
-
return key.name === "q" || key.ctrl === true && key.name === "c";
|
|
2774
|
-
}
|
|
2775
|
-
function isAlternateBufferCompletionKey(key) {
|
|
2776
|
-
return key.name === "enter" || key.sequence === "\r" || key.sequence === `
|
|
2777
|
-
`;
|
|
2778
|
-
}
|
|
2779
|
-
function reportAlternateBufferFailure({
|
|
2780
|
-
context,
|
|
2781
|
-
error,
|
|
2782
|
-
exit,
|
|
2783
|
-
log = console.error
|
|
2784
|
-
}) {
|
|
2785
|
-
const message = describeAlternateBufferFailure(context, error);
|
|
2786
|
-
exit();
|
|
2787
|
-
log(message);
|
|
2788
|
-
}
|
|
2789
|
-
async function resolveLazyFlowComponent({
|
|
2790
|
-
loader,
|
|
2791
|
-
onLoaded,
|
|
2792
|
-
onFailure,
|
|
2793
|
-
isDisposed
|
|
2794
|
-
}) {
|
|
2795
|
-
try {
|
|
2796
|
-
const module = await loader();
|
|
2797
|
-
if (!isDisposed()) {
|
|
2798
|
-
onLoaded(module.default);
|
|
2799
|
-
}
|
|
2800
|
-
} catch (error) {
|
|
2801
|
-
if (!isDisposed()) {
|
|
2802
|
-
onFailure(error);
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
2806
|
-
function useAlternateBufferExitKeys(options = {}) {
|
|
2807
|
-
const runtime = useRuntime();
|
|
2808
|
-
const exit = options.exit ?? (() => runtime.exit());
|
|
2809
|
-
const enabled = options.enabled ?? true;
|
|
2810
|
-
useKeyboard((key) => {
|
|
2811
|
-
if (!enabled) {
|
|
2812
|
-
return;
|
|
2813
|
-
}
|
|
2814
|
-
if (isAlternateBufferExitKey(key)) {
|
|
2815
|
-
exit();
|
|
2816
|
-
}
|
|
2817
|
-
});
|
|
2818
|
-
}
|
|
2819
|
-
function useAlternateBufferCompletionKeys(options = {}) {
|
|
2820
|
-
const runtime = useRuntime();
|
|
2821
|
-
const exit = options.exit ?? (() => runtime.exit());
|
|
2822
|
-
const enabled = options.enabled ?? false;
|
|
2823
|
-
useKeyboard((key) => {
|
|
2824
|
-
if (!enabled) {
|
|
2825
|
-
return;
|
|
2826
|
-
}
|
|
2827
|
-
if (isAlternateBufferCompletionKey(key) || isAlternateBufferExitKey(key)) {
|
|
2828
|
-
exit();
|
|
2829
|
-
}
|
|
2830
|
-
});
|
|
2831
|
-
}
|
|
2832
|
-
function isAlternateBufferCompletionPayload(value) {
|
|
2833
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
2834
|
-
return false;
|
|
2835
|
-
}
|
|
2836
|
-
const candidate = value;
|
|
2837
|
-
return typeof candidate.title === "string" && candidate.title.trim().length > 0;
|
|
2838
|
-
}
|
|
2839
|
-
function useAlternateBufferLifecycle(context, options = {}) {
|
|
2840
|
-
const runtime = useRuntime();
|
|
2841
|
-
const [completion, setCompletion] = import_react32.useState(null);
|
|
2842
|
-
const [progress, setProgress] = import_react32.useState(null);
|
|
2843
|
-
const [status, setStatus] = import_react32.useState("editing");
|
|
2844
|
-
const exit = import_react32.useCallback(() => {
|
|
2845
|
-
runtime.exit();
|
|
2846
|
-
}, [runtime]);
|
|
2847
|
-
useAlternateBufferExitKeys({
|
|
2848
|
-
enabled: (options.enableExitKeys ?? true) && status !== "completed",
|
|
2849
|
-
exit
|
|
2850
|
-
});
|
|
2851
|
-
useAlternateBufferCompletionKeys({
|
|
2852
|
-
enabled: status === "completed",
|
|
2853
|
-
exit
|
|
2854
|
-
});
|
|
2855
|
-
const handleCancel = import_react32.useCallback(() => {
|
|
2856
|
-
setCompletion(null);
|
|
2857
|
-
setProgress(null);
|
|
2858
|
-
setStatus("editing");
|
|
2859
|
-
exit();
|
|
2860
|
-
}, [exit]);
|
|
2861
|
-
const handleFailure = import_react32.useCallback((error) => {
|
|
2862
|
-
setCompletion(null);
|
|
2863
|
-
setProgress(null);
|
|
2864
|
-
setStatus("editing");
|
|
2865
|
-
reportAlternateBufferFailure({
|
|
2866
|
-
context,
|
|
2867
|
-
error,
|
|
2868
|
-
exit
|
|
2869
|
-
});
|
|
2870
|
-
}, [context, exit]);
|
|
2871
|
-
const handleSubmit = import_react32.useCallback(async (action) => {
|
|
2872
|
-
setCompletion(null);
|
|
2873
|
-
setProgress(null);
|
|
2874
|
-
setStatus("submitting");
|
|
2875
|
-
try {
|
|
2876
|
-
const result = await action();
|
|
2877
|
-
if (isAlternateBufferCompletionPayload(result)) {
|
|
2878
|
-
setCompletion(result);
|
|
2879
|
-
setProgress(null);
|
|
2880
|
-
setStatus("completed");
|
|
2881
|
-
return;
|
|
2882
|
-
}
|
|
2883
|
-
exit();
|
|
2884
|
-
} catch (error) {
|
|
2885
|
-
setCompletion(null);
|
|
2886
|
-
setProgress(null);
|
|
2887
|
-
setStatus("editing");
|
|
2888
|
-
reportAlternateBufferFailure({
|
|
2889
|
-
context,
|
|
2890
|
-
error,
|
|
2891
|
-
exit
|
|
2892
|
-
});
|
|
2893
|
-
}
|
|
2894
|
-
}, [context, exit]);
|
|
2895
|
-
const reportProgress = import_react32.useCallback((payload) => {
|
|
2896
|
-
setProgress(payload);
|
|
2897
|
-
}, []);
|
|
2898
|
-
return {
|
|
2899
|
-
completion,
|
|
2900
|
-
handleCancel,
|
|
2901
|
-
handleFailure,
|
|
2902
|
-
handleSubmit,
|
|
2903
|
-
progress,
|
|
2904
|
-
reportProgress,
|
|
2905
|
-
status
|
|
2906
|
-
};
|
|
2907
|
-
}
|
|
2908
|
-
|
|
2909
|
-
// src/ui/lazy-flow.tsx
|
|
2910
|
-
function LazyFlow({ loader, props }) {
|
|
2911
|
-
const [Component, setComponent] = import_react33.useState(null);
|
|
2912
|
-
const { handleFailure } = useAlternateBufferLifecycle("wp-typia TUI flow failed", {
|
|
2913
|
-
enableExitKeys: false
|
|
2914
|
-
});
|
|
2915
|
-
useAlternateBufferExitKeys({
|
|
2916
|
-
enabled: Component === null
|
|
2917
|
-
});
|
|
2918
|
-
import_react33.useEffect(() => {
|
|
2919
|
-
let disposed = false;
|
|
2920
|
-
resolveLazyFlowComponent({
|
|
2921
|
-
isDisposed: () => disposed,
|
|
2922
|
-
loader,
|
|
2923
|
-
onFailure: handleFailure,
|
|
2924
|
-
onLoaded: (component) => {
|
|
2925
|
-
setComponent(() => component);
|
|
2926
|
-
}
|
|
2927
|
-
});
|
|
2928
|
-
return () => {
|
|
2929
|
-
disposed = true;
|
|
2930
|
-
};
|
|
2931
|
-
}, [handleFailure, loader]);
|
|
2932
|
-
if (!Component) {
|
|
2933
|
-
return null;
|
|
2934
|
-
}
|
|
2935
|
-
return import_react33.createElement(Component, props);
|
|
2936
|
-
}
|
|
2937
|
-
|
|
2938
|
-
// src/commands/add.ts
|
|
2939
|
-
function loadAddFlow() {
|
|
2940
|
-
return import(resolveBundledModuleHref(import.meta.url, ["./ui/add-flow.js", "../ui/add-flow.js", "../ui/add-flow.tsx"], {
|
|
2941
|
-
moduleLabel: "the add-flow UI"
|
|
2942
|
-
})).then((module) => ({ default: module.AddFlow }));
|
|
2943
|
-
}
|
|
2944
|
-
var addOptions = buildCommandOptions(ADD_OPTION_METADATA);
|
|
2945
|
-
function resolveAddCommandName(positional) {
|
|
2946
|
-
if (positional[0] === "core-variation" && positional[2]) {
|
|
2947
|
-
return positional[2];
|
|
2948
|
-
}
|
|
2949
|
-
return positional[1];
|
|
2950
|
-
}
|
|
2951
|
-
var addCommand = defineCommand({
|
|
2952
|
-
defaultFormat: "toon",
|
|
2953
|
-
description: "Extend an official wp-typia workspace with blocks, integration envs, variations, block styles, transforms, patterns, binding sources, standalone contracts, plugin-level REST resources, post meta contracts, workflow abilities, server-only AI features, editor plugins, or hooked blocks.",
|
|
2954
|
-
handler: async (args) => {
|
|
2955
|
-
const prefersStructuredOutput = prefersStructuredCliOutput(args);
|
|
2956
|
-
const { printLine, warnLine } = resolveCommandOutputAdapters(args);
|
|
2957
|
-
try {
|
|
2958
|
-
if (prefersStructuredOutput) {
|
|
2959
|
-
const completion = await executeAddCommand({
|
|
2960
|
-
cwd: args.cwd,
|
|
2961
|
-
emitOutput: false,
|
|
2962
|
-
flags: args.flags,
|
|
2963
|
-
interactive: false,
|
|
2964
|
-
kind: args.positional[0],
|
|
2965
|
-
name: resolveAddCommandName(args.positional),
|
|
2966
|
-
positionalArgs: args.positional,
|
|
2967
|
-
printLine,
|
|
2968
|
-
warnLine
|
|
2969
|
-
});
|
|
2970
|
-
args.output(buildStructuredCompletionSuccessPayload("add", completion, {
|
|
2971
|
-
dryRun: Boolean(args.flags["dry-run"]),
|
|
2972
|
-
kind: args.positional[0],
|
|
2973
|
-
name: resolveAddCommandName(args.positional),
|
|
2974
|
-
projectDir: extractCompletionProjectDir(completion) ?? args.cwd
|
|
2975
|
-
}));
|
|
2976
|
-
return;
|
|
2977
|
-
}
|
|
2978
|
-
await executeAddCommand({
|
|
2979
|
-
cwd: args.cwd,
|
|
2980
|
-
flags: args.flags,
|
|
2981
|
-
kind: args.positional[0],
|
|
2982
|
-
name: resolveAddCommandName(args.positional),
|
|
2983
|
-
positionalArgs: args.positional,
|
|
2984
|
-
printLine,
|
|
2985
|
-
warnLine
|
|
2986
|
-
});
|
|
2987
|
-
} catch (error) {
|
|
2988
|
-
emitCliDiagnosticFailure(args, {
|
|
2989
|
-
command: "add",
|
|
2990
|
-
error
|
|
2991
|
-
});
|
|
2992
|
-
}
|
|
2993
|
-
},
|
|
2994
|
-
name: "add",
|
|
2995
|
-
options: addOptions,
|
|
2996
|
-
...supportsInteractiveTui() ? {
|
|
2997
|
-
render: (args) => {
|
|
2998
|
-
const config = args.context?.store?.wpTypiaUserConfig && typeof args.context.store.wpTypiaUserConfig === "object" ? getAddBlockDefaults(args.context.store.wpTypiaUserConfig) : {};
|
|
2999
|
-
const initialValues = resolveCommandOptionValues(ADD_OPTION_METADATA, {
|
|
3000
|
-
defaults: config,
|
|
3001
|
-
flags: args.flags,
|
|
3002
|
-
optionNames: Object.keys(ADD_OPTION_METADATA).filter((optionName) => optionName !== "dry-run")
|
|
3003
|
-
});
|
|
3004
|
-
return import_react34.createElement(LazyFlow, {
|
|
3005
|
-
loader: loadAddFlow,
|
|
3006
|
-
props: {
|
|
3007
|
-
cwd: args.cwd,
|
|
3008
|
-
initialValues: {
|
|
3009
|
-
...initialValues,
|
|
3010
|
-
kind: args.positional[0] ?? "block",
|
|
3011
|
-
name: resolveAddCommandName(args.positional) ?? "",
|
|
3012
|
-
...args.positional[0] === "core-variation" && args.positional[2] ? { block: args.positional[1] } : {},
|
|
3013
|
-
position: initialValues.position ?? "after",
|
|
3014
|
-
slot: initialValues.slot ?? "sidebar"
|
|
3015
|
-
}
|
|
3016
|
-
}
|
|
3017
|
-
});
|
|
3018
|
-
},
|
|
3019
|
-
tui: {
|
|
3020
|
-
renderer: {
|
|
3021
|
-
bufferMode: "alternate"
|
|
3022
|
-
}
|
|
3023
|
-
}
|
|
3024
|
-
} : {}
|
|
3025
|
-
});
|
|
3026
|
-
|
|
3027
|
-
// src/commands/create.ts
|
|
3028
|
-
var import_react35 = __toESM(require_react(), 1);
|
|
3029
|
-
function loadCreateFlow() {
|
|
3030
|
-
return import(resolveBundledModuleHref(import.meta.url, [
|
|
3031
|
-
"./ui/create-flow.js",
|
|
3032
|
-
"../ui/create-flow.js",
|
|
3033
|
-
"../ui/create-flow.tsx"
|
|
3034
|
-
], {
|
|
3035
|
-
moduleLabel: "the create-flow UI"
|
|
3036
|
-
})).then((module) => ({ default: module.CreateFlow }));
|
|
3037
|
-
}
|
|
3038
|
-
var createOptions = buildCommandOptions(CREATE_OPTION_METADATA);
|
|
3039
|
-
var createCommand = defineCommand({
|
|
3040
|
-
defaultFormat: "toon",
|
|
3041
|
-
description: "Scaffold a new wp-typia project.",
|
|
3042
|
-
handler: async (args) => {
|
|
3043
|
-
const prefersStructuredOutput = prefersStructuredCliOutput(args);
|
|
3044
|
-
const { printLine, warnLine } = resolveCommandOutputAdapters(args);
|
|
3045
|
-
const projectDir = args.positional[0];
|
|
3046
|
-
if (!projectDir) {
|
|
3047
|
-
emitCliDiagnosticFailure(args, {
|
|
3048
|
-
code: CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT,
|
|
3049
|
-
command: "create",
|
|
3050
|
-
detailLines: buildMissingCreateProjectDirDetailLines()
|
|
3051
|
-
});
|
|
3052
|
-
return;
|
|
3053
|
-
}
|
|
3054
|
-
try {
|
|
3055
|
-
const completion = await executeCreateCommand({
|
|
3056
|
-
cwd: args.cwd,
|
|
3057
|
-
emitOutput: !prefersStructuredOutput,
|
|
3058
|
-
flags: args.flags,
|
|
3059
|
-
interactive: prefersStructuredOutput ? false : undefined,
|
|
3060
|
-
printLine,
|
|
3061
|
-
projectDir,
|
|
3062
|
-
warnLine
|
|
3063
|
-
});
|
|
3064
|
-
if (prefersStructuredOutput) {
|
|
3065
|
-
args.output(buildStructuredCompletionSuccessPayload("create", completion, {
|
|
3066
|
-
dryRun: Boolean(args.flags["dry-run"]),
|
|
3067
|
-
projectDir: extractCompletionProjectDir(completion) ?? projectDir,
|
|
3068
|
-
template: typeof args.flags.template === "string" ? args.flags.template : undefined
|
|
3069
|
-
}));
|
|
3070
|
-
}
|
|
3071
|
-
} catch (error) {
|
|
3072
|
-
emitCliDiagnosticFailure(args, {
|
|
3073
|
-
command: "create",
|
|
3074
|
-
error
|
|
3075
|
-
});
|
|
3076
|
-
}
|
|
3077
|
-
},
|
|
3078
|
-
name: "create",
|
|
3079
|
-
options: createOptions,
|
|
3080
|
-
...supportsInteractiveTui() ? {
|
|
3081
|
-
render: (args) => {
|
|
3082
|
-
const config = args.context?.store?.wpTypiaUserConfig && typeof args.context.store.wpTypiaUserConfig === "object" ? getCreateDefaults(args.context.store.wpTypiaUserConfig) : {};
|
|
3083
|
-
const initialValues = resolveCommandOptionValues(CREATE_OPTION_METADATA, {
|
|
3084
|
-
defaults: config,
|
|
3085
|
-
flags: args.flags
|
|
3086
|
-
});
|
|
3087
|
-
return import_react35.createElement(LazyFlow, {
|
|
3088
|
-
loader: loadCreateFlow,
|
|
3089
|
-
props: {
|
|
3090
|
-
cwd: args.cwd,
|
|
3091
|
-
initialValues: {
|
|
3092
|
-
...initialValues,
|
|
3093
|
-
"project-dir": args.positional[0] ?? ""
|
|
3094
|
-
}
|
|
3095
|
-
}
|
|
3096
|
-
});
|
|
3097
|
-
},
|
|
3098
|
-
tui: {
|
|
3099
|
-
renderer: {
|
|
3100
|
-
bufferMode: "alternate"
|
|
3101
|
-
}
|
|
3102
|
-
}
|
|
3103
|
-
} : {}
|
|
3104
|
-
});
|
|
3105
|
-
|
|
3106
|
-
// src/commands/doctor.ts
|
|
3107
|
-
var doctorCommand = defineCommand({
|
|
3108
|
-
defaultFormat: "toon",
|
|
3109
|
-
description: "Run repository and project diagnostics.",
|
|
3110
|
-
handler: async (args) => {
|
|
3111
|
-
const prefersStructuredOutput = prefersStructuredCliOutput(args);
|
|
3112
|
-
const doctorExitPolicy = args.flags["workspace-only"] ? "workspace-only" : "strict";
|
|
3113
|
-
if (prefersStructuredOutput) {
|
|
3114
|
-
const {
|
|
3115
|
-
createDoctorRunSummary,
|
|
3116
|
-
getDoctorChecks,
|
|
3117
|
-
getDoctorExitFailureDetailLines
|
|
3118
|
-
} = await import("./cli-doctor-6fyxq940.js");
|
|
3119
|
-
const checks = await getDoctorChecks(args.cwd);
|
|
3120
|
-
const summary = createDoctorRunSummary(checks, {
|
|
3121
|
-
exitPolicy: doctorExitPolicy
|
|
3122
|
-
});
|
|
3123
|
-
if (summary.exitCode === 1) {
|
|
3124
|
-
emitCliDiagnosticFailure(args, {
|
|
3125
|
-
code: CLI_DIAGNOSTIC_CODES.DOCTOR_CHECK_FAILED,
|
|
3126
|
-
command: "doctor",
|
|
3127
|
-
detailLines: getDoctorExitFailureDetailLines(checks, {
|
|
3128
|
-
exitPolicy: doctorExitPolicy
|
|
3129
|
-
}),
|
|
3130
|
-
extraOutput: { checks, summary },
|
|
3131
|
-
summary: "One or more doctor checks failed."
|
|
3132
|
-
});
|
|
3133
|
-
return;
|
|
3134
|
-
}
|
|
3135
|
-
args.output({ checks, summary });
|
|
3136
|
-
return;
|
|
3137
|
-
}
|
|
3138
|
-
try {
|
|
3139
|
-
await executeDoctorCommand(args.cwd, { exitPolicy: doctorExitPolicy });
|
|
3140
|
-
} catch (error) {
|
|
3141
|
-
emitCliDiagnosticFailure(args, {
|
|
3142
|
-
command: "doctor",
|
|
3143
|
-
error
|
|
3144
|
-
});
|
|
3145
|
-
}
|
|
3146
|
-
},
|
|
3147
|
-
name: "doctor",
|
|
3148
|
-
options: buildCommandOptions(DOCTOR_OPTION_METADATA)
|
|
3149
|
-
});
|
|
3150
|
-
|
|
3151
|
-
// src/commands/init.ts
|
|
3152
|
-
var initCommand = defineCommand({
|
|
3153
|
-
defaultFormat: "toon",
|
|
3154
|
-
description: "Preview or apply the minimum wp-typia retrofit plan for an existing project.",
|
|
3155
|
-
handler: async (args) => {
|
|
3156
|
-
const prefersStructuredOutput = prefersStructuredCliOutput(args);
|
|
3157
|
-
const { printLine, warnLine } = resolveCommandOutputAdapters(args);
|
|
3158
|
-
try {
|
|
3159
|
-
const plan = await executeInitCommand({
|
|
3160
|
-
apply: Boolean(args.flags.apply),
|
|
3161
|
-
cwd: args.cwd,
|
|
3162
|
-
packageManager: typeof args.flags["package-manager"] === "string" ? args.flags["package-manager"] : undefined,
|
|
3163
|
-
projectDir: args.positional[0]
|
|
3164
|
-
}, {
|
|
3165
|
-
emitOutput: !prefersStructuredOutput,
|
|
3166
|
-
printLine,
|
|
3167
|
-
warnLine
|
|
3168
|
-
});
|
|
3169
|
-
if (prefersStructuredOutput) {
|
|
3170
|
-
args.output(buildStructuredInitSuccessPayload(plan));
|
|
3171
|
-
}
|
|
3172
|
-
} catch (error) {
|
|
3173
|
-
emitCliDiagnosticFailure(args, {
|
|
3174
|
-
command: "init",
|
|
3175
|
-
error
|
|
3176
|
-
});
|
|
3177
|
-
}
|
|
3178
|
-
},
|
|
3179
|
-
name: "init",
|
|
3180
|
-
options: buildCommandOptions(INIT_OPTION_METADATA)
|
|
3181
|
-
});
|
|
3182
|
-
|
|
3183
|
-
// src/mcp.ts
|
|
3184
|
-
import fs4 from "fs/promises";
|
|
3185
|
-
import path4 from "path";
|
|
3186
|
-
|
|
3187
|
-
// ../../node_modules/.bun/@bunli+plugin-mcp@0.2.5+ef72ce197b058209/node_modules/@bunli/plugin-mcp/src/errors.ts
|
|
3188
|
-
class SchemaConversionError extends TaggedError("SchemaConversionError")() {
|
|
3189
|
-
}
|
|
3190
|
-
|
|
3191
|
-
class ConvertToolsError extends TaggedError("ConvertToolsError")() {
|
|
3192
|
-
}
|
|
3193
|
-
|
|
3194
|
-
class GenerateMCPTypesError extends TaggedError("GenerateMCPTypesError")() {
|
|
3195
|
-
}
|
|
3196
|
-
|
|
3197
|
-
class McpToolsProviderError extends TaggedError("McpToolsProviderError")() {
|
|
3198
|
-
}
|
|
3199
|
-
|
|
3200
|
-
// ../../node_modules/.bun/@bunli+plugin-mcp@0.2.5+ef72ce197b058209/node_modules/@bunli/plugin-mcp/src/schema-to-zod.ts
|
|
3201
|
-
function jsonSchemaToZodSchema(schema, options = {}) {
|
|
3202
|
-
return convertSchema(schema, options, "$");
|
|
3203
|
-
}
|
|
3204
|
-
function convertSchema(schema, options, path4) {
|
|
3205
|
-
const { coerce = true } = options;
|
|
3206
|
-
if (!schema || typeof schema !== "object") {
|
|
3207
|
-
return Result.ok(exports_external.unknown());
|
|
3208
|
-
}
|
|
3209
|
-
if (schema.const !== undefined) {
|
|
3210
|
-
return Result.ok(exports_external.literal(schema.const));
|
|
3211
|
-
}
|
|
3212
|
-
if (schema.enum && schema.enum.length > 0) {
|
|
3213
|
-
const enumValues = schema.enum.filter((v) => v !== null);
|
|
3214
|
-
if (enumValues.length > 0) {
|
|
3215
|
-
if (enumValues.every((v) => typeof v === "string")) {
|
|
3216
|
-
return Result.ok(exports_external.enum(enumValues));
|
|
3217
|
-
}
|
|
3218
|
-
const literals = enumValues.map((v) => exports_external.literal(v));
|
|
3219
|
-
return unionFromSchemas(literals, path4);
|
|
3220
|
-
}
|
|
3221
|
-
}
|
|
3222
|
-
if (schema.anyOf && schema.anyOf.length > 0) {
|
|
3223
|
-
const schemas = mapSchemas(schema.anyOf, options, `${path4}.anyOf`);
|
|
3224
|
-
if (Result.isError(schemas)) {
|
|
3225
|
-
return schemas;
|
|
3226
|
-
}
|
|
3227
|
-
return unionFromSchemas(schemas.value, `${path4}.anyOf`);
|
|
3228
|
-
}
|
|
3229
|
-
if (schema.oneOf && schema.oneOf.length > 0) {
|
|
3230
|
-
const schemas = mapSchemas(schema.oneOf, options, `${path4}.oneOf`);
|
|
3231
|
-
if (Result.isError(schemas)) {
|
|
3232
|
-
return schemas;
|
|
3233
|
-
}
|
|
3234
|
-
return unionFromSchemas(schemas.value, `${path4}.oneOf`);
|
|
3235
|
-
}
|
|
3236
|
-
const schemaType = Array.isArray(schema.type) ? schema.type[0] : schema.type;
|
|
3237
|
-
switch (schemaType) {
|
|
3238
|
-
case "string":
|
|
3239
|
-
return buildStringSchema(schema, path4);
|
|
3240
|
-
case "number":
|
|
3241
|
-
case "integer":
|
|
3242
|
-
return Result.ok(buildNumberSchema(schema, coerce));
|
|
3243
|
-
case "boolean":
|
|
3244
|
-
return Result.ok(buildBooleanSchema());
|
|
3245
|
-
case "array":
|
|
3246
|
-
return buildArraySchema(schema, options, path4);
|
|
3247
|
-
case "object":
|
|
3248
|
-
return buildObjectSchema(schema, options, path4);
|
|
3249
|
-
case "null":
|
|
3250
|
-
return Result.ok(exports_external.null());
|
|
3251
|
-
default:
|
|
3252
|
-
if (schema.properties) {
|
|
3253
|
-
return buildObjectSchema(schema, options, path4);
|
|
3254
|
-
}
|
|
3255
|
-
if (schema.items) {
|
|
3256
|
-
return buildArraySchema(schema, options, path4);
|
|
3257
|
-
}
|
|
3258
|
-
return Result.ok(exports_external.unknown());
|
|
3259
|
-
}
|
|
3260
|
-
}
|
|
3261
|
-
function buildStringSchema(schema, path4) {
|
|
3262
|
-
let zodSchema = exports_external.string();
|
|
3263
|
-
if (schema.minLength !== undefined) {
|
|
3264
|
-
zodSchema = zodSchema.min(schema.minLength);
|
|
3265
|
-
}
|
|
3266
|
-
if (schema.maxLength !== undefined) {
|
|
3267
|
-
zodSchema = zodSchema.max(schema.maxLength);
|
|
3268
|
-
}
|
|
3269
|
-
if (schema.pattern) {
|
|
3270
|
-
const pattern = schema.pattern;
|
|
3271
|
-
const regexResult = Result.try({
|
|
3272
|
-
try: () => new RegExp(pattern),
|
|
3273
|
-
catch: (cause) => new SchemaConversionError({
|
|
3274
|
-
path: path4,
|
|
3275
|
-
message: `Invalid regex pattern "${pattern}"`,
|
|
3276
|
-
cause
|
|
3277
|
-
})
|
|
3278
|
-
});
|
|
3279
|
-
if (Result.isError(regexResult)) {
|
|
3280
|
-
return regexResult;
|
|
3281
|
-
}
|
|
3282
|
-
zodSchema = zodSchema.regex(regexResult.value);
|
|
3283
|
-
}
|
|
3284
|
-
if (schema.format) {
|
|
3285
|
-
switch (schema.format) {
|
|
3286
|
-
case "email":
|
|
3287
|
-
zodSchema = zodSchema.email();
|
|
3288
|
-
break;
|
|
3289
|
-
case "uri":
|
|
3290
|
-
case "url":
|
|
3291
|
-
zodSchema = zodSchema.url();
|
|
3292
|
-
break;
|
|
3293
|
-
case "uuid":
|
|
3294
|
-
zodSchema = zodSchema.uuid();
|
|
3295
|
-
break;
|
|
3296
|
-
case "date-time":
|
|
3297
|
-
zodSchema = zodSchema.datetime();
|
|
3298
|
-
break;
|
|
3299
|
-
case "date":
|
|
3300
|
-
zodSchema = zodSchema.date();
|
|
3301
|
-
break;
|
|
3302
|
-
}
|
|
3303
|
-
}
|
|
3304
|
-
return Result.ok(zodSchema);
|
|
3305
|
-
}
|
|
3306
|
-
function buildNumberSchema(schema, coerce) {
|
|
3307
|
-
let zodSchema = coerce ? exports_external.coerce.number() : exports_external.number();
|
|
3308
|
-
if (schema.type === "integer" || Array.isArray(schema.type) && schema.type.includes("integer")) {
|
|
3309
|
-
zodSchema = zodSchema.int();
|
|
3310
|
-
}
|
|
3311
|
-
if (schema.minimum !== undefined) {
|
|
3312
|
-
zodSchema = zodSchema.min(schema.minimum);
|
|
3313
|
-
}
|
|
3314
|
-
if (schema.maximum !== undefined) {
|
|
3315
|
-
zodSchema = zodSchema.max(schema.maximum);
|
|
3316
|
-
}
|
|
3317
|
-
if (schema.exclusiveMinimum !== undefined) {
|
|
3318
|
-
zodSchema = zodSchema.gt(schema.exclusiveMinimum);
|
|
3319
|
-
}
|
|
3320
|
-
if (schema.exclusiveMaximum !== undefined) {
|
|
3321
|
-
zodSchema = zodSchema.lt(schema.exclusiveMaximum);
|
|
3322
|
-
}
|
|
3323
|
-
if (schema.multipleOf !== undefined) {
|
|
3324
|
-
zodSchema = zodSchema.multipleOf(schema.multipleOf);
|
|
3325
|
-
}
|
|
3326
|
-
return zodSchema;
|
|
3327
|
-
}
|
|
3328
|
-
function buildBooleanSchema() {
|
|
3329
|
-
return exports_external.boolean();
|
|
3330
|
-
}
|
|
3331
|
-
function buildArraySchema(schema, options, path4) {
|
|
3332
|
-
let itemSchema = exports_external.unknown();
|
|
3333
|
-
if (schema.items) {
|
|
3334
|
-
if (Array.isArray(schema.items)) {
|
|
3335
|
-
if (schema.items.length > 0) {
|
|
3336
|
-
const itemResult = convertSchema(schema.items[0], options, `${path4}.items[0]`);
|
|
3337
|
-
if (Result.isError(itemResult)) {
|
|
3338
|
-
return itemResult;
|
|
3339
|
-
}
|
|
3340
|
-
itemSchema = itemResult.value;
|
|
3341
|
-
}
|
|
3342
|
-
} else {
|
|
3343
|
-
const itemResult = convertSchema(schema.items, options, `${path4}.items`);
|
|
3344
|
-
if (Result.isError(itemResult)) {
|
|
3345
|
-
return itemResult;
|
|
3346
|
-
}
|
|
3347
|
-
itemSchema = itemResult.value;
|
|
3348
|
-
}
|
|
3349
|
-
}
|
|
3350
|
-
let zodSchema = exports_external.array(itemSchema);
|
|
3351
|
-
if (schema.minItems !== undefined) {
|
|
3352
|
-
zodSchema = zodSchema.min(schema.minItems);
|
|
3353
|
-
}
|
|
3354
|
-
if (schema.maxItems !== undefined) {
|
|
3355
|
-
zodSchema = zodSchema.max(schema.maxItems);
|
|
3356
|
-
}
|
|
3357
|
-
return Result.ok(zodSchema);
|
|
3358
|
-
}
|
|
3359
|
-
function buildObjectSchema(schema, options, path4) {
|
|
3360
|
-
if (!schema.properties) {
|
|
3361
|
-
return Result.ok(exports_external.record(exports_external.string(), exports_external.unknown()));
|
|
3362
|
-
}
|
|
3363
|
-
const shape = {};
|
|
3364
|
-
const requiredFields = new Set(schema.required || []);
|
|
3365
|
-
for (const [propName, propSchema] of Object.entries(schema.properties)) {
|
|
3366
|
-
const propResult = convertSchema(propSchema, options, `${path4}.properties.${propName}`);
|
|
3367
|
-
if (Result.isError(propResult)) {
|
|
3368
|
-
return propResult;
|
|
3369
|
-
}
|
|
3370
|
-
let propZodSchema = propResult.value;
|
|
3371
|
-
if (propSchema.default !== undefined) {
|
|
3372
|
-
propZodSchema = propZodSchema.default(propSchema.default);
|
|
3373
|
-
}
|
|
3374
|
-
if (!requiredFields.has(propName)) {
|
|
3375
|
-
propZodSchema = propZodSchema.optional();
|
|
3376
|
-
}
|
|
3377
|
-
shape[propName] = propZodSchema;
|
|
3378
|
-
}
|
|
3379
|
-
return Result.ok(exports_external.object(shape));
|
|
3380
|
-
}
|
|
3381
|
-
function mapSchemas(schemas, options, path4) {
|
|
3382
|
-
const zodSchemas = [];
|
|
3383
|
-
for (let index = 0;index < schemas.length; index += 1) {
|
|
3384
|
-
const converted = convertSchema(schemas[index], options, `${path4}[${index}]`);
|
|
3385
|
-
if (Result.isError(converted)) {
|
|
3386
|
-
return converted;
|
|
3387
|
-
}
|
|
3388
|
-
zodSchemas.push(converted.value);
|
|
3389
|
-
}
|
|
3390
|
-
return Result.ok(zodSchemas);
|
|
3391
|
-
}
|
|
3392
|
-
function unionFromSchemas(schemas, path4) {
|
|
3393
|
-
if (schemas.length === 0) {
|
|
3394
|
-
return Result.err(new SchemaConversionError({
|
|
3395
|
-
path: path4,
|
|
3396
|
-
message: `Cannot create union from an empty schema set at ${path4}`,
|
|
3397
|
-
cause: new Error("Empty schema union")
|
|
3398
|
-
}));
|
|
3399
|
-
}
|
|
3400
|
-
if (schemas.length === 1) {
|
|
3401
|
-
return Result.ok(schemas[0]);
|
|
3402
|
-
}
|
|
3403
|
-
let unionSchema = exports_external.union([schemas[0], schemas[1]]);
|
|
3404
|
-
for (let index = 2;index < schemas.length; index += 1) {
|
|
3405
|
-
unionSchema = exports_external.union([unionSchema, schemas[index]]);
|
|
3406
|
-
}
|
|
3407
|
-
return Result.ok(unionSchema);
|
|
3408
|
-
}
|
|
3409
|
-
|
|
3410
|
-
// ../../node_modules/.bun/@bunli+plugin-mcp@0.2.5+ef72ce197b058209/node_modules/@bunli/plugin-mcp/src/utils.ts
|
|
3411
|
-
function toKebabCase(str) {
|
|
3412
|
-
return str.replace(/_/g, "-").replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
3413
|
-
}
|
|
3414
|
-
function toCommandName(toolName, namespace) {
|
|
3415
|
-
const kebabName = toKebabCase(toolName);
|
|
3416
|
-
return namespace ? `${namespace}:${kebabName}` : kebabName;
|
|
3417
|
-
}
|
|
3418
|
-
function toFlagName(propName) {
|
|
3419
|
-
return toKebabCase(propName);
|
|
3420
|
-
}
|
|
3421
|
-
function toPascalCase(str) {
|
|
3422
|
-
return str.split(/[-:_]/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()).join("");
|
|
3423
|
-
}
|
|
3424
|
-
function escapeString(str) {
|
|
3425
|
-
return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/"/g, "\\\"").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
|
|
3426
|
-
}
|
|
3427
|
-
|
|
3428
|
-
// ../../node_modules/.bun/@bunli+plugin-mcp@0.2.5+ef72ce197b058209/node_modules/@bunli/plugin-mcp/src/converter.ts
|
|
3429
|
-
function createCommandsFromMCPTools(tools, options) {
|
|
3430
|
-
const commands = [];
|
|
3431
|
-
for (const tool of tools) {
|
|
3432
|
-
const converted = convertToolToCommand(tool, options);
|
|
3433
|
-
if (Result.isError(converted)) {
|
|
3434
|
-
return converted;
|
|
3435
|
-
}
|
|
3436
|
-
commands.push(converted.value);
|
|
3437
|
-
}
|
|
3438
|
-
return Result.ok(commands);
|
|
3439
|
-
}
|
|
3440
|
-
function convertToolToCommand(tool, options) {
|
|
3441
|
-
const {
|
|
3442
|
-
namespace,
|
|
3443
|
-
createHandler,
|
|
3444
|
-
commandName: customCommandName,
|
|
3445
|
-
flagName: customFlagName
|
|
3446
|
-
} = options;
|
|
3447
|
-
const commandName = customCommandName ? customCommandName(tool.name) : toCommandName(tool.name, namespace);
|
|
3448
|
-
const bunliOptionsResult = convertInputSchemaToOptions(tool.name, tool.inputSchema, customFlagName || toFlagName);
|
|
3449
|
-
if (Result.isError(bunliOptionsResult)) {
|
|
3450
|
-
return bunliOptionsResult;
|
|
3451
|
-
}
|
|
3452
|
-
const command = {
|
|
3453
|
-
name: commandName,
|
|
3454
|
-
description: tool.description || `Invoke MCP tool: ${tool.name}`,
|
|
3455
|
-
options: bunliOptionsResult.value,
|
|
3456
|
-
handler: createHandler(tool.name)
|
|
3457
|
-
};
|
|
3458
|
-
return Result.ok(command);
|
|
3459
|
-
}
|
|
3460
|
-
function convertInputSchemaToOptions(toolName, inputSchema, flagNameTransform) {
|
|
3461
|
-
const bunliOptions = {};
|
|
3462
|
-
if (!inputSchema?.properties) {
|
|
3463
|
-
return Result.ok(bunliOptions);
|
|
3464
|
-
}
|
|
3465
|
-
const requiredFields = new Set(inputSchema.required || []);
|
|
3466
|
-
for (const [propName, propSchema] of Object.entries(inputSchema.properties)) {
|
|
3467
|
-
const schemaResult = jsonSchemaToZodSchema(propSchema, { coerce: true });
|
|
3468
|
-
if (Result.isError(schemaResult)) {
|
|
3469
|
-
return Result.err(new ConvertToolsError({
|
|
3470
|
-
toolName,
|
|
3471
|
-
message: `Failed to convert input schema field "${propName}" for tool "${toolName}"`,
|
|
3472
|
-
cause: schemaResult.error
|
|
3473
|
-
}));
|
|
3474
|
-
}
|
|
3475
|
-
let zodSchema = schemaResult.value;
|
|
3476
|
-
if (propSchema.default !== undefined) {
|
|
3477
|
-
zodSchema = zodSchema.default(propSchema.default);
|
|
3478
|
-
}
|
|
3479
|
-
if (!requiredFields.has(propName)) {
|
|
3480
|
-
zodSchema = zodSchema.optional();
|
|
3481
|
-
}
|
|
3482
|
-
const flagName = flagNameTransform(propName);
|
|
3483
|
-
const shortMatch = propSchema.description?.match(/^\[-([a-zA-Z])\]\s*/);
|
|
3484
|
-
const short = shortMatch ? shortMatch[1] : undefined;
|
|
3485
|
-
const description = shortMatch ? propSchema.description?.slice(shortMatch[0].length) : propSchema.description;
|
|
3486
|
-
bunliOptions[flagName] = option(zodSchema, {
|
|
3487
|
-
description,
|
|
3488
|
-
short
|
|
3489
|
-
});
|
|
3490
|
-
}
|
|
3491
|
-
return Result.ok(bunliOptions);
|
|
3492
|
-
}
|
|
3493
|
-
function extractCommandMetadata(tool, namespace, flagNameTransform = toFlagName) {
|
|
3494
|
-
const commandName = toCommandName(tool.name, namespace);
|
|
3495
|
-
const optionsMeta = {};
|
|
3496
|
-
if (tool.inputSchema?.properties) {
|
|
3497
|
-
const requiredFields = new Set(tool.inputSchema.required || []);
|
|
3498
|
-
for (const [propName, propSchema] of Object.entries(tool.inputSchema.properties)) {
|
|
3499
|
-
const flagName = flagNameTransform(propName);
|
|
3500
|
-
const schemaType = Array.isArray(propSchema.type) ? propSchema.type[0] : propSchema.type;
|
|
3501
|
-
const shortMatch = propSchema.description?.match(/^\[-([a-zA-Z])\]\s*/);
|
|
3502
|
-
const short = shortMatch ? shortMatch[1] : undefined;
|
|
3503
|
-
const description = shortMatch ? propSchema.description?.slice(shortMatch[0].length) : propSchema.description;
|
|
3504
|
-
optionsMeta[flagName] = {
|
|
3505
|
-
type: schemaType || "unknown",
|
|
3506
|
-
required: requiredFields.has(propName) && propSchema.default === undefined,
|
|
3507
|
-
description,
|
|
3508
|
-
short,
|
|
3509
|
-
hasDefault: propSchema.default !== undefined,
|
|
3510
|
-
default: propSchema.default
|
|
3511
|
-
};
|
|
3512
|
-
if (propSchema.enum) {
|
|
3513
|
-
optionsMeta[flagName].enumValues = propSchema.enum.filter((v) => typeof v === "string" || typeof v === "number");
|
|
3514
|
-
}
|
|
3515
|
-
if (propSchema.minimum !== undefined) {
|
|
3516
|
-
optionsMeta[flagName].minimum = propSchema.minimum;
|
|
3517
|
-
}
|
|
3518
|
-
if (propSchema.maximum !== undefined) {
|
|
3519
|
-
optionsMeta[flagName].maximum = propSchema.maximum;
|
|
3520
|
-
}
|
|
3521
|
-
}
|
|
3522
|
-
}
|
|
3523
|
-
return {
|
|
3524
|
-
name: commandName,
|
|
3525
|
-
toolName: tool.name,
|
|
3526
|
-
namespace,
|
|
3527
|
-
description: tool.description,
|
|
3528
|
-
options: optionsMeta
|
|
3529
|
-
};
|
|
3530
|
-
}
|
|
3531
|
-
// ../../node_modules/.bun/@bunli+plugin-mcp@0.2.5+ef72ce197b058209/node_modules/@bunli/plugin-mcp/src/codegen.ts
|
|
3532
|
-
import { mkdir, writeFile } from "fs/promises";
|
|
3533
|
-
import { join as join2 } from "path";
|
|
3534
|
-
async function generateMCPTypes(options) {
|
|
3535
|
-
const { tools, outputDir } = options;
|
|
3536
|
-
return await Result.tryPromise({
|
|
3537
|
-
try: async () => {
|
|
3538
|
-
await mkdir(outputDir, { recursive: true });
|
|
3539
|
-
for (const { namespace, tools: toolList } of tools) {
|
|
3540
|
-
if (!toolList || toolList.length === 0)
|
|
3541
|
-
continue;
|
|
3542
|
-
const content = generateNamespaceTypes(namespace, toolList);
|
|
3543
|
-
const fileName = `mcp-${namespace}.gen.ts`;
|
|
3544
|
-
const filePath = join2(outputDir, fileName);
|
|
3545
|
-
await writeFile(filePath, content, "utf-8");
|
|
3546
|
-
}
|
|
3547
|
-
const indexContent = generateIndexFile(tools);
|
|
3548
|
-
await writeFile(join2(outputDir, "mcp-index.gen.ts"), indexContent, "utf-8");
|
|
3549
|
-
},
|
|
3550
|
-
catch: (cause) => new GenerateMCPTypesError({
|
|
3551
|
-
outputDir,
|
|
3552
|
-
message: `Failed to generate MCP types in ${outputDir}`,
|
|
3553
|
-
cause
|
|
3554
|
-
})
|
|
3555
|
-
});
|
|
3556
|
-
}
|
|
3557
|
-
function generateNamespaceTypes(namespace, tools) {
|
|
3558
|
-
const lines = [];
|
|
3559
|
-
lines.push(`// This file was automatically generated by @bunli/plugin-mcp`);
|
|
3560
|
-
lines.push(`// DO NOT EDIT - changes will be overwritten`);
|
|
3561
|
-
lines.push(``);
|
|
3562
|
-
lines.push(`import type { Command, Options, CLIOption } from '@bunli/core'`);
|
|
3563
|
-
lines.push(`import { option } from '@bunli/core'`);
|
|
3564
|
-
lines.push(`import { z } from 'zod'`);
|
|
3565
|
-
lines.push(``);
|
|
3566
|
-
const metadata = tools.map((tool) => extractCommandMetadata(tool, namespace));
|
|
3567
|
-
for (const cmd of metadata) {
|
|
3568
|
-
lines.push(generateCommandSchema(cmd));
|
|
3569
|
-
lines.push(``);
|
|
3570
|
-
}
|
|
3571
|
-
lines.push(generateModuleAugmentation(namespace, metadata));
|
|
3572
|
-
return lines.join(`
|
|
3573
|
-
`);
|
|
3574
|
-
}
|
|
3575
|
-
function generateCommandSchema(cmd) {
|
|
3576
|
-
const lines = [];
|
|
3577
|
-
const baseName = toPascalCase(cmd.name);
|
|
3578
|
-
lines.push(`// ${cmd.description || cmd.toolName}`);
|
|
3579
|
-
lines.push(`export const ${baseName}Options = {`);
|
|
3580
|
-
for (const [flagName, opt] of Object.entries(cmd.options)) {
|
|
3581
|
-
const zodSchema = generateZodSchemaString(opt);
|
|
3582
|
-
const metadata = [];
|
|
3583
|
-
if (opt.description) {
|
|
3584
|
-
metadata.push(`description: '${escapeString(opt.description)}'`);
|
|
3585
|
-
}
|
|
3586
|
-
if (opt.short) {
|
|
3587
|
-
metadata.push(`short: '${opt.short}'`);
|
|
3588
|
-
}
|
|
3589
|
-
const metadataStr = metadata.length > 0 ? `, { ${metadata.join(", ")} }` : "";
|
|
3590
|
-
lines.push(` '${flagName}': option(${zodSchema}${metadataStr}),`);
|
|
3591
|
-
}
|
|
3592
|
-
lines.push(`} as const`);
|
|
3593
|
-
lines.push(``);
|
|
3594
|
-
lines.push(`export type ${baseName}Flags = {`);
|
|
3595
|
-
for (const [flagName, opt] of Object.entries(cmd.options)) {
|
|
3596
|
-
const tsType = jsonSchemaTypeToTS(opt.type, opt.enumValues);
|
|
3597
|
-
const optional = !opt.required ? "?" : "";
|
|
3598
|
-
lines.push(` '${flagName}'${optional}: ${tsType}`);
|
|
3599
|
-
}
|
|
3600
|
-
lines.push(`}`);
|
|
3601
|
-
return lines.join(`
|
|
3602
|
-
`);
|
|
3603
|
-
}
|
|
3604
|
-
function generateZodSchemaString(opt) {
|
|
3605
|
-
let schema;
|
|
3606
|
-
if (opt.enumValues && opt.enumValues.length > 0) {
|
|
3607
|
-
if (opt.enumValues.every((v) => typeof v === "string")) {
|
|
3608
|
-
const values = opt.enumValues.map((v) => `'${escapeString(v)}'`).join(", ");
|
|
3609
|
-
schema = `z.enum([${values}])`;
|
|
3610
|
-
} else {
|
|
3611
|
-
const literals = opt.enumValues.map((v) => typeof v === "string" ? `z.literal('${escapeString(v)}')` : `z.literal(${v})`).join(", ");
|
|
3612
|
-
schema = `z.union([${literals}])`;
|
|
3613
|
-
}
|
|
3614
|
-
} else {
|
|
3615
|
-
switch (opt.type) {
|
|
3616
|
-
case "string":
|
|
3617
|
-
schema = "z.string()";
|
|
3618
|
-
break;
|
|
3619
|
-
case "number":
|
|
3620
|
-
schema = "z.coerce.number()";
|
|
3621
|
-
break;
|
|
3622
|
-
case "integer":
|
|
3623
|
-
schema = "z.coerce.number().int()";
|
|
3624
|
-
break;
|
|
3625
|
-
case "boolean":
|
|
3626
|
-
schema = "z.boolean()";
|
|
3627
|
-
break;
|
|
3628
|
-
case "array":
|
|
3629
|
-
schema = "z.array(z.unknown())";
|
|
3630
|
-
break;
|
|
3631
|
-
case "object":
|
|
3632
|
-
schema = "z.record(z.unknown())";
|
|
3633
|
-
break;
|
|
3634
|
-
default:
|
|
3635
|
-
schema = "z.unknown()";
|
|
3636
|
-
}
|
|
3637
|
-
}
|
|
3638
|
-
if (opt.minimum !== undefined) {
|
|
3639
|
-
schema += `.min(${opt.minimum})`;
|
|
3640
|
-
}
|
|
3641
|
-
if (opt.maximum !== undefined) {
|
|
3642
|
-
schema += `.max(${opt.maximum})`;
|
|
3643
|
-
}
|
|
3644
|
-
if (opt.hasDefault && opt.default !== undefined) {
|
|
3645
|
-
const defaultVal = typeof opt.default === "string" ? `'${escapeString(opt.default)}'` : JSON.stringify(opt.default);
|
|
3646
|
-
schema += `.default(${defaultVal})`;
|
|
3647
|
-
}
|
|
3648
|
-
if (!opt.required && !opt.hasDefault) {
|
|
3649
|
-
schema += ".optional()";
|
|
3650
|
-
}
|
|
3651
|
-
return schema;
|
|
3652
|
-
}
|
|
3653
|
-
function jsonSchemaTypeToTS(type, enumValues) {
|
|
3654
|
-
if (enumValues && enumValues.length > 0) {
|
|
3655
|
-
return enumValues.map((v) => typeof v === "string" ? `'${escapeString(v)}'` : String(v)).join(" | ");
|
|
3656
|
-
}
|
|
3657
|
-
switch (type) {
|
|
3658
|
-
case "string":
|
|
3659
|
-
return "string";
|
|
3660
|
-
case "number":
|
|
3661
|
-
case "integer":
|
|
3662
|
-
return "number";
|
|
3663
|
-
case "boolean":
|
|
3664
|
-
return "boolean";
|
|
3665
|
-
case "array":
|
|
3666
|
-
return "unknown[]";
|
|
3667
|
-
case "object":
|
|
3668
|
-
return "Record<string, unknown>";
|
|
3669
|
-
case "null":
|
|
3670
|
-
return "null";
|
|
3671
|
-
default:
|
|
3672
|
-
return "unknown";
|
|
3673
|
-
}
|
|
3674
|
-
}
|
|
3675
|
-
function generateModuleAugmentation(namespace, metadata) {
|
|
3676
|
-
const lines = [];
|
|
3677
|
-
lines.push(`// Module augmentation for type-safe execute()`);
|
|
3678
|
-
lines.push(`declare module '@bunli/core' {`);
|
|
3679
|
-
lines.push(` interface RegisteredCommands {`);
|
|
3680
|
-
for (const cmd of metadata) {
|
|
3681
|
-
const baseName = toPascalCase(cmd.name);
|
|
3682
|
-
lines.push(` '${cmd.name}': Command<typeof ${baseName}Options>`);
|
|
3683
|
-
}
|
|
3684
|
-
lines.push(` }`);
|
|
3685
|
-
lines.push(`}`);
|
|
3686
|
-
return lines.join(`
|
|
3687
|
-
`);
|
|
3688
|
-
}
|
|
3689
|
-
function generateIndexFile(toolGroups) {
|
|
3690
|
-
const lines = [];
|
|
3691
|
-
lines.push(`// This file was automatically generated by @bunli/plugin-mcp`);
|
|
3692
|
-
lines.push(`// DO NOT EDIT - changes will be overwritten`);
|
|
3693
|
-
lines.push(``);
|
|
3694
|
-
for (const { namespace } of toolGroups) {
|
|
3695
|
-
if (!namespace)
|
|
3696
|
-
continue;
|
|
3697
|
-
lines.push(`export * from './mcp-${namespace}.gen.js'`);
|
|
3698
|
-
}
|
|
3699
|
-
return lines.join(`
|
|
3700
|
-
`);
|
|
3701
|
-
}
|
|
3702
|
-
// src/mcp.ts
|
|
3703
|
-
function isObject(value) {
|
|
3704
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3705
|
-
}
|
|
3706
|
-
function isTool(value) {
|
|
3707
|
-
return isObject(value) && typeof value.name === "string" && (value.description === undefined || typeof value.description === "string");
|
|
3708
|
-
}
|
|
3709
|
-
function isToolGroup(value) {
|
|
3710
|
-
return isObject(value) && typeof value.namespace === "string" && Array.isArray(value.tools) && value.tools.every(isTool);
|
|
3711
|
-
}
|
|
3712
|
-
function getErrorMessage(error) {
|
|
3713
|
-
return error instanceof Error ? error.message : String(error);
|
|
3714
|
-
}
|
|
3715
|
-
function getErrorCauseOptions(error) {
|
|
3716
|
-
return error instanceof Error ? { cause: error } : undefined;
|
|
3717
|
-
}
|
|
3718
|
-
async function readSchemaSource(cwd, source) {
|
|
3719
|
-
const schemaPath = path4.resolve(cwd, source.path);
|
|
3720
|
-
const raw = await fs4.readFile(schemaPath, "utf8");
|
|
3721
|
-
let parsed;
|
|
3722
|
-
try {
|
|
3723
|
-
parsed = JSON.parse(raw);
|
|
3724
|
-
} catch (error) {
|
|
3725
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `Schema source "${source.path}" must contain valid JSON. ${getErrorMessage(error)}`, getErrorCauseOptions(error));
|
|
3726
|
-
}
|
|
3727
|
-
if (isToolGroup(parsed)) {
|
|
3728
|
-
return parsed;
|
|
3729
|
-
}
|
|
3730
|
-
if (Array.isArray(parsed) && parsed.every(isTool)) {
|
|
3731
|
-
return {
|
|
3732
|
-
namespace: source.namespace,
|
|
3733
|
-
tools: parsed
|
|
3734
|
-
};
|
|
3735
|
-
}
|
|
3736
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `Schema source "${source.path}" must contain either one MCPToolGroup object or an array of MCP tools.`);
|
|
3737
|
-
}
|
|
3738
|
-
async function loadMcpToolGroups(cwd, schemaSources) {
|
|
3739
|
-
return Promise.all(schemaSources.map((source) => readSchemaSource(cwd, source)));
|
|
3740
|
-
}
|
|
3741
|
-
async function syncMcpSchemas(cwd, schemaSources, outputDir = path4.join(cwd, ".bunli", "mcp")) {
|
|
3742
|
-
const groups = await loadMcpToolGroups(cwd, schemaSources);
|
|
3743
|
-
const result = await generateMCPTypes({
|
|
3744
|
-
outputDir,
|
|
3745
|
-
tools: groups
|
|
3746
|
-
});
|
|
3747
|
-
if (Result.isError(result)) {
|
|
3748
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, getErrorMessage(result.error), getErrorCauseOptions(result.error));
|
|
3749
|
-
}
|
|
3750
|
-
const registry = groups.map((group) => ({
|
|
3751
|
-
namespace: group.namespace,
|
|
3752
|
-
tools: group.tools.map((tool) => extractCommandMetadata(tool, group.namespace))
|
|
3753
|
-
}));
|
|
3754
|
-
for (const group of groups) {
|
|
3755
|
-
const convert = createCommandsFromMCPTools(group.tools, {
|
|
3756
|
-
createHandler: () => async () => {},
|
|
3757
|
-
namespace: group.namespace
|
|
3758
|
-
});
|
|
3759
|
-
if (Result.isError(convert)) {
|
|
3760
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, getErrorMessage(convert.error), getErrorCauseOptions(convert.error));
|
|
3761
|
-
}
|
|
3762
|
-
}
|
|
3763
|
-
await fs4.mkdir(outputDir, { recursive: true });
|
|
3764
|
-
await fs4.writeFile(path4.join(outputDir, "registry.json"), `${JSON.stringify(registry, null, 2)}
|
|
3765
|
-
`, "utf8");
|
|
3766
|
-
return {
|
|
3767
|
-
commandCount: registry.reduce((count, group) => count + group.tools.length, 0),
|
|
3768
|
-
groups,
|
|
3769
|
-
outputDir
|
|
3770
|
-
};
|
|
3771
|
-
}
|
|
3772
|
-
|
|
3773
|
-
// src/commands/mcp.ts
|
|
3774
|
-
function printMcpToolGroupSummary(summary, printLine) {
|
|
3775
|
-
for (const group of summary) {
|
|
3776
|
-
printLine(`${group.namespace} (${group.toolCount})`);
|
|
3777
|
-
for (const tool of group.tools) {
|
|
3778
|
-
printLine(` - ${tool}`);
|
|
3779
|
-
}
|
|
3780
|
-
}
|
|
3781
|
-
}
|
|
3782
|
-
function printMcpSyncSummary(result, printLine) {
|
|
3783
|
-
printLine(`Synced ${result.commandCount} MCP tools across ${result.groups.length} namespaces into ${result.outputDir}.`);
|
|
3784
|
-
}
|
|
3785
|
-
var mcpCommand = defineCommand({
|
|
3786
|
-
defaultFormat: "json",
|
|
3787
|
-
description: "Inspect or sync schema-driven MCP metadata for wp-typia.",
|
|
3788
|
-
handler: async (args) => {
|
|
3789
|
-
const subcommand = args.positional[0] ?? "list";
|
|
3790
|
-
const prefersStructuredOutput = prefersStructuredCliOutput(args);
|
|
3791
|
-
const printLine = resolveCommandPrintLine(args);
|
|
3792
|
-
const userConfig = args.context?.store?.wpTypiaUserConfig && typeof args.context.store.wpTypiaUserConfig === "object" ? args.context.store.wpTypiaUserConfig : {};
|
|
3793
|
-
const schemaSources = getMcpSchemaSources(userConfig);
|
|
3794
|
-
if (schemaSources.length === 0) {
|
|
3795
|
-
emitCliDiagnosticFailure(args, {
|
|
3796
|
-
code: CLI_DIAGNOSTIC_CODES.CONFIGURATION_MISSING,
|
|
3797
|
-
command: "mcp",
|
|
3798
|
-
detailLines: [
|
|
3799
|
-
"No MCP schema sources are configured. Add `mcp.schemaSources` in ~/.config/wp-typia/config.json, .wp-typiarc(.json), or package.json#wp-typia."
|
|
3800
|
-
]
|
|
3801
|
-
});
|
|
3802
|
-
return;
|
|
3803
|
-
}
|
|
3804
|
-
try {
|
|
3805
|
-
if (subcommand === "list") {
|
|
3806
|
-
const groups = await loadMcpToolGroups(args.cwd, schemaSources);
|
|
3807
|
-
const summary = groups.map((group) => ({
|
|
3808
|
-
namespace: group.namespace,
|
|
3809
|
-
toolCount: group.tools.length,
|
|
3810
|
-
tools: group.tools.map((tool) => tool.name)
|
|
3811
|
-
}));
|
|
3812
|
-
if (prefersStructuredOutput) {
|
|
3813
|
-
args.output({ groups: summary });
|
|
3814
|
-
return;
|
|
3815
|
-
}
|
|
3816
|
-
printMcpToolGroupSummary(summary, printLine);
|
|
3817
|
-
return;
|
|
3818
|
-
}
|
|
3819
|
-
if (subcommand === "sync") {
|
|
3820
|
-
const outputDir = args.flags["output-dir"] ?? `${args.cwd}/.bunli/mcp`;
|
|
3821
|
-
const result = await syncMcpSchemas(args.cwd, schemaSources, outputDir);
|
|
3822
|
-
if (prefersStructuredOutput) {
|
|
3823
|
-
args.output({ sync: result });
|
|
3824
|
-
return;
|
|
3825
|
-
}
|
|
3826
|
-
printMcpSyncSummary(result, printLine);
|
|
3827
|
-
return;
|
|
3828
|
-
}
|
|
3829
|
-
emitCliDiagnosticFailure(args, {
|
|
3830
|
-
code: CLI_DIAGNOSTIC_CODES.INVALID_COMMAND,
|
|
3831
|
-
command: "mcp",
|
|
3832
|
-
detailLines: [
|
|
3833
|
-
`Unknown mcp subcommand "${subcommand}". Expected list or sync.`
|
|
3834
|
-
]
|
|
3835
|
-
});
|
|
3836
|
-
} catch (error) {
|
|
3837
|
-
emitCliDiagnosticFailure(args, {
|
|
3838
|
-
command: "mcp",
|
|
3839
|
-
error
|
|
3840
|
-
});
|
|
3841
|
-
}
|
|
3842
|
-
},
|
|
3843
|
-
name: "mcp",
|
|
3844
|
-
options: buildCommandOptions(MCP_OPTION_METADATA)
|
|
3845
|
-
});
|
|
3846
|
-
|
|
3847
|
-
// src/commands/migrate.ts
|
|
3848
|
-
var import_react36 = __toESM(require_react(), 1);
|
|
3849
|
-
function loadMigrateFlow() {
|
|
3850
|
-
return import(resolveBundledModuleHref(import.meta.url, [
|
|
3851
|
-
"./ui/migrate-flow.js",
|
|
3852
|
-
"../ui/migrate-flow.js",
|
|
3853
|
-
"../ui/migrate-flow.tsx"
|
|
3854
|
-
], {
|
|
3855
|
-
moduleLabel: "the migrate-flow UI"
|
|
3856
|
-
})).then((module) => ({ default: module.MigrateFlow }));
|
|
3857
|
-
}
|
|
3858
|
-
var migrateOptions = buildCommandOptions(MIGRATE_OPTION_METADATA);
|
|
3859
|
-
var migrateCommand = defineCommand({
|
|
3860
|
-
defaultFormat: "toon",
|
|
3861
|
-
description: "Run migration workflows for migration-capable wp-typia projects.",
|
|
3862
|
-
handler: async (args) => {
|
|
3863
|
-
const printLine = resolveCommandPrintLine(args);
|
|
3864
|
-
try {
|
|
3865
|
-
await executeMigrateCommand({
|
|
3866
|
-
command: args.positional[0],
|
|
3867
|
-
cwd: args.cwd,
|
|
3868
|
-
flags: args.flags,
|
|
3869
|
-
printLine
|
|
3870
|
-
});
|
|
3871
|
-
} catch (error) {
|
|
3872
|
-
emitCliDiagnosticFailure(args, {
|
|
3873
|
-
command: "migrate",
|
|
3874
|
-
error
|
|
3875
|
-
});
|
|
3876
|
-
}
|
|
3877
|
-
},
|
|
3878
|
-
name: "migrate",
|
|
3879
|
-
options: migrateOptions,
|
|
3880
|
-
...supportsInteractiveTui() ? {
|
|
3881
|
-
render: (args) => {
|
|
3882
|
-
const initialValues = resolveCommandOptionValues(MIGRATE_OPTION_METADATA, {
|
|
3883
|
-
flags: args.flags
|
|
3884
|
-
});
|
|
3885
|
-
return import_react36.createElement(LazyFlow, {
|
|
3886
|
-
loader: loadMigrateFlow,
|
|
3887
|
-
props: {
|
|
3888
|
-
cwd: args.cwd,
|
|
3889
|
-
initialValues: {
|
|
3890
|
-
...initialValues,
|
|
3891
|
-
command: args.positional[0] ?? "plan",
|
|
3892
|
-
"to-migration-version": initialValues["to-migration-version"] ?? "current"
|
|
3893
|
-
}
|
|
3894
|
-
}
|
|
3895
|
-
});
|
|
3896
|
-
},
|
|
3897
|
-
tui: {
|
|
3898
|
-
renderer: {
|
|
3899
|
-
bufferMode: "alternate"
|
|
3900
|
-
}
|
|
3901
|
-
}
|
|
3902
|
-
} : {}
|
|
3903
|
-
});
|
|
3904
|
-
|
|
3905
|
-
// src/commands/sync.ts
|
|
3906
|
-
var syncCommand = defineCommand({
|
|
3907
|
-
description: "Run the generated-project sync workflow from a scaffolded project or official workspace root.",
|
|
3908
|
-
handler: async (args) => {
|
|
3909
|
-
const check = Boolean(args.flags.check);
|
|
3910
|
-
const dryRun = Boolean(args.flags["dry-run"]);
|
|
3911
|
-
const prefersStructuredOutput = prefersStructuredCliOutput(args);
|
|
3912
|
-
try {
|
|
3913
|
-
const target = resolveSyncExecutionTarget(args.positional[0]);
|
|
3914
|
-
const sync = await executeSyncCommand({
|
|
3915
|
-
captureOutput: prefersStructuredOutput && !dryRun,
|
|
3916
|
-
check,
|
|
3917
|
-
cwd: args.cwd,
|
|
3918
|
-
dryRun,
|
|
3919
|
-
target
|
|
3920
|
-
});
|
|
3921
|
-
if (prefersStructuredOutput) {
|
|
3922
|
-
args.output({ sync });
|
|
3923
|
-
return;
|
|
3924
|
-
}
|
|
3925
|
-
if (dryRun) {
|
|
3926
|
-
printCompletionPayload(buildSyncDryRunPayload({
|
|
3927
|
-
check: sync.check,
|
|
3928
|
-
packageManager: sync.packageManager,
|
|
3929
|
-
plannedCommands: sync.plannedCommands,
|
|
3930
|
-
projectDir: sync.projectDir,
|
|
3931
|
-
target: sync.target
|
|
3932
|
-
}));
|
|
3933
|
-
}
|
|
3934
|
-
} catch (error) {
|
|
3935
|
-
emitCliDiagnosticFailure(args, {
|
|
3936
|
-
command: "sync",
|
|
3937
|
-
error
|
|
3938
|
-
});
|
|
3939
|
-
}
|
|
3940
|
-
},
|
|
3941
|
-
name: "sync",
|
|
3942
|
-
options: buildCommandOptions(SYNC_OPTION_METADATA)
|
|
3943
|
-
});
|
|
3944
|
-
|
|
3945
|
-
// src/commands/templates.ts
|
|
3946
|
-
var templatesCommand = defineCommand({
|
|
3947
|
-
defaultFormat: "json",
|
|
3948
|
-
description: "Inspect built-in and external scaffold templates.",
|
|
3949
|
-
handler: async (args) => {
|
|
3950
|
-
const subcommand = args.positional[0] ?? "list";
|
|
3951
|
-
const id = args.positional[1] ?? args.flags.id;
|
|
3952
|
-
const effectiveSubcommand = subcommand === "list" && typeof id === "string" && id.length > 0 ? "inspect" : subcommand;
|
|
3953
|
-
const prefersStructuredOutput = prefersStructuredCliOutput(args);
|
|
3954
|
-
const printLine = resolveCommandPrintLine(args);
|
|
3955
|
-
try {
|
|
3956
|
-
if (prefersStructuredOutput) {
|
|
3957
|
-
const templates = await listTemplatesForRuntime();
|
|
3958
|
-
if (effectiveSubcommand === "list") {
|
|
3959
|
-
args.output({ templates });
|
|
3960
|
-
return;
|
|
3961
|
-
}
|
|
3962
|
-
if (effectiveSubcommand === "inspect" && id) {
|
|
3963
|
-
const { getTemplateById } = await import("./cli-templates-g8t4fm11.js");
|
|
3964
|
-
let template;
|
|
3965
|
-
try {
|
|
3966
|
-
template = getTemplateById(id);
|
|
3967
|
-
} catch (lookupError) {
|
|
3968
|
-
const message = lookupError instanceof Error ? lookupError.message : String(lookupError);
|
|
3969
|
-
if (!message.startsWith("Unknown template")) {
|
|
3970
|
-
throw lookupError;
|
|
3971
|
-
}
|
|
3972
|
-
emitCliDiagnosticFailure(args, {
|
|
3973
|
-
code: CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT,
|
|
3974
|
-
command: "templates",
|
|
3975
|
-
detailLines: [`Unknown template "${id}".`]
|
|
3976
|
-
});
|
|
3977
|
-
return;
|
|
3978
|
-
}
|
|
3979
|
-
args.output({ template });
|
|
3980
|
-
return;
|
|
3981
|
-
}
|
|
3982
|
-
}
|
|
3983
|
-
await executeTemplatesCommand({
|
|
3984
|
-
flags: { id, subcommand: effectiveSubcommand }
|
|
3985
|
-
}, printLine);
|
|
3986
|
-
} catch (error) {
|
|
3987
|
-
emitCliDiagnosticFailure(args, {
|
|
3988
|
-
command: "templates",
|
|
3989
|
-
error
|
|
3990
|
-
});
|
|
3991
|
-
}
|
|
3992
|
-
},
|
|
3993
|
-
name: "templates",
|
|
3994
|
-
options: buildCommandOptions(TEMPLATES_OPTION_METADATA)
|
|
3995
|
-
});
|
|
3996
|
-
|
|
3997
|
-
// src/command-list.ts
|
|
3998
|
-
var WP_TYPIA_COMMANDS_BY_NAME = {
|
|
3999
|
-
add: addCommand,
|
|
4000
|
-
create: createCommand,
|
|
4001
|
-
doctor: doctorCommand,
|
|
4002
|
-
init: initCommand,
|
|
4003
|
-
mcp: mcpCommand,
|
|
4004
|
-
migrate: migrateCommand,
|
|
4005
|
-
sync: syncCommand,
|
|
4006
|
-
templates: templatesCommand
|
|
4007
|
-
};
|
|
4008
|
-
var wpTypiaCommands = WP_TYPIA_TOP_LEVEL_COMMAND_NAMES.map((commandName) => WP_TYPIA_COMMANDS_BY_NAME[commandName]);
|
|
4009
|
-
export {
|
|
4010
|
-
wpTypiaCommands
|
|
4011
|
-
};
|
|
4012
|
-
|
|
4013
|
-
//# debugId=3C2BF11DC520694164756E2164756E21
|