core: modularize config parsing to improve maintainability
Extract error handling, parsing logic, and variable substitution into dedicated modules. This reduces duplication between tui.json and opencode.json parsing and makes the config system easier to extend for future config formats.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { existsSync } from "fs"
|
||||
import os from "os"
|
||||
import path from "path"
|
||||
import { type Info, parseConfig } from "./config"
|
||||
import { Log, Process } from "../util"
|
||||
|
||||
const log = Log.create({ service: "config" })
|
||||
@@ -33,16 +32,16 @@ function managedConfigDir() {
|
||||
return process.env.OPENCODE_TEST_MANAGED_CONFIG_DIR || systemManagedConfigDir()
|
||||
}
|
||||
|
||||
function parseManagedPlist(json: string, source: string): Info {
|
||||
function parseManagedPlist(json: string): string {
|
||||
const raw = JSON.parse(json)
|
||||
for (const key of Object.keys(raw)) {
|
||||
if (PLIST_META.has(key)) delete raw[key]
|
||||
}
|
||||
return parseConfig(JSON.stringify(raw), source)
|
||||
return JSON.stringify(raw)
|
||||
}
|
||||
|
||||
async function readManagedPreferences(): Promise<Info> {
|
||||
if (process.platform !== "darwin") return {}
|
||||
async function readManagedPreferences() {
|
||||
if (process.platform !== "darwin") return
|
||||
|
||||
const user = os.userInfo().username
|
||||
const paths = [
|
||||
@@ -58,10 +57,13 @@ async function readManagedPreferences(): Promise<Info> {
|
||||
log.warn("failed to convert managed preferences plist", { path: plist })
|
||||
continue
|
||||
}
|
||||
return parseManagedPlist(result.stdout.toString(), `mobileconfig:${plist}`)
|
||||
return {
|
||||
source: `mobileconfig:${plist}`,
|
||||
text: parseManagedPlist(result.stdout.toString()),
|
||||
}
|
||||
}
|
||||
|
||||
return {}
|
||||
return
|
||||
}
|
||||
|
||||
export const ConfigManaged = {
|
||||
|
||||
Reference in New Issue
Block a user