@t0.labs/daxta 0.4.3 → 0.4.4
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/dist/cli/install.js +5 -0
- package/dist/cli/tree.d.ts +10 -2
- package/dist/cli/tree.js +76 -33
- package/package.json +1 -1
package/dist/cli/install.js
CHANGED
|
@@ -40,6 +40,7 @@ const child_process_1 = require("child_process");
|
|
|
40
40
|
const inject_main_1 = require("./inject-main");
|
|
41
41
|
const discover_test_1 = require("./discover-test");
|
|
42
42
|
const jest_hooks_1 = require("./jest-hooks");
|
|
43
|
+
const tree_1 = require("./tree");
|
|
43
44
|
const ui_1 = require("./ui");
|
|
44
45
|
function readJson(filePath) {
|
|
45
46
|
return JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
|
|
@@ -291,10 +292,14 @@ async function installDaxta(options = {}) {
|
|
|
291
292
|
else {
|
|
292
293
|
await (0, ui_1.step)('Attach test hooks', () => 'skipped', { paceMs });
|
|
293
294
|
}
|
|
295
|
+
if (!dryRun) {
|
|
296
|
+
await (0, tree_1.runTreeWizard)({ embedded: true, yes: Boolean(options.yes) });
|
|
297
|
+
}
|
|
294
298
|
(0, ui_1.box)('Done', [
|
|
295
299
|
`${ui_1.c.green('✔')} DAxTA wired for ${ui_1.c.bold(project)}`,
|
|
296
300
|
`${ui_1.c.dim('env')} ${ui_1.c.cyan('DAXTA_DOCS=true')} or ${ui_1.c.cyan('false')}`,
|
|
297
301
|
`${ui_1.c.dim('tests')} run your usual script — Docs ready prints when Jest finishes`,
|
|
302
|
+
`${ui_1.c.dim('sidebar')} ${ui_1.c.cyan('daxta tree')} anytime to re-arrange folders`,
|
|
298
303
|
]);
|
|
299
304
|
const wired = testScript && pkg.scripts?.[testScript] ? testScript : null;
|
|
300
305
|
(0, ui_1.nextSteps)([
|
package/dist/cli/tree.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type TreeWizardOptions = {
|
|
2
2
|
path?: string;
|
|
3
3
|
layout?: string;
|
|
4
|
-
|
|
4
|
+
/** Called from install — no extra banner, always ask layout when TTY */
|
|
5
|
+
embedded?: boolean;
|
|
6
|
+
yes?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Interactive sidebar layout wizard.
|
|
10
|
+
* Also used at the end of `daxta install` so the question is not a hidden separate command.
|
|
11
|
+
*/
|
|
12
|
+
export declare function runTreeWizard(options?: TreeWizardOptions): Promise<void>;
|
package/dist/cli/tree.js
CHANGED
|
@@ -61,13 +61,18 @@ function listKnownPaths() {
|
|
|
61
61
|
catch {
|
|
62
62
|
// ignore
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
try {
|
|
65
|
+
for (const pathTemplate of (0, dto_fields_1.listControllerPathTemplates)())
|
|
66
|
+
fromSpec.add(pathTemplate);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// controllers may not parse yet
|
|
70
|
+
}
|
|
66
71
|
return [...fromSpec].sort((a, b) => a.localeCompare(b));
|
|
67
72
|
}
|
|
68
73
|
function printPathChoices(paths, limit = 12) {
|
|
69
74
|
if (!paths.length) {
|
|
70
|
-
console.log(` ${ui_1.c.dim('
|
|
75
|
+
console.log(` ${ui_1.c.dim('tip')} type a path like ${ui_1.c.cyan('/v1/admin/baskets')}`);
|
|
71
76
|
return;
|
|
72
77
|
}
|
|
73
78
|
console.log(` ${ui_1.c.dim('known paths')}`);
|
|
@@ -83,7 +88,7 @@ async function pickPath(flagPath) {
|
|
|
83
88
|
const known = listKnownPaths();
|
|
84
89
|
printPathChoices(known);
|
|
85
90
|
const answer = await prompt(` ${ui_1.c.yellow('?')} ${ui_1.c.bold('Path')} to arrange in the sidebar\n` +
|
|
86
|
-
` ${ui_1.c.dim('number
|
|
91
|
+
` ${ui_1.c.dim('number · /v1/admin/baskets · or n to skip')}\n ${ui_1.c.cyan('›')} `);
|
|
87
92
|
if (!answer || /^n(o)?$/i.test(answer))
|
|
88
93
|
return null;
|
|
89
94
|
if (/^\d+$/.test(answer)) {
|
|
@@ -95,12 +100,21 @@ async function pickPath(flagPath) {
|
|
|
95
100
|
return normalizePathInput(answer);
|
|
96
101
|
}
|
|
97
102
|
async function pickGlobalLayout(current) {
|
|
103
|
+
const sample = '/v1/admin/baskets';
|
|
104
|
+
console.log('');
|
|
105
|
+
console.log(` ${ui_1.c.bold('Docs sidebar layout')}`);
|
|
106
|
+
console.log(` ${ui_1.c.dim('Example')} ${ui_1.c.cyan(sample)}`);
|
|
107
|
+
console.log('');
|
|
108
|
+
console.log(` ${ui_1.c.cyan('1')} resource-first`);
|
|
109
|
+
console.log(` ${(0, config_edit_1.previewTree)(resourceFirstSegments(sample))}`);
|
|
110
|
+
console.log(` ${ui_1.c.dim('v1 → baskets → admin')}`);
|
|
111
|
+
console.log('');
|
|
112
|
+
console.log(` ${ui_1.c.cyan('2')} url-order`);
|
|
113
|
+
console.log(` ${(0, config_edit_1.previewTree)(urlOrderSegments(sample))}`);
|
|
114
|
+
console.log(` ${ui_1.c.dim('v1 → admin → baskets')}`);
|
|
98
115
|
console.log('');
|
|
99
|
-
console.log(`
|
|
100
|
-
|
|
101
|
-
console.log(` ${ui_1.c.cyan('2')} url-order ${ui_1.c.dim('v1 › admin › baskets')}`);
|
|
102
|
-
console.log(` ${ui_1.c.cyan('3')} keep current`);
|
|
103
|
-
const answer = await prompt(` ${ui_1.c.yellow('?')} Choose default\n ${ui_1.c.cyan('›')} `);
|
|
116
|
+
console.log(` ${ui_1.c.cyan('3')} keep ${ui_1.c.dim(`(${current})`)}`);
|
|
117
|
+
const answer = await prompt(` ${ui_1.c.yellow('?')} How should folders nest under /docs?\n ${ui_1.c.cyan('›')} `);
|
|
104
118
|
if (!answer || answer === '3' || /^k(eep)?$/i.test(answer))
|
|
105
119
|
return null;
|
|
106
120
|
if (answer === '1' || /^resource/i.test(answer))
|
|
@@ -127,22 +141,25 @@ async function pickSegments(pathTemplate) {
|
|
|
127
141
|
const choices = layoutChoicesFor(pathTemplate);
|
|
128
142
|
console.log('');
|
|
129
143
|
console.log(` ${ui_1.c.bold('Sidebar for')} ${ui_1.c.cyan(pathTemplate)}`);
|
|
144
|
+
console.log(` ${ui_1.c.dim('Which nesting do you want?')}`);
|
|
130
145
|
choices.forEach((choice, index) => {
|
|
131
146
|
const mark = ui_1.c.cyan(String(index + 1));
|
|
132
147
|
console.log(` ${mark} ${ui_1.c.bold(choice.label)}`);
|
|
133
148
|
console.log(` ${(0, config_edit_1.previewTree)(choice.segments)}`);
|
|
134
149
|
});
|
|
135
|
-
const answer = await prompt(` ${ui_1.c.yellow('?')}
|
|
150
|
+
const answer = await prompt(` ${ui_1.c.yellow('?')} Choose\n ${ui_1.c.cyan('›')} `);
|
|
136
151
|
if (!answer || /^n(o)?$/i.test(answer))
|
|
137
152
|
return null;
|
|
138
|
-
const index = /^\d+$/.test(answer)
|
|
153
|
+
const index = /^\d+$/.test(answer)
|
|
154
|
+
? Number(answer) - 1
|
|
155
|
+
: choices.findIndex((choice) => choice.id === answer || choice.label.toLowerCase().startsWith(answer.toLowerCase()));
|
|
139
156
|
const selected = choices[index];
|
|
140
157
|
if (!selected)
|
|
141
158
|
throw new Error(`Unknown choice: ${answer}`);
|
|
142
159
|
if (selected.id !== 'custom')
|
|
143
160
|
return selected.segments;
|
|
144
161
|
const typed = await prompt(` ${ui_1.c.yellow('?')} Segments in order ${ui_1.c.dim('(space or › separated)')}\n` +
|
|
145
|
-
` ${ui_1.c.dim(
|
|
162
|
+
` ${ui_1.c.dim('e.g. v1 baskets admin')}\n ${ui_1.c.cyan('›')} `);
|
|
146
163
|
if (!typed)
|
|
147
164
|
return null;
|
|
148
165
|
return typed
|
|
@@ -150,42 +167,68 @@ async function pickSegments(pathTemplate) {
|
|
|
150
167
|
.map((part) => part.trim())
|
|
151
168
|
.filter(Boolean);
|
|
152
169
|
}
|
|
170
|
+
function saveLayout(configPath, layout) {
|
|
171
|
+
(0, config_edit_1.upsertConfigValue)(configPath, 'treeLayout', (0, config_edit_1.formatTsString)(layout));
|
|
172
|
+
}
|
|
173
|
+
function saveOverride(configPath, pathTemplate, segments) {
|
|
174
|
+
const overrides = (0, config_edit_1.readTreePathOverrides)();
|
|
175
|
+
overrides[pathTemplate] = segments;
|
|
176
|
+
(0, config_edit_1.upsertConfigValue)(configPath, 'treePathOverrides', (0, config_edit_1.formatTsStringRecord)(overrides));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Interactive sidebar layout wizard.
|
|
180
|
+
* Also used at the end of `daxta install` so the question is not a hidden separate command.
|
|
181
|
+
*/
|
|
153
182
|
async function runTreeWizard(options = {}) {
|
|
154
|
-
(
|
|
183
|
+
if (options.yes || !process.stdin.isTTY) {
|
|
184
|
+
if (!options.embedded) {
|
|
185
|
+
console.log(` ${ui_1.c.dim('tree wizard skipped (non-interactive)')}`);
|
|
186
|
+
}
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (!options.embedded)
|
|
190
|
+
(0, ui_1.banner)('DAxTA tree', 'sidebar folder order');
|
|
155
191
|
const configPath = (0, config_edit_1.findDaxtaConfigPath)();
|
|
156
192
|
if (!configPath) {
|
|
157
193
|
throw new Error('No daxta.config.ts found. Run `daxta install` first.');
|
|
158
194
|
}
|
|
159
195
|
(0, config_1.resetConfig)();
|
|
160
196
|
const config = (0, config_1.getConfig)(true);
|
|
197
|
+
console.log('');
|
|
198
|
+
console.log(` ${ui_1.c.yellow(ui_1.c.bold('?'))} ${ui_1.c.bold('Sidebar')} ${ui_1.c.dim('— how /docs folders nest')}`);
|
|
161
199
|
if (options.layout === 'resource-first' || options.layout === 'url-order') {
|
|
162
|
-
(
|
|
200
|
+
saveLayout(configPath, options.layout);
|
|
163
201
|
console.log(` ${ui_1.c.green('✔')} treeLayout → ${ui_1.c.cyan(options.layout)}`);
|
|
164
202
|
}
|
|
165
|
-
else
|
|
203
|
+
else {
|
|
166
204
|
const layout = await pickGlobalLayout(config.treeLayout);
|
|
167
205
|
if (layout) {
|
|
168
|
-
(
|
|
206
|
+
saveLayout(configPath, layout);
|
|
169
207
|
console.log(` ${ui_1.c.green('✔')} treeLayout → ${ui_1.c.cyan(layout)}`);
|
|
170
208
|
}
|
|
209
|
+
else {
|
|
210
|
+
console.log(` ${ui_1.c.dim('kept')} treeLayout ${ui_1.c.cyan(config.treeLayout)}`);
|
|
211
|
+
}
|
|
171
212
|
}
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
213
|
+
const customize = options.path
|
|
214
|
+
? 'y'
|
|
215
|
+
: await prompt(` ${ui_1.c.yellow('?')} Customize a specific path now?\n` +
|
|
216
|
+
` ${ui_1.c.dim('Y')} yes · ${ui_1.c.dim('n')} later ${ui_1.c.dim('(daxta tree)')}\n ${ui_1.c.cyan('›')} `);
|
|
217
|
+
if (customize && !/^n(o)?$/i.test(customize)) {
|
|
218
|
+
const pathTemplate = await pickPath(options.path);
|
|
219
|
+
if (pathTemplate) {
|
|
220
|
+
const segments = await pickSegments(pathTemplate);
|
|
221
|
+
if (segments?.length) {
|
|
222
|
+
saveOverride(configPath, pathTemplate, segments);
|
|
223
|
+
console.log('');
|
|
224
|
+
console.log(` ${ui_1.c.green('✔')} ${ui_1.c.cyan(pathTemplate)}`);
|
|
225
|
+
console.log(` ${(0, config_edit_1.previewTree)(segments)}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
176
228
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
console.log(` ${ui_1.c.dim('
|
|
180
|
-
|
|
229
|
+
if (!options.embedded) {
|
|
230
|
+
console.log(` ${ui_1.c.dim('saved to')} ${configPath}`);
|
|
231
|
+
console.log(` ${ui_1.c.dim('refresh docs:')} ${ui_1.c.cyan('daxta build')}`);
|
|
232
|
+
console.log('');
|
|
181
233
|
}
|
|
182
|
-
const overrides = (0, config_edit_1.readTreePathOverrides)();
|
|
183
|
-
overrides[pathTemplate] = segments;
|
|
184
|
-
(0, config_edit_1.upsertConfigValue)(configPath, 'treePathOverrides', (0, config_edit_1.formatTsStringRecord)(overrides));
|
|
185
|
-
console.log('');
|
|
186
|
-
console.log(` ${ui_1.c.green('✔')} ${ui_1.c.cyan(pathTemplate)}`);
|
|
187
|
-
console.log(` ${(0, config_edit_1.previewTree)(segments)}`);
|
|
188
|
-
console.log(` ${ui_1.c.dim('saved to')} ${configPath}`);
|
|
189
|
-
console.log(` ${ui_1.c.dim('refresh docs:')} ${ui_1.c.cyan('daxta build')}`);
|
|
190
|
-
console.log('');
|
|
191
234
|
}
|