@mintlify/previewing 4.0.1017 → 4.0.1018
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.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/local-preview/export.d.ts +2 -0
- package/dist/local-preview/export.js +208 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/export-scripts/serve.js +82 -0
- package/export-scripts/start-docs.bat +10 -0
- package/export-scripts/start-docs.sh +9 -0
- package/package.json +5 -3
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Serves the exported docs folder as a local static site. This is shipped with the export zip from `mint export`.
|
|
3
|
+
const http = require('http');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { execFile } = require('child_process');
|
|
7
|
+
|
|
8
|
+
const PORT = process.env.PORT || 3000;
|
|
9
|
+
const DIR = __dirname;
|
|
10
|
+
|
|
11
|
+
const MIME_TYPES = {
|
|
12
|
+
'.html': 'text/html',
|
|
13
|
+
'.css': 'text/css',
|
|
14
|
+
'.js': 'application/javascript',
|
|
15
|
+
'.json': 'application/json',
|
|
16
|
+
'.png': 'image/png',
|
|
17
|
+
'.jpg': 'image/jpeg',
|
|
18
|
+
'.jpeg': 'image/jpeg',
|
|
19
|
+
'.gif': 'image/gif',
|
|
20
|
+
'.svg': 'image/svg+xml',
|
|
21
|
+
'.ico': 'image/x-icon',
|
|
22
|
+
'.woff': 'font/woff',
|
|
23
|
+
'.woff2': 'font/woff2',
|
|
24
|
+
'.ttf': 'font/ttf',
|
|
25
|
+
'.webp': 'image/webp',
|
|
26
|
+
'.mp4': 'video/mp4',
|
|
27
|
+
'.webm': 'video/webm',
|
|
28
|
+
'.xml': 'application/xml',
|
|
29
|
+
'.txt': 'text/plain',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function openInBrowser(url) {
|
|
33
|
+
let command = 'xdg-open';
|
|
34
|
+
switch (process.platform) {
|
|
35
|
+
case 'darwin':
|
|
36
|
+
command = 'open';
|
|
37
|
+
break;
|
|
38
|
+
case 'win32':
|
|
39
|
+
command = 'explorer.exe';
|
|
40
|
+
break;
|
|
41
|
+
default:
|
|
42
|
+
command = 'xdg-open';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
execFile(command, [url], () => undefined);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function resolveFile(urlPath) {
|
|
49
|
+
const filePath = path.resolve(DIR, urlPath.replace(/^\/+/, ''));
|
|
50
|
+
if (!filePath.startsWith(DIR + path.sep) && filePath !== DIR) return undefined;
|
|
51
|
+
const candidates = [filePath, path.join(filePath, 'index.html'), filePath + '.html'];
|
|
52
|
+
return candidates.find((c) => fs.existsSync(c) && fs.statSync(c).isFile());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
http
|
|
56
|
+
.createServer((req, res) => {
|
|
57
|
+
let urlPath;
|
|
58
|
+
try {
|
|
59
|
+
const rawPath = (req.url || '/').split('?')[0];
|
|
60
|
+
urlPath = decodeURIComponent(rawPath);
|
|
61
|
+
} catch {
|
|
62
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
63
|
+
res.end('404 Not Found');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const file = resolveFile(urlPath);
|
|
68
|
+
|
|
69
|
+
if (file) {
|
|
70
|
+
const ext = path.extname(file).toLowerCase();
|
|
71
|
+
res.writeHead(200, { 'Content-Type': MIME_TYPES[ext] || 'application/octet-stream' });
|
|
72
|
+
fs.createReadStream(file).pipe(res);
|
|
73
|
+
} else {
|
|
74
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
75
|
+
res.end('404 Not Found');
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
.listen(PORT, () => {
|
|
79
|
+
const url = 'http://localhost:' + PORT;
|
|
80
|
+
console.log('Serving docs at ' + url);
|
|
81
|
+
openInBrowser(url);
|
|
82
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mintlify/previewing",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1018",
|
|
4
4
|
"description": "Preview Mintlify docs locally",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.0.0"
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"main": "./dist/index.js",
|
|
29
29
|
"types": "./dist/index.d.ts",
|
|
30
30
|
"files": [
|
|
31
|
-
"dist"
|
|
31
|
+
"dist",
|
|
32
|
+
"export-scripts"
|
|
32
33
|
],
|
|
33
34
|
"scripts": {
|
|
34
35
|
"prepare": "npm run build",
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"@mintlify/common": "1.0.818",
|
|
47
48
|
"@mintlify/prebuild": "1.0.959",
|
|
48
49
|
"@mintlify/validation": "0.1.643",
|
|
50
|
+
"adm-zip": "0.5.16",
|
|
49
51
|
"better-opn": "3.0.2",
|
|
50
52
|
"chalk": "5.2.0",
|
|
51
53
|
"chokidar": "3.5.3",
|
|
@@ -86,5 +88,5 @@
|
|
|
86
88
|
"vitest": "2.1.9",
|
|
87
89
|
"vitest-mock-process": "1.0.4"
|
|
88
90
|
},
|
|
89
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "689313194fd46d5dd2211b59062a041ba91f3981"
|
|
90
92
|
}
|