obsidian-plugin-config 1.4.4 → 1.4.7

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.
@@ -1,28 +1,28 @@
1
1
  #!/usr/bin/env tsx
2
2
 
3
- import fs from "fs";
4
- import path from "path";
5
- import { execSync } from "child_process";
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import { execSync } from 'child_process';
6
6
 
7
7
  /**
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
@@ -190,139 +190,156 @@ function main() {
190
190
  main();
191
191
  `;
192
192
 
193
- fs.writeFileSync(binPath, binContent, "utf8");
194
- console.log(` āœ… Generated ${binPath}`);
193
+ fs.writeFileSync(binPath, binContent, 'utf8');
194
+ console.log(` āœ… Generated ${binPath}`);
195
195
  }
196
196
 
197
197
  /**
198
198
  * Complete NPM workflow - Version, Commit, Push, Publish
199
199
  */
200
200
  async function buildAndPublishNpm(): Promise<void> {
201
- console.log(`šŸš€ Obsidian Plugin Config - Complete NPM Workflow`);
202
- console.log(`Full automation: version → exports → bin → commit → publish\n`);
203
-
204
- try {
205
- // Step 0: Check NPM login
206
- console.log(`šŸ” Checking NPM authentication...`);
207
- try {
208
- const whoami = execSync('npm whoami --registry https://registry.npmjs.org/', {
209
- stdio: 'pipe', encoding: 'utf8'
210
- }).trim();
211
- console.log(` āœ… Logged in as: ${whoami}\n`);
212
- } catch {
213
- console.error(` āŒ Not logged in to NPM. Run: npm login`);
214
- process.exit(1);
215
- }
216
-
217
- // Step 1: Update version
218
- console.log(`šŸ“‹ Step 1/7: Updating version...`);
219
- execSync('tsx scripts/update-version-config.ts', { stdio: 'inherit' });
220
-
221
- // Step 2: Update exports
222
- console.log(`\nšŸ“¦ Step 2/7: Updating exports...`);
223
- execSync('yarn update-exports', { stdio: 'inherit' });
224
-
225
- // Step 3: Generate bin file
226
- console.log(`\nšŸ”§ Step 3/7: Generating bin/obsidian-inject.js...`);
227
- await generateBinFile();
228
-
229
- // Step 4: Verify package and sync versions.json
230
- console.log(`\nšŸ“‹ Step 4/7: Verifying package...`);
231
- verifyPackage();
232
-
233
- // Step 5: Commit and push
234
- console.log(`\nšŸ“¤ Step 5/7: Committing and pushing changes...`);
235
- try {
236
- execSync('echo "Publish NPM package" | tsx scripts/acp.ts -b', { stdio: 'inherit' });
237
- } catch {
238
- console.log(` ā„¹ļø No additional changes to commit`);
239
- }
240
-
241
- // Step 6: Publish to NPM
242
- console.log(`\nšŸ“¤ Step 6/7: Publishing to NPM...`);
243
- execSync('npm publish --registry https://registry.npmjs.org/', { stdio: 'inherit' });
244
-
245
- // Step 7: Offer global update
246
- console.log(`\nšŸŒ Step 7/7: Update global CLI?`);
247
- const { askConfirmation, createReadlineInterface } = await import("./utils.js");
248
- const rl = createReadlineInterface();
249
- const doUpdate = await askConfirmation(
250
- `Install npm install -g obsidian-plugin-config@latest?`, rl
251
- );
252
- rl.close();
253
- if (doUpdate) {
254
- execSync('npm install -g obsidian-plugin-config@latest --force --engine-strict=false', { stdio: 'inherit' });
255
- console.log(` āœ… Global CLI updated`);
256
- }
257
-
258
- console.log(`\nšŸŽ‰ Complete workflow successful!`);
259
- console.log(` Test: cd any-plugin && obsidian-inject`);
260
-
261
- } catch (error) {
262
- console.error(`\nāŒ Workflow failed: ${error instanceof Error ? error.message : String(error)}`);
263
- process.exit(1);
264
- }
201
+ console.log(`šŸš€ Obsidian Plugin Config - Complete NPM Workflow`);
202
+ console.log(`Full automation: version → exports → bin → commit → publish\n`);
203
+
204
+ try {
205
+ // Step 0: Check NPM login
206
+ console.log(`šŸ” Checking NPM authentication...`);
207
+ try {
208
+ const whoami = execSync('npm whoami --registry https://registry.npmjs.org/', {
209
+ stdio: 'pipe',
210
+ encoding: 'utf8'
211
+ }).trim();
212
+ console.log(` āœ… Logged in as: ${whoami}\n`);
213
+ } catch {
214
+ console.error(` āŒ Not logged in to NPM. Run: npm login`);
215
+ process.exit(1);
216
+ }
217
+
218
+ // Step 1: Update version
219
+ console.log(`šŸ“‹ Step 1/7: Updating version...`);
220
+ execSync('tsx scripts/update-version-config.ts', { stdio: 'inherit' });
221
+
222
+ // Step 2: Update exports
223
+ console.log(`\nšŸ“¦ Step 2/7: Updating exports...`);
224
+ execSync('yarn update-exports', { stdio: 'inherit' });
225
+
226
+ // Step 3: Generate bin file
227
+ console.log(`\nšŸ”§ Step 3/7: Generating bin/obsidian-inject.js...`);
228
+ await generateBinFile();
229
+
230
+ // Step 4: Verify package and sync versions.json
231
+ console.log(`\nšŸ“‹ Step 4/7: Verifying package...`);
232
+ verifyPackage();
233
+
234
+ // Step 5: Commit and push
235
+ console.log(`\nšŸ“¤ Step 5/7: Committing and pushing changes...`);
236
+ try {
237
+ execSync('echo "Publish NPM package" | tsx scripts/acp.ts -b', {
238
+ stdio: 'inherit'
239
+ });
240
+ } catch {
241
+ console.log(` ā„¹ļø No additional changes to commit`);
242
+ }
243
+
244
+ // Step 6: Publish to NPM
245
+ console.log(`\nšŸ“¤ Step 6/7: Publishing to NPM...`);
246
+ execSync('npm publish --registry https://registry.npmjs.org/', {
247
+ stdio: 'inherit'
248
+ });
249
+
250
+ // Step 7: Offer global update
251
+ console.log(`\nšŸŒ Step 7/7: Update global CLI?`);
252
+ const { askConfirmation, createReadlineInterface } = await import('./utils.js');
253
+ const rl = createReadlineInterface();
254
+ const doUpdate = await askConfirmation(
255
+ `Install npm install -g obsidian-plugin-config@latest?`,
256
+ rl
257
+ );
258
+ rl.close();
259
+ if (doUpdate) {
260
+ execSync(
261
+ 'npm install -g obsidian-plugin-config@latest --force --engine-strict=false',
262
+ { stdio: 'inherit' }
263
+ );
264
+ console.log(` āœ… Global CLI updated`);
265
+ }
266
+
267
+ console.log(`\nšŸŽ‰ Complete workflow successful!`);
268
+ console.log(` Test: cd any-plugin && obsidian-inject`);
269
+ } catch (error) {
270
+ console.error(
271
+ `\nāŒ Workflow failed: ${error instanceof Error ? error.message : String(error)}`
272
+ );
273
+ process.exit(1);
274
+ }
265
275
  }
266
276
 
267
277
  /**
268
278
  * Verify package is ready for publication
269
279
  */
270
280
  function verifyPackage(): void {
271
- // Check required scripts
272
- const requiredScripts = [
273
- "scripts/inject-path.ts",
274
- "scripts/inject-prompt.ts",
275
- "scripts/utils.ts",
276
- "scripts/esbuild.config.ts",
277
- "scripts/acp.ts",
278
- "scripts/update-version-config.ts",
279
- "scripts/help.ts"
280
- ];
281
-
282
- for (const script of requiredScripts) {
283
- if (!fs.existsSync(script)) {
284
- throw new Error(`Missing required script: ${script}`);
285
- }
286
- }
287
- console.log(` āœ… All required scripts present`);
288
-
289
- // Check package.json
290
- const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
291
- const requiredFields = ['name', 'version', 'description', 'bin', 'repository', 'author'];
292
-
293
- for (const field of requiredFields) {
294
- if (!packageJson[field]) {
295
- throw new Error(`Missing required package.json field: ${field}`);
296
- }
297
- }
298
- console.log(` āœ… Package.json valid (v${packageJson.version})`);
299
-
300
- // Check bin file exists
301
- if (!fs.existsSync("bin/obsidian-inject.js")) {
302
- throw new Error(`Missing bin file: bin/obsidian-inject.js`);
303
- }
304
- console.log(` āœ… Bin file ready`);
305
-
306
- // Sync versions.json
307
- const versionsPath = "versions.json";
308
- let versions: Record<string, string> = {};
309
-
310
- if (fs.existsSync(versionsPath)) {
311
- versions = JSON.parse(fs.readFileSync(versionsPath, "utf8"));
312
- }
313
-
314
- if (!versions[packageJson.version]) {
315
- const manifest = JSON.parse(fs.readFileSync("manifest.json", "utf8"));
316
- versions[packageJson.version] = manifest.minAppVersion;
317
- fs.writeFileSync(versionsPath, JSON.stringify(versions, null, "\t"), "utf8");
318
- console.log(` āœ… Added version ${packageJson.version} to versions.json`);
319
- } else {
320
- console.log(` āœ… Version ${packageJson.version} in versions.json`);
321
- }
322
-
323
- // Quick build test
324
- execSync('yarn build', { stdio: 'pipe' });
325
- console.log(` āœ… Build test passed`);
281
+ // Check required scripts
282
+ const requiredScripts = [
283
+ 'scripts/inject-path.ts',
284
+ 'scripts/inject-prompt.ts',
285
+ 'scripts/utils.ts',
286
+ 'scripts/esbuild.config.ts',
287
+ 'scripts/acp.ts',
288
+ 'scripts/update-version-config.ts',
289
+ 'scripts/help.ts'
290
+ ];
291
+
292
+ for (const script of requiredScripts) {
293
+ if (!fs.existsSync(script)) {
294
+ throw new Error(`Missing required script: ${script}`);
295
+ }
296
+ }
297
+ console.log(` āœ… All required scripts present`);
298
+
299
+ // Check package.json
300
+ const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
301
+ const requiredFields = [
302
+ 'name',
303
+ 'version',
304
+ 'description',
305
+ 'bin',
306
+ 'repository',
307
+ 'author'
308
+ ];
309
+
310
+ for (const field of requiredFields) {
311
+ if (!packageJson[field]) {
312
+ throw new Error(`Missing required package.json field: ${field}`);
313
+ }
314
+ }
315
+ console.log(` āœ… Package.json valid (v${packageJson.version})`);
316
+
317
+ // Check bin file exists
318
+ if (!fs.existsSync('bin/obsidian-inject.js')) {
319
+ throw new Error(`Missing bin file: bin/obsidian-inject.js`);
320
+ }
321
+ console.log(` āœ… Bin file ready`);
322
+
323
+ // Sync versions.json
324
+ const versionsPath = 'versions.json';
325
+ let versions: Record<string, string> = {};
326
+
327
+ if (fs.existsSync(versionsPath)) {
328
+ versions = JSON.parse(fs.readFileSync(versionsPath, 'utf8'));
329
+ }
330
+
331
+ if (!versions[packageJson.version]) {
332
+ const manifest = JSON.parse(fs.readFileSync('manifest.json', 'utf8'));
333
+ versions[packageJson.version] = manifest.minAppVersion;
334
+ fs.writeFileSync(versionsPath, JSON.stringify(versions, null, '\t'), 'utf8');
335
+ console.log(` āœ… Added version ${packageJson.version} to versions.json`);
336
+ } else {
337
+ console.log(` āœ… Version ${packageJson.version} in versions.json`);
338
+ }
339
+
340
+ // Quick build test
341
+ execSync('yarn build', { stdio: 'pipe' });
342
+ console.log(` āœ… Build test passed`);
326
343
  }
327
344
 
328
345
  // Run the script