Added to configuration directory path resolution and dynamic config loader.

This commit is contained in:
2026-02-08 08:00:09 +01:00
parent 04132f024a
commit 483f8878b7

View File

@@ -1 +1,41 @@
// Module entry point import os from "node:os";
import path from "node:path";
import { pathToFileURL } from "node:url";
export function getUserConfigDir() {
if (process.platform === "win32") {
return process.env.LOCALAPPDATA ?? path.join(os.homedir(), "AppData", "Local");
}
return process.env.XDG_CONFIG_HOME ?? path.join(os.homedir(), ".config");
}
export async function loadConfig(type) {
const configBaseDir = getUserConfigDir();
const configType = typeof type === "string" ? type.toLowerCase() : "";
let configFileName;
switch (configType) {
case "public":
case "p":
configFileName = "public-config.js";
break;
case "confidential":
case "c":
configFileName = "confidential-config.js";
break;
default:
configFileName = null;
}
if (!configFileName) {
throw new Error(
`Invalid config type: ${type}. Expected "public"|"p" or "confidential"|"c".`,
);
}
const configPath = path.join(configBaseDir, "sk-az-tools", configFileName);
const configUrl = pathToFileURL(configPath).href;
const { config } = await import(configUrl);
return config;
}