MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / parseEnvFile

Function parseEnvFile

src/cli.ts:1067–1096  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

1065}
1066
1067function parseEnvFile(filePath: string): Record<string, string> {
1068 if (!fs.existsSync(filePath)) {
1069 return {};
1070 }
1071 const content = fs.readFileSync(filePath, 'utf8');
1072 const env: Record<string, string> = {};
1073 for (const rawLine of content.split(/\r?\n/u)) {
1074 const line = rawLine.trim();
1075 if (!line || line.startsWith('#')) {
1076 continue;
1077 }
1078 const index = line.indexOf('=');
1079 if (index <= 0) {
1080 continue;
1081 }
1082 const key = line.slice(0, index).trim();
1083 if (!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(key)) {
1084 continue;
1085 }
1086 let value = line.slice(index + 1).trim();
1087 if (
1088 (value.startsWith('"') && value.endsWith('"'))
1089 || (value.startsWith("'") && value.endsWith("'"))
1090 ) {
1091 value = value.slice(1, -1);
1092 }
1093 env[key] = value;
1094 }
1095 return env;
1096}
1097
1098if (process.argv[1] && path.resolve(process.argv[1]) === CLI_FILE) {
1099 await main();

Callers 1

loadRepoEnvDefaultsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected