obsidian-plugin-config 1.5.0 β†’ 1.5.1

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.5.0
6
+ * Version: 1.5.1
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.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "SystΓ¨me d'injection pour plugins Obsidian autonomes",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -1,357 +1,359 @@
1
- #!/usr/bin/env tsx
2
-
3
- import fs from 'fs';
4
- import path from 'path';
5
- import { execSync } from 'child_process';
6
-
7
- /**
8
- * Generate bin/obsidian-inject.js from template
9
- */
10
- async function generateBinFile(): Promise<void> {
11
- console.log(`\nπŸ”§ Generating bin/obsidian-inject.js...`);
12
-
13
- const binDir = 'bin';
14
- const binPath = path.join(binDir, 'obsidian-inject.js');
15
-
16
- // Ensure bin directory exists
17
- if (!fs.existsSync(binDir)) {
18
- fs.mkdirSync(binDir, { recursive: true });
19
- console.log(` πŸ“ Created ${binDir} directory`);
20
- }
21
-
22
- // Read package.json for version info
23
- const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
24
-
25
- const binContent = `#!/usr/bin/env node
26
-
27
- /**
28
- * Obsidian Plugin Config - CLI Entry Point
29
- * Global command: obsidian-inject
30
- * Version: ${packageJson.version}
31
- */
32
-
33
- import { execSync } from 'child_process';
34
- import { fileURLToPath } from 'url';
35
- import { dirname, join, isAbsolute, resolve } from 'path';
36
- import fs from 'fs';
37
-
38
- // Get the directory of this script
39
- const __filename = fileURLToPath(import.meta.url);
40
- const __dirname = dirname(__filename);
41
- const packageRoot = dirname(__dirname);
42
-
43
- // Path to the injection script
44
- const injectScriptPath = join(packageRoot, 'scripts', 'inject-path.ts');
45
-
46
- function showHelp() {
47
- console.log(\`
48
- Obsidian Plugin Config - Global CLI
49
- Injection system for autonomous Obsidian plugins
50
-
51
- USAGE:
52
- obsidian-inject # Inject in current directory
53
- obsidian-inject <path> # Inject by path
54
- obsidian-inject <path> --sass # Inject with SASS support
55
- obsidian-inject --help, -h # Show this help
56
-
57
- EXAMPLES:
58
- cd my-plugin && obsidian-inject
59
- obsidian-inject ../my-other-plugin
60
- obsidian-inject ../my-plugin --sass
61
- obsidian-inject "C:\\\\Users\\\\dev\\\\plugins\\\\my-plugin"
62
-
63
- WHAT IS INJECTED:
64
- βœ… Local scripts (esbuild.config.ts, acp.ts, utils.ts, etc.)
65
- βœ… Package.json configuration (scripts, dependencies)
66
- βœ… Yarn protection enforced
67
- βœ… Automatic dependency installation
68
- 🎨 SASS support (with --sass option): esbuild-sass-plugin + SCSS compilation
69
-
70
- ARCHITECTURE:
71
- - Plugin becomes AUTONOMOUS with local scripts
72
- - No external dependencies required after injection
73
- - Updates possible via re-injection
74
-
75
- More info: https://github.com/3C0D/obsidian-plugin-config
76
- \`);
77
- }
78
-
79
- function main() {
80
- const args = process.argv.slice(2);
81
-
82
- // Handle help flags
83
- if (args.includes('--help') || args.includes('-h')) {
84
- showHelp();
85
- process.exit(0);
86
- }
87
-
88
- // Check if injection script exists
89
- if (!fs.existsSync(injectScriptPath)) {
90
- console.error(\`❌ Error: Injection script not found at \${injectScriptPath}\`);
91
- console.error(\` Make sure obsidian-plugin-config is properly installed.\`);
92
- process.exit(1);
93
- }
94
-
95
- // Parse arguments
96
- const sassFlag = args.includes('--sass');
97
- const pathArg = args.find(arg => !arg.startsWith('-'));
98
-
99
- // Determine target path (resolve relative to user's current directory)
100
- const userCwd = process.cwd();
101
- let targetPath = pathArg || userCwd;
102
-
103
- // If relative path, resolve from user's current directory
104
- if (pathArg && !isAbsolute(pathArg)) {
105
- targetPath = resolve(userCwd, pathArg);
106
- }
107
-
108
- console.log(\`🎯 Obsidian Plugin Config - Global Injection\`);
109
- console.log(\`πŸ“ Target: \${targetPath}\`);
110
- console.log(\`🎨 SASS: \${sassFlag ? 'Enabled' : 'Disabled'}\`);
111
- console.log(\`πŸ“¦ From: \${packageRoot}\\n\`);
112
-
113
- try {
114
- // Check if target directory has package.json
115
- const targetPackageJson = join(targetPath, 'package.json');
116
- if (!fs.existsSync(targetPackageJson)) {
117
- console.error(\`❌ Error: package.json not found in \${targetPath}\`);
118
- console.error(\` Make sure this is a valid Node.js project.\`);
119
- process.exit(1);
120
- }
121
-
122
- // Prevent injecting into obsidian-plugin-config itself
123
- const pkg = JSON.parse(fs.readFileSync(targetPackageJson, 'utf8'));
124
- if (pkg.name === 'obsidian-plugin-config') {
125
- console.error(\`❌ Cannot inject into obsidian-plugin-config itself.\`);
126
- process.exit(1);
127
- }
128
-
129
- // Clean NPM artifacts if package-lock.json exists
130
- const packageLockPath = join(targetPath, 'package-lock.json');
131
- if (fs.existsSync(packageLockPath)) {
132
- console.log(\`🧹 NPM installation detected, cleaning...\`);
133
-
134
- try {
135
- // Remove package-lock.json
136
- fs.unlinkSync(packageLockPath);
137
- console.log(\` πŸ—‘οΈ package-lock.json removed\`);
138
-
139
- // Remove node_modules if it exists
140
- const nodeModulesPath = join(targetPath, 'node_modules');
141
- if (fs.existsSync(nodeModulesPath)) {
142
- fs.rmSync(nodeModulesPath, { recursive: true, force: true });
143
- console.log(\` πŸ—‘οΈ node_modules removed (will be reinstalled with Yarn)\`);
144
- }
145
-
146
- console.log(\` βœ… NPM artifacts cleaned to avoid Yarn conflicts\`);
147
-
148
- } catch (cleanError) {
149
- console.error(\` ❌ Cleanup failed:\`, cleanError.message);
150
- console.log(\` πŸ’‘ Manually remove package-lock.json and node_modules\`);
151
- }
152
- }
153
-
154
- // Check if tsx is available locally in target
155
- let tsxCommand = 'npx tsx';
156
- try {
157
- execSync('npx tsx --version', {
158
- cwd: targetPath,
159
- stdio: 'pipe'
160
- });
161
- console.log(\`βœ… tsx available locally\`);
162
- } catch {
163
- console.log(\`⚠️ tsx not found, installing...\`);
164
-
165
- // Install tsx locally in target directory
166
- try {
167
- execSync('yarn add -D tsx', {
168
- cwd: targetPath,
169
- stdio: 'inherit'
170
- });
171
- console.log(\`βœ… tsx installed successfully\`);
172
- } catch (installError) {
173
- console.error(\`❌ tsx installation failed:\`, installError.message);
174
- console.error(\` Try installing tsx manually: cd "\${targetPath}" && yarn add -D tsx\`);
175
- process.exit(1);
176
- }
177
- }
178
-
179
- // Execute the injection script with tsx
180
- const sassOption = sassFlag ? ' --sass' : '';
181
- const command = \`npx tsx "\${injectScriptPath}" "\${targetPath}" --yes\${sassOption}\`;
182
-
183
- execSync(command, {
184
- stdio: 'inherit',
185
- cwd: targetPath // Use target directory to ensure tsx is available
186
- });
187
-
188
- console.log(\`\\nβœ… Injection completed successfully!\`);
189
-
190
- } catch (error) {
191
- console.error(\`\\n❌ Injection error:\`, error.message);
192
- process.exit(1);
193
- }
194
- }
195
-
196
- // Run the CLI
197
- main();
198
- `;
199
-
200
- fs.writeFileSync(binPath, binContent, 'utf8');
201
- console.log(` βœ… Generated ${binPath}`);
202
- }
203
-
204
- /**
205
- * Complete NPM workflow - Version, Commit, Push, Publish
206
- */
207
- async function buildAndPublishNpm(): Promise<void> {
208
- console.log(`πŸš€ Obsidian Plugin Config - Complete NPM Workflow`);
209
- console.log(`Full automation: version β†’ exports β†’ bin β†’ commit β†’ publish\n`);
210
-
211
- try {
212
- // Step 0: Check NPM login
213
- console.log(`πŸ” Checking NPM authentication...`);
214
- try {
215
- const whoami = execSync('npm whoami --registry https://registry.npmjs.org/', {
216
- stdio: 'pipe',
217
- encoding: 'utf8'
218
- }).trim();
219
- console.log(` βœ… Logged in as: ${whoami}\n`);
220
- } catch {
221
- console.error(` ❌ Not logged in to NPM. Run: npm login`);
222
- process.exit(1);
223
- }
224
-
225
- // Step 1: Update version
226
- console.log(`πŸ“‹ Step 1/7: Updating version...`);
227
- execSync('tsx scripts/update-version-config.ts', { stdio: 'inherit' });
228
-
229
- // Step 2: Update exports
230
- console.log(`\nπŸ“¦ Step 2/7: Updating exports...`);
231
- execSync('yarn update-exports', { stdio: 'inherit' });
232
-
233
- // Step 3: Generate bin file
234
- console.log(`\nπŸ”§ Step 3/7: Generating bin/obsidian-inject.js...`);
235
- await generateBinFile();
236
-
237
- // Step 4: Verify package and sync versions.json
238
- console.log(`\nπŸ“‹ Step 4/7: Verifying package...`);
239
- verifyPackage();
240
-
241
- // Step 5: Commit and push
242
- console.log(`\nπŸ“€ Step 5/7: Committing and pushing changes...`);
243
- try {
244
- execSync('echo "Publish NPM package" | tsx scripts/acp.ts -b', {
245
- stdio: 'inherit'
246
- });
247
- } catch {
248
- console.log(` ℹ️ No additional changes to commit`);
249
- }
250
-
251
- // Step 6: Publish to NPM
252
- console.log(`\nπŸ“€ Step 6/7: Publishing to NPM...`);
253
- execSync('npm publish --registry https://registry.npmjs.org/', {
254
- stdio: 'inherit'
255
- });
256
-
257
- // Step 7: Update global CLI (auto if --auto-update, else ask)
258
- console.log(`\n🌍 Step 7/7: Update global CLI?`);
259
- const autoUpdate = process.argv.includes('--auto-update');
260
- let doUpdate = autoUpdate;
261
- if (!autoUpdate) {
262
- const { askConfirmation, createReadlineInterface } = await import('./utils.js');
263
- const rl = createReadlineInterface();
264
- doUpdate = await askConfirmation(
265
- `Install obsidian-plugin-config@latest globally?`,
266
- rl
267
- );
268
- rl.close();
269
- }
270
- if (doUpdate) {
271
- execSync(
272
- 'npm install -g obsidian-plugin-config@latest --force --engine-strict=false',
273
- { stdio: 'inherit' }
274
- );
275
- console.log(` βœ… Global CLI updated`);
276
- }
277
-
278
- console.log(`\nπŸŽ‰ Complete workflow successful!`);
279
- console.log(` Test: cd any-plugin && obsidian-inject`);
280
- } catch (error) {
281
- console.error(
282
- `\n❌ Workflow failed: ${error instanceof Error ? error.message : String(error)}`
283
- );
284
- process.exit(1);
285
- }
286
- }
287
-
288
- /**
289
- * Verify package is ready for publication
290
- */
291
- function verifyPackage(): void {
292
- // Check required scripts
293
- const requiredScripts = [
294
- 'scripts/inject-path.ts',
295
- 'scripts/inject-prompt.ts',
296
- 'scripts/utils.ts',
297
- 'scripts/esbuild.config.ts',
298
- 'scripts/acp.ts',
299
- 'scripts/update-version-config.ts',
300
- 'scripts/help.ts'
301
- ];
302
-
303
- for (const script of requiredScripts) {
304
- if (!fs.existsSync(script)) {
305
- throw new Error(`Missing required script: ${script}`);
306
- }
307
- }
308
- console.log(` βœ… All required scripts present`);
309
-
310
- // Check package.json
311
- const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
312
- const requiredFields = [
313
- 'name',
314
- 'version',
315
- 'description',
316
- 'bin',
317
- 'repository',
318
- 'author'
319
- ];
320
-
321
- for (const field of requiredFields) {
322
- if (!packageJson[field]) {
323
- throw new Error(`Missing required package.json field: ${field}`);
324
- }
325
- }
326
- console.log(` βœ… Package.json valid (v${packageJson.version})`);
327
-
328
- // Check bin file exists
329
- if (!fs.existsSync('bin/obsidian-inject.js')) {
330
- throw new Error(`Missing bin file: bin/obsidian-inject.js`);
331
- }
332
- console.log(` βœ… Bin file ready`);
333
-
334
- // Sync versions.json
335
- const versionsPath = 'versions.json';
336
- let versions: Record<string, string> = {};
337
-
338
- if (fs.existsSync(versionsPath)) {
339
- versions = JSON.parse(fs.readFileSync(versionsPath, 'utf8'));
340
- }
341
-
342
- if (!versions[packageJson.version]) {
343
- const manifest = JSON.parse(fs.readFileSync('manifest.json', 'utf8'));
344
- versions[packageJson.version] = manifest.minAppVersion;
345
- fs.writeFileSync(versionsPath, JSON.stringify(versions, null, '\t'), 'utf8');
346
- console.log(` βœ… Added version ${packageJson.version} to versions.json`);
347
- } else {
348
- console.log(` βœ… Version ${packageJson.version} in versions.json`);
349
- }
350
-
351
- // Quick build test
352
- execSync('yarn build', { stdio: 'pipe' });
353
- console.log(` βœ… Build test passed`);
354
- }
355
-
356
- // Run the script
357
- await buildAndPublishNpm();
1
+ #!/usr/bin/env tsx
2
+
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import { execSync } from 'child_process';
6
+
7
+ /**
8
+ * Generate bin/obsidian-inject.js from template
9
+ */
10
+ async function generateBinFile(): Promise<void> {
11
+ console.log(`\nπŸ”§ Generating bin/obsidian-inject.js...`);
12
+
13
+ const binDir = 'bin';
14
+ const binPath = path.join(binDir, 'obsidian-inject.js');
15
+
16
+ // Ensure bin directory exists
17
+ if (!fs.existsSync(binDir)) {
18
+ fs.mkdirSync(binDir, { recursive: true });
19
+ console.log(` πŸ“ Created ${binDir} directory`);
20
+ }
21
+
22
+ // Read package.json for version info
23
+ const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
24
+
25
+ const binContent = `#!/usr/bin/env node
26
+
27
+ /**
28
+ * Obsidian Plugin Config - CLI Entry Point
29
+ * Global command: obsidian-inject
30
+ * Version: ${packageJson.version}
31
+ */
32
+
33
+ import { execSync } from 'child_process';
34
+ import { fileURLToPath } from 'url';
35
+ import { dirname, join, isAbsolute, resolve } from 'path';
36
+ import fs from 'fs';
37
+
38
+ // Get the directory of this script
39
+ const __filename = fileURLToPath(import.meta.url);
40
+ const __dirname = dirname(__filename);
41
+ const packageRoot = dirname(__dirname);
42
+
43
+ // Path to the injection script
44
+ const injectScriptPath = join(packageRoot, 'scripts', 'inject-path.ts');
45
+
46
+ function showHelp() {
47
+ console.log(\`
48
+ Obsidian Plugin Config - Global CLI
49
+ Injection system for autonomous Obsidian plugins
50
+
51
+ USAGE:
52
+ obsidian-inject # Inject in current directory
53
+ obsidian-inject <path> # Inject by path
54
+ obsidian-inject <path> --sass # Inject with SASS support
55
+ obsidian-inject --help, -h # Show this help
56
+
57
+ EXAMPLES:
58
+ cd my-plugin && obsidian-inject
59
+ obsidian-inject ../my-other-plugin
60
+ obsidian-inject ../my-plugin --sass
61
+ obsidian-inject "C:\\\\Users\\\\dev\\\\plugins\\\\my-plugin"
62
+
63
+ WHAT IS INJECTED:
64
+ βœ… Local scripts (esbuild.config.ts, acp.ts, utils.ts, etc.)
65
+ βœ… Package.json configuration (scripts, dependencies)
66
+ βœ… Yarn protection enforced
67
+ βœ… Automatic dependency installation
68
+ 🎨 SASS support (with --sass option): esbuild-sass-plugin + SCSS compilation
69
+
70
+ ARCHITECTURE:
71
+ - Plugin becomes AUTONOMOUS with local scripts
72
+ - No external dependencies required after injection
73
+ - Updates possible via re-injection
74
+
75
+ More info: https://github.com/3C0D/obsidian-plugin-config
76
+ \`);
77
+ }
78
+
79
+ function main() {
80
+ const args = process.argv.slice(2);
81
+
82
+ // Handle help flags
83
+ if (args.includes('--help') || args.includes('-h')) {
84
+ showHelp();
85
+ process.exit(0);
86
+ }
87
+
88
+ // Check if injection script exists
89
+ if (!fs.existsSync(injectScriptPath)) {
90
+ console.error(\`❌ Error: Injection script not found at \${injectScriptPath}\`);
91
+ console.error(\` Make sure obsidian-plugin-config is properly installed.\`);
92
+ process.exit(1);
93
+ }
94
+
95
+ // Parse arguments
96
+ const sassFlag = args.includes('--sass');
97
+ const pathArg = args.find(arg => !arg.startsWith('-'));
98
+
99
+ // Determine target path (resolve relative to user's current directory)
100
+ const userCwd = process.cwd();
101
+ let targetPath = pathArg || userCwd;
102
+
103
+ // If relative path, resolve from user's current directory
104
+ if (pathArg && !isAbsolute(pathArg)) {
105
+ targetPath = resolve(userCwd, pathArg);
106
+ }
107
+
108
+ console.log(\`🎯 Obsidian Plugin Config - Global Injection\`);
109
+ console.log(\`πŸ“ Target: \${targetPath}\`);
110
+ console.log(\`🎨 SASS: \${sassFlag ? 'Enabled' : 'Disabled'}\`);
111
+ console.log(\`πŸ“¦ From: \${packageRoot}\\n\`);
112
+
113
+ try {
114
+ // Check if target directory has package.json
115
+ const targetPackageJson = join(targetPath, 'package.json');
116
+ if (!fs.existsSync(targetPackageJson)) {
117
+ console.error(\`❌ Error: package.json not found in \${targetPath}\`);
118
+ console.error(\` Make sure this is a valid Node.js project.\`);
119
+ process.exit(1);
120
+ }
121
+
122
+ // Prevent injecting into obsidian-plugin-config itself
123
+ const pkg = JSON.parse(fs.readFileSync(targetPackageJson, 'utf8'));
124
+ if (pkg.name === 'obsidian-plugin-config') {
125
+ console.error(\`❌ Cannot inject into obsidian-plugin-config itself.\`);
126
+ process.exit(1);
127
+ }
128
+
129
+ // Clean NPM artifacts if package-lock.json exists
130
+ const packageLockPath = join(targetPath, 'package-lock.json');
131
+ if (fs.existsSync(packageLockPath)) {
132
+ console.log(\`🧹 NPM installation detected, cleaning...\`);
133
+
134
+ try {
135
+ // Remove package-lock.json
136
+ fs.unlinkSync(packageLockPath);
137
+ console.log(\` πŸ—‘οΈ package-lock.json removed\`);
138
+
139
+ // Remove node_modules if it exists
140
+ const nodeModulesPath = join(targetPath, 'node_modules');
141
+ if (fs.existsSync(nodeModulesPath)) {
142
+ fs.rmSync(nodeModulesPath, { recursive: true, force: true });
143
+ console.log(\` πŸ—‘οΈ node_modules removed (will be reinstalled with Yarn)\`);
144
+ }
145
+
146
+ console.log(\` βœ… NPM artifacts cleaned to avoid Yarn conflicts\`);
147
+
148
+ } catch (cleanError) {
149
+ console.error(\` ❌ Cleanup failed:\`, cleanError.message);
150
+ console.log(\` πŸ’‘ Manually remove package-lock.json and node_modules\`);
151
+ }
152
+ }
153
+
154
+ // Check if tsx is available locally in target
155
+ let tsxCommand = 'npx tsx';
156
+ try {
157
+ execSync('npx tsx --version', {
158
+ cwd: targetPath,
159
+ stdio: 'pipe'
160
+ });
161
+ console.log(\`βœ… tsx available locally\`);
162
+ } catch {
163
+ console.log(\`⚠️ tsx not found, installing...\`);
164
+
165
+ // Install tsx locally in target directory
166
+ try {
167
+ execSync('yarn add -D tsx', {
168
+ cwd: targetPath,
169
+ stdio: 'inherit'
170
+ });
171
+ console.log(\`βœ… tsx installed successfully\`);
172
+ } catch (installError) {
173
+ console.error(\`❌ tsx installation failed:\`, installError.message);
174
+ console.error(\` Try installing tsx manually: cd "\${targetPath}" && yarn add -D tsx\`);
175
+ process.exit(1);
176
+ }
177
+ }
178
+
179
+ // Execute the injection script with tsx
180
+ const sassOption = sassFlag ? ' --sass' : '';
181
+ const command = \`npx tsx "\${injectScriptPath}" "\${targetPath}" --yes\${sassOption}\`;
182
+
183
+ execSync(command, {
184
+ stdio: 'inherit',
185
+ cwd: targetPath // Use target directory to ensure tsx is available
186
+ });
187
+
188
+ console.log(\`\\nβœ… Injection completed successfully!\`);
189
+
190
+ } catch (error) {
191
+ console.error(\`\\n❌ Injection error:\`, error.message);
192
+ process.exit(1);
193
+ }
194
+ }
195
+
196
+ // Run the CLI
197
+ main();
198
+ `;
199
+
200
+ fs.writeFileSync(binPath, binContent, 'utf8');
201
+ console.log(` βœ… Generated ${binPath}`);
202
+ }
203
+
204
+ /**
205
+ * Complete NPM workflow - Version, Commit, Push, Publish
206
+ */
207
+ async function buildAndPublishNpm(): Promise<void> {
208
+ console.log(`πŸš€ Obsidian Plugin Config - Complete NPM Workflow`);
209
+ console.log(`Full automation: version β†’ exports β†’ bin β†’ commit β†’ publish\n`);
210
+
211
+ try {
212
+ // Step 0: Check NPM login
213
+ console.log(`πŸ” Checking NPM authentication...`);
214
+ try {
215
+ const whoami = execSync('npm whoami --registry https://registry.npmjs.org/', {
216
+ stdio: 'pipe',
217
+ encoding: 'utf8'
218
+ }).trim();
219
+ console.log(` βœ… Logged in as: ${whoami}\n`);
220
+ } catch {
221
+ console.error(` ❌ Not logged in to NPM. Run: npm login`);
222
+ process.exit(1);
223
+ }
224
+
225
+ // Step 1: Update version
226
+ console.log(`πŸ“‹ Step 1/7: Updating version...`);
227
+ execSync('tsx scripts/update-version-config.ts', { stdio: 'inherit' });
228
+
229
+ // Step 2: Update exports
230
+ console.log(`\nπŸ“¦ Step 2/7: Updating exports...`);
231
+ execSync('yarn update-exports', { stdio: 'inherit' });
232
+
233
+ // Step 3: Generate bin file
234
+ console.log(`\nπŸ”§ Step 3/7: Generating bin/obsidian-inject.js...`);
235
+ await generateBinFile();
236
+
237
+ // Step 4: Verify package and sync versions.json
238
+ console.log(`\nπŸ“‹ Step 4/7: Verifying package...`);
239
+ verifyPackage();
240
+
241
+ // Step 5: Commit and push
242
+ console.log(`\nπŸ“€ Step 5/7: Committing and pushing changes...`);
243
+ try {
244
+ execSync('echo "Publish NPM package" | tsx scripts/acp.ts -b', {
245
+ stdio: 'inherit'
246
+ });
247
+ } catch {
248
+ console.log(` ℹ️ No additional changes to commit`);
249
+ }
250
+
251
+ // Step 6: Publish to NPM
252
+ console.log(`\nπŸ“€ Step 6/7: Publishing to NPM...`);
253
+ execSync('npm publish --registry https://registry.npmjs.org/', {
254
+ stdio: 'inherit'
255
+ });
256
+
257
+ // Step 7: Update global CLI (auto if --auto-update, else ask)
258
+ console.log(`\n🌍 Step 7/7: Update global CLI?`);
259
+ const autoUpdate = process.argv.includes('--auto-update');
260
+ let doUpdate = autoUpdate;
261
+ if (!autoUpdate) {
262
+ const { askConfirmation, createReadlineInterface } = await import('./utils.js');
263
+ const rl = createReadlineInterface();
264
+ doUpdate = await askConfirmation(
265
+ `Install obsidian-plugin-config@latest globally?`,
266
+ rl
267
+ );
268
+ rl.close();
269
+ }
270
+ if (doUpdate) {
271
+ console.log(` ⏳ Waiting 15s for NPM registry propagation...`);
272
+ await new Promise(resolve => setTimeout(resolve, 5000));
273
+ execSync(
274
+ 'npm install -g obsidian-plugin-config@latest --force --engine-strict=false',
275
+ { stdio: 'inherit' }
276
+ );
277
+ console.log(` βœ… Global CLI updated`);
278
+ }
279
+
280
+ console.log(`\nπŸŽ‰ Complete workflow successful!`);
281
+ console.log(` Test: cd any-plugin && obsidian-inject`);
282
+ } catch (error) {
283
+ console.error(
284
+ `\n❌ Workflow failed: ${error instanceof Error ? error.message : String(error)}`
285
+ );
286
+ process.exit(1);
287
+ }
288
+ }
289
+
290
+ /**
291
+ * Verify package is ready for publication
292
+ */
293
+ function verifyPackage(): void {
294
+ // Check required scripts
295
+ const requiredScripts = [
296
+ 'scripts/inject-path.ts',
297
+ 'scripts/inject-prompt.ts',
298
+ 'scripts/utils.ts',
299
+ 'scripts/esbuild.config.ts',
300
+ 'scripts/acp.ts',
301
+ 'scripts/update-version-config.ts',
302
+ 'scripts/help.ts'
303
+ ];
304
+
305
+ for (const script of requiredScripts) {
306
+ if (!fs.existsSync(script)) {
307
+ throw new Error(`Missing required script: ${script}`);
308
+ }
309
+ }
310
+ console.log(` βœ… All required scripts present`);
311
+
312
+ // Check package.json
313
+ const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
314
+ const requiredFields = [
315
+ 'name',
316
+ 'version',
317
+ 'description',
318
+ 'bin',
319
+ 'repository',
320
+ 'author'
321
+ ];
322
+
323
+ for (const field of requiredFields) {
324
+ if (!packageJson[field]) {
325
+ throw new Error(`Missing required package.json field: ${field}`);
326
+ }
327
+ }
328
+ console.log(` βœ… Package.json valid (v${packageJson.version})`);
329
+
330
+ // Check bin file exists
331
+ if (!fs.existsSync('bin/obsidian-inject.js')) {
332
+ throw new Error(`Missing bin file: bin/obsidian-inject.js`);
333
+ }
334
+ console.log(` βœ… Bin file ready`);
335
+
336
+ // Sync versions.json
337
+ const versionsPath = 'versions.json';
338
+ let versions: Record<string, string> = {};
339
+
340
+ if (fs.existsSync(versionsPath)) {
341
+ versions = JSON.parse(fs.readFileSync(versionsPath, 'utf8'));
342
+ }
343
+
344
+ if (!versions[packageJson.version]) {
345
+ const manifest = JSON.parse(fs.readFileSync('manifest.json', 'utf8'));
346
+ versions[packageJson.version] = manifest.minAppVersion;
347
+ fs.writeFileSync(versionsPath, JSON.stringify(versions, null, '\t'), 'utf8');
348
+ console.log(` βœ… Added version ${packageJson.version} to versions.json`);
349
+ } else {
350
+ console.log(` βœ… Version ${packageJson.version} in versions.json`);
351
+ }
352
+
353
+ // Quick build test
354
+ execSync('yarn build', { stdio: 'pipe' });
355
+ console.log(` βœ… Build test passed`);
356
+ }
357
+
358
+ // Run the script
359
+ await buildAndPublishNpm();
package/versions.json CHANGED
@@ -48,5 +48,6 @@
48
48
  "1.4.6": "1.8.9",
49
49
  "1.4.7": "1.8.9",
50
50
  "1.4.8": "1.8.9",
51
- "1.5.0": "1.8.9"
51
+ "1.5.0": "1.8.9",
52
+ "1.5.1": "1.8.9"
52
53
  }