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.
- package/bin/obsidian-inject.js +1 -1
- package/package.json +1 -1
- package/scripts/build-npm.ts +39 -20
- package/scripts/inject-core.ts +37 -13
- package/versions.json +3 -1
package/bin/obsidian-inject.js
CHANGED
package/package.json
CHANGED
package/scripts/build-npm.ts
CHANGED
|
@@ -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(
|
|
202
|
+
console.log(
|
|
203
|
+
`Full automation: version β exports β bin β commit β publish\n`
|
|
204
|
+
);
|
|
203
205
|
|
|
204
206
|
try {
|
|
205
|
-
// Step 1: Update version
|
|
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', {
|
|
208
|
-
|
|
209
|
-
|
|
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
|
|
218
|
-
console.log(`\nπ¦ Step
|
|
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
|
|
222
|
-
console.log(`\nπ§ Step
|
|
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
|
|
226
|
-
|
|
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(
|
|
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(
|
|
249
|
+
console.log(
|
|
250
|
+
` 2. Test injection: cd any-plugin && obsidian-inject`
|
|
251
|
+
);
|
|
237
252
|
|
|
238
253
|
} catch (error) {
|
|
239
|
-
console.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
|
}
|
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
|