obsidian-plugin-config 1.3.7 β†’ 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.7
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.7",
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",
@@ -199,44 +199,63 @@ main();
199
199
  */
200
200
  function buildAndPublishNpm(): void {
201
201
  console.log(`πŸš€ Obsidian Plugin Config - Complete NPM Workflow`);
202
- console.log(`Full automation: version β†’ commit β†’ push β†’ exports β†’ bin β†’ publish\n`);
202
+ console.log(
203
+ `Full automation: version β†’ exports β†’ bin β†’ commit β†’ publish\n`
204
+ );
203
205
 
204
206
  try {
205
- // Step 1: Update version and push to GitHub
207
+ // Step 1: Update version in package.json only
208
+ // (no commit yet - we'll do one big commit after)
206
209
  console.log(`πŸ“‹ Step 1/6: Updating version...`);
207
- execSync('tsx scripts/update-version-config.ts', { stdio: 'inherit' });
208
-
209
- // Step 2: Commit and push any remaining changes
210
- console.log(`\nπŸ“€ Step 2/6: Committing and pushing changes...`);
211
- try {
212
- execSync('echo "Prepare NPM package publication" | tsx scripts/acp.ts -b', { stdio: 'inherit' });
213
- } catch {
214
- console.log(` ℹ️ No additional changes to commit`);
215
- }
210
+ execSync('tsx scripts/update-version-config.ts', {
211
+ stdio: 'inherit'
212
+ });
216
213
 
217
- // Step 3: Update exports automatically
218
- console.log(`\nπŸ“¦ Step 3/6: Updating exports...`);
214
+ // Step 2: Update exports automatically
215
+ console.log(`\nπŸ“¦ Step 2/6: Updating exports...`);
219
216
  execSync('yarn update-exports', { stdio: 'inherit' });
220
217
 
221
- // Step 4: Generate bin file
222
- console.log(`\nπŸ”§ Step 4/6: Generating bin/obsidian-inject.js...`);
218
+ // Step 3: Generate bin file (uses updated version)
219
+ console.log(`\nπŸ”§ Step 3/6: Generating bin/obsidian-inject.js...`);
223
220
  generateBinFile();
224
221
 
225
- // Step 5: Verify package is ready
226
- console.log(`\nπŸ“‹ Step 5/6: Verifying package...`);
222
+ // Step 4: Verify package and sync versions.json
223
+ // (must happen before commit so versions.json is included)
224
+ console.log(`\nπŸ“‹ Step 4/6: Verifying package...`);
227
225
  verifyPackage();
228
226
 
227
+ // Step 5: Commit and push ALL changes together
228
+ // (package.json version, bin/, versions.json, exports)
229
+ console.log(`\nπŸ“€ Step 5/6: Committing and pushing changes...`);
230
+ try {
231
+ execSync(
232
+ 'echo "Publish NPM package" | tsx scripts/acp.ts -b',
233
+ { stdio: 'inherit' }
234
+ );
235
+ } catch {
236
+ console.log(` ℹ️ No additional changes to commit`);
237
+ }
238
+
229
239
  // Step 6: Publish to NPM
230
240
  console.log(`\nπŸ“€ Step 6/6: Publishing to NPM...`);
231
- execSync('npm publish --registry https://registry.npmjs.org/', { stdio: 'inherit' });
241
+ execSync(
242
+ 'npm publish --registry https://registry.npmjs.org/',
243
+ { stdio: 'inherit' }
244
+ );
232
245
 
233
246
  console.log(`\nπŸŽ‰ Complete workflow successful!`);
234
247
  console.log(`\nπŸ“‹ Next steps:`);
235
248
  console.log(` 1. npm install -g obsidian-plugin-config`);
236
- console.log(` 2. Test injection: cd any-plugin && obsidian-inject`);
249
+ console.log(
250
+ ` 2. Test injection: cd any-plugin && obsidian-inject`
251
+ );
237
252
 
238
253
  } catch (error) {
239
- console.error(`\n❌ Workflow failed: ${error instanceof Error ? error.message : String(error)}`);
254
+ console.error(
255
+ `\n❌ Workflow failed: ${
256
+ error instanceof Error ? error.message : String(error)
257
+ }`
258
+ );
240
259
  process.exit(1);
241
260
  }
242
261
  }
@@ -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
@@ -33,5 +33,7 @@
33
33
  "1.3.4": "1.8.9",
34
34
  "1.3.5": "1.8.9",
35
35
  "1.3.6": "1.8.9",
36
- "1.3.7": "1.8.9"
36
+ "1.3.7": "1.8.9",
37
+ "1.3.8": "1.8.9",
38
+ "1.3.9": "1.8.9"
37
39
  }