MCPcopy
hub / github.com/callstack/agent-device / loadSingleConfigFile

Function loadSingleConfigFile

src/utils/cli-config.ts:63–94  ·  view source on GitHub ↗
(filePath: string, required: boolean)

Source from the content-addressed store, hash-verified

61}
62
63function loadSingleConfigFile(filePath: string, required: boolean): Partial<CliFlags> {
64 if (!fs.existsSync(filePath)) {
65 if (required) {
66 throw new AppError('INVALID_ARGS', `Config file not found: ${filePath}`);
67 }
68 return {};
69 }
70
71 let raw: string;
72 try {
73 raw = fs.readFileSync(filePath, 'utf8');
74 } catch (error) {
75 throw new AppError('INVALID_ARGS', `Failed to read config file: ${filePath}`, {
76 cause: error instanceof Error ? error.message : String(error),
77 });
78 }
79
80 let parsed: unknown;
81 try {
82 parsed = JSON.parse(raw);
83 } catch (error) {
84 throw new AppError('INVALID_ARGS', `Invalid JSON in config file: ${filePath}`, {
85 cause: error instanceof Error ? error.message : String(error),
86 });
87 }
88
89 if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
90 throw new AppError('INVALID_ARGS', `Config file must contain a JSON object: ${filePath}`);
91 }
92
93 return parseConfigObject(parsed as Record<string, unknown>, `config file ${filePath}`);
94}
95
96function parseConfigObject(
97 source: Record<string, unknown>,

Callers 1

loadConfigFileDefaultsFunction · 0.85

Calls 2

parseConfigObjectFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected