@t0.labs/daxta 0.2.1 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,12 +38,23 @@ const fs_1 = require("fs");
38
38
  const path = __importStar(require("path"));
39
39
  const child_process_1 = require("child_process");
40
40
  const inject_main_1 = require("./inject-main");
41
+ const discover_test_1 = require("./discover-test");
42
+ const ui_1 = require("./ui");
41
43
  function readJson(filePath) {
42
44
  return JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
43
45
  }
44
46
  function writeJson(filePath, value) {
45
47
  (0, fs_1.writeFileSync)(filePath, `${JSON.stringify(value, null, 2)}\n`);
46
48
  }
49
+ function selfVersion() {
50
+ try {
51
+ const pkgPath = path.join(__dirname, '..', '..', 'package.json');
52
+ return (readJson(pkgPath).version || '').trim() || 'latest';
53
+ }
54
+ catch {
55
+ return 'latest';
56
+ }
57
+ }
47
58
  function detectPackageManager(cwd, pkg) {
48
59
  if ((0, fs_1.existsSync)(path.join(cwd, 'pnpm-lock.yaml')) || pkg.packageManager?.startsWith('pnpm'))
49
60
  return 'pnpm';
@@ -51,12 +62,11 @@ function detectPackageManager(cwd, pkg) {
51
62
  return 'yarn';
52
63
  return 'npm';
53
64
  }
54
- function ensureDependency(pkg) {
55
- const inDeps = Boolean(pkg.dependencies?.['@t0.labs/daxta'] || pkg.devDependencies?.['@t0.labs/daxta']);
56
- if (inDeps)
57
- return false;
58
- pkg.devDependencies = { ...(pkg.devDependencies ?? {}), '@t0.labs/daxta': '^0.2.0' };
59
- return true;
65
+ function isDaxtaListed(pkg) {
66
+ return Boolean(pkg.dependencies?.['@t0.labs/daxta'] || pkg.devDependencies?.['@t0.labs/daxta']);
67
+ }
68
+ function isDaxtaInstalled(cwd) {
69
+ return (0, fs_1.existsSync)(path.join(cwd, 'node_modules', '@t0.labs', 'daxta', 'package.json'));
60
70
  }
61
71
  function ensureScripts(pkg) {
62
72
  const scripts = (pkg.scripts ??= {});
@@ -74,14 +84,12 @@ function ensureScripts(pkg) {
74
84
  changed.push(key);
75
85
  }
76
86
  }
77
- // drop legacy alias that wrapped NODE_OPTIONS
78
87
  if (scripts['daxta:start']) {
79
88
  delete scripts['daxta:start'];
80
89
  changed.push('removed daxta:start');
81
90
  }
82
91
  return changed;
83
92
  }
84
- /** Remove NODE_OPTIONS=--require @t0.labs/daxta/register hacks from start scripts. */
85
93
  function stripRegisterNodeOptions(pkg) {
86
94
  const scripts = pkg.scripts ?? {};
87
95
  const changed = [];
@@ -90,7 +98,6 @@ function stripRegisterNodeOptions(pkg) {
90
98
  if (!value.includes('@t0.labs/daxta/register'))
91
99
  continue;
92
100
  let next = value.replace(re, '');
93
- // also strip mid-string require if somehow embedded
94
101
  next = next
95
102
  .replace(/\s*--require\s+@t0\.labs\/daxta\/register\b/g, '')
96
103
  .replace(/NODE_OPTIONS=(['"])\s*\1\s*/g, '')
@@ -105,8 +112,9 @@ function stripRegisterNodeOptions(pkg) {
105
112
  }
106
113
  function writeConfig(cwd, dryRun) {
107
114
  const configPath = path.join(cwd, 'daxta.config.ts');
115
+ const rel = 'daxta.config.ts';
108
116
  if ((0, fs_1.existsSync)(configPath))
109
- return `exists ${configPath}`;
117
+ return { created: false, rel };
110
118
  const body = `import { defineConfig } from '@t0.labs/daxta';
111
119
 
112
120
  export default defineConfig({
@@ -121,90 +129,145 @@ export default defineConfig({
121
129
  `;
122
130
  if (!dryRun)
123
131
  (0, fs_1.writeFileSync)(configPath, body);
124
- return `wrote ${configPath}`;
132
+ return { created: true, rel };
125
133
  }
126
134
  function ensureGitignore(cwd, dryRun) {
127
135
  const gitignorePath = path.join(cwd, '.gitignore');
128
- const entry = 'daxta/out/';
136
+ const entries = ['daxta/out/', '**/.jest.daxta.runtime.json'];
129
137
  if (!(0, fs_1.existsSync)(gitignorePath)) {
130
138
  if (!dryRun)
131
- (0, fs_1.writeFileSync)(gitignorePath, `${entry}\n**/.jest.daxta.runtime.json\n`);
132
- return `wrote .gitignore (+ ${entry})`;
139
+ (0, fs_1.writeFileSync)(gitignorePath, `${entries.join('\n')}\n`);
140
+ return entries.map((e) => `created .gitignore (+ ${e})`);
133
141
  }
134
142
  const text = (0, fs_1.readFileSync)(gitignorePath, 'utf8');
135
- const lines = text.split(/\r?\n/).map((l) => l.trim());
136
- if (lines.includes(entry) || lines.includes('daxta/') || lines.includes('daxta/out')) {
137
- return null;
143
+ const lines = new Set(text.split(/\r?\n/).map((l) => l.trim()));
144
+ const added = [];
145
+ let next = text;
146
+ for (const entry of entries) {
147
+ if (lines.has(entry) || lines.has('daxta/') || (entry === 'daxta/out/' && lines.has('daxta/out')))
148
+ continue;
149
+ next = next.endsWith('\n') ? `${next}${entry}\n` : `${next}\n${entry}\n`;
150
+ added.push(entry);
138
151
  }
139
- const extra = `${entry}\n**/.jest.daxta.runtime.json`;
140
- if (!dryRun)
141
- (0, fs_1.writeFileSync)(gitignorePath, text.endsWith('\n') ? `${text}${extra}\n` : `${text}\n${extra}\n`);
142
- return `gitignore += ${entry}, **/.jest.daxta.runtime.json`;
152
+ if (added.length && !dryRun)
153
+ (0, fs_1.writeFileSync)(gitignorePath, next);
154
+ return added.map((e) => `.gitignore += ${e}`);
143
155
  }
144
- function runPackageInstall(cwd, pm, dryRun) {
156
+ function runPackageInstall(cwd, pm, version, dryRun) {
145
157
  if (dryRun)
146
- return 'dry-run skip package install';
147
- const args = pm === 'pnpm' ? ['add', '-D', '@t0.labs/daxta'] : pm === 'yarn' ? ['add', '-D', '@t0.labs/daxta'] : ['install', '-D', '@t0.labs/daxta'];
158
+ return 'dry-run';
159
+ const spec = version === 'latest' ? '@t0.labs/daxta' : `@t0.labs/daxta@${version}`;
160
+ const args = pm === 'npm' ? ['install', '-D', spec] : ['add', '-D', spec];
148
161
  const result = (0, child_process_1.spawnSync)(pm, args, { cwd, stdio: 'inherit', shell: process.platform === 'win32' });
149
162
  if (result.status !== 0)
150
163
  throw new Error(`${pm} ${args.join(' ')} failed`);
151
- return `installed @t0.labs/daxta via ${pm}`;
164
+ return spec;
152
165
  }
153
166
  /**
154
- * Bootstrap: config, outDir, scripts, strip NODE_OPTIONS hacks,
155
- * prompt to inject `docs(app)` into main.ts.
167
+ * One-shot bootstrap with paced, colored steps.
168
+ * Prefer: `pnpm dlx @t0.labs/daxta install`
156
169
  */
157
170
  async function installDaxta(options = {}) {
158
171
  const cwd = options.cwd ?? process.cwd();
159
172
  const dryRun = Boolean(options.dryRun);
173
+ const paceMs = options.fast || dryRun || process.env.CI ? 0 : 2200;
160
174
  const pkgPath = path.join(cwd, 'package.json');
161
175
  if (!(0, fs_1.existsSync)(pkgPath))
162
176
  throw new Error(`No package.json in ${cwd}`);
163
- const pkg = readJson(pkgPath);
177
+ let pkg = readJson(pkgPath);
164
178
  const pm = detectPackageManager(cwd, pkg);
165
- const log = [];
166
- log.push(writeConfig(cwd, dryRun));
167
- const depAdded = ensureDependency(pkg);
168
- if (depAdded)
169
- log.push('package.json: added @t0.labs/daxta to devDependencies');
170
- const stripped = stripRegisterNodeOptions(pkg);
171
- if (stripped.length)
172
- log.push(`removed NODE_OPTIONS register from: ${stripped.join(', ')}`);
173
- const scriptChanges = ensureScripts(pkg);
174
- if (scriptChanges.length)
175
- log.push(`package.json scripts: ${scriptChanges.join(', ')}`);
176
- if (!dryRun)
177
- writeJson(pkgPath, pkg);
178
- const outDir = path.join(cwd, 'daxta', 'out');
179
- if (!dryRun)
180
- (0, fs_1.mkdirSync)(outDir, { recursive: true });
181
- log.push('outDir ready: daxta/out');
182
- const gi = ensureGitignore(cwd, dryRun);
183
- if (gi)
184
- log.push(gi);
185
- if (!options.skipDep && depAdded)
186
- log.push(runPackageInstall(cwd, pm, dryRun));
187
- else if (!options.skipDep)
188
- log.push('@t0.labs/daxta already listed (skip package manager add)');
179
+ const version = selfVersion();
180
+ const project = pkg.name || path.basename(cwd);
181
+ (0, ui_1.banner)('DAxTA install', `v${version} · ${project}`);
182
+ if (paceMs)
183
+ await (0, ui_1.sleep)(700);
184
+ await (0, ui_1.step)('Detect package manager', () => pm, { paceMs });
185
+ if (!options.skipDep) {
186
+ if (!isDaxtaListed(pkg) || !isDaxtaInstalled(cwd)) {
187
+ await (0, ui_1.step)(`Add @t0.labs/daxta via ${pm}`, () => {
188
+ const spec = runPackageInstall(cwd, pm, version, dryRun);
189
+ if (!dryRun)
190
+ pkg = readJson(pkgPath);
191
+ return { summary: 'devDependency', details: [spec] };
192
+ }, { paceMs: paceMs ? 600 : 0 });
193
+ }
194
+ else {
195
+ await (0, ui_1.step)('Package dependency', () => 'already installed — skip add', { paceMs });
196
+ }
197
+ }
198
+ await (0, ui_1.step)('Write daxta.config.ts', () => {
199
+ const { created, rel } = writeConfig(cwd, dryRun);
200
+ return created ? `created ${rel}` : `exists · ${rel}`;
201
+ }, { paceMs });
202
+ await (0, ui_1.step)('Patch package.json scripts', () => {
203
+ const stripped = stripRegisterNodeOptions(pkg);
204
+ const scriptChanges = ensureScripts(pkg);
205
+ if (!dryRun)
206
+ writeJson(pkgPath, pkg);
207
+ const details = [];
208
+ if (stripped.length)
209
+ details.push(`removed NODE_OPTIONS register: ${stripped.join(', ')}`);
210
+ if (scriptChanges.length)
211
+ details.push(`+ ${scriptChanges.join(', ')}`);
212
+ if (!details.length)
213
+ return 'unchanged';
214
+ return { summary: `${details.length} change(s)`, details };
215
+ }, { paceMs });
216
+ await (0, ui_1.step)('Prepare output dir', () => {
217
+ if (!dryRun)
218
+ (0, fs_1.mkdirSync)(path.join(cwd, 'daxta', 'out'), { recursive: true });
219
+ return 'daxta/out';
220
+ }, { paceMs });
221
+ await (0, ui_1.step)('Update .gitignore', () => {
222
+ const notes = ensureGitignore(cwd, dryRun);
223
+ if (!notes.length)
224
+ return 'already ignored';
225
+ return { summary: `${notes.length} entr${notes.length === 1 ? 'y' : 'ies'}`, details: notes };
226
+ }, { paceMs });
189
227
  if (!options.skipMain) {
190
- const note = await (0, inject_main_1.promptAndInjectMain)({
228
+ console.log('');
229
+ console.log(` ${ui_1.c.yellow(ui_1.c.bold('?'))} ${ui_1.c.bold('Nest entry')} ${ui_1.c.dim('— wire apiDocs(app)')}`);
230
+ const target = await (0, inject_main_1.resolveMainTarget)({
191
231
  cwd,
192
- dryRun,
193
232
  yes: options.yes,
194
233
  mainPath: options.mainPath,
195
234
  });
196
- if (note)
197
- log.push(note);
235
+ if (!target) {
236
+ await (0, ui_1.step)('Inject apiDocs(app)', () => 'skipped', { paceMs });
237
+ }
238
+ else {
239
+ await (0, ui_1.step)('Inject apiDocs(app)', () => {
240
+ const note = (0, inject_main_1.injectApiDocs)(target, dryRun);
241
+ const rel = path.relative(cwd, target);
242
+ return {
243
+ summary: rel,
244
+ details: [
245
+ note.includes('already') ? 'apiDocs(app) already present' : 'import { apiDocs } + apiDocs(app)',
246
+ `file · ${rel}`,
247
+ ],
248
+ };
249
+ }, { paceMs });
250
+ }
198
251
  }
199
- console.log('DAxTA install complete:\n' + log.map((line) => ` - ${line}`).join('\n'));
200
- console.log(`
201
- Set in .env (required when docs(app) runs):
202
- DAXTA_DOCS=true # enable /docs
203
- DAXTA_DOCS=false # disable (explicit)
204
-
205
- Then:
206
- daxta test # record hits from integration tests
207
- daxta serve # standalone docs viewer
208
- daxta build # rebuild OpenAPI from hits
209
- `);
252
+ console.log('');
253
+ console.log(` ${ui_1.c.yellow(ui_1.c.bold('?'))} ${ui_1.c.bold('Test script')} ${ui_1.c.dim('— used by daxta test')}`);
254
+ const testScript = await (0, discover_test_1.resolveTestScript)({
255
+ cwd,
256
+ scripts: pkg.scripts,
257
+ yes: options.yes,
258
+ });
259
+ if (testScript) {
260
+ await (0, ui_1.step)('Save test script', () => (0, discover_test_1.upsertTestScriptInConfig)(cwd, testScript, dryRun), { paceMs });
261
+ }
262
+ else {
263
+ await (0, ui_1.step)('Save test script', () => 'skipped — daxta test will ask later', { paceMs });
264
+ }
265
+ (0, ui_1.box)('Done', [
266
+ `${ui_1.c.green('✔')} DAxTA wired for ${ui_1.c.bold(project)}`,
267
+ `${ui_1.c.dim('env')} ${ui_1.c.cyan('DAXTA_DOCS=true')} or ${ui_1.c.cyan('false')} ${ui_1.c.dim('(required — app throws if missing)')}`,
268
+ ]);
269
+ (0, ui_1.nextSteps)([
270
+ { cmd: 'echo "DAXTA_DOCS=true" >> .env', why: 'enable /docs on the app port' },
271
+ { cmd: 'daxta test', why: 'run tests → build OpenAPI → serve docs' },
272
+ ]);
210
273
  }
package/dist/cli/main.js CHANGED
@@ -11,18 +11,20 @@ function usage() {
11
11
  console.log(`DAxTA CLI (@t0.labs/daxta)
12
12
 
13
13
  Usage:
14
- daxta install [--dry-run] [--skip-dep] [--skip-main] [--yes] [--main <path>]
14
+ daxta install [--dry-run] [--skip-dep] [--skip-main] [--yes] [--main <path>] [--fast]
15
15
  daxta init (alias of install)
16
- daxta test [--config <jest.json>] [-- <jest args>]
16
+ daxta test [--script <name>] [--config <jest.json>] [--port <n>] [--no-serve] [--yes]
17
17
  daxta build
18
18
  daxta serve [--port <n>]
19
19
  daxta fields [METHOD] [PATH] [--out <file>]
20
20
  daxta call [METHOD] [PATH] [--fields <file>] [--header k:v ...]
21
21
  daxta call --file <values.json> [--header k:v ...]
22
22
 
23
- install:
24
- writes config, strips NODE_OPTIONS register hacks, asks to inject
25
- docs(app) into main.ts (requires DAXTA_DOCS env at runtime)
23
+ One-shot setup:
24
+ pnpm dlx @t0.labs/daxta install
25
+ npx @t0.labs/daxta install
26
+
27
+ daxta test = learn/run project tests → build → serve docs
26
28
  `);
27
29
  }
28
30
  function parseArgs(argv) {
@@ -69,13 +71,14 @@ async function main() {
69
71
  skipDep: Boolean(flags['skip-dep']),
70
72
  skipMain: Boolean(flags['skip-main']),
71
73
  yes: Boolean(flags.yes),
74
+ fast: Boolean(flags.fast),
72
75
  mainPath: typeof flags.main === 'string' ? flags.main : undefined,
73
76
  });
74
77
  return;
75
78
  }
76
79
  if (command === 'test') {
77
80
  const argv = rest[0] === '--' ? rest.slice(1) : rest;
78
- (0, test_1.runDaxtaTest)({ argv });
81
+ await (0, test_1.runDaxtaTest)({ argv });
79
82
  return;
80
83
  }
81
84
  if (command === 'build') {
@@ -84,7 +87,7 @@ async function main() {
84
87
  }
85
88
  if (command === 'serve') {
86
89
  const port = flags.port ? Number(flags.port) : undefined;
87
- (0, serve_1.serveDocs)({ port });
90
+ (0, serve_1.serveApiDocs)({ port });
88
91
  return;
89
92
  }
90
93
  if (command === 'fields') {
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Run Jest with DAxTA recording injected via a temp config — no project file edits.
2
+ * Learn project test script → run with recording → build OpenAPI → serve docs.
3
3
  */
4
4
  export declare function runDaxtaTest(options?: {
5
5
  cwd?: string;
6
6
  argv?: string[];
7
- }): void;
7
+ }): Promise<void>;
package/dist/cli/test.js CHANGED
@@ -39,7 +39,12 @@ const path = __importStar(require("path"));
39
39
  const child_process_1 = require("child_process");
40
40
  const build_spec_1 = require("../build/build-spec");
41
41
  const incremental_1 = require("../build/incremental");
42
+ const config_1 = require("../config");
42
43
  const recorder_1 = require("../recorder");
44
+ const paths_1 = require("../serve/paths");
45
+ const serve_1 = require("../serve");
46
+ const discover_test_1 = require("./discover-test");
47
+ const ui_1 = require("./ui");
43
48
  function walk(dir, match, out = [], depth = 0) {
44
49
  if (depth > 6 || !(0, fs_1.existsSync)(dir))
45
50
  return out;
@@ -78,6 +83,10 @@ function preferIntegrationConfig(files) {
78
83
  function parseTestArgs(argv) {
79
84
  const passthrough = [];
80
85
  let configFromFlag;
86
+ let scriptFromFlag;
87
+ let port;
88
+ let noServe = false;
89
+ let yes = false;
81
90
  for (let i = 0; i < argv.length; i += 1) {
82
91
  const token = argv[i];
83
92
  if (token === '--') {
@@ -92,9 +101,29 @@ function parseTestArgs(argv) {
92
101
  configFromFlag = token.slice('--config='.length);
93
102
  continue;
94
103
  }
104
+ if (token === '--script') {
105
+ scriptFromFlag = argv[++i];
106
+ continue;
107
+ }
108
+ if (token.startsWith('--script=')) {
109
+ scriptFromFlag = token.slice('--script='.length);
110
+ continue;
111
+ }
112
+ if (token === '--port') {
113
+ port = Number(argv[++i]);
114
+ continue;
115
+ }
116
+ if (token === '--no-serve') {
117
+ noServe = true;
118
+ continue;
119
+ }
120
+ if (token === '--yes' || token === '-y') {
121
+ yes = true;
122
+ continue;
123
+ }
95
124
  passthrough.push(token);
96
125
  }
97
- return { configFromFlag, passthrough };
126
+ return { configFromFlag, scriptFromFlag, passthrough, port, noServe, yes };
98
127
  }
99
128
  function loadJestJson(filePath) {
100
129
  return JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
@@ -125,24 +154,71 @@ function resolveJestBin(cwd) {
125
154
  return local;
126
155
  return 'jest';
127
156
  }
157
+ function readPkg(cwd) {
158
+ return JSON.parse((0, fs_1.readFileSync)(path.join(cwd, 'package.json'), 'utf8'));
159
+ }
160
+ function detectPackageManager(cwd, pkg) {
161
+ if ((0, fs_1.existsSync)(path.join(cwd, 'pnpm-lock.yaml')) || pkg.packageManager?.startsWith('pnpm'))
162
+ return 'pnpm';
163
+ if ((0, fs_1.existsSync)(path.join(cwd, 'yarn.lock')))
164
+ return 'yarn';
165
+ return 'npm';
166
+ }
167
+ function resolveBaseConfigPath(cwd, options) {
168
+ if (options.configFromFlag) {
169
+ return path.isAbsolute(options.configFromFlag)
170
+ ? options.configFromFlag
171
+ : path.join(cwd, options.configFromFlag);
172
+ }
173
+ if (options.jestConfig) {
174
+ return path.isAbsolute(options.jestConfig) ? options.jestConfig : path.join(cwd, options.jestConfig);
175
+ }
176
+ if (options.scriptCommand) {
177
+ const fromScript = (0, discover_test_1.extractJestConfigFromCommand)(options.scriptCommand);
178
+ if (fromScript) {
179
+ return path.isAbsolute(fromScript) ? fromScript : path.join(cwd, fromScript);
180
+ }
181
+ }
182
+ const found = walk(cwd, (name) => name.startsWith('jest.') && name.endsWith('.json'));
183
+ const preferred = preferIntegrationConfig(found);
184
+ if (!preferred) {
185
+ throw new Error('No Jest JSON config found. Pass --config test/setup/jest.integration.json');
186
+ }
187
+ return preferred;
188
+ }
128
189
  /**
129
- * Run Jest with DAxTA recording injected via a temp config — no project file edits.
190
+ * Learn project test script → run with recording → build OpenAPI → serve docs.
130
191
  */
131
- function runDaxtaTest(options = {}) {
192
+ async function runDaxtaTest(options = {}) {
132
193
  const cwd = options.cwd ?? process.cwd();
133
- const { configFromFlag, passthrough } = parseTestArgs(options.argv ?? []);
134
- let baseConfigPath = configFromFlag
135
- ? path.isAbsolute(configFromFlag)
136
- ? configFromFlag
137
- : path.join(cwd, configFromFlag)
138
- : undefined;
139
- if (!baseConfigPath) {
140
- const found = walk(cwd, (name) => name.startsWith('jest.') && name.endsWith('.json'));
141
- baseConfigPath = preferIntegrationConfig(found);
194
+ const parsed = parseTestArgs(options.argv ?? []);
195
+ const pkg = readPkg(cwd);
196
+ const pm = detectPackageManager(cwd, pkg);
197
+ (0, config_1.resetConfig)();
198
+ let config = (0, config_1.getConfig)(true);
199
+ (0, ui_1.banner)('DAxTA test', pkg.name || path.basename(cwd));
200
+ const scriptName = await (0, discover_test_1.resolveTestScript)({
201
+ cwd,
202
+ scripts: pkg.scripts,
203
+ configured: config.testScript,
204
+ yes: parsed.yes,
205
+ flag: parsed.scriptFromFlag,
206
+ });
207
+ if (scriptName && scriptName !== config.testScript) {
208
+ await (0, ui_1.step)('Remember test script', () => (0, discover_test_1.upsertTestScriptInConfig)(cwd, scriptName), { paceMs: 800 });
209
+ (0, config_1.resetConfig)();
210
+ config = (0, config_1.getConfig)(true);
142
211
  }
143
- if (!baseConfigPath || !(0, fs_1.existsSync)(baseConfigPath)) {
144
- throw new Error('No Jest JSON config found. Pass one: daxta test --config test/setup/jest.integration.json');
212
+ const scriptCommand = scriptName ? pkg.scripts?.[scriptName] : undefined;
213
+ if (scriptName) {
214
+ await (0, ui_1.step)('Test command', () => `${pm} run ${scriptName}`, { paceMs: 600 });
145
215
  }
216
+ const baseConfigPath = resolveBaseConfigPath(cwd, {
217
+ configFromFlag: parsed.configFromFlag,
218
+ jestConfig: config.jestConfig,
219
+ scriptCommand,
220
+ });
221
+ await (0, ui_1.step)('Jest config', () => path.relative(cwd, baseConfigPath), { paceMs: 600 });
146
222
  let base;
147
223
  try {
148
224
  base = loadJestJson(baseConfigPath);
@@ -151,45 +227,91 @@ function runDaxtaTest(options = {}) {
151
227
  throw new Error(`Jest config must be JSON for dynamic merge: ${baseConfigPath}`);
152
228
  }
153
229
  const merged = mergeDaxtaHooks(base);
154
- // Paths in jest config are relative to the config file directory
155
230
  const configDir = path.dirname(baseConfigPath);
156
231
  const tmpDir = path.join(cwd, 'daxta', 'out');
157
232
  (0, fs_1.mkdirSync)(tmpDir, { recursive: true });
158
233
  const tmpConfig = path.join(tmpDir, 'jest.daxta.runtime.json');
159
- // Rewrite relative paths that jest resolves from config location — keep same dir as base
160
- // by writing next to base via a name that won't be committed (under daxta/out) and setting root.
161
- // Jest resolves <rootDir> from config's rootDir or cwd of config file.
162
- // Put runtime config beside original so relative globalSetup paths still work:
163
234
  const siblingTmp = path.join(configDir, '.jest.daxta.runtime.json');
164
235
  (0, fs_1.writeFileSync)(siblingTmp, `${JSON.stringify(merged, null, 2)}\n`);
165
- // also keep a copy under out for debugging
166
- (0, fs_1.writeFileSync)(tmpConfig, `${JSON.stringify({ ...merged, _extends: path.relative(tmpDir, baseConfigPath) }, null, 2)}\n`);
236
+ (0, fs_1.writeFileSync)(tmpConfig, `${JSON.stringify({ ...merged, _source: path.relative(tmpDir, baseConfigPath) }, null, 2)}\n`);
167
237
  (0, recorder_1.clearWorkerHits)();
168
- const jestBin = resolveJestBin(cwd);
169
- const result = (0, child_process_1.spawnSync)(jestBin, ['--config', siblingTmp, ...passthrough], {
170
- cwd,
171
- stdio: 'inherit',
172
- shell: process.platform === 'win32',
173
- env: process.env,
174
- });
175
- try {
176
- const build = (0, build_spec_1.buildDaxtaSpec)({ silent: true });
177
- if (!build.skipped) {
178
- console.log(`DAxTA ${build.changed ? 'updated' : 'ready'}: ${build.hits} hits, ${build.operations} operations`);
238
+ let testStatus = 0;
239
+ await (0, ui_1.step)('Run tests (recording hits)', () => {
240
+ const jestBin = resolveJestBin(cwd);
241
+ // Prefer running via package script env when possible, but always inject our config:
242
+ // jest --config <merged> + any extra args from the user / script beyond config.
243
+ const extraFromScript = [];
244
+ if (scriptCommand) {
245
+ // strip jest binary and --config pair from script; keep other flags
246
+ const tokens = scriptCommand.split(/\s+/).filter(Boolean);
247
+ for (let i = 0; i < tokens.length; i += 1) {
248
+ const t = tokens[i];
249
+ if (t === 'jest' || t.endsWith('/jest') || t === 'cross-env')
250
+ continue;
251
+ if (t.startsWith('NODE_OPTIONS=') || t.includes('='))
252
+ continue;
253
+ if (t === '--config' || t === '-c') {
254
+ i += 1;
255
+ continue;
256
+ }
257
+ if (t.startsWith('--config='))
258
+ continue;
259
+ extraFromScript.push(t);
260
+ }
179
261
  }
180
- (0, incremental_1.clearPartialMarker)();
181
- }
182
- catch (error) {
183
- console.error('DAxTA build failed:', error instanceof Error ? error.message : error);
184
- }
262
+ const result = (0, child_process_1.spawnSync)(jestBin, ['--config', siblingTmp, ...extraFromScript, ...parsed.passthrough], {
263
+ cwd,
264
+ stdio: 'inherit',
265
+ shell: process.platform === 'win32',
266
+ env: process.env,
267
+ });
268
+ testStatus = result.status ?? 1;
269
+ if (result.error)
270
+ throw result.error;
271
+ return testStatus === 0 ? 'passed' : `exit ${testStatus}`;
272
+ }, { paceMs: 400 });
185
273
  try {
186
274
  (0, fs_1.unlinkSync)(siblingTmp);
187
275
  }
188
276
  catch {
189
277
  // ignore
190
278
  }
191
- if (result.status && result.status !== 0)
192
- process.exit(result.status);
193
- if (result.error)
194
- throw result.error;
279
+ let buildSummary = 'skipped';
280
+ await (0, ui_1.step)('Build OpenAPI + HTML', () => {
281
+ const build = (0, build_spec_1.buildDaxtaSpec)({ silent: true, html: true });
282
+ (0, incremental_1.clearPartialMarker)();
283
+ if (build.skipped) {
284
+ buildSummary = 'no hits yet';
285
+ return buildSummary;
286
+ }
287
+ buildSummary = `${build.hits} hits · ${build.operations} ops`;
288
+ return {
289
+ summary: build.changed ? 'updated' : 'ready',
290
+ details: [
291
+ `${build.hits} recorded hits`,
292
+ `${build.operations} operations`,
293
+ `out · ${path.relative(cwd, config.outDir)}`,
294
+ ],
295
+ };
296
+ }, { paceMs: 800 });
297
+ if (parsed.noServe) {
298
+ (0, ui_1.box)('Done', [
299
+ `${ui_1.c.green('✔')} docs built (${buildSummary})`,
300
+ `${ui_1.c.dim('serve later')} ${ui_1.c.cyan('daxta serve')}`,
301
+ ]);
302
+ if (testStatus !== 0)
303
+ process.exit(testStatus);
304
+ return;
305
+ }
306
+ const port = parsed.port ?? config.port;
307
+ const docsBase = (0, paths_1.getDocsBasePath)();
308
+ (0, ui_1.box)('Docs ready', [
309
+ `${ui_1.c.green('✔')} ${ui_1.c.bold(`http://127.0.0.1:${port}${docsBase}`)}`,
310
+ `${ui_1.c.dim('openapi')} http://127.0.0.1:${port}${docsBase}/openapi.json`,
311
+ testStatus !== 0 ? `${ui_1.c.yellow('!')} tests exited ${testStatus} — docs still served` : `${ui_1.c.dim('ctrl+c')} to stop`,
312
+ ]);
313
+ (0, ui_1.nextSteps)([
314
+ { cmd: `open http://127.0.0.1:${port}${docsBase}`, why: 'viewer' },
315
+ ]);
316
+ (0, serve_1.serveApiDocs)({ port });
195
317
  }
@@ -0,0 +1,26 @@
1
+ export declare const c: {
2
+ bold: (t: string) => string;
3
+ dim: (t: string) => string;
4
+ cyan: (t: string) => string;
5
+ green: (t: string) => string;
6
+ yellow: (t: string) => string;
7
+ magenta: (t: string) => string;
8
+ red: (t: string) => string;
9
+ };
10
+ export declare function sleep(ms: number): Promise<void>;
11
+ export declare function banner(title: string, subtitle?: string): void;
12
+ export type StepResult = string | {
13
+ summary: string;
14
+ details?: string[];
15
+ } | void;
16
+ /**
17
+ * Spinner while work runs → ✔ / ✖, optional detail lines, then a short pause to read.
18
+ */
19
+ export declare function step(label: string, work: () => StepResult | Promise<StepResult>, options?: {
20
+ paceMs?: number;
21
+ }): Promise<void>;
22
+ export declare function box(title: string, lines: string[]): void;
23
+ export declare function nextSteps(lines: Array<{
24
+ cmd: string;
25
+ why: string;
26
+ }>): void;