@mdocs/server 0.1.0 → 0.1.1
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 +12 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -33,9 +33,11 @@ function healthRouter() {
|
|
|
33
33
|
import { Router as Router3 } from "express";
|
|
34
34
|
import { randomUUID } from "crypto";
|
|
35
35
|
import { join as join4 } from "path";
|
|
36
|
+
import { mkdirSync } from "fs";
|
|
36
37
|
|
|
37
38
|
// src/config.ts
|
|
38
39
|
import { resolve } from "path";
|
|
40
|
+
import { homedir } from "os";
|
|
39
41
|
var DEFAULT_PORT = 4873;
|
|
40
42
|
var DEFAULT_HOST = "127.0.0.1";
|
|
41
43
|
var MDOCS_DIR = ".mdocs";
|
|
@@ -43,13 +45,13 @@ var REPOS_SUBDIR = "repos";
|
|
|
43
45
|
var DEFAULT_ORIGINS = [
|
|
44
46
|
"http://localhost:3000",
|
|
45
47
|
"http://127.0.0.1:3000",
|
|
46
|
-
"https://
|
|
48
|
+
"https://idocs-md-viewer.vercel.app/"
|
|
47
49
|
];
|
|
48
50
|
function parseConfig(overrides = {}) {
|
|
49
51
|
return {
|
|
50
52
|
port: overrides.port ?? parseInt(process.env["PORT"] ?? String(DEFAULT_PORT), 10),
|
|
51
53
|
host: overrides.host ?? process.env["HOST"] ?? DEFAULT_HOST,
|
|
52
|
-
dataDir: overrides.dataDir ?? process.env["DATA_DIR"] ??
|
|
54
|
+
dataDir: overrides.dataDir ?? process.env["DATA_DIR"] ?? homedir(),
|
|
53
55
|
origins: overrides.origins ?? DEFAULT_ORIGINS
|
|
54
56
|
};
|
|
55
57
|
}
|
|
@@ -87,7 +89,13 @@ function run(args, cwd) {
|
|
|
87
89
|
if (code === 0) resolve4(stdout.trim());
|
|
88
90
|
else reject(new Error(stderr.trim() || `git exited with code ${code}`));
|
|
89
91
|
});
|
|
90
|
-
proc.on("error",
|
|
92
|
+
proc.on("error", (err) => {
|
|
93
|
+
if (err.code === "ENOENT") {
|
|
94
|
+
reject(new Error("git not found \u2014 make sure Git is installed and available in PATH"));
|
|
95
|
+
} else {
|
|
96
|
+
reject(err);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
91
99
|
});
|
|
92
100
|
}
|
|
93
101
|
async function cloneRepo(url, dest, branch) {
|
|
@@ -277,6 +285,7 @@ function reposRouter(config) {
|
|
|
277
285
|
const id = randomUUID();
|
|
278
286
|
const cloneDir = join4(reposDir2, id);
|
|
279
287
|
try {
|
|
288
|
+
mkdirSync(reposDir2, { recursive: true });
|
|
280
289
|
await cloneRepo(url, cloneDir, branch);
|
|
281
290
|
const detectedBranch = branch ?? await getDefaultBranch(cloneDir);
|
|
282
291
|
const currentCommit = await getHeadCommit(cloneDir);
|