@t0.labs/daxta 1.1.8 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -26
- package/assets/viewer.html +37 -11
- package/dist/build/build-spec.d.ts +2 -0
- package/dist/build/build-spec.js +60 -12
- package/dist/build/incremental.d.ts +2 -0
- package/dist/build/incremental.js +6 -2
- package/dist/catalog/index.d.ts +2 -1
- package/dist/catalog/index.js +38 -3
- package/dist/catalog/it-case.js +16 -5
- package/dist/catalog/test-title.js +3 -0
- package/dist/cli/discover-test.js +24 -22
- package/dist/cli/inject-main.js +22 -22
- package/dist/cli/install.d.ts +1 -0
- package/dist/cli/install.js +20 -6
- package/dist/cli/main.js +282 -23
- package/dist/cli/test.js +9 -4
- package/dist/cli/titles.js +57 -35
- package/dist/cli/tree.js +230 -75
- package/dist/cli/ui.d.ts +18 -0
- package/dist/cli/ui.js +124 -1
- package/dist/cli/uninstall.js +5 -3
- package/dist/config.d.ts +31 -1
- package/dist/config.js +8 -0
- package/dist/export/postman.d.ts +150 -0
- package/dist/export/postman.js +351 -0
- package/dist/jest/reporter.js +1 -1
- package/dist/recorder/index.js +85 -9
- package/dist/setup.js +6 -0
- package/package.json +1 -1
package/dist/cli/tree.js
CHANGED
|
@@ -77,77 +77,124 @@ async function pickPath(flagPath) {
|
|
|
77
77
|
}
|
|
78
78
|
async function pickLayout(current) {
|
|
79
79
|
const sample = '/v1/admin/baskets/{id}/lock';
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
throw new Error(`Unknown layout: ${answer}`);
|
|
80
|
+
return (0, ui_1.selectMenu)({
|
|
81
|
+
title: 'Folder order',
|
|
82
|
+
subtitle: `sample: ${sample}`,
|
|
83
|
+
initialIndex: current === 'resource-role' ? 1 : 0,
|
|
84
|
+
options: [
|
|
85
|
+
{
|
|
86
|
+
value: 'role-resource',
|
|
87
|
+
label: 'role → resource',
|
|
88
|
+
badge: 'recommended',
|
|
89
|
+
preview: (0, config_edit_1.previewTree)(layoutSegments(sample, 'role-resource', true)),
|
|
90
|
+
hint: 'URL order — ops grouped under resource',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
value: 'resource-role',
|
|
94
|
+
label: 'resource → role',
|
|
95
|
+
preview: (0, config_edit_1.previewTree)(layoutSegments(sample, 'resource-role', true)),
|
|
96
|
+
hint: 'Resource first, then role',
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
});
|
|
101
100
|
}
|
|
102
101
|
async function pickSkipParams(current) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
102
|
+
return (0, ui_1.selectMenu)({
|
|
103
|
+
title: 'Stop folders at path params',
|
|
104
|
+
subtitle: 'Avoid {id} → complete / lock as nested folders',
|
|
105
|
+
initialIndex: current ? 0 : 1,
|
|
106
|
+
options: [
|
|
107
|
+
{
|
|
108
|
+
value: true,
|
|
109
|
+
label: 'Fold under resource',
|
|
110
|
+
badge: 'recommended',
|
|
111
|
+
hint: 'POST /baskets/{id}/lock stays under baskets',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
value: false,
|
|
115
|
+
label: 'Nest full path',
|
|
116
|
+
hint: 'Create folders for every URL segment',
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async function pickSubResourceMode(current, layout) {
|
|
122
|
+
const roleFirst = layout === 'role-resource';
|
|
123
|
+
return (0, ui_1.selectMenu)({
|
|
124
|
+
title: 'Sub-resources after main resource',
|
|
125
|
+
subtitle: 'e.g. /v1/public/shopping-cart/items/{id}/quantity',
|
|
126
|
+
initialIndex: current === 'merge' ? 0 : current === 'root' ? 1 : 2,
|
|
127
|
+
options: [
|
|
128
|
+
{
|
|
129
|
+
value: 'merge',
|
|
130
|
+
label: 'Merge into one folder (shopping-cart-items)',
|
|
131
|
+
badge: 'recommended',
|
|
132
|
+
preview: roleFirst ? 'v1 › public › shopping-cart-items' : 'v1 › shopping-cart-items › public',
|
|
133
|
+
hint: 'Joins sub-resources with "-" instead of opening extra subfolders',
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
value: 'root',
|
|
137
|
+
label: 'Group under main resource (shopping-cart)',
|
|
138
|
+
preview: roleFirst ? 'v1 › public › shopping-cart' : 'v1 › shopping-cart › public',
|
|
139
|
+
hint: 'Keeps all sub-routes directly under the main resource folder',
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
value: 'nested',
|
|
143
|
+
label: 'Keep nested subfolders (shopping-cart › items)',
|
|
144
|
+
preview: roleFirst ? 'v1 › public › shopping-cart › items' : 'v1 › shopping-cart › public › items',
|
|
145
|
+
hint: 'Creates a separate subfolder for every segment',
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
async function pickWriteMode(current) {
|
|
151
|
+
return (0, ui_1.selectMenu)({
|
|
152
|
+
title: 'When to write API docs',
|
|
153
|
+
subtitle: 'During Jest test execution',
|
|
154
|
+
initialIndex: current === 'incremental' ? 1 : 0,
|
|
155
|
+
options: [
|
|
156
|
+
{
|
|
157
|
+
value: 'on-complete',
|
|
158
|
+
label: 'When all tests finish',
|
|
159
|
+
badge: 'recommended',
|
|
160
|
+
hint: 'Fastest — builds OpenAPI + HTML once in onRunComplete',
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
value: 'incremental',
|
|
164
|
+
label: 'As tests run (after each suite)',
|
|
165
|
+
hint: 'Live updates — rebuilds docs after each test file finishes',
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
});
|
|
117
169
|
}
|
|
118
170
|
async function pickExampleStyle(current) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (answer === '2' || /status-case/i.test(answer))
|
|
147
|
-
return 'status-case';
|
|
148
|
-
if (answer === '3' || /^full/i.test(answer))
|
|
149
|
-
return 'full';
|
|
150
|
-
throw new Error(`Unknown style: ${answer}`);
|
|
171
|
+
const initialIndex = current === 'status-case' ? 0 : current === 'status-title-case' ? 1 : 2;
|
|
172
|
+
return (0, ui_1.selectMenu)({
|
|
173
|
+
title: 'Example / scenario labels',
|
|
174
|
+
subtitle: 'How each test case appears in API docs & Postman',
|
|
175
|
+
initialIndex,
|
|
176
|
+
options: [
|
|
177
|
+
{
|
|
178
|
+
value: 'status-case',
|
|
179
|
+
label: 'status-case (short)',
|
|
180
|
+
badge: 'recommended',
|
|
181
|
+
preview: ui_1.c.ice('201 — cyprus payload shape'),
|
|
182
|
+
hint: 'Clean status + scenario clause (best for Postman)',
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
value: 'status-title-case',
|
|
186
|
+
label: 'status-title-case',
|
|
187
|
+
preview: ui_1.c.ice('201 — Create Mock Tbs — cyprus payload shape'),
|
|
188
|
+
hint: 'Status + operation title + scenario clause',
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
value: 'full',
|
|
192
|
+
label: 'full (verbose)',
|
|
193
|
+
preview: ui_1.c.ice('201 — Create Mock Tbs - POST /v1/admin/mock-tbs POSITIVE CASES cyprus payload shape'),
|
|
194
|
+
hint: 'Includes HTTP method, path, and test section',
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
});
|
|
151
198
|
}
|
|
152
199
|
function layoutChoicesFor(pathTemplate, layout, skipParams) {
|
|
153
200
|
const role = layoutSegments(pathTemplate, 'role-resource', skipParams);
|
|
@@ -181,6 +228,107 @@ async function pickSegments(pathTemplate, layout, skipParams) {
|
|
|
181
228
|
return null;
|
|
182
229
|
return typed.split(/›|>|,|\s+/).map((part) => part.trim()).filter(Boolean);
|
|
183
230
|
}
|
|
231
|
+
function detectNestedResources(paths, skipParams) {
|
|
232
|
+
const groups = new Map();
|
|
233
|
+
for (const p of paths) {
|
|
234
|
+
const rawParts = p.split('/').filter(Boolean);
|
|
235
|
+
const paramIdx = skipParams ? rawParts.findIndex((seg) => seg.startsWith('{') || seg.startsWith(':')) : -1;
|
|
236
|
+
const folded = paramIdx >= 0 ? rawParts.slice(0, paramIdx) : rawParts;
|
|
237
|
+
// Expect /v1/<role>/<resource1>/<resource2>...
|
|
238
|
+
const startIdx = /^v\d+$/i.test(folded[0] || '') ? 2 : 1;
|
|
239
|
+
const role = startIdx === 2 ? folded[1] : 'api';
|
|
240
|
+
const resourceParts = folded.slice(startIdx).filter((seg) => !seg.startsWith('{') && !seg.startsWith(':'));
|
|
241
|
+
if (resourceParts.length < 2)
|
|
242
|
+
continue;
|
|
243
|
+
const pattern = resourceParts.slice(0, 2).join('/');
|
|
244
|
+
const existing = groups.get(pattern) ?? { roles: new Set(), samplePath: p };
|
|
245
|
+
if (role)
|
|
246
|
+
existing.roles.add(role);
|
|
247
|
+
groups.set(pattern, existing);
|
|
248
|
+
}
|
|
249
|
+
return [...groups.entries()]
|
|
250
|
+
.map(([pattern, info]) => ({
|
|
251
|
+
pattern,
|
|
252
|
+
suggested: pattern.replace(/\//g, '-'),
|
|
253
|
+
roles: [...info.roles].sort(),
|
|
254
|
+
samplePath: info.samplePath,
|
|
255
|
+
}))
|
|
256
|
+
.sort((a, b) => a.pattern.localeCompare(b.pattern));
|
|
257
|
+
}
|
|
258
|
+
async function pickResourceAliases(current, skipParams) {
|
|
259
|
+
const detected = detectNestedResources(listKnownPaths(), skipParams);
|
|
260
|
+
if (!detected.length)
|
|
261
|
+
return null;
|
|
262
|
+
const previewList = detected
|
|
263
|
+
.slice(0, 4)
|
|
264
|
+
.map((g) => g.pattern)
|
|
265
|
+
.join(', ') + (detected.length > 4 ? ` (+${detected.length - 4})` : '');
|
|
266
|
+
const review = await (0, ui_1.confirmPrompt)({
|
|
267
|
+
title: `${detected.length} nested resource(s) detected — merge any into single folders?`,
|
|
268
|
+
hint: previewList,
|
|
269
|
+
defaultYes: detected.length <= 5,
|
|
270
|
+
});
|
|
271
|
+
if (!review)
|
|
272
|
+
return null;
|
|
273
|
+
const next = { ...current };
|
|
274
|
+
// Let the user pick only the specific groups they want to merge instead of stepping through all 60+.
|
|
275
|
+
while (true) {
|
|
276
|
+
const picked = await (0, ui_1.selectMenu)({
|
|
277
|
+
title: 'Select a nested resource to merge (or Done)',
|
|
278
|
+
subtitle: `${Object.keys(next).length} merged so far`,
|
|
279
|
+
options: [
|
|
280
|
+
{ value: '__done__', label: 'Done — save & continue', badge: 'finish' },
|
|
281
|
+
...detected.map((group) => ({
|
|
282
|
+
value: group.pattern,
|
|
283
|
+
label: group.pattern,
|
|
284
|
+
badge: next[group.pattern] ? `→ ${next[group.pattern]}` : undefined,
|
|
285
|
+
hint: `${group.roles.join(', ')} · e.g. ${group.samplePath}`,
|
|
286
|
+
})),
|
|
287
|
+
],
|
|
288
|
+
});
|
|
289
|
+
if (picked === '__done__')
|
|
290
|
+
break;
|
|
291
|
+
const group = detected.find((g) => g.pattern === picked);
|
|
292
|
+
if (!group)
|
|
293
|
+
break;
|
|
294
|
+
const existing = next[group.pattern];
|
|
295
|
+
const choice = await (0, ui_1.selectMenu)({
|
|
296
|
+
title: `Folder for ${group.pattern}`,
|
|
297
|
+
subtitle: `${group.roles.join(', ')} · e.g. ${group.samplePath}`,
|
|
298
|
+
initialIndex: existing ? 1 : 0,
|
|
299
|
+
options: [
|
|
300
|
+
{
|
|
301
|
+
value: '__keep__',
|
|
302
|
+
label: `Keep nested (${group.pattern.replace('/', ' › ')})`,
|
|
303
|
+
hint: 'Separate subfolders',
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
value: group.suggested,
|
|
307
|
+
label: `Merge → ${group.suggested}`,
|
|
308
|
+
badge: existing === group.suggested ? 'active' : 'flatten',
|
|
309
|
+
hint: `Single folder: ${group.suggested}`,
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
value: '__custom__',
|
|
313
|
+
label: 'Custom folder name',
|
|
314
|
+
hint: 'Type your own folder name',
|
|
315
|
+
},
|
|
316
|
+
],
|
|
317
|
+
});
|
|
318
|
+
if (choice === '__keep__') {
|
|
319
|
+
delete next[group.pattern];
|
|
320
|
+
}
|
|
321
|
+
else if (choice === '__custom__') {
|
|
322
|
+
const typed = (await (0, ui_1.readlineAsk)(` ${ui_1.c.gold('?')} Folder name ${ui_1.c.dim(`(for ${group.pattern})`)}\n ${ui_1.c.ice('›')} `)).trim();
|
|
323
|
+
if (typed)
|
|
324
|
+
next[group.pattern] = typed;
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
next[group.pattern] = choice;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return next;
|
|
331
|
+
}
|
|
184
332
|
/**
|
|
185
333
|
* Company API docs presentation wizard — install / migrate / `daxta tree`.
|
|
186
334
|
*/
|
|
@@ -207,18 +355,25 @@ async function runTreeWizard(options = {}) {
|
|
|
207
355
|
if (!options.layout)
|
|
208
356
|
layout = await pickLayout(layout);
|
|
209
357
|
(0, config_edit_1.upsertConfigValue)(configPath, 'treeLayout', (0, config_edit_1.formatTsString)(layout));
|
|
210
|
-
console.log(` ${ui_1.c.mint('✔')} treeLayout → ${ui_1.c.ice(layout)}`);
|
|
211
358
|
const skipParams = await pickSkipParams(config.treeSkipParams !== false);
|
|
212
359
|
(0, config_edit_1.upsertConfigValue)(configPath, 'treeSkipParams', skipParams ? 'true' : 'false');
|
|
213
|
-
|
|
360
|
+
const subResourceMode = await pickSubResourceMode(config.treeSubResourceMode ?? 'nested', layout);
|
|
361
|
+
(0, config_edit_1.upsertConfigValue)(configPath, 'treeSubResourceMode', (0, config_edit_1.formatTsString)(subResourceMode));
|
|
214
362
|
const exampleStyle = await pickExampleStyle(config.exampleLabelStyle ?? 'status-title-case');
|
|
215
363
|
(0, config_edit_1.upsertConfigValue)(configPath, 'exampleLabelStyle', (0, config_edit_1.formatTsString)(exampleStyle));
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
364
|
+
const writeMode = await pickWriteMode(config.writeMode ?? 'on-complete');
|
|
365
|
+
(0, config_edit_1.upsertConfigValue)(configPath, 'writeMode', (0, config_edit_1.formatTsString)(writeMode));
|
|
366
|
+
if (!options.path && subResourceMode === 'nested') {
|
|
367
|
+
const aliases = await pickResourceAliases(config.treeResourceAliases ?? {}, skipParams);
|
|
368
|
+
if (aliases) {
|
|
369
|
+
const entries = Object.entries(aliases)
|
|
370
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
371
|
+
.map(([k, v]) => ` ${(0, config_edit_1.formatTsString)(k)}: ${(0, config_edit_1.formatTsString)(v)},`);
|
|
372
|
+
const literal = entries.length ? `{\n${entries.join('\n')}\n }` : '{}';
|
|
373
|
+
(0, config_edit_1.upsertConfigValue)(configPath, 'treeResourceAliases', literal);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (options.path) {
|
|
222
377
|
const pathTemplate = await pickPath(options.path);
|
|
223
378
|
if (pathTemplate) {
|
|
224
379
|
const segments = await pickSegments(pathTemplate, layout, skipParams);
|
package/dist/cli/ui.d.ts
CHANGED
|
@@ -40,6 +40,24 @@ export declare function step(label: string, work: () => StepResult | Promise<Ste
|
|
|
40
40
|
n?: number;
|
|
41
41
|
of?: number;
|
|
42
42
|
}): Promise<void>;
|
|
43
|
+
export type SelectOption<T> = {
|
|
44
|
+
value: T;
|
|
45
|
+
label: string;
|
|
46
|
+
badge?: string;
|
|
47
|
+
hint?: string;
|
|
48
|
+
preview?: string;
|
|
49
|
+
};
|
|
50
|
+
export declare function selectMenu<T>(params: {
|
|
51
|
+
title: string;
|
|
52
|
+
subtitle?: string;
|
|
53
|
+
options: Array<SelectOption<T>>;
|
|
54
|
+
initialIndex?: number;
|
|
55
|
+
}): Promise<T>;
|
|
56
|
+
export declare function confirmPrompt(params: {
|
|
57
|
+
title: string;
|
|
58
|
+
hint?: string;
|
|
59
|
+
defaultYes?: boolean;
|
|
60
|
+
}): Promise<boolean>;
|
|
43
61
|
export declare function box(title: string, lines: string[]): void;
|
|
44
62
|
export declare function nextSteps(lines: Array<{
|
|
45
63
|
cmd: string;
|
package/dist/cli/ui.js
CHANGED
|
@@ -9,6 +9,8 @@ exports.phase = phase;
|
|
|
9
9
|
exports.askLine = askLine;
|
|
10
10
|
exports.readlineAsk = readlineAsk;
|
|
11
11
|
exports.step = step;
|
|
12
|
+
exports.selectMenu = selectMenu;
|
|
13
|
+
exports.confirmPrompt = confirmPrompt;
|
|
12
14
|
exports.box = box;
|
|
13
15
|
exports.nextSteps = nextSteps;
|
|
14
16
|
const readline_1 = require("readline");
|
|
@@ -135,6 +137,7 @@ async function step(label, work, options = {}) {
|
|
|
135
137
|
console.log(` ${prefix}${exports.tone.ice('▸')} ${label}`);
|
|
136
138
|
}
|
|
137
139
|
try {
|
|
140
|
+
const startedAt = Date.now();
|
|
138
141
|
const result = await work();
|
|
139
142
|
if (timer)
|
|
140
143
|
clearInterval(timer);
|
|
@@ -146,7 +149,9 @@ async function step(label, work, options = {}) {
|
|
|
146
149
|
summary = result.summary;
|
|
147
150
|
details = result.details ?? [];
|
|
148
151
|
}
|
|
149
|
-
const
|
|
152
|
+
const elapsed = Date.now() - startedAt;
|
|
153
|
+
const timing = elapsed >= 20 ? exports.c.dim(` ${elapsed}ms`) : '';
|
|
154
|
+
const line = summary ? `${label} ${exports.tone.mist(summary)}${timing}` : `${label}${timing}`;
|
|
150
155
|
const ok = `${prefix}${exports.tone.mint('✔')} ${line}`;
|
|
151
156
|
if (useSpinner)
|
|
152
157
|
process.stdout.write(`\r ${ok}${' '.repeat(16)}\n`);
|
|
@@ -170,6 +175,124 @@ async function step(label, work, options = {}) {
|
|
|
170
175
|
throw error;
|
|
171
176
|
}
|
|
172
177
|
}
|
|
178
|
+
async function selectMenu(params) {
|
|
179
|
+
const { title, subtitle, options } = params;
|
|
180
|
+
const startIdx = Math.max(0, Math.min(options.length - 1, params.initialIndex ?? 0));
|
|
181
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY || typeof process.stdin.setRawMode !== 'function') {
|
|
182
|
+
console.log('');
|
|
183
|
+
console.log(` ${exports.tone.gold('◆')} ${exports.c.bold(title)}${subtitle ? exports.tone.mist(` — ${subtitle}`) : ''}`);
|
|
184
|
+
options.forEach((opt, i) => {
|
|
185
|
+
console.log(` ${exports.c.ice(String(i + 1))} ${opt.label}${opt.badge ? ` ${exports.c.dim(opt.badge)}` : ''}`);
|
|
186
|
+
if (opt.preview)
|
|
187
|
+
console.log(` ${opt.preview}`);
|
|
188
|
+
if (opt.hint)
|
|
189
|
+
console.log(` ${exports.c.dim(opt.hint)}`);
|
|
190
|
+
});
|
|
191
|
+
const ans = await readlineAsk(` ${exports.c.ice('›')} `);
|
|
192
|
+
const idx = Number(ans) - 1;
|
|
193
|
+
if (Number.isInteger(idx) && idx >= 0 && idx < options.length)
|
|
194
|
+
return options[idx].value;
|
|
195
|
+
return options[startIdx].value;
|
|
196
|
+
}
|
|
197
|
+
let selected = startIdx;
|
|
198
|
+
let renderedLines = 0;
|
|
199
|
+
const render = (final = false) => {
|
|
200
|
+
if (renderedLines > 0) {
|
|
201
|
+
process.stdout.write(`\x1b[${renderedLines}A\x1b[J`);
|
|
202
|
+
}
|
|
203
|
+
const lines = [];
|
|
204
|
+
if (final) {
|
|
205
|
+
const chosen = options[selected];
|
|
206
|
+
lines.push(` ${exports.tone.mint('✔')} ${exports.c.bold(title)} ${exports.tone.ice(chosen.label)}`);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
lines.push(` ${exports.tone.gold('◆')} ${exports.c.bold(title)}${subtitle ? exports.tone.mist(` ${subtitle}`) : ''}`);
|
|
210
|
+
lines.push(` ${exports.c.dim('│')}`);
|
|
211
|
+
options.forEach((opt, idx) => {
|
|
212
|
+
const active = idx === selected;
|
|
213
|
+
const bullet = active ? exports.tone.ice('●') : exports.c.dim('○');
|
|
214
|
+
const label = active ? exports.c.bold(exports.tone.paper(opt.label)) : exports.tone.mist(opt.label);
|
|
215
|
+
const badge = opt.badge ? (active ? ` ${exports.tone.mint(opt.badge)}` : ` ${exports.c.dim(opt.badge)}`) : '';
|
|
216
|
+
lines.push(` ${bullet} ${label}${badge}`);
|
|
217
|
+
if (opt.preview && active) {
|
|
218
|
+
lines.push(` ${exports.c.dim('│')} ${opt.preview}`);
|
|
219
|
+
}
|
|
220
|
+
if (opt.hint && active) {
|
|
221
|
+
lines.push(` ${exports.c.dim('│')} ${exports.c.dim(opt.hint)}`);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
lines.push(` ${exports.c.dim('│')}`);
|
|
225
|
+
lines.push(` ${exports.c.dim('└')} ${exports.c.dim('↑↓ move · 1-' + options.length + ' jump · Enter select')}`);
|
|
226
|
+
}
|
|
227
|
+
const output = `${lines.join('\n')}\n`;
|
|
228
|
+
process.stdout.write(output);
|
|
229
|
+
renderedLines = lines.length;
|
|
230
|
+
};
|
|
231
|
+
return new Promise((resolve, reject) => {
|
|
232
|
+
const stdin = process.stdin;
|
|
233
|
+
const wasRaw = stdin.isRaw;
|
|
234
|
+
(0, readline_1.emitKeypressEvents)(stdin);
|
|
235
|
+
stdin.setRawMode(true);
|
|
236
|
+
stdin.resume();
|
|
237
|
+
process.stdout.write('\x1b[?25l');
|
|
238
|
+
console.log('');
|
|
239
|
+
render(false);
|
|
240
|
+
const cleanup = () => {
|
|
241
|
+
stdin.removeListener('keypress', onKeypress);
|
|
242
|
+
try {
|
|
243
|
+
stdin.setRawMode(Boolean(wasRaw));
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
// ignore
|
|
247
|
+
}
|
|
248
|
+
stdin.pause();
|
|
249
|
+
process.stdout.write('\x1b[?25h');
|
|
250
|
+
};
|
|
251
|
+
const onKeypress = (_str, key) => {
|
|
252
|
+
if (key?.ctrl && key.name === 'c') {
|
|
253
|
+
cleanup();
|
|
254
|
+
process.stdout.write('\n');
|
|
255
|
+
reject(new Error('Cancelled'));
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (key?.name === 'up' || key?.name === 'k') {
|
|
259
|
+
selected = (selected - 1 + options.length) % options.length;
|
|
260
|
+
render(false);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (key?.name === 'down' || key?.name === 'j') {
|
|
264
|
+
selected = (selected + 1) % options.length;
|
|
265
|
+
render(false);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (key?.name === 'return' || key?.name === 'enter') {
|
|
269
|
+
cleanup();
|
|
270
|
+
render(true);
|
|
271
|
+
resolve(options[selected].value);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const num = Number(key?.sequence);
|
|
275
|
+
if (Number.isInteger(num) && num >= 1 && num <= options.length) {
|
|
276
|
+
selected = num - 1;
|
|
277
|
+
cleanup();
|
|
278
|
+
render(true);
|
|
279
|
+
resolve(options[selected].value);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
stdin.on('keypress', onKeypress);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
async function confirmPrompt(params) {
|
|
286
|
+
return selectMenu({
|
|
287
|
+
title: params.title,
|
|
288
|
+
subtitle: params.hint,
|
|
289
|
+
initialIndex: params.defaultYes === false ? 1 : 0,
|
|
290
|
+
options: [
|
|
291
|
+
{ value: true, label: 'Yes', badge: params.defaultYes !== false ? 'default' : undefined },
|
|
292
|
+
{ value: false, label: 'No', badge: params.defaultYes === false ? 'default' : undefined },
|
|
293
|
+
],
|
|
294
|
+
});
|
|
295
|
+
}
|
|
173
296
|
function box(title, lines) {
|
|
174
297
|
const width = 58;
|
|
175
298
|
console.log('');
|
package/dist/cli/uninstall.js
CHANGED
|
@@ -145,9 +145,11 @@ async function uninstallDaxta(options = {}) {
|
|
|
145
145
|
const pm = detectPackageManager(cwd, pkg);
|
|
146
146
|
(0, ui_1.banner)('DAxTA uninstall', project);
|
|
147
147
|
if (!options.yes && process.stdin.isTTY) {
|
|
148
|
-
const
|
|
149
|
-
`
|
|
150
|
-
|
|
148
|
+
const confirmed = await (0, ui_1.confirmPrompt)({
|
|
149
|
+
title: `Remove DAxTA from ${project}?`,
|
|
150
|
+
defaultYes: true,
|
|
151
|
+
});
|
|
152
|
+
if (!confirmed) {
|
|
151
153
|
console.log(` ${ui_1.c.dim('cancelled')}`);
|
|
152
154
|
return;
|
|
153
155
|
}
|
package/dist/config.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export type TreeLayout = 'role-resource' | 'resource-role';
|
|
|
3
3
|
/** @deprecated use role-resource / resource-role */
|
|
4
4
|
export type LegacyTreeLayout = 'url-order' | 'resource-first';
|
|
5
5
|
export type ExampleLabelStyle = 'status-case' | 'status-title-case' | 'full';
|
|
6
|
+
export type WriteMode = 'on-complete' | 'incremental';
|
|
7
|
+
export type SubResourceMode = 'nested' | 'merge' | 'root';
|
|
6
8
|
export type SpecInfo = {
|
|
7
9
|
title?: string;
|
|
8
10
|
version?: string;
|
|
@@ -48,7 +50,19 @@ export type DaxtaConfig = {
|
|
|
48
50
|
* One level only. Default true.
|
|
49
51
|
*/
|
|
50
52
|
treeCollapseSingle?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* How segments after the main resource are grouped into folders:
|
|
55
|
+
* - nested → v1 › shopping-cart › public › items (default)
|
|
56
|
+
* - merge → v1 › shopping-cart-items › public
|
|
57
|
+
* - root → v1 › shopping-cart › public (all sub-routes under main resource)
|
|
58
|
+
*/
|
|
59
|
+
treeSubResourceMode?: SubResourceMode;
|
|
51
60
|
treePathOverrides?: Record<string, string[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Merge multi-segment resource paths into a single folder name, e.g.
|
|
63
|
+
* `{ 'shopping-cart/items': 'shopping-cart-items' }`.
|
|
64
|
+
*/
|
|
65
|
+
treeResourceAliases?: Record<string, string>;
|
|
52
66
|
/**
|
|
53
67
|
* OpenAPI example + scenario labels:
|
|
54
68
|
* - status-case → `201 — cyprus payload shape`
|
|
@@ -57,6 +71,12 @@ export type DaxtaConfig = {
|
|
|
57
71
|
* Ideal it(): docs take the when-clause. Parametric it(): pre-when field context is kept.
|
|
58
72
|
*/
|
|
59
73
|
exampleLabelStyle?: ExampleLabelStyle;
|
|
74
|
+
/**
|
|
75
|
+
* When to build OpenAPI + HTML during Jest runs:
|
|
76
|
+
* - on-complete → once after all tests finish (fastest, default)
|
|
77
|
+
* - incremental → after each test suite finishes (live updates)
|
|
78
|
+
*/
|
|
79
|
+
writeMode?: WriteMode;
|
|
60
80
|
port?: number;
|
|
61
81
|
fieldsFile?: string;
|
|
62
82
|
/**
|
|
@@ -77,12 +97,22 @@ export type DaxtaConfig = {
|
|
|
77
97
|
operationTag?: (pathTemplate: string, method: string) => string | undefined;
|
|
78
98
|
operationTitle?: (method: string, pathTemplate: string) => string | undefined;
|
|
79
99
|
securitySchemeId?: (headerName: string) => string | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Map recorded header names to Postman/Try-it template values, e.g.:
|
|
102
|
+
* `{ 'x-user-id': '{{X_USER_ID}}', authorization: 'Bearer {{AUTH_TOKEN}}' }`
|
|
103
|
+
*/
|
|
104
|
+
headerVariables?: Record<string, string>;
|
|
105
|
+
/**
|
|
106
|
+
* Dynamic header-to-template-value resolver, e.g.:
|
|
107
|
+
* `(name) => \`{{\${name.toUpperCase().replace(/-/g, '_')}}}\``
|
|
108
|
+
*/
|
|
109
|
+
headerVariable?: (headerName: string) => string | undefined;
|
|
80
110
|
specInfo?: () => SpecInfo | undefined;
|
|
81
111
|
operationOrder?: (opKey: string) => number | undefined;
|
|
82
112
|
includeHit?: (method: string, pathTemplate: string, test?: string) => boolean;
|
|
83
113
|
treePathSegments?: (pathTemplate: string) => string[] | undefined;
|
|
84
114
|
};
|
|
85
|
-
export type ResolvedDaxtaConfig = Required<Pick<DaxtaConfig, 'workspace' | 'baseUrl' | 'controllersRoot' | 'outDir' | 'treeLayout' | 'treePathOverrides' | 'treeSkipParams' | 'treeCollapseSingle' | 'exampleLabelStyle' | 'port' | 'fieldsFile' | 'docsPath' | 'viewerStoreFile'>> & DaxtaConfig;
|
|
115
|
+
export type ResolvedDaxtaConfig = Required<Pick<DaxtaConfig, 'workspace' | 'baseUrl' | 'controllersRoot' | 'outDir' | 'treeLayout' | 'treePathOverrides' | 'treeResourceAliases' | 'treeSkipParams' | 'treeCollapseSingle' | 'treeSubResourceMode' | 'exampleLabelStyle' | 'writeMode' | 'port' | 'fieldsFile' | 'docsPath' | 'viewerStoreFile'>> & DaxtaConfig;
|
|
86
116
|
export declare const DEFAULT_DOCS_PATH = "/docs";
|
|
87
117
|
export declare function normalizeDocsPath(raw?: string | null): string;
|
|
88
118
|
export declare function defineConfig(config: DaxtaConfig): DaxtaConfig;
|
package/dist/config.js
CHANGED
|
@@ -53,8 +53,12 @@ const DEFAULTS = {
|
|
|
53
53
|
treeLayout: 'role-resource',
|
|
54
54
|
treeSkipParams: true,
|
|
55
55
|
treeCollapseSingle: true,
|
|
56
|
+
treeSubResourceMode: 'nested',
|
|
56
57
|
treePathOverrides: {},
|
|
58
|
+
treeResourceAliases: {},
|
|
59
|
+
headerVariables: {},
|
|
57
60
|
exampleLabelStyle: 'status-title-case',
|
|
61
|
+
writeMode: 'on-complete',
|
|
58
62
|
port: 5199,
|
|
59
63
|
fieldsFile: '.daxta/out/fields.json',
|
|
60
64
|
docsPath: '/docs',
|
|
@@ -118,6 +122,10 @@ function resolveConfig(cwd = process.cwd(), overrides) {
|
|
|
118
122
|
merged.treeCollapseSingle = DEFAULTS.treeCollapseSingle;
|
|
119
123
|
if (merged.exampleLabelStyle == null)
|
|
120
124
|
merged.exampleLabelStyle = DEFAULTS.exampleLabelStyle;
|
|
125
|
+
if (merged.writeMode == null)
|
|
126
|
+
merged.writeMode = DEFAULTS.writeMode;
|
|
127
|
+
if (merged.treeSubResourceMode == null)
|
|
128
|
+
merged.treeSubResourceMode = DEFAULTS.treeSubResourceMode;
|
|
121
129
|
merged.envPresets = normalizeEnvPresets(merged.envPresets, merged.baseUrl);
|
|
122
130
|
merged.docsPath = normalizeDocsPath(process.env.DAXTA_DOCS_PATH || merged.docsPath);
|
|
123
131
|
merged.controllersRoot = path.isAbsolute(merged.controllersRoot)
|