@easydocs/cli 0.4.2 → 0.5.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/dist/index.js +16 -29
- package/package.json +7 -2
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { createDB, getAllEndpoints, getEndpointsByProject, findOrCreateProject } from "@easydocs/core";
|
|
5
|
-
import {
|
|
4
|
+
import { createDB, getAllEndpoints, getEndpointsByProject, findOrCreateProject, buildFullSpec } from "@easydocs/core";
|
|
5
|
+
import { createCapturer, parseConfig } from "@easydocs/core";
|
|
6
6
|
import { createServer } from "http";
|
|
7
7
|
import { createRequire } from "module";
|
|
8
8
|
import { existsSync } from "fs";
|
|
@@ -101,23 +101,13 @@ async function runExport(args2) {
|
|
|
101
101
|
} else {
|
|
102
102
|
endpoints = await getAllEndpoints(db);
|
|
103
103
|
}
|
|
104
|
-
const spec =
|
|
105
|
-
openapi: "3.0.3",
|
|
106
|
-
info: { title: projectSlug ?? "API Documentation", version: "1.0.0" },
|
|
107
|
-
paths: endpoints.reduce((acc, e) => {
|
|
108
|
-
if (!e.path || !e.method) return acc;
|
|
109
|
-
const activeSpec = e.isManuallyEdited && e.manualSpec ? e.manualSpec : e.spec;
|
|
110
|
-
if (!activeSpec) return acc;
|
|
111
|
-
if (!acc[e.path]) acc[e.path] = {};
|
|
112
|
-
acc[e.path][e.method.toLowerCase()] = activeSpec;
|
|
113
|
-
return acc;
|
|
114
|
-
}, {})
|
|
115
|
-
};
|
|
104
|
+
const spec = buildFullSpec(endpoints, projectSlug ?? void 0);
|
|
116
105
|
process.stdout.write(format === "yaml" ? yaml.dump(spec) : JSON.stringify(spec, null, 2));
|
|
117
106
|
}
|
|
118
107
|
async function runProxy(args2) {
|
|
119
108
|
const port = parseInt(getFlag(args2, "port") ?? "3999", 10);
|
|
120
109
|
const projectSlug = getFlag(args2, "project") ?? "default";
|
|
110
|
+
const capturer = createCapturer(parseConfig({ project: projectSlug }));
|
|
121
111
|
const server = createServer(async (req, res) => {
|
|
122
112
|
const reqUrl = new URL(req.url ?? "/", `http://localhost:${port}`);
|
|
123
113
|
const targetParam = reqUrl.searchParams.get("target");
|
|
@@ -167,21 +157,18 @@ async function runProxy(args2) {
|
|
|
167
157
|
parsedRequestBody = requestBody.toString();
|
|
168
158
|
}
|
|
169
159
|
}
|
|
170
|
-
capture(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
},
|
|
183
|
-
{ project: projectSlug }
|
|
184
|
-
);
|
|
160
|
+
capturer.capture({
|
|
161
|
+
method,
|
|
162
|
+
path: targetUrl.pathname,
|
|
163
|
+
query: Object.fromEntries(targetUrl.searchParams.entries()),
|
|
164
|
+
params: {},
|
|
165
|
+
body: parsedRequestBody,
|
|
166
|
+
response: responseBody,
|
|
167
|
+
status: upstream.status,
|
|
168
|
+
requestHeaders: req.headers,
|
|
169
|
+
responseHeaders: Object.fromEntries(upstream.headers.entries()),
|
|
170
|
+
durationMs: Date.now() - startedAt
|
|
171
|
+
});
|
|
185
172
|
res.writeHead(upstream.status, Object.fromEntries(upstream.headers.entries()));
|
|
186
173
|
res.end(responseText);
|
|
187
174
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easydocs/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"README.md"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"js-yaml": "^4.1.0",
|
|
15
|
-
"@easydocs/core": "0.
|
|
15
|
+
"@easydocs/core": "0.5.2"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -20,6 +20,11 @@
|
|
|
20
20
|
"tsup": "^8.3.0",
|
|
21
21
|
"typescript": "^5"
|
|
22
22
|
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/RubenGlez/easydocs",
|
|
26
|
+
"directory": ""
|
|
27
|
+
},
|
|
23
28
|
"scripts": {
|
|
24
29
|
"build": "tsup",
|
|
25
30
|
"dev": "tsup --watch",
|