@t0.labs/daxta 0.2.2 → 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.
- package/README.md +13 -12
- package/dist/cli/discover-test.d.ts +21 -0
- package/dist/cli/discover-test.js +150 -0
- package/dist/cli/inject-main.d.ts +2 -1
- package/dist/cli/inject-main.js +24 -24
- package/dist/cli/install.d.ts +4 -2
- package/dist/cli/install.js +130 -67
- package/dist/cli/main.js +9 -6
- package/dist/cli/test.d.ts +2 -2
- package/dist/cli/test.js +163 -41
- package/dist/cli/ui.d.ts +26 -0
- package/dist/cli/ui.js +110 -0
- package/dist/config.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,28 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
DAxTA — NestJS integration-test traffic → API docs, DTO required/optional, terminal Try-it, and app `/docs`.
|
|
4
4
|
|
|
5
|
-
## Install
|
|
5
|
+
## Install (one command)
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
pnpm dlx @t0.labs/daxta install
|
|
9
|
+
# or
|
|
10
|
+
npx @t0.labs/daxta install
|
|
10
11
|
```
|
|
11
12
|
|
|
12
|
-
`
|
|
13
|
+
Adds the package as a devDependency **and** wires the project (config, scripts, `apiDocs(app)` into `main.ts`).
|
|
14
|
+
|
|
15
|
+
Flags: `--yes`, `--main src/main.ts`, `--skip-main`, `--dry-run`, `--skip-dep`, `--fast` (skip step delays)
|
|
13
16
|
|
|
14
|
-
- writes `daxta.config.ts` + `daxta/out`
|
|
15
|
-
- strips any `NODE_OPTIONS=--require @t0.labs/daxta/register` from start scripts
|
|
16
|
-
- finds `main.ts`, asks **Y / n / other path**, injects:
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
19
|
import { apiDocs } from '@t0.labs/daxta';
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
const app = await NestFactory.create(AppModule);
|
|
22
22
|
apiDocs(app);
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
Flags: `--yes`, `--main src/main.ts`, `--skip-main`, `--dry-run`, `--skip-dep`
|
|
26
|
-
|
|
27
25
|
## Required env
|
|
28
26
|
|
|
29
27
|
`apiDocs(app)` **throws** if `DAXTA_DOCS` is missing:
|
|
@@ -36,14 +34,17 @@ DAXTA_DOCS=false # disable (must be set explicitly)
|
|
|
36
34
|
## Runtime CLI
|
|
37
35
|
|
|
38
36
|
```bash
|
|
39
|
-
daxta test
|
|
40
|
-
daxta test --
|
|
37
|
+
daxta test # run project tests → build → serve docs
|
|
38
|
+
daxta test --no-serve # build only, don't open server
|
|
39
|
+
daxta test --script test:integration
|
|
41
40
|
daxta serve
|
|
42
41
|
daxta build
|
|
43
42
|
daxta fields
|
|
44
43
|
daxta call
|
|
45
44
|
```
|
|
46
45
|
|
|
46
|
+
`daxta test` uses `testScript` from `daxta.config.ts` (set during install). It injects recording into Jest, builds OpenAPI/HTML, then serves the viewer.
|
|
47
|
+
|
|
47
48
|
## API
|
|
48
49
|
|
|
49
50
|
```ts
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type TestScriptChoice = {
|
|
2
|
+
name: string;
|
|
3
|
+
command: string;
|
|
4
|
+
};
|
|
5
|
+
/** package.json scripts that look like runnable test entrypoints */
|
|
6
|
+
export declare function listTestScripts(scripts: Record<string, string> | undefined): TestScriptChoice[];
|
|
7
|
+
/** Extract `--config` / `-c` path from a script command string */
|
|
8
|
+
export declare function extractJestConfigFromCommand(command: string): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Ask which package.json script to use for `daxta test`.
|
|
11
|
+
* Returns script name (e.g. test:integration) or null to skip.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveTestScript(options: {
|
|
14
|
+
cwd: string;
|
|
15
|
+
scripts?: Record<string, string>;
|
|
16
|
+
configured?: string;
|
|
17
|
+
yes?: boolean;
|
|
18
|
+
flag?: string;
|
|
19
|
+
}): Promise<string | null>;
|
|
20
|
+
/** Insert or update `testScript` in daxta.config.ts */
|
|
21
|
+
export declare function upsertTestScriptInConfig(cwd: string, testScript: string, dryRun?: boolean): string;
|
|
@@ -0,0 +1,150 @@
|
|
|
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
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.listTestScripts = listTestScripts;
|
|
37
|
+
exports.extractJestConfigFromCommand = extractJestConfigFromCommand;
|
|
38
|
+
exports.resolveTestScript = resolveTestScript;
|
|
39
|
+
exports.upsertTestScriptInConfig = upsertTestScriptInConfig;
|
|
40
|
+
const readline_1 = require("readline");
|
|
41
|
+
const fs_1 = require("fs");
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const ui_1 = require("./ui");
|
|
44
|
+
function prompt(question) {
|
|
45
|
+
const rl = (0, readline_1.createInterface)({ input: process.stdin, output: process.stdout });
|
|
46
|
+
return new Promise((resolve) => {
|
|
47
|
+
rl.question(question, (answer) => {
|
|
48
|
+
rl.close();
|
|
49
|
+
resolve(answer.trim());
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function scoreScript(name, command) {
|
|
54
|
+
const n = name.toLowerCase();
|
|
55
|
+
const cmd = command.toLowerCase();
|
|
56
|
+
let score = 0;
|
|
57
|
+
if (n.includes('integration'))
|
|
58
|
+
score += 100;
|
|
59
|
+
if (n.includes('e2e'))
|
|
60
|
+
score += 80;
|
|
61
|
+
if (n.includes('api'))
|
|
62
|
+
score += 40;
|
|
63
|
+
if (n === 'test')
|
|
64
|
+
score += 10;
|
|
65
|
+
if (cmd.includes('jest'))
|
|
66
|
+
score += 30;
|
|
67
|
+
if (cmd.includes('integration'))
|
|
68
|
+
score += 20;
|
|
69
|
+
if (n.includes('unit') || n.includes('watch') || n.includes('cov'))
|
|
70
|
+
score -= 50;
|
|
71
|
+
return score;
|
|
72
|
+
}
|
|
73
|
+
/** package.json scripts that look like runnable test entrypoints */
|
|
74
|
+
function listTestScripts(scripts) {
|
|
75
|
+
if (!scripts)
|
|
76
|
+
return [];
|
|
77
|
+
const out = [];
|
|
78
|
+
for (const [name, command] of Object.entries(scripts)) {
|
|
79
|
+
if (name.startsWith('daxta:'))
|
|
80
|
+
continue;
|
|
81
|
+
const n = name.toLowerCase();
|
|
82
|
+
if (!(n === 'test' || n.startsWith('test:') || n.includes('e2e') || n.includes('integration')))
|
|
83
|
+
continue;
|
|
84
|
+
out.push({ name, command });
|
|
85
|
+
}
|
|
86
|
+
return out.sort((a, b) => scoreScript(b.name, b.command) - scoreScript(a.name, a.command));
|
|
87
|
+
}
|
|
88
|
+
/** Extract `--config` / `-c` path from a script command string */
|
|
89
|
+
function extractJestConfigFromCommand(command) {
|
|
90
|
+
const m = command.match(/--config(?:=|\s+)(['"]?)([^'"\s]+)\1/) ||
|
|
91
|
+
command.match(/(?:^|\s)-c(?:=|\s+)(['"]?)([^'"\s]+)\1/);
|
|
92
|
+
return m?.[2] ?? null;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Ask which package.json script to use for `daxta test`.
|
|
96
|
+
* Returns script name (e.g. test:integration) or null to skip.
|
|
97
|
+
*/
|
|
98
|
+
async function resolveTestScript(options) {
|
|
99
|
+
if (options.flag)
|
|
100
|
+
return options.flag;
|
|
101
|
+
if (options.configured)
|
|
102
|
+
return options.configured;
|
|
103
|
+
const choices = listTestScripts(options.scripts);
|
|
104
|
+
if (!choices.length) {
|
|
105
|
+
if (options.yes || !process.stdin.isTTY)
|
|
106
|
+
return null;
|
|
107
|
+
const typed = await prompt(` ${ui_1.c.yellow('?')} ${ui_1.c.bold('No test script found.')} Enter script name, or ${ui_1.c.dim('n')} to skip:\n ${ui_1.c.cyan('›')} `);
|
|
108
|
+
if (!typed || /^n(o)?$/i.test(typed))
|
|
109
|
+
return null;
|
|
110
|
+
return typed;
|
|
111
|
+
}
|
|
112
|
+
const def = choices[0];
|
|
113
|
+
if (options.yes || !process.stdin.isTTY)
|
|
114
|
+
return def.name;
|
|
115
|
+
console.log(` ${ui_1.c.dim('test scripts')}`);
|
|
116
|
+
choices.slice(0, 8).forEach((choice, i) => {
|
|
117
|
+
const mark = i === 0 ? ui_1.c.cyan('●') : ui_1.c.dim('○');
|
|
118
|
+
const label = i === 0 ? ui_1.c.bold(choice.name) : ui_1.c.dim(choice.name);
|
|
119
|
+
console.log(` ${mark} ${label} ${ui_1.c.dim(choice.command.slice(0, 60))}`);
|
|
120
|
+
});
|
|
121
|
+
const answer = await prompt(` ${ui_1.c.yellow('?')} Use ${ui_1.c.cyan(def.name)} for ${ui_1.c.bold('daxta test')}?\n` +
|
|
122
|
+
` ${ui_1.c.dim('Y')} yes · ${ui_1.c.dim('n')} skip · or type another script name\n ${ui_1.c.cyan('›')} `);
|
|
123
|
+
if (!answer || /^y(es)?$/i.test(answer))
|
|
124
|
+
return def.name;
|
|
125
|
+
if (/^n(o)?$/i.test(answer))
|
|
126
|
+
return null;
|
|
127
|
+
return answer;
|
|
128
|
+
}
|
|
129
|
+
/** Insert or update `testScript` in daxta.config.ts */
|
|
130
|
+
function upsertTestScriptInConfig(cwd, testScript, dryRun = false) {
|
|
131
|
+
const configPath = path.join(cwd, 'daxta.config.ts');
|
|
132
|
+
if (!(0, fs_1.existsSync)(configPath)) {
|
|
133
|
+
return 'no daxta.config.ts to update';
|
|
134
|
+
}
|
|
135
|
+
let text = (0, fs_1.readFileSync)(configPath, 'utf8');
|
|
136
|
+
if (/testScript\s*:/.test(text)) {
|
|
137
|
+
const next = text.replace(/testScript\s*:\s*['`][^'"`]*['`]/, `testScript: '${testScript}'`);
|
|
138
|
+
if (next === text)
|
|
139
|
+
return `testScript already '${testScript}'`;
|
|
140
|
+
if (!dryRun)
|
|
141
|
+
(0, fs_1.writeFileSync)(configPath, next);
|
|
142
|
+
return `updated testScript → '${testScript}'`;
|
|
143
|
+
}
|
|
144
|
+
const next = text.replace(/defineConfig\(\s*\{/, `defineConfig({\n testScript: '${testScript}',`);
|
|
145
|
+
if (next === text)
|
|
146
|
+
throw new Error('Could not insert testScript into daxta.config.ts');
|
|
147
|
+
if (!dryRun)
|
|
148
|
+
(0, fs_1.writeFileSync)(configPath, next);
|
|
149
|
+
return `set testScript: '${testScript}'`;
|
|
150
|
+
}
|
|
@@ -12,4 +12,5 @@ export type InjectMainOptions = {
|
|
|
12
12
|
mainPath?: string;
|
|
13
13
|
yes?: boolean;
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
/** Resolve which file to inject into (prompt / --main / --yes). Null = skip. */
|
|
16
|
+
export declare function resolveMainTarget(options?: InjectMainOptions): Promise<string | null>;
|
package/dist/cli/inject-main.js
CHANGED
|
@@ -36,10 +36,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.findMainCandidates = findMainCandidates;
|
|
37
37
|
exports.resolveMainPath = resolveMainPath;
|
|
38
38
|
exports.injectApiDocs = injectApiDocs;
|
|
39
|
-
exports.
|
|
39
|
+
exports.resolveMainTarget = resolveMainTarget;
|
|
40
40
|
const readline_1 = require("readline");
|
|
41
41
|
const fs_1 = require("fs");
|
|
42
42
|
const path = __importStar(require("path"));
|
|
43
|
+
const ui_1 = require("./ui");
|
|
43
44
|
const IMPORT_LINE = `import { apiDocs } from '@t0.labs/daxta';`;
|
|
44
45
|
const MARKER = 'apiDocs(';
|
|
45
46
|
function walk(dir, match, out = [], depth = 0) {
|
|
@@ -93,7 +94,7 @@ function prompt(question) {
|
|
|
93
94
|
async function resolveMainPath(cwd, candidates) {
|
|
94
95
|
const def = candidates[0];
|
|
95
96
|
if (!def) {
|
|
96
|
-
const typed = await prompt('No main.ts found. Enter path
|
|
97
|
+
const typed = await prompt(` ${ui_1.c.yellow('?')} ${ui_1.c.bold('No main.ts found.')} Enter path, or ${ui_1.c.dim('n')} to skip:\n ${ui_1.c.cyan('›')} `);
|
|
97
98
|
if (!typed || /^n(o)?$/i.test(typed))
|
|
98
99
|
return null;
|
|
99
100
|
const full = path.isAbsolute(typed) ? typed : path.join(cwd, typed);
|
|
@@ -102,13 +103,17 @@ async function resolveMainPath(cwd, candidates) {
|
|
|
102
103
|
return full;
|
|
103
104
|
}
|
|
104
105
|
const rel = path.relative(cwd, def);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
.
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
if (candidates.length > 1) {
|
|
107
|
+
console.log(` ${ui_1.c.dim('candidates')}`);
|
|
108
|
+
for (const file of candidates.slice(0, 5)) {
|
|
109
|
+
const r = path.relative(cwd, file);
|
|
110
|
+
console.log(` ${r === rel ? ui_1.c.cyan('●') : ui_1.c.dim('○')} ${r === rel ? ui_1.c.bold(r) : ui_1.c.dim(r)}`);
|
|
111
|
+
}
|
|
112
|
+
if (candidates.length > 5)
|
|
113
|
+
console.log(` ${ui_1.c.dim(`… +${candidates.length - 5} more`)}`);
|
|
114
|
+
}
|
|
115
|
+
const answer = await prompt(` ${ui_1.c.yellow('?')} Inject ${ui_1.c.bold('apiDocs(app)')} into ${ui_1.c.cyan(rel)}?\n` +
|
|
116
|
+
` ${ui_1.c.dim('Y')} yes · ${ui_1.c.dim('n')} skip · or type another path\n ${ui_1.c.cyan('›')} `);
|
|
112
117
|
if (!answer || /^y(es)?$/i.test(answer))
|
|
113
118
|
return def;
|
|
114
119
|
if (/^n(o)?$/i.test(answer))
|
|
@@ -186,29 +191,24 @@ function injectApiDocs(filePath, dryRun = false) {
|
|
|
186
191
|
(0, fs_1.writeFileSync)(filePath, next);
|
|
187
192
|
return `injected apiDocs() into ${path.relative(process.cwd(), filePath)}`;
|
|
188
193
|
}
|
|
189
|
-
|
|
194
|
+
/** Resolve which file to inject into (prompt / --main / --yes). Null = skip. */
|
|
195
|
+
async function resolveMainTarget(options = {}) {
|
|
190
196
|
const cwd = options.cwd ?? process.cwd();
|
|
191
197
|
const candidates = findMainCandidates(cwd);
|
|
192
|
-
let target;
|
|
193
198
|
if (options.mainPath) {
|
|
194
|
-
target = path.isAbsolute(options.mainPath) ? options.mainPath : path.join(cwd, options.mainPath);
|
|
199
|
+
const target = path.isAbsolute(options.mainPath) ? options.mainPath : path.join(cwd, options.mainPath);
|
|
195
200
|
if (!(0, fs_1.existsSync)(target))
|
|
196
201
|
throw new Error(`File not found: ${target}`);
|
|
202
|
+
return target;
|
|
197
203
|
}
|
|
198
|
-
|
|
199
|
-
target = candidates[0] ?? null;
|
|
204
|
+
if (options.yes) {
|
|
205
|
+
const target = candidates[0] ?? null;
|
|
200
206
|
if (!target)
|
|
201
207
|
throw new Error('No main.ts found; pass --main <path>');
|
|
208
|
+
return target;
|
|
202
209
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (!target)
|
|
206
|
-
return 'skip main inject (no TTY / no main.ts)';
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
target = await resolveMainPath(cwd, candidates);
|
|
210
|
+
if (!process.stdin.isTTY) {
|
|
211
|
+
return candidates[0] ?? null;
|
|
210
212
|
}
|
|
211
|
-
|
|
212
|
-
return 'skipped main.ts inject';
|
|
213
|
-
return injectApiDocs(target, options.dryRun);
|
|
213
|
+
return resolveMainPath(cwd, candidates);
|
|
214
214
|
}
|
package/dist/cli/install.d.ts
CHANGED
|
@@ -5,9 +5,11 @@ export type InstallOptions = {
|
|
|
5
5
|
yes?: boolean;
|
|
6
6
|
mainPath?: string;
|
|
7
7
|
skipMain?: boolean;
|
|
8
|
+
/** Skip dramatic pacing delays */
|
|
9
|
+
fast?: boolean;
|
|
8
10
|
};
|
|
9
11
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
+
* One-shot bootstrap with paced, colored steps.
|
|
13
|
+
* Prefer: `pnpm dlx @t0.labs/daxta install`
|
|
12
14
|
*/
|
|
13
15
|
export declare function installDaxta(options?: InstallOptions): Promise<void>;
|
package/dist/cli/install.js
CHANGED
|
@@ -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
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
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
|
|
132
|
+
return { created: true, rel };
|
|
125
133
|
}
|
|
126
134
|
function ensureGitignore(cwd, dryRun) {
|
|
127
135
|
const gitignorePath = path.join(cwd, '.gitignore');
|
|
128
|
-
const
|
|
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, `${
|
|
132
|
-
return `
|
|
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
|
-
|
|
137
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
|
147
|
-
const
|
|
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
|
|
164
|
+
return spec;
|
|
152
165
|
}
|
|
153
166
|
/**
|
|
154
|
-
*
|
|
155
|
-
*
|
|
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
|
-
|
|
177
|
+
let pkg = readJson(pkgPath);
|
|
164
178
|
const pm = detectPackageManager(cwd, pkg);
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
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 (
|
|
197
|
-
|
|
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('
|
|
200
|
-
console.log(`
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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>] [-- <
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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') {
|
package/dist/cli/test.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
-
*
|
|
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
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
144
|
-
|
|
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
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
cwd
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
}
|
package/dist/cli/ui.d.ts
ADDED
|
@@ -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;
|
package/dist/cli/ui.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.c = void 0;
|
|
4
|
+
exports.sleep = sleep;
|
|
5
|
+
exports.banner = banner;
|
|
6
|
+
exports.step = step;
|
|
7
|
+
exports.box = box;
|
|
8
|
+
exports.nextSteps = nextSteps;
|
|
9
|
+
const isTTY = Boolean(process.stdout.isTTY);
|
|
10
|
+
const useColor = isTTY && !process.env.NO_COLOR && process.env.FORCE_COLOR !== '0';
|
|
11
|
+
const ansi = {
|
|
12
|
+
reset: '\x1b[0m',
|
|
13
|
+
bold: '\x1b[1m',
|
|
14
|
+
dim: '\x1b[2m',
|
|
15
|
+
cyan: '\x1b[36m',
|
|
16
|
+
green: '\x1b[32m',
|
|
17
|
+
yellow: '\x1b[33m',
|
|
18
|
+
magenta: '\x1b[35m',
|
|
19
|
+
red: '\x1b[31m',
|
|
20
|
+
};
|
|
21
|
+
function paint(code, text) {
|
|
22
|
+
if (!useColor)
|
|
23
|
+
return text;
|
|
24
|
+
return `${code}${text}${ansi.reset}`;
|
|
25
|
+
}
|
|
26
|
+
exports.c = {
|
|
27
|
+
bold: (t) => paint(ansi.bold, t),
|
|
28
|
+
dim: (t) => paint(ansi.dim, t),
|
|
29
|
+
cyan: (t) => paint(ansi.cyan, t),
|
|
30
|
+
green: (t) => paint(ansi.green, t),
|
|
31
|
+
yellow: (t) => paint(ansi.yellow, t),
|
|
32
|
+
magenta: (t) => paint(ansi.magenta, t),
|
|
33
|
+
red: (t) => paint(ansi.red, t),
|
|
34
|
+
};
|
|
35
|
+
function sleep(ms) {
|
|
36
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
37
|
+
}
|
|
38
|
+
function banner(title, subtitle) {
|
|
39
|
+
console.log('');
|
|
40
|
+
console.log(`${exports.c.cyan(exports.c.bold('◆'))} ${exports.c.bold(title)}${subtitle ? exports.c.dim(` ${subtitle}`) : ''}`);
|
|
41
|
+
console.log(exports.c.dim('─'.repeat(Math.min(56, Math.max(28, title.length + 10)))));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Spinner while work runs → ✔ / ✖, optional detail lines, then a short pause to read.
|
|
45
|
+
*/
|
|
46
|
+
async function step(label, work, options = {}) {
|
|
47
|
+
const paceMs = options.paceMs ?? 0;
|
|
48
|
+
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
49
|
+
let i = 0;
|
|
50
|
+
let timer;
|
|
51
|
+
if (isTTY) {
|
|
52
|
+
process.stdout.write(` ${exports.c.cyan(frames[0])} ${label}`);
|
|
53
|
+
timer = setInterval(() => {
|
|
54
|
+
i = (i + 1) % frames.length;
|
|
55
|
+
process.stdout.write(`\r ${exports.c.cyan(frames[i])} ${label}`);
|
|
56
|
+
}, 80);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.log(` … ${label}`);
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const result = await work();
|
|
63
|
+
if (timer)
|
|
64
|
+
clearInterval(timer);
|
|
65
|
+
let summary = '';
|
|
66
|
+
let details = [];
|
|
67
|
+
if (typeof result === 'string')
|
|
68
|
+
summary = result;
|
|
69
|
+
else if (result && typeof result === 'object') {
|
|
70
|
+
summary = result.summary;
|
|
71
|
+
details = result.details ?? [];
|
|
72
|
+
}
|
|
73
|
+
const line = summary ? `${label} ${exports.c.dim(summary)}` : label;
|
|
74
|
+
if (isTTY)
|
|
75
|
+
process.stdout.write(`\r ${exports.c.green('✔')} ${line}${' '.repeat(12)}\n`);
|
|
76
|
+
else
|
|
77
|
+
console.log(` ✔ ${line}`);
|
|
78
|
+
for (const d of details) {
|
|
79
|
+
console.log(` ${exports.c.dim('→')} ${d}`);
|
|
80
|
+
}
|
|
81
|
+
if (paceMs > 0)
|
|
82
|
+
await sleep(paceMs);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (timer)
|
|
86
|
+
clearInterval(timer);
|
|
87
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
88
|
+
if (isTTY)
|
|
89
|
+
process.stdout.write(`\r ${exports.c.red('✖')} ${label} ${exports.c.red(msg)}${' '.repeat(8)}\n`);
|
|
90
|
+
else
|
|
91
|
+
console.log(` ✖ ${label} ${msg}`);
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function box(title, lines) {
|
|
96
|
+
console.log('');
|
|
97
|
+
console.log(` ${exports.c.magenta(exports.c.bold(title))}`);
|
|
98
|
+
for (const line of lines) {
|
|
99
|
+
console.log(` ${exports.c.dim('│')} ${line}`);
|
|
100
|
+
}
|
|
101
|
+
console.log('');
|
|
102
|
+
}
|
|
103
|
+
function nextSteps(lines) {
|
|
104
|
+
console.log(` ${exports.c.bold('Next')}`);
|
|
105
|
+
for (const { cmd, why } of lines) {
|
|
106
|
+
console.log(` ${exports.c.cyan('$')} ${exports.c.bold(cmd)}`);
|
|
107
|
+
console.log(` ${exports.c.dim(why)}`);
|
|
108
|
+
}
|
|
109
|
+
console.log('');
|
|
110
|
+
}
|
package/dist/config.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ export type DaxtaConfig = {
|
|
|
14
14
|
port?: number;
|
|
15
15
|
fieldsFile?: string;
|
|
16
16
|
docsPath?: string;
|
|
17
|
+
/** package.json script name used by `daxta test` (e.g. test:integration) */
|
|
18
|
+
testScript?: string;
|
|
19
|
+
/** Optional explicit Jest JSON config path */
|
|
20
|
+
jestConfig?: string;
|
|
17
21
|
templatize?: (pathname: string, test?: string) => string | null | undefined;
|
|
18
22
|
operationTag?: (pathTemplate: string, method: string) => string | undefined;
|
|
19
23
|
operationTitle?: (method: string, pathTemplate: string) => string | undefined;
|