obsidian-plugin-config 1.3.8 → 1.3.9

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.
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * Obsidian Plugin Config - CLI Entry Point
5
5
  * Global command: obsidian-inject
6
- * Version: 1.3.8
6
+ * Version: 1.3.9
7
7
  */
8
8
 
9
9
  import { execSync } from 'child_process';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "obsidian-plugin-config",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "description": "Système d'injection pour plugins Obsidian autonomes",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -293,9 +293,9 @@ export async function injectScripts(targetPath: string, useSass: boolean = false
293
293
  "templates/scripts/help.ts"
294
294
  ];
295
295
 
296
- // Files that should NOT be overwritten if they
297
- // already exist (contain user-specific config)
298
- const skipIfExists = new Set([".env"]);
296
+ // Files that need value-preserving merge instead
297
+ // of full overwrite (user fills in their paths)
298
+ const mergeEnvFile = new Set([".env"]);
299
299
 
300
300
  // Files with .template suffix (NPM excludes dotfiles)
301
301
  // Map: { source: targetName }
@@ -331,7 +331,9 @@ export async function injectScripts(targetPath: string, useSass: boolean = false
331
331
  fs.writeFileSync(targetFile, content, "utf8");
332
332
  console.log(` ✅ ${fileName}`);
333
333
  } catch (error) {
334
- console.error(` ❌ Failed to inject ${scriptFile}: ${error}`);
334
+ console.error(
335
+ ` ❌ Failed to inject ${scriptFile}: ${error}`
336
+ );
335
337
  }
336
338
  }
337
339
 
@@ -342,27 +344,49 @@ export async function injectScripts(targetPath: string, useSass: boolean = false
342
344
  configFileMap
343
345
  )) {
344
346
  try {
345
- const targetFile = path.join(
346
- targetPath, destName
347
- );
348
- // Skip if file exists and is user-specific
347
+ const targetFile = path.join(targetPath, destName);
348
+ const templateContent = copyFromLocal(src);
349
+
350
+ // For .env: merge existing values into the template
349
351
  if (
350
- skipIfExists.has(destName) &&
352
+ mergeEnvFile.has(destName) &&
351
353
  fs.existsSync(targetFile)
352
354
  ) {
353
- console.log(
354
- ` ⏭️ ${destName} (kept existing)`
355
+ const existing = fs.readFileSync(
356
+ targetFile, "utf8"
355
357
  );
358
+ // Parse existing key=value pairs
359
+ const existingVals: Record<string, string> = {};
360
+ for (const line of existing.split(/\r?\n/)) {
361
+ const m = line.match(/^([^#=]+)=(.*)$/);
362
+ if (m) existingVals[m[1].trim()] = m[2].trim();
363
+ }
364
+ // Re-write template, substituting existing values
365
+ const merged = templateContent
366
+ .split(/\r?\n/)
367
+ .map((line) => {
368
+ const m = line.match(/^([^#=]+)=(.*)$/);
369
+ if (m) {
370
+ const key = m[1].trim();
371
+ const val = existingVals[key] ?? m[2].trim();
372
+ return `${key}=${val}`;
373
+ }
374
+ return line;
375
+ })
376
+ .join("\n");
377
+ fs.writeFileSync(targetFile, merged, "utf8");
378
+ console.log(` ✅ ${destName} (values preserved)`);
356
379
  continue;
357
380
  }
358
- const content = copyFromLocal(src);
359
- fs.writeFileSync(targetFile, content, "utf8");
381
+
382
+ fs.writeFileSync(targetFile, templateContent, "utf8");
360
383
  console.log(` ✅ ${destName}`);
361
384
  } catch (error) {
362
385
  console.error(
363
386
  ` ❌ Failed to inject ${destName}: ${error}`
364
387
  );
365
388
  }
389
+
366
390
  }
367
391
 
368
392
  // Copy .vscode config files
package/versions.json CHANGED
@@ -34,5 +34,6 @@
34
34
  "1.3.5": "1.8.9",
35
35
  "1.3.6": "1.8.9",
36
36
  "1.3.7": "1.8.9",
37
- "1.3.8": "1.8.9"
37
+ "1.3.8": "1.8.9",
38
+ "1.3.9": "1.8.9"
38
39
  }