@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.
@@ -110,31 +110,33 @@ async function resolveTestScript(options) {
110
110
  const def = shown[0];
111
111
  if (options.yes || !process.stdin.isTTY)
112
112
  return def.name;
113
- console.log(` ${ui_1.c.gold('?')} ${ui_1.c.bold('Test script')} ${ui_1.c.dim('— reporter + globalSetup')}`);
114
- shown.forEach((choice, i) => {
115
- const n = String(i + 1);
116
- const rec = i === 0 ? ui_1.c.dim(' recommended') : '';
117
- const cmd = isDaxtaWrappedScript(choice.command)
118
- ? '(already wired → daxta test)'
119
- : choice.command.length > 52
120
- ? `${choice.command.slice(0, 52)}…`
121
- : choice.command;
122
- console.log(` ${ui_1.c.ice(n)} ${ui_1.c.bold(choice.name)}${rec}`);
123
- console.log(` ${ui_1.c.dim(cmd)}`);
113
+ const picked = await (0, ui_1.selectMenu)({
114
+ title: 'Test script',
115
+ subtitle: 'reporter + globalSetup',
116
+ options: [
117
+ ...shown.map((choice, i) => ({
118
+ value: choice.name,
119
+ label: choice.name,
120
+ badge: i === 0 ? 'recommended' : undefined,
121
+ hint: isDaxtaWrappedScript(choice.command)
122
+ ? '(already wired → daxta test)'
123
+ : choice.command.length > 64
124
+ ? `${choice.command.slice(0, 64)}…`
125
+ : choice.command,
126
+ })),
127
+ { value: '__custom__', label: 'Custom script name', hint: 'Type a script name from package.json' },
128
+ { value: '__skip__', label: 'Skip', hint: 'Configure testScript later' },
129
+ ],
124
130
  });
125
- console.log(` ${ui_1.c.dim('n')} skip`);
126
- const answer = await (0, ui_1.readlineAsk)(` ${ui_1.c.dim(`Enter = 1 (${def.name})`)} ${ui_1.c.dim('·')} ${ui_1.c.dim('or type a script name')}\n ${ui_1.c.ice('›')} `);
127
- if (!answer)
128
- return def.name;
129
- if (/^n(o)?$/i.test(answer))
131
+ if (picked === '__skip__')
130
132
  return null;
131
- if (/^\d+$/.test(answer)) {
132
- const picked = shown[Number(answer) - 1];
133
- if (!picked)
134
- throw new Error(`No script #${answer}`);
135
- return picked.name;
133
+ if (picked === '__custom__') {
134
+ const typed = await (0, ui_1.readlineAsk)((0, ui_1.askLine)('Test script name', 'or n to skip'));
135
+ if (!typed || /^n(o)?$/i.test(typed))
136
+ return null;
137
+ return typed;
136
138
  }
137
- return answer;
139
+ return picked;
138
140
  }
139
141
  function upsertConfigFields(cwd, fields, dryRun = false) {
140
142
  const configPath = path.join(cwd, 'daxta.config.ts');
@@ -93,32 +93,32 @@ async function resolveMainPath(cwd, candidates) {
93
93
  throw new Error(`File not found: ${full}`);
94
94
  return full;
95
95
  }
96
- const rel = path.relative(cwd, def);
97
96
  const shown = candidates.slice(0, 8);
98
- console.log(` ${ui_1.c.gold('?')} ${ui_1.c.bold('Nest entry')} ${ui_1.c.dim('— apiDocs(app)')}`);
99
- shown.forEach((file, i) => {
100
- const r = path.relative(cwd, file);
101
- const rec = i === 0 ? ui_1.c.dim(' recommended') : '';
102
- console.log(` ${ui_1.c.ice(String(i + 1))} ${ui_1.c.bold(r)}${rec}`);
97
+ const picked = await (0, ui_1.selectMenu)({
98
+ title: 'Nest entry',
99
+ subtitle: 'apiDocs(app)',
100
+ options: [
101
+ ...shown.map((file, i) => ({
102
+ value: file,
103
+ label: path.relative(cwd, file),
104
+ badge: i === 0 ? 'recommended' : undefined,
105
+ })),
106
+ { value: '__custom__', label: 'Custom path', hint: 'Type another main.ts path' },
107
+ { value: '__skip__', label: 'Skip', hint: 'Do not modify main.ts' },
108
+ ],
103
109
  });
104
- if (candidates.length > shown.length)
105
- console.log(` ${ui_1.c.dim(`… +${candidates.length - shown.length} more`)}`);
106
- console.log(` ${ui_1.c.dim('n')} skip`);
107
- const answer = await (0, ui_1.readlineAsk)(` ${ui_1.c.dim(`Enter = 1 (${rel})`)} ${ui_1.c.dim('·')} ${ui_1.c.dim('or type a path')}\n ${ui_1.c.ice('›')} `);
108
- if (!answer)
109
- return def;
110
- if (/^n(o)?$/i.test(answer))
110
+ if (picked === '__skip__')
111
111
  return null;
112
- if (/^\d+$/.test(answer)) {
113
- const picked = shown[Number(answer) - 1];
114
- if (!picked)
115
- throw new Error(`No file #${answer}`);
116
- return picked;
112
+ if (picked === '__custom__') {
113
+ const typed = await (0, ui_1.readlineAsk)((0, ui_1.askLine)('Nest entry path', 'or n to skip'));
114
+ if (!typed || /^n(o)?$/i.test(typed))
115
+ return null;
116
+ const full = path.isAbsolute(typed) ? typed : path.join(cwd, typed);
117
+ if (!(0, fs_1.existsSync)(full))
118
+ throw new Error(`File not found: ${full}`);
119
+ return full;
117
120
  }
118
- const full = path.isAbsolute(answer) ? answer : path.join(cwd, answer);
119
- if (!(0, fs_1.existsSync)(full))
120
- throw new Error(`File not found: ${full}`);
121
- return full;
121
+ return picked;
122
122
  }
123
123
  function ensureImport(source) {
124
124
  if (source.includes("from '@t0.labs/daxta'") || source.includes('from "@t0.labs/daxta"')) {
@@ -5,6 +5,7 @@ export type InstallOptions = {
5
5
  yes?: boolean;
6
6
  mainPath?: string;
7
7
  skipMain?: boolean;
8
+ serviceName?: string;
8
9
  /** Skip dramatic pacing delays */
9
10
  fast?: boolean;
10
11
  };
@@ -102,19 +102,26 @@ function stripRegisterNodeOptions(pkg) {
102
102
  }
103
103
  return changed;
104
104
  }
105
- function writeConfig(cwd, dryRun) {
105
+ function serviceNameFromPkg(raw) {
106
+ const clean = raw?.replace(/^@[^/]+\//, '').trim();
107
+ if (!clean)
108
+ return 'API';
109
+ return clean.replace(/[-_]+/g, ' ').replace(/\b\w/g, (ch) => ch.toUpperCase());
110
+ }
111
+ function writeConfig(cwd, dryRun, serviceName) {
106
112
  const configPath = path.join(cwd, 'daxta.config.ts');
107
113
  const rel = 'daxta.config.ts';
108
114
  if ((0, fs_1.existsSync)(configPath))
109
115
  return { created: false, rel };
116
+ const safeName = serviceName.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
110
117
  const body = `import { defineConfig } from '@t0.labs/daxta';
111
118
 
112
119
  export default defineConfig({
113
120
  specInfo: () => ({
114
- title: 'API',
115
- version: '1.0.0',
121
+ title: '${safeName}',
122
+ // version defaults to package.json version automatically
116
123
  }),
117
- workspace: 'API',
124
+ workspace: '${safeName}',
118
125
  baseUrl: 'http://localhost:3000',
119
126
  controllersRoot: 'src',
120
127
  outDir: '.daxta/out',
@@ -231,9 +238,16 @@ async function installDaxta(options = {}) {
231
238
  }
232
239
  }
233
240
  (0, ui_1.phase)(2, of, 'Workspace files', 'config, gitignore, NODE_ENV');
241
+ const detectedName = serviceNameFromPkg(pkg.name);
242
+ let serviceName = options.serviceName?.trim() || detectedName;
243
+ if (!(0, fs_1.existsSync)(path.join(cwd, 'daxta.config.ts')) && !options.serviceName && !options.yes && process.stdin.isTTY) {
244
+ const typed = await (0, ui_1.readlineAsk)((0, ui_1.askLine)('API / service title', `Enter = ${detectedName}`));
245
+ if (typed)
246
+ serviceName = typed;
247
+ }
234
248
  await (0, ui_1.step)('Write daxta.config.ts', () => {
235
- const { created, rel } = writeConfig(cwd, dryRun);
236
- return created ? `created ${rel}` : `exists · ${rel}`;
249
+ const { created, rel } = writeConfig(cwd, dryRun, serviceName);
250
+ return created ? `created ${rel} (${serviceName})` : `exists · ${rel}`;
237
251
  }, { paceMs, n: 2, of });
238
252
  await (0, ui_1.step)('Clean package.json scripts', () => {
239
253
  const stripped = stripRegisterNodeOptions(pkg);
package/dist/cli/main.js CHANGED
@@ -1,10 +1,48 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ const fs_1 = require("fs");
37
+ const path = __importStar(require("path"));
3
38
  const build_spec_1 = require("../build/build-spec");
4
39
  const call_1 = require("../call");
5
40
  const config_1 = require("../config");
41
+ const postman_1 = require("../export/postman");
6
42
  const export_fields_1 = require("../fields/export-fields");
7
43
  const serve_1 = require("../serve");
44
+ const paths_1 = require("../serve/paths");
45
+ const spec_utils_1 = require("../serve/spec-utils");
8
46
  const install_1 = require("./install");
9
47
  const migrate_1 = require("./migrate");
10
48
  const test_1 = require("./test");
@@ -12,30 +50,168 @@ const tree_1 = require("./tree");
12
50
  const titles_1 = require("./titles");
13
51
  const uninstall_1 = require("./uninstall");
14
52
  const ui_1 = require("./ui");
53
+ const VALUE_FLAGS = new Set([
54
+ '--port',
55
+ '--out',
56
+ '--fields',
57
+ '--file',
58
+ '--main',
59
+ '--layout',
60
+ '--env',
61
+ '--script',
62
+ '--title',
63
+ '--version',
64
+ '--name',
65
+ ]);
15
66
  function usage() {
16
- const cmd = (name) => ui_1.c.bold(ui_1.c.ice(name));
67
+ const cmd = (name) => ui_1.c.bold(ui_1.c.ice(name.padEnd(14)));
17
68
  console.log('');
18
- console.log(` ${ui_1.c.bold(ui_1.c.ice('DAxTA'))}`);
19
- console.log(` ${ui_1.c.dim('Tested behavior. Trusted API docs.')}`);
69
+ console.log(` ${ui_1.c.bold(ui_1.c.ice('◆ DAxTA'))} ${ui_1.c.dim('Tested behavior. Trusted API docs.')}`);
70
+ console.log(` ${ui_1.c.dim('│')} ${ui_1.c.mint('Quick start')} ${ui_1.c.ice('pnpm dlx @t0.labs/daxta install')}`);
71
+ console.log(` ${ui_1.c.dim('│')}`);
72
+ console.log(` ${ui_1.c.dim('├─')} ${ui_1.c.gold('Setup')}`);
73
+ console.log(` ${ui_1.c.dim('│')} ${cmd('install')} ${ui_1.c.dim('Attach DAxTA to Jest and NestJS')}`);
74
+ console.log(` ${ui_1.c.dim('│')} ${cmd('migrate')} ${ui_1.c.dim('Upgrade project wiring after a package bump')}`);
75
+ console.log(` ${ui_1.c.dim('│')} ${cmd('uninstall')} ${ui_1.c.dim('Remove DAxTA from this project')}`);
76
+ console.log(` ${ui_1.c.dim('│')}`);
77
+ console.log(` ${ui_1.c.dim('├─')} ${ui_1.c.gold('Generate & Export')}`);
78
+ console.log(` ${ui_1.c.dim('│')} ${cmd('generate')} ${ui_1.c.dim('Build OpenAPI + HTML (--postman for Postman collection)')}`);
79
+ console.log(` ${ui_1.c.dim('│')} ${cmd('export')} ${ui_1.c.dim('Export Postman collection + env, or OpenAPI JSON')}`);
80
+ console.log(` ${ui_1.c.dim('│')} ${cmd('serve')} ${ui_1.c.dim('Serve API documentation locally')}`);
81
+ console.log(` ${ui_1.c.dim('│')}`);
82
+ console.log(` ${ui_1.c.dim('├─')} ${ui_1.c.gold('Tests & Naming')}`);
83
+ console.log(` ${ui_1.c.dim('│')} ${cmd('test')} ${ui_1.c.dim('Run project test script (--check-titles to lint names)')}`);
84
+ console.log(` ${ui_1.c.dim('│')} ${cmd('titles')} ${ui_1.c.dim('Align describe/it() names with API docs & examples')}`);
85
+ console.log(` ${ui_1.c.dim('│')} ${cmd('tree')} ${ui_1.c.dim('Configure sidebar folder layout & example label style')}`);
86
+ console.log(` ${ui_1.c.dim('│')}`);
87
+ console.log(` ${ui_1.c.dim('└─')} ${ui_1.c.gold('Try-it')}`);
88
+ console.log(` ${cmd('fields')} ${ui_1.c.dim('Export API field map')}`);
89
+ console.log(` ${cmd('call')} ${ui_1.c.dim('Send a Try-it request from the CLI')}`);
20
90
  console.log('');
21
- console.log(` ${ui_1.c.gold('Setup')}`);
22
- console.log(` ${cmd('daxta install')} ${ui_1.c.dim('Install DAxTA in this project')}`);
23
- console.log(` ${cmd('daxta uninstall')} ${ui_1.c.dim('Remove DAxTA from this project')}`);
24
- console.log(` ${cmd('daxta migrate')} ${ui_1.c.dim('Upgrade project wiring after a package bump')}`);
91
+ console.log(` ${ui_1.c.dim('Run')} ${ui_1.c.ice('pnpm dlx @t0.labs/daxta <command> --help')} ${ui_1.c.dim('for flags and examples.')}`);
25
92
  console.log('');
26
- console.log(` ${ui_1.c.gold('API docs')}`);
27
- console.log(` ${cmd('daxta generate')} ${ui_1.c.dim('Generate API documentation from test execution')}`);
28
- console.log(` ${cmd('daxta serve')} ${ui_1.c.dim('Serve API documentation locally')}`);
29
- console.log(` ${cmd('daxta tree')} ${ui_1.c.dim('Configure API docs sidebar layout')}`);
30
- console.log(` ${cmd('daxta titles')} ${ui_1.c.dim('Align test titles with API docs examples')}`);
31
- console.log(` ${cmd('daxta test')} ${ui_1.c.dim('Run the project test script (Jest stays parent)')}`);
93
+ }
94
+ const COMMAND_HELP = {
95
+ install: {
96
+ summary: 'Attach DAxTA to Jest, create daxta.config.ts, and wire apiDocs(app).',
97
+ usage: 'daxta install [--dry-run] [--yes] [--main <path>] [--skip-dep] [--skip-main]',
98
+ flags: [
99
+ ['--dry-run', 'Preview changes without writing files'],
100
+ ['--yes', 'Accept defaults without interactive prompts'],
101
+ ['--main <path>', 'Path to NestJS main.ts'],
102
+ ['--skip-dep', 'Skip installing @t0.labs/daxta'],
103
+ ['--skip-main', 'Do not inject apiDocs(app) into main.ts'],
104
+ ],
105
+ examples: ['daxta install', 'daxta install --yes --main src/main.ts'],
106
+ },
107
+ generate: {
108
+ summary: 'Build OpenAPI spec and standalone HTML viewer from recorded test hits.',
109
+ usage: 'daxta generate [--postman] [--ui] [--out <path>] [--env <name>]',
110
+ flags: [
111
+ ['--postman', 'Also export Postman Collection v2.1 + Environment'],
112
+ ['--ui', 'Refresh only the HTML viewer from existing openapi.json'],
113
+ ['--out <path>', 'Output file/directory for Postman export (with --postman)'],
114
+ ['--env <name>', 'Environment preset name from daxta.config.ts'],
115
+ ],
116
+ examples: ['daxta generate', 'daxta generate --ui', 'daxta generate --postman', 'daxta generate --postman --out ./collections'],
117
+ },
118
+ export: {
119
+ summary: 'Export Postman Collection v2.1 (+ Environment) or stripped OpenAPI JSON.',
120
+ usage: 'daxta export [postman|openapi] [--out <path>] [--env <name>] [--no-env] [--no-vars]',
121
+ flags: [
122
+ ['--out <path>', 'Output file or directory'],
123
+ ['--env <name>', 'Select envPreset from daxta.config.ts'],
124
+ ['--no-env', 'Skip writing .postman_environment.json'],
125
+ ['--no-vars', 'Use concrete server URL instead of {{baseUrl}}'],
126
+ ],
127
+ examples: [
128
+ 'daxta export',
129
+ 'daxta export postman --out ./postman',
130
+ 'daxta export openapi --out ./openapi.json',
131
+ ],
132
+ },
133
+ serve: {
134
+ summary: 'Serve generated API docs locally with Try-it proxy.',
135
+ usage: 'daxta serve [--port <number>]',
136
+ flags: [['--port <number>', 'Port to listen on (default from daxta.config.ts or 4400)']],
137
+ examples: ['daxta serve', 'daxta serve --port 4500'],
138
+ },
139
+ test: {
140
+ summary: 'Run the project test script (Jest stays parent and records HTTP traffic).',
141
+ usage: 'daxta test [--check-titles] [--yes] [--strict] [--script <name>] [-- <jest args>]',
142
+ flags: [
143
+ ['--check-titles', 'Run title/example naming check before tests'],
144
+ ['--yes', 'Auto-apply safe naming fixes (with --check-titles)'],
145
+ ['--strict', 'Fail if unformatted test names remain'],
146
+ ['--script <name>', 'Override package.json test script'],
147
+ ],
148
+ examples: ['daxta test', 'daxta test --check-titles', 'daxta test -- --runInBand'],
149
+ },
150
+ titles: {
151
+ summary: 'Scan and align describe() / it() test names for clean operation & example labels.',
152
+ usage: 'daxta titles [--check] [--yes] [--strict]',
153
+ flags: [
154
+ ['--check', 'Report findings without modifying files'],
155
+ ['--yes', 'Auto-apply recommended rewrites'],
156
+ ['--strict', 'Exit with code 1 if findings remain'],
157
+ ],
158
+ examples: ['daxta titles', 'daxta titles --check', 'daxta titles --yes'],
159
+ },
160
+ tree: {
161
+ summary: 'Configure sidebar folder layout and example label style in daxta.config.ts.',
162
+ usage: 'daxta tree [<path>] [--layout <role-resource|resource-role>]',
163
+ flags: [['--layout <mode>', 'Set treeLayout: role-resource or resource-role']],
164
+ examples: ['daxta tree', 'daxta tree --layout resource-role'],
165
+ },
166
+ fields: {
167
+ summary: 'Export API field map JSON for Try-it / CLI calls.',
168
+ usage: 'daxta fields [<method> <path>] [--out <file>]',
169
+ flags: [['--out <file>', 'Target JSON file path']],
170
+ examples: ['daxta fields', 'daxta fields post /v1/users'],
171
+ },
172
+ call: {
173
+ summary: 'Send an interactive or file-driven Try-it HTTP request.',
174
+ usage: 'daxta call [<method> <path>] [--file <values.json>] [--fields <file>] [--header <k:v>]',
175
+ flags: [
176
+ ['--file <path>', 'Execute request from a JSON values file'],
177
+ ['--fields <path>', 'Field map JSON file'],
178
+ ['--header <k:v>', 'Add a request header (repeatable)'],
179
+ ],
180
+ examples: ['daxta call', 'daxta call get /v1/users --header "Authorization: Bearer ..."'],
181
+ },
182
+ };
183
+ function printCommandHelp(command) {
184
+ const canonical = command === 'build'
185
+ ? 'generate'
186
+ : command === 'init'
187
+ ? 'install'
188
+ : command === 'title'
189
+ ? 'titles'
190
+ : command;
191
+ const info = COMMAND_HELP[canonical];
192
+ if (!info)
193
+ return false;
32
194
  console.log('');
33
- console.log(` ${ui_1.c.gold('Try-it')}`);
34
- console.log(` ${cmd('daxta fields')} ${ui_1.c.dim('Export API field map')}`);
35
- console.log(` ${cmd('daxta call')} ${ui_1.c.dim('Send a Try-it request from the CLI')}`);
195
+ console.log(` ${ui_1.c.bold(ui_1.c.ice(`daxta ${canonical}`))} ${ui_1.c.dim(info.summary)}`);
36
196
  console.log('');
37
- console.log(` ${ui_1.c.mint('First time')} ${ui_1.c.ice('pnpm dlx @t0.labs/daxta install')}`);
197
+ console.log(` ${ui_1.c.gold('Usage')}`);
198
+ console.log(` ${info.usage}`);
199
+ if (info.flags.length) {
200
+ console.log('');
201
+ console.log(` ${ui_1.c.gold('Flags')}`);
202
+ for (const [flag, desc] of info.flags) {
203
+ console.log(` ${ui_1.c.ice(flag.padEnd(20))} ${ui_1.c.dim(desc)}`);
204
+ }
205
+ }
206
+ if (info.examples.length) {
207
+ console.log('');
208
+ console.log(` ${ui_1.c.gold('Examples')}`);
209
+ for (const ex of info.examples) {
210
+ console.log(` ${ui_1.c.dim('$')} ${ex}`);
211
+ }
212
+ }
38
213
  console.log('');
214
+ return true;
39
215
  }
40
216
  function parseArgs(argv) {
41
217
  const args = argv.slice(2);
@@ -48,32 +224,98 @@ function parseArgs(argv) {
48
224
  const token = rest[i];
49
225
  if (token === '--')
50
226
  break;
51
- if (token === '--port' || token === '--out' || token === '--fields' || token === '--file' || token === '--main' || token === '--layout') {
52
- flags[token.slice(2)] = rest[++i];
227
+ if (VALUE_FLAGS.has(token)) {
228
+ const next = rest[++i];
229
+ if (!next || next.startsWith('--')) {
230
+ throw new Error(`Missing value for ${token}`);
231
+ }
232
+ flags[token.slice(2)] = next;
53
233
  }
54
234
  else if (token === '--header') {
55
235
  const raw = rest[++i] ?? '';
56
236
  const idx = raw.indexOf(':');
57
237
  if (idx === -1)
58
- throw new Error(`Invalid --header ${raw}; expected name:value`);
238
+ throw new Error(`Invalid --header "${raw}"; expected name:value`);
59
239
  headers[raw.slice(0, idx).trim()] = raw.slice(idx + 1).trim();
60
240
  }
241
+ else if (token.startsWith('--no-')) {
242
+ flags[token.slice(5)] = false;
243
+ }
61
244
  else if (token.startsWith('--')) {
62
245
  flags[token.slice(2)] = true;
63
246
  }
247
+ else if (token === '-h') {
248
+ flags.help = true;
249
+ }
250
+ else if (token === '-y') {
251
+ flags.yes = true;
252
+ }
64
253
  else {
65
254
  positional.push(token);
66
255
  }
67
256
  }
68
257
  return { command, rest, positional, flags, headers };
69
258
  }
259
+ async function handleExport(positional, flags) {
260
+ const format = (positional[0] || 'postman').toLowerCase();
261
+ if (format !== 'postman' && format !== 'openapi') {
262
+ throw new Error(`Unknown export format "${format}". Expected "postman" or "openapi".`);
263
+ }
264
+ if (!(0, fs_1.existsSync)((0, paths_1.getSpecJsonPath)())) {
265
+ await (0, ui_1.step)('Building OpenAPI spec from recorded hits', () => {
266
+ const build = (0, build_spec_1.generateApiDocs)({ requireHits: false, silent: true });
267
+ if (build.skipped) {
268
+ throw new Error('No OpenAPI spec or recorded hits found. Run your integration tests first.');
269
+ }
270
+ return `${build.operations} ops · ${build.hits} hits`;
271
+ });
272
+ }
273
+ if (format === 'openapi') {
274
+ const body = (0, spec_utils_1.readStrippedOpenApiJson)();
275
+ if (!body)
276
+ throw new Error('Failed to read OpenAPI spec.');
277
+ const target = typeof flags.out === 'string' ? path.resolve(flags.out) : path.resolve('openapi.json');
278
+ await (0, ui_1.step)('Writing OpenAPI JSON', () => {
279
+ (0, fs_1.mkdirSync)(path.dirname(target), { recursive: true });
280
+ (0, fs_1.writeFileSync)(target, body);
281
+ return path.basename(target);
282
+ });
283
+ (0, ui_1.box)('OpenAPI Export Ready', [`Spec: ${ui_1.c.ice(path.relative(process.cwd(), target) || target)}`]);
284
+ return;
285
+ }
286
+ let result;
287
+ await (0, ui_1.step)('Exporting Postman Collection v2.1', () => {
288
+ result = (0, postman_1.exportPostmanFiles)({
289
+ out: typeof flags.out === 'string' ? flags.out : undefined,
290
+ envName: typeof flags.env === 'string' ? flags.env : undefined,
291
+ includeEnv: flags.env !== false,
292
+ useEnvVar: flags.vars !== false,
293
+ });
294
+ return `${result.operations} ops · ${result.examples} examples`;
295
+ });
296
+ const relCol = path.relative(process.cwd(), result.collectionPath) || result.collectionPath;
297
+ const lines = [`Collection: ${ui_1.c.ice(relCol)}`];
298
+ if (result.environmentPath) {
299
+ const relEnv = path.relative(process.cwd(), result.environmentPath) || result.environmentPath;
300
+ lines.push(`Environment: ${ui_1.c.ice(relEnv)}`);
301
+ }
302
+ lines.push(`Coverage: ${result.operations} operations · ${result.examples} named examples`);
303
+ (0, ui_1.box)('Postman Export Ready', lines);
304
+ }
70
305
  async function main() {
71
306
  const { command, rest, positional, flags, headers } = parseArgs(process.argv);
72
307
  if (!command || command === 'help' || command === '--help' || command === '-h') {
308
+ if (positional[0] && printCommandHelp(positional[0]))
309
+ return;
310
+ usage();
311
+ return;
312
+ }
313
+ if (flags.help) {
314
+ if (printCommandHelp(command))
315
+ return;
73
316
  usage();
74
317
  return;
75
318
  }
76
- // Migrate only on package version bump (or daxta migrate --force)
77
319
  if (command === 'migrate') {
78
320
  const migration = (0, migrate_1.migrateProject)(process.cwd(), { force: true });
79
321
  if (!migration.changed) {
@@ -95,9 +337,12 @@ async function main() {
95
337
  });
96
338
  return;
97
339
  }
98
- (0, migrate_1.reportMigration)((0, migrate_1.migrateProject)());
99
340
  (0, config_1.resetConfig)();
100
341
  (0, config_1.getConfig)(true);
342
+ if (typeof flags.title === 'string')
343
+ process.env.DAXTA_SPEC_TITLE = flags.title;
344
+ if (typeof flags.version === 'string')
345
+ process.env.DAXTA_SPEC_VERSION = flags.version;
101
346
  if (command === 'install' || command === 'init') {
102
347
  await (0, install_1.installDaxta)({
103
348
  dryRun: Boolean(flags['dry-run']),
@@ -106,6 +351,11 @@ async function main() {
106
351
  yes: Boolean(flags.yes),
107
352
  fast: Boolean(flags.fast),
108
353
  mainPath: typeof flags.main === 'string' ? flags.main : undefined,
354
+ serviceName: typeof flags.name === 'string'
355
+ ? flags.name
356
+ : typeof flags.title === 'string'
357
+ ? flags.title
358
+ : undefined,
109
359
  });
110
360
  (0, migrate_1.reportMigration)((0, migrate_1.migrateProject)(process.cwd(), { force: true }));
111
361
  return;
@@ -127,7 +377,15 @@ async function main() {
127
377
  return;
128
378
  }
129
379
  if (command === 'generate' || command === 'build') {
130
- (0, build_spec_1.generateApiDocs)({ requireHits: true });
380
+ (0, migrate_1.reportMigration)((0, migrate_1.migrateProject)());
381
+ (0, build_spec_1.generateApiDocs)({ requireHits: !flags.ui, uiOnly: Boolean(flags.ui) });
382
+ if (flags.postman) {
383
+ await handleExport(['postman'], flags);
384
+ }
385
+ return;
386
+ }
387
+ if (command === 'export') {
388
+ await handleExport(positional, flags);
131
389
  return;
132
390
  }
133
391
  if (command === 'serve') {
@@ -165,6 +423,7 @@ async function main() {
165
423
  });
166
424
  return;
167
425
  }
426
+ console.error(` ${ui_1.c.red('✖')} Unknown command: ${ui_1.c.bold(command)}`);
168
427
  usage();
169
428
  process.exitCode = 1;
170
429
  }
package/dist/cli/test.js CHANGED
@@ -64,6 +64,7 @@ async function runDaxtaTest(options = {}) {
64
64
  const passthrough = [];
65
65
  let yes = false;
66
66
  let strict = false;
67
+ let checkTitles = false;
67
68
  let scriptFlag;
68
69
  for (let i = 0; i < (options.argv ?? []).length; i += 1) {
69
70
  const token = (options.argv ?? [])[i];
@@ -71,6 +72,8 @@ async function runDaxtaTest(options = {}) {
71
72
  yes = true;
72
73
  else if (token === '--strict')
73
74
  strict = true;
75
+ else if (token === '--check-titles' || token === '--titles')
76
+ checkTitles = true;
74
77
  else if (token === '--script')
75
78
  scriptFlag = (options.argv ?? [])[++i];
76
79
  else if (token === '--')
@@ -95,10 +98,12 @@ async function runDaxtaTest(options = {}) {
95
98
  process.exitCode = 1;
96
99
  return;
97
100
  }
98
- const titleExit = await (0, titles_1.runTitleCheck)({ cwd, yes, strict });
99
- if (titleExit !== 0) {
100
- process.exitCode = titleExit;
101
- return;
101
+ if (checkTitles) {
102
+ const titleExit = await (0, titles_1.runTitleCheck)({ cwd, yes, strict });
103
+ if (titleExit !== 0) {
104
+ process.exitCode = titleExit;
105
+ return;
106
+ }
102
107
  }
103
108
  console.log(`${ui_1.c.dim('DAxTA')} forwarding to ${ui_1.c.cyan(`${pm} run ${scriptName}`)} ${ui_1.c.dim('(Jest stays parent)')}`);
104
109
  const args = pm === 'npm' ? ['run', scriptName, '--', ...passthrough] : ['run', scriptName, ...passthrough];