@huydao/karrot 0.1.6 → 0.1.8
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 +496 -243
- package/dist/executors/adapters/ag-ui-post.d.ts +10 -0
- package/dist/executors/adapters/ag-ui-post.js +174 -21
- package/dist/executors/adapters/ag-ui.js +5 -3
- package/dist/executors/execute.js +1 -0
- package/dist/executors/executor.js +2 -1
- package/dist/executors/run-result.d.ts +3 -0
- package/dist/reports/report.js +20 -0
- package/dist/scenarios/scenario.d.ts +1 -0
- package/dist/utils/config.d.ts +9 -0
- package/package.json +5 -2
- package/site/assets/app.js +201 -0
- package/site/assets/karrot-mark.svg +10 -0
- package/site/assets/styles.css +698 -0
- package/site/check.js +43 -0
- package/site/docs/index.html +505 -0
- package/site/index.html +162 -0
- package/site/serve.js +50 -0
package/site/serve.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const http = require('node:http');
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
|
|
5
|
+
const root = __dirname;
|
|
6
|
+
const port = Number(process.env.PORT || 4173);
|
|
7
|
+
|
|
8
|
+
const contentTypes = {
|
|
9
|
+
'.css': 'text/css; charset=utf-8',
|
|
10
|
+
'.html': 'text/html; charset=utf-8',
|
|
11
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
12
|
+
'.svg': 'image/svg+xml',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function resolveRequestPath(url) {
|
|
16
|
+
const requestUrl = new URL(url, `http://localhost:${port}`);
|
|
17
|
+
const decodedPath = decodeURIComponent(requestUrl.pathname);
|
|
18
|
+
const normalizedPath = decodedPath === '/' ? '/index.html' : decodedPath;
|
|
19
|
+
const absolutePath = path.normalize(path.join(root, normalizedPath));
|
|
20
|
+
|
|
21
|
+
if (!absolutePath.startsWith(root)) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (fs.existsSync(absolutePath) && fs.statSync(absolutePath).isDirectory()) {
|
|
26
|
+
return path.join(absolutePath, 'index.html');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return absolutePath;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const server = http.createServer((request, response) => {
|
|
33
|
+
const filePath = resolveRequestPath(request.url || '/');
|
|
34
|
+
|
|
35
|
+
if (!filePath || !fs.existsSync(filePath)) {
|
|
36
|
+
response.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' });
|
|
37
|
+
response.end('Not found');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const extension = path.extname(filePath);
|
|
42
|
+
response.writeHead(200, {
|
|
43
|
+
'content-type': contentTypes[extension] || 'application/octet-stream',
|
|
44
|
+
});
|
|
45
|
+
fs.createReadStream(filePath).pipe(response);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
server.listen(port, () => {
|
|
49
|
+
console.log(`Karrot docs site: http://localhost:${port}`);
|
|
50
|
+
});
|