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.
- package/bin/obsidian-inject.js +1 -1
- package/package.json +1 -1
- package/scripts/build-npm.ts +359 -357
- package/versions.json +2 -1
package/bin/obsidian-inject.js
CHANGED
package/package.json
CHANGED
package/scripts/build-npm.ts
CHANGED
|
@@ -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
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
console.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
'scripts/
|
|
297
|
-
'scripts/
|
|
298
|
-
'scripts/
|
|
299
|
-
'scripts/
|
|
300
|
-
'scripts/
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
'
|
|
316
|
-
'
|
|
317
|
-
'
|
|
318
|
-
'
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
console.log(` β
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
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();
|