(partial)
| 102 | } |
| 103 | |
| 104 | function 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 | |
| 135 | function clearModelSettings() { |
| 136 | const reset = {}; |
no test coverage detected