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.
- package/bin/obsidian-inject.js +1 -1
- package/package.json +1 -1
- package/scripts/inject-core.ts +37 -13
- package/versions.json +2 -1
package/bin/obsidian-inject.js
CHANGED
package/package.json
CHANGED
package/scripts/inject-core.ts
CHANGED
|
@@ -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
|
|
297
|
-
//
|
|
298
|
-
const
|
|
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(
|
|
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
|
-
|
|
347
|
-
|
|
348
|
-
//
|
|
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
|
-
|
|
352
|
+
mergeEnvFile.has(destName) &&
|
|
351
353
|
fs.existsSync(targetFile)
|
|
352
354
|
) {
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
359
|
-
fs.writeFileSync(targetFile,
|
|
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
|