MCPcopy Create free account
hub / github.com/AICoderTudou/claude-code-tudou / writeEnvSettings

Function writeEnvSettings

desktop/main.cjs:104–133  ·  view source on GitHub ↗
(partial)

Source from the content-addressed store, hash-verified

102}
103
104function writeEnvSettings(partial) {
105 const safePartial = partial || {};
106 const existing = fs.existsSync(ENV_PATH) ? fs.readFileSync(ENV_PATH, "utf8") : "";
107 const { lines, map } = parseEnvLines(existing);
108
109 for (const key of SETTINGS_KEYS) {
110 if (Object.prototype.hasOwnProperty.call(safePartial, key)) {
111 map.set(key, `${safePartial[key] ?? ""}`);
112 }
113 }
114
115 const used = new Set();
116 const next = lines.map((line) => {
117 const idx = line.indexOf("=");
118 if (idx <= 0) return line;
119 const key = line.slice(0, idx).trim();
120 if (!SETTINGS_KEYS.includes(key)) return line;
121 used.add(key);
122 return `${key}=${map.get(key) ?? ""}`;
123 });
124
125 for (const key of SETTINGS_KEYS) {
126 if (!used.has(key) && map.has(key)) {
127 next.push(`${key}=${map.get(key)}`);
128 }
129 }
130
131 fs.writeFileSync(ENV_PATH, `${next.join("\n").replace(/\n{3,}/g, "\n\n").trim()}\n`, "utf8");
132 return readEnvSettings();
133}
134
135function clearModelSettings() {
136 const reset = {};

Callers 2

clearModelSettingsFunction · 0.85
main.cjsFile · 0.85

Calls 6

parseEnvLinesFunction · 0.85
readEnvSettingsFunction · 0.85
setMethod · 0.80
addMethod · 0.45
getMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected