@t0.labs/daxta 1.1.8 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -26
- package/assets/viewer.html +52 -11
- package/dist/build/build-spec.d.ts +2 -0
- package/dist/build/build-spec.js +85 -14
- package/dist/build/incremental.d.ts +2 -0
- package/dist/build/incremental.js +6 -2
- package/dist/catalog/index.d.ts +3 -1
- package/dist/catalog/index.js +39 -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 +37 -1
- package/dist/config.js +9 -0
- package/dist/export/postman.d.ts +150 -0
- package/dist/export/postman.js +357 -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/titles.js
CHANGED
|
@@ -7,34 +7,32 @@ const scan_1 = require("../titles/scan");
|
|
|
7
7
|
const ui_1 = require("./ui");
|
|
8
8
|
async function pickFromSuggestions(finding, extra, validate) {
|
|
9
9
|
const suggestions = finding.suggestions;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
const options = [
|
|
11
|
+
...suggestions.map((name, index) => ({
|
|
12
|
+
value: name,
|
|
13
|
+
label: name,
|
|
14
|
+
badge: index === 0 ? 'recommended' : undefined,
|
|
15
|
+
hint: index === 0 ? `${finding.file}:${finding.line}` : undefined,
|
|
16
|
+
})),
|
|
17
|
+
...(suggestions.length
|
|
18
|
+
? [{ value: '__all__', label: 'Apply all remaining auto-fixes', hint: 'Accept recommended names for the rest' }]
|
|
19
|
+
: []),
|
|
20
|
+
{ value: '__custom__', label: 'Custom title', hint: 'Type your own text' },
|
|
21
|
+
{ value: '__skip__', label: 'Skip this one' },
|
|
22
|
+
{ value: '__skip_all__', label: 'Skip all remaining' },
|
|
23
|
+
];
|
|
24
|
+
const choice = await (0, ui_1.selectMenu)({
|
|
25
|
+
title: `${finding.file}:${finding.line}`,
|
|
26
|
+
subtitle: `${finding.raw}${extra ? ` · ${extra}` : ''}`,
|
|
27
|
+
options,
|
|
21
28
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const answer = (await (0, ui_1.readlineAsk)(` ${ui_1.c.ice('›')} `)).trim();
|
|
26
|
-
const lower = answer.toLowerCase();
|
|
27
|
-
if (!answer)
|
|
28
|
-
return suggestions[0] ? suggestions[0] : 'skip';
|
|
29
|
-
if (lower === 's')
|
|
29
|
+
if (choice === '__all__')
|
|
30
|
+
return 'all';
|
|
31
|
+
if (choice === '__skip__')
|
|
30
32
|
return 'skip';
|
|
31
|
-
if (
|
|
33
|
+
if (choice === '__skip_all__')
|
|
32
34
|
return 'skip-all';
|
|
33
|
-
if (
|
|
34
|
-
return 'all';
|
|
35
|
-
if (lower === 'y' || lower === 'yes')
|
|
36
|
-
return suggestions[0] ? suggestions[0] : 'skip';
|
|
37
|
-
if (lower === 'c') {
|
|
35
|
+
if (choice === '__custom__') {
|
|
38
36
|
const custom = await (0, ui_1.readlineAsk)(` ${ui_1.c.dim('text')} ${ui_1.c.ice('›')} `);
|
|
39
37
|
if (!validate(custom)) {
|
|
40
38
|
console.log(` ${ui_1.c.gold('!')} does not match the format — skipped`);
|
|
@@ -42,12 +40,7 @@ async function pickFromSuggestions(finding, extra, validate) {
|
|
|
42
40
|
}
|
|
43
41
|
return custom;
|
|
44
42
|
}
|
|
45
|
-
|
|
46
|
-
if (Number.isInteger(index) && index >= 1 && index <= suggestions.length)
|
|
47
|
-
return suggestions[index - 1];
|
|
48
|
-
if (validate(answer))
|
|
49
|
-
return answer;
|
|
50
|
-
return 'skip';
|
|
43
|
+
return choice;
|
|
51
44
|
}
|
|
52
45
|
function writeTitle(cwd, finding) {
|
|
53
46
|
if (!finding.auto)
|
|
@@ -137,14 +130,43 @@ async function runTitleCheck(options) {
|
|
|
137
130
|
console.log(` ${ui_1.c.dim('→ scenario clause (when-clause; keeps pre-when field context when needed)')}`);
|
|
138
131
|
console.log(` ${ui_1.c.dim('label')} 201 — Create Mock Tbs — cyprus payload shape`);
|
|
139
132
|
console.log(` ${ui_1.c.dim('→')} ${ui_1.c.ice('exampleLabelStyle')} ${ui_1.c.dim('in')} ${ui_1.c.ice('daxta tree')} ${ui_1.c.dim('· change with')} ${ui_1.c.ice('2')} ${ui_1.c.dim('for short labels')}`);
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
133
|
+
const autoCount = report.titles.filter((t) => t.auto && t.suggestions[0]).length +
|
|
134
|
+
report.cases.filter((k) => k.auto && k.suggestions[0]).length;
|
|
135
|
+
const shouldOptimize = await (0, ui_1.confirmPrompt)({
|
|
136
|
+
title: `Found ${total} test naming issue(s) — optimize now?`,
|
|
137
|
+
hint: `${report.titles.length} describe · ${report.cases.length} it() (${autoCount} auto-fixable)`,
|
|
138
|
+
defaultYes: true,
|
|
139
|
+
});
|
|
140
|
+
if (!shouldOptimize) {
|
|
143
141
|
console.log(` ${ui_1.c.dim('skipped')} ${ui_1.c.ice('daxta titles')} ${ui_1.c.dim('anytime')}`);
|
|
144
142
|
console.log('');
|
|
145
143
|
return 0;
|
|
146
144
|
}
|
|
147
|
-
|
|
145
|
+
if (autoCount > 0) {
|
|
146
|
+
const result = applyAllRecommended(cwd, report.titles, report.cases, 0, 0);
|
|
147
|
+
console.log('');
|
|
148
|
+
console.log(` ${ui_1.c.mint('✔')} ${result.written} updated ${ui_1.c.dim(`${result.skipped} skipped`)}`);
|
|
149
|
+
if (result.pending.length) {
|
|
150
|
+
const reviewPending = await (0, ui_1.confirmPrompt)({
|
|
151
|
+
title: `${result.pending.length} title(s) need a custom name — review now?`,
|
|
152
|
+
defaultYes: false,
|
|
153
|
+
});
|
|
154
|
+
if (reviewPending) {
|
|
155
|
+
for (const pending of result.pending) {
|
|
156
|
+
const customChoice = await pickFromSuggestions(pending, `docs would show ${pending.path} — custom title required`, test_title_1.isHumanOperationTitle);
|
|
157
|
+
if (customChoice === 'skip-all')
|
|
158
|
+
break;
|
|
159
|
+
if (customChoice && customChoice !== 'skip' && customChoice !== 'all') {
|
|
160
|
+
if ((0, scan_1.applyTitle)(cwd, pending, customChoice)) {
|
|
161
|
+
console.log(` ${ui_1.c.mint('✔')} ${customChoice}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
console.log('');
|
|
168
|
+
return 0;
|
|
169
|
+
}
|
|
148
170
|
let written = 0;
|
|
149
171
|
let skipped = 0;
|
|
150
172
|
for (let i = 0; i < report.titles.length; i += 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
|
}
|