apigrip 0.2.0 → 0.2.2
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/cli/commands/serve.js
CHANGED
|
@@ -3,13 +3,12 @@ import path from 'node:path';
|
|
|
3
3
|
import { parseSpec } from '../../core/spec-parser.js';
|
|
4
4
|
import { createServer } from '../../server/index.js';
|
|
5
5
|
import { findProjectForDir } from '../../core/projects-store.js';
|
|
6
|
-
|
|
7
|
-
const ROOT_SPEC_FILES = ['openapi.yaml', 'openapi.yml', 'openapi.json', 'swagger.yaml', 'swagger.yml', 'swagger.json'];
|
|
6
|
+
import { discoverSpec } from '../../core/spec-discovery.js';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Quick project resolution for the serve command.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Uses full spec discovery for known project dirs (bookmarks, explicit flags, git repos)
|
|
11
|
+
* but never does BFS on arbitrary directories like home.
|
|
13
12
|
*/
|
|
14
13
|
async function resolveServeProject(argv) {
|
|
15
14
|
// 1. Explicit flags take priority
|
|
@@ -18,24 +17,25 @@ async function resolveServeProject(argv) {
|
|
|
18
17
|
return { projectDir, specPath: argv.spec };
|
|
19
18
|
}
|
|
20
19
|
if (argv.project) {
|
|
21
|
-
const
|
|
22
|
-
return { projectDir: argv.project, specPath };
|
|
20
|
+
const discovered = await discoverSpec(argv.project);
|
|
21
|
+
return { projectDir: argv.project, specPath: discovered?.specPath || null };
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
// 2. Check if cwd is inside a bookmarked project
|
|
26
25
|
const cwd = process.cwd();
|
|
27
26
|
const bookmark = findProjectForDir(cwd);
|
|
28
27
|
if (bookmark) {
|
|
29
|
-
const
|
|
28
|
+
const discovered = bookmark.spec ? null : await discoverSpec(bookmark.path);
|
|
29
|
+
const specPath = bookmark.spec || discovered?.specPath || null;
|
|
30
30
|
return { projectDir: bookmark.path, specPath };
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
// 3.
|
|
33
|
+
// 3. Auto-open cwd if it's a git repo (bounded dir, safe to search)
|
|
34
34
|
const isGitRepo = fs.existsSync(path.join(cwd, '.git'));
|
|
35
35
|
if (isGitRepo) {
|
|
36
|
-
const
|
|
37
|
-
if (specPath) {
|
|
38
|
-
return { projectDir: cwd, specPath };
|
|
36
|
+
const discovered = await discoverSpec(cwd);
|
|
37
|
+
if (discovered?.specPath) {
|
|
38
|
+
return { projectDir: cwd, specPath: discovered.specPath };
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -43,16 +43,6 @@ async function resolveServeProject(argv) {
|
|
|
43
43
|
return { projectDir: null, specPath: null };
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
function findRootSpec(dir) {
|
|
47
|
-
for (const name of ROOT_SPEC_FILES) {
|
|
48
|
-
const p = path.join(dir, name);
|
|
49
|
-
try {
|
|
50
|
-
if (fs.statSync(p).isFile()) return p;
|
|
51
|
-
} catch { /* not found */ }
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
46
|
export async function serveCommand(argv) {
|
|
57
47
|
const { projectDir, specPath } = await resolveServeProject(argv);
|
|
58
48
|
|