@l4yercak3/cli 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/connect.js +17 -7
package/package.json
CHANGED
package/src/commands/connect.js
CHANGED
|
@@ -219,21 +219,31 @@ async function handleConnect() {
|
|
|
219
219
|
* @param {Object<string, string>} vars - Key-value pairs to set
|
|
220
220
|
*/
|
|
221
221
|
function updateEnvFile(envPath, vars) {
|
|
222
|
-
let
|
|
222
|
+
let existing = '';
|
|
223
223
|
if (fs.existsSync(envPath)) {
|
|
224
|
-
|
|
224
|
+
existing = fs.readFileSync(envPath, 'utf8');
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
const linesToAppend = [];
|
|
228
|
+
const skipped = [];
|
|
229
|
+
|
|
227
230
|
for (const [key, value] of Object.entries(vars)) {
|
|
228
|
-
const regex = new RegExp(`^${key}
|
|
229
|
-
if (regex.test(
|
|
230
|
-
|
|
231
|
+
const regex = new RegExp(`^${key}=`, 'm');
|
|
232
|
+
if (regex.test(existing)) {
|
|
233
|
+
skipped.push(key);
|
|
231
234
|
} else {
|
|
232
|
-
|
|
235
|
+
linesToAppend.push(`${key}=${value}`);
|
|
233
236
|
}
|
|
234
237
|
}
|
|
235
238
|
|
|
236
|
-
|
|
239
|
+
if (skipped.length > 0) {
|
|
240
|
+
console.log(chalk.gray(` Skipped (already set): ${skipped.join(', ')}`));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (linesToAppend.length > 0) {
|
|
244
|
+
const suffix = `\n# Added by l4yercak3 CLI\n${linesToAppend.join('\n')}\n`;
|
|
245
|
+
fs.appendFileSync(envPath, existing.endsWith('\n') ? suffix : `\n${suffix}`, 'utf8');
|
|
246
|
+
}
|
|
237
247
|
}
|
|
238
248
|
|
|
239
249
|
module.exports = {
|