tangled
alpha
login
or
join now
dunkirk.sh
/
traverse
1
fork
atom
snatching amp's walkthrough for my own purposes mwhahaha
traverse.dunkirk.sh/diagram/6121f05c-a5ef-4ecf-8ffc-02534c5e767c
1
fork
atom
overview
issues
pulls
pipelines
feat: update config
dunkirk.sh
1 month ago
53b9c13c
bc7c8f95
verified
This commit was signed with the committer's
known signature
.
dunkirk.sh
SSH Key Fingerprint:
SHA256:DqcG0RXYExE26KiWo3VxJnsxswN1QNfTBvB+bdSpk80=
+20
-15
3 changed files
expand all
collapse all
unified
split
src
config.ts
index.ts
types.ts
+15
-10
src/config.ts
···
2
2
import { homedir } from "node:os";
3
3
import type { TraverseConfig } from "./types.ts";
4
4
5
5
-
const DEFAULT_SHARE_URL = "https://traverse.dunkirk.sh";
5
5
+
const DEFAULTS: TraverseConfig = {
6
6
+
shareServerUrl: "https://traverse.dunkirk.sh",
7
7
+
port: 4173,
8
8
+
mode: "local",
9
9
+
};
6
10
7
11
function getConfigDir(): string {
8
12
const platform = process.platform;
···
14
18
}
15
19
16
20
export function loadConfig(): TraverseConfig {
17
17
-
if (process.env.TRAVERSE_SHARE_URL) {
18
18
-
return { shareServerUrl: process.env.TRAVERSE_SHARE_URL };
19
19
-
}
21
21
+
let fileConfig: Partial<TraverseConfig> = {};
20
22
21
23
const configPath = join(getConfigDir(), "config.json");
22
22
-
23
24
try {
24
25
const text = require("node:fs").readFileSync(configPath, "utf-8");
25
25
-
const parsed = JSON.parse(text);
26
26
-
return {
27
27
-
shareServerUrl: parsed.shareServerUrl || DEFAULT_SHARE_URL,
28
28
-
};
26
26
+
fileConfig = JSON.parse(text);
29
27
} catch {
30
30
-
return { shareServerUrl: DEFAULT_SHARE_URL };
28
28
+
// no config file, use defaults
31
29
}
30
30
+
31
31
+
// Env vars override config file, config file overrides defaults
32
32
+
return {
33
33
+
shareServerUrl: process.env.TRAVERSE_SHARE_URL || fileConfig.shareServerUrl || DEFAULTS.shareServerUrl,
34
34
+
port: parseInt(process.env.TRAVERSE_PORT || String(fileConfig.port || DEFAULTS.port), 10),
35
35
+
mode: (process.env.TRAVERSE_MODE || fileConfig.mode || DEFAULTS.mode) as "local" | "server",
36
36
+
};
32
37
}
+3
-5
src/index.ts
···
7
7
import { generateOgImage } from "./og.ts";
8
8
import { loadConfig } from "./config.ts";
9
9
10
10
-
const PORT = parseInt(process.env.TRAVERSE_PORT || "4173", 10);
11
11
-
const MODE = (process.env.TRAVERSE_MODE || "local") as "local" | "server";
12
12
-
const GIT_HASH = await Bun.$`git rev-parse --short HEAD`.text().then(s => s.trim()).catch(() => "dev");
13
13
-
14
14
-
// Load config and init persistence
15
10
const config = loadConfig();
11
11
+
const PORT = config.port;
12
12
+
const MODE = config.mode;
13
13
+
const GIT_HASH = await Bun.$`git rev-parse --short HEAD`.text().then(s => s.trim()).catch(() => "dev");
16
14
initDb();
17
15
18
16
// Load persisted diagrams
+2
src/types.ts
···
19
19
20
20
export interface TraverseConfig {
21
21
shareServerUrl: string;
22
22
+
port: number;
23
23
+
mode: "local" | "server";
22
24
}