@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@l4yercak3/cli",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Icing on the L4yercak3 - The sweet finishing touch for your Layer Cake integration",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -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 content = '';
222
+ let existing = '';
223
223
  if (fs.existsSync(envPath)) {
224
- content = fs.readFileSync(envPath, 'utf8');
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}=.*$`, 'm');
229
- if (regex.test(content)) {
230
- content = content.replace(regex, `${key}=${value}`);
231
+ const regex = new RegExp(`^${key}=`, 'm');
232
+ if (regex.test(existing)) {
233
+ skipped.push(key);
231
234
  } else {
232
- content = `${content.trimEnd()}${content ? '\n' : ''}${key}=${value}\n`;
235
+ linesToAppend.push(`${key}=${value}`);
233
236
  }
234
237
  }
235
238
 
236
- fs.writeFileSync(envPath, content, 'utf8');
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 = {