obsidian-plugin-config 1.6.18 → 1.7.0

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.
@@ -8,21 +8,21 @@ import { execSync } from 'child_process';
8
8
  * Generate bin/obsidian-inject.js from template
9
9
  */
10
10
  async function generateBinFile(): Promise<void> {
11
- console.log(`\nšŸ”§ Generating bin/obsidian-inject.js...`);
11
+ console.log(`\nšŸ”§ Generating bin/obsidian-inject.js...`);
12
12
 
13
- const binDir = 'bin';
14
- const binPath = path.join(binDir, 'obsidian-inject.js');
13
+ const binDir = 'bin';
14
+ const binPath = path.join(binDir, 'obsidian-inject.js');
15
15
 
16
- // Ensure bin directory exists
17
- if (!fs.existsSync(binDir)) {
18
- fs.mkdirSync(binDir, { recursive: true });
19
- console.log(` šŸ“ Created ${binDir} directory`);
20
- }
16
+ // Ensure bin directory exists
17
+ if (!fs.existsSync(binDir)) {
18
+ fs.mkdirSync(binDir, { recursive: true });
19
+ console.log(` šŸ“ Created ${binDir} directory`);
20
+ }
21
21
 
22
- // Read package.json for version info
23
- const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
22
+ // Read package.json for version info
23
+ const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
24
24
 
25
- const binContent = `#!/usr/bin/env node
25
+ const binContent = `#!/usr/bin/env node
26
26
 
27
27
  /**
28
28
  * Obsidian Plugin Config - CLI Entry Point
@@ -210,170 +210,174 @@ function main() {
210
210
  main();
211
211
  `;
212
212
 
213
- fs.writeFileSync(binPath, binContent, 'utf8');
214
- console.log(` āœ… Generated ${binPath}`);
213
+ fs.writeFileSync(binPath, binContent, 'utf8');
214
+ console.log(` āœ… Generated ${binPath}`);
215
215
  }
216
216
 
217
217
  /**
218
218
  * Check NPM authentication and prompt login if needed
219
219
  */
220
220
  async function ensureNpmAuth(): Promise<void> {
221
- console.log(`šŸ” Checking NPM authentication...`);
222
-
223
- try {
224
- const whoami = execSync('npm whoami --registry https://registry.npmjs.org/', {
225
- stdio: 'pipe',
226
- encoding: 'utf8'
227
- }).trim();
228
- console.log(` āœ… Logged in as: ${whoami}\n`);
229
- } catch {
230
- console.log(` āš ļø Not logged in to NPM\n`);
231
- console.log(`šŸ”‘ Please login to NPM to publish the package`);
232
- console.log(` Opening browser for authentication...\n`);
233
-
234
- try {
235
- execSync('npm login --auth-type=web --registry https://registry.npmjs.org/', {
236
- stdio: 'inherit'
237
- });
238
- console.log(`\n āœ… Successfully logged in to NPM\n`);
239
- } catch {
240
- console.error(`\n āŒ NPM login failed`);
241
- console.error(` Please run 'npm login' manually and try again`);
242
- throw new Error('NPM authentication required');
243
- }
244
- }
221
+ console.log(`šŸ” Checking NPM authentication...`);
222
+
223
+ try {
224
+ const whoami = execSync('npm whoami --registry https://registry.npmjs.org/', {
225
+ stdio: 'pipe',
226
+ encoding: 'utf8'
227
+ }).trim();
228
+ console.log(` āœ… Logged in as: ${whoami}\n`);
229
+ } catch {
230
+ console.log(` āš ļø Not logged in to NPM\n`);
231
+ console.log(`šŸ”‘ Please login to NPM to publish the package`);
232
+ console.log(` Opening browser for authentication...\n`);
233
+
234
+ try {
235
+ execSync('npm login --auth-type=web --registry https://registry.npmjs.org/', {
236
+ stdio: 'inherit'
237
+ });
238
+ console.log(`\n āœ… Successfully logged in to NPM\n`);
239
+ } catch {
240
+ console.error(`\n āŒ NPM login failed`);
241
+ console.error(` Please run 'npm login' manually and try again`);
242
+ throw new Error('NPM authentication required');
243
+ }
244
+ }
245
245
  }
246
246
 
247
247
  /**
248
248
  * Complete NPM workflow - Version, Commit, Push, Publish
249
249
  */
250
250
  async function buildAndPublishNpm(): Promise<void> {
251
- console.log(`šŸš€ Obsidian Plugin Config - NPM Publish Workflow`);
252
- console.log(`Automation: version → bin → verify → commit → publish\n`);
253
-
254
- try {
255
- // Step 0: Check NPM authentication
256
- await ensureNpmAuth();
257
-
258
- // Step 1: Update version
259
- console.log(`šŸ“‹ Step 1/5: Updating version...`);
260
- execSync('tsx scripts/update-version-config.ts', { stdio: 'inherit' });
261
-
262
- // Step 2: Generate bin file
263
- console.log(`\nšŸ”§ Step 2/5: Generating bin/obsidian-inject.js...`);
264
- await generateBinFile();
265
-
266
- // Step 3: Verify package
267
- console.log(`\nšŸ“‹ Step 3/5: Verifying package...`);
268
- verifyPackage();
269
-
270
- // Step 4: Commit and push
271
- console.log(`\nšŸ“¤ Step 4/5: Committing and pushing changes...`);
272
- try {
273
- // Add all changes
274
- execSync('git add -A', { stdio: 'pipe' });
275
-
276
- // Check if there are changes to commit
277
- const status = execSync('git status --porcelain', { encoding: 'utf8' });
278
- if (status.trim()) {
279
- const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
280
- execSync(`git commit -m "Publish NPM package v${packageJson.version}"`, {
281
- stdio: 'pipe'
282
- });
283
-
284
- // Get current branch and push
285
- const currentBranch = execSync('git rev-parse --abbrev-ref HEAD', {
286
- encoding: 'utf8'
287
- }).trim();
288
- execSync(`git push origin ${currentBranch}`, { stdio: 'inherit' });
289
- console.log(` āœ… Changes committed and pushed`);
290
- } else {
291
- console.log(` ā„¹ļø No changes to commit`);
292
- }
293
- } catch (error) {
294
- console.error(` āŒ Commit/push failed: ${error instanceof Error ? error.message : String(error)}`);
295
- throw error;
296
- }
297
-
298
- // Step 5: Publish to NPM
299
- console.log(`\nšŸ“¤ Step 5/5: Publishing to NPM...`);
300
- execSync('npm publish --registry https://registry.npmjs.org/', {
301
- stdio: 'inherit'
302
- });
303
-
304
- // Optional: Update global CLI automatically
305
- console.log(`\nšŸŒ Updating global CLI...`);
306
- console.log(` ā³ Waiting 30s for NPM registry propagation...`);
307
- await new Promise((resolve) => setTimeout(resolve, 30000));
308
- try {
309
- execSync(
310
- 'npm install -g obsidian-plugin-config@latest --force --engine-strict=false',
311
- { stdio: 'inherit' }
312
- );
313
- console.log(` āœ… Global CLI updated`);
314
- } catch {
315
- console.log(` āš ļø Global CLI update failed (NPM registry may need more time)`);
316
- console.log(` šŸ’” Run manually in a few minutes: npm install -g obsidian-plugin-config@latest --force`);
317
- }
318
- console.log(`\nšŸŽ‰ Complete workflow successful!`);
319
- console.log(` Test: cd any-plugin && obsidian-inject`);
320
- } catch (error) {
321
- console.error(
322
- `\nāŒ Workflow failed: ${error instanceof Error ? error.message : String(error)}`
323
- );
324
- process.exit(1);
325
- }
251
+ console.log(`šŸš€ Obsidian Plugin Config - NPM Publish Workflow`);
252
+ console.log(`Automation: version → bin → verify → commit → publish\n`);
253
+
254
+ try {
255
+ // Step 0: Check NPM authentication
256
+ await ensureNpmAuth();
257
+
258
+ // Step 1: Update version
259
+ console.log(`šŸ“‹ Step 1/5: Updating version...`);
260
+ execSync('tsx scripts/update-version-config.ts', { stdio: 'inherit' });
261
+
262
+ // Step 2: Generate bin file
263
+ console.log(`\nšŸ”§ Step 2/5: Generating bin/obsidian-inject.js...`);
264
+ await generateBinFile();
265
+
266
+ // Step 3: Verify package
267
+ console.log(`\nšŸ“‹ Step 3/5: Verifying package...`);
268
+ verifyPackage();
269
+
270
+ // Step 4: Commit and push
271
+ console.log(`\nšŸ“¤ Step 4/5: Committing and pushing changes...`);
272
+ try {
273
+ // Add all changes
274
+ execSync('git add -A', { stdio: 'pipe' });
275
+
276
+ // Check if there are changes to commit
277
+ const status = execSync('git status --porcelain', { encoding: 'utf8' });
278
+ if (status.trim()) {
279
+ const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
280
+ execSync(`git commit -m "Publish NPM package v${packageJson.version}"`, {
281
+ stdio: 'pipe'
282
+ });
283
+
284
+ // Get current branch and push
285
+ const currentBranch = execSync('git rev-parse --abbrev-ref HEAD', {
286
+ encoding: 'utf8'
287
+ }).trim();
288
+ execSync(`git push origin ${currentBranch}`, { stdio: 'inherit' });
289
+ console.log(` āœ… Changes committed and pushed`);
290
+ } else {
291
+ console.log(` ā„¹ļø No changes to commit`);
292
+ }
293
+ } catch (error) {
294
+ console.error(
295
+ ` āŒ Commit/push failed: ${error instanceof Error ? error.message : String(error)}`
296
+ );
297
+ throw error;
298
+ }
299
+
300
+ // Step 5: Publish to NPM
301
+ console.log(`\nšŸ“¤ Step 5/5: Publishing to NPM...`);
302
+ execSync('npm publish --registry https://registry.npmjs.org/', {
303
+ stdio: 'inherit'
304
+ });
305
+
306
+ // Optional: Update global CLI automatically
307
+ console.log(`\nšŸŒ Updating global CLI...`);
308
+ console.log(` ā³ Waiting 30s for NPM registry propagation...`);
309
+ await new Promise((resolve) => setTimeout(resolve, 30000));
310
+ try {
311
+ execSync(
312
+ 'npm install -g obsidian-plugin-config@latest --force --engine-strict=false',
313
+ { stdio: 'inherit' }
314
+ );
315
+ console.log(` āœ… Global CLI updated`);
316
+ } catch {
317
+ console.log(` āš ļø Global CLI update failed (NPM registry may need more time)`);
318
+ console.log(
319
+ ` šŸ’” Run manually in a few minutes: npm install -g obsidian-plugin-config@latest --force`
320
+ );
321
+ }
322
+ console.log(`\nšŸŽ‰ Complete workflow successful!`);
323
+ console.log(` Test: cd any-plugin && obsidian-inject`);
324
+ } catch (error) {
325
+ console.error(
326
+ `\nāŒ Workflow failed: ${error instanceof Error ? error.message : String(error)}`
327
+ );
328
+ process.exit(1);
329
+ }
326
330
  }
327
331
 
328
332
  /**
329
333
  * Verify package is ready for publication
330
334
  */
331
335
  function verifyPackage(): void {
332
- // Check required scripts
333
- const requiredScripts = [
334
- 'scripts/inject-path.ts',
335
- 'scripts/inject-prompt.ts',
336
- 'scripts/inject-core.ts',
337
- 'scripts/utils.ts',
338
- 'scripts/acp.ts',
339
- 'scripts/update-version-config.ts',
340
- 'scripts/help.ts'
341
- ];
342
-
343
- for (const script of requiredScripts) {
344
- if (!fs.existsSync(script)) {
345
- throw new Error(`Missing required script: ${script}`);
346
- }
347
- }
348
- console.log(` āœ… All required scripts present`);
349
-
350
- // Check package.json
351
- const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
352
- const requiredFields = [
353
- 'name',
354
- 'version',
355
- 'description',
356
- 'bin',
357
- 'repository',
358
- 'author'
359
- ];
360
-
361
- for (const field of requiredFields) {
362
- if (!packageJson[field]) {
363
- throw new Error(`Missing required package.json field: ${field}`);
364
- }
365
- }
366
- console.log(` āœ… Package.json valid (v${packageJson.version})`);
367
-
368
- // Check bin file exists
369
- if (!fs.existsSync('bin/obsidian-inject.js')) {
370
- throw new Error(`Missing bin file: bin/obsidian-inject.js`);
371
- }
372
- console.log(` āœ… Bin file ready`);
373
-
374
- // Quick build test
375
- execSync('tsc --noEmit', { stdio: 'pipe' });
376
- console.log(` āœ… TypeScript check passed`);
336
+ // Check required scripts
337
+ const requiredScripts = [
338
+ 'scripts/inject-path.ts',
339
+ 'scripts/inject-prompt.ts',
340
+ 'scripts/inject-core.ts',
341
+ 'scripts/utils.ts',
342
+ 'scripts/acp.ts',
343
+ 'scripts/update-version-config.ts',
344
+ 'scripts/help.ts'
345
+ ];
346
+
347
+ for (const script of requiredScripts) {
348
+ if (!fs.existsSync(script)) {
349
+ throw new Error(`Missing required script: ${script}`);
350
+ }
351
+ }
352
+ console.log(` āœ… All required scripts present`);
353
+
354
+ // Check package.json
355
+ const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
356
+ const requiredFields = [
357
+ 'name',
358
+ 'version',
359
+ 'description',
360
+ 'bin',
361
+ 'repository',
362
+ 'author'
363
+ ];
364
+
365
+ for (const field of requiredFields) {
366
+ if (!packageJson[field]) {
367
+ throw new Error(`Missing required package.json field: ${field}`);
368
+ }
369
+ }
370
+ console.log(` āœ… Package.json valid (v${packageJson.version})`);
371
+
372
+ // Check bin file exists
373
+ if (!fs.existsSync('bin/obsidian-inject.js')) {
374
+ throw new Error(`Missing bin file: bin/obsidian-inject.js`);
375
+ }
376
+ console.log(` āœ… Bin file ready`);
377
+
378
+ // Quick build test
379
+ execSync('tsc --noEmit', { stdio: 'pipe' });
380
+ console.log(` āœ… TypeScript check passed`);
377
381
  }
378
382
 
379
383
  // Run the script