()
| 39 | * Returns defaults if the file doesn't exist or is malformed. |
| 40 | */ |
| 41 | export async function loadConfig(): Promise<UserConfig> { |
| 42 | try { |
| 43 | const dir = await getDevCtxDir(); |
| 44 | const configPath = path.join(dir, "config.json"); |
| 45 | |
| 46 | if (!fs.existsSync(configPath)) return { ...DEFAULT_CONFIG }; |
| 47 | |
| 48 | const raw = JSON.parse(fs.readFileSync(configPath, "utf-8")); |
| 49 | return { ...DEFAULT_CONFIG, ...raw }; |
| 50 | } catch { |
| 51 | return { ...DEFAULT_CONFIG }; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Save user preferences to `.devctx/config.json`. |
no test coverage detected