feat: add configurable paseo home and port

This commit is contained in:
Mohamed Boudra
2025-11-30 02:46:44 +00:00
parent cc34ea722a
commit b8d942cb6b
7 changed files with 50 additions and 114 deletions
+37
View File
@@ -0,0 +1,37 @@
import os from "node:os";
import path from "node:path";
import { mkdirSync } from "node:fs";
let cachedHomeDir: string | null = null;
let cachedPort: number | null = null;
function expandHomeDir(input: string): string {
if (input.startsWith("~/")) {
return path.join(os.homedir(), input.slice(2));
}
if (input === "~") {
return os.homedir();
}
return input;
}
export function resolvePaseoHome(): string {
if (cachedHomeDir) {
return cachedHomeDir;
}
const raw = process.env.PASEO_HOME ?? process.env.PASEO_HOME_DIR ?? "~/.paseo";
const expanded = path.resolve(expandHomeDir(raw));
mkdirSync(expanded, { recursive: true });
cachedHomeDir = expanded;
return cachedHomeDir;
}
export function resolvePaseoPort(): number {
if (cachedPort !== null) {
return cachedPort;
}
const raw = process.env.PASEO_PORT ?? process.env.PORT ?? "6767";
const parsed = Number.parseInt(raw, 10);
cachedPort = Number.isFinite(parsed) ? parsed : 6767;
return cachedPort;
}