obsidian-plugin-config 1.1.12 → 1.1.13
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/README.md +59 -28
- package/bin/obsidian-inject.js +1 -1
- package/manifest.json +11 -0
- package/package.json +4 -5
- package/scripts/esbuild.config.ts +29 -87
- package/scripts/help.ts +45 -28
- package/scripts/utils.ts +11 -6
- package/src/main.ts +24 -9
- package/templates/scripts/esbuild.config.ts +13 -87
- package/templates/scripts/utils.ts +11 -6
- package/versions.json +2 -1
package/README.md
CHANGED
|
@@ -22,23 +22,32 @@ npm update -g obsidian-plugin-config
|
|
|
22
22
|
### For Plugin Config Development
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
#
|
|
26
|
-
yarn
|
|
27
|
-
yarn
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
#
|
|
32
|
-
yarn
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
# Installation & Setup
|
|
26
|
+
yarn i # Install dependencies
|
|
27
|
+
yarn update-exports # Update package.json exports
|
|
28
|
+
|
|
29
|
+
# Git & Version Management
|
|
30
|
+
yarn acp # Add, commit, push
|
|
31
|
+
yarn bacp # Build + add, commit, push
|
|
32
|
+
yarn v # Update version
|
|
33
|
+
|
|
34
|
+
# Build & Testing
|
|
35
|
+
yarn build # TypeScript check (no build needed)
|
|
36
|
+
yarn dev # Development build (watch mode)
|
|
37
|
+
yarn real # Build to real vault
|
|
38
|
+
yarn lint, lint:fix # ESLint verification/correction
|
|
39
|
+
|
|
40
|
+
# Injection (Development phase)
|
|
41
|
+
yarn inject-prompt # Interactive injection
|
|
42
|
+
yarn inject-path # Direct injection
|
|
43
|
+
yarn inject, check-plugin # Injection shortcuts
|
|
35
44
|
|
|
36
45
|
# NPM Publishing
|
|
37
|
-
yarn
|
|
38
|
-
yarn
|
|
46
|
+
yarn npm-publish # Complete NPM workflow
|
|
47
|
+
yarn build-npm # Alias for npm-publish
|
|
39
48
|
|
|
40
49
|
# Help
|
|
41
|
-
yarn help
|
|
50
|
+
yarn help # Show help
|
|
42
51
|
```
|
|
43
52
|
|
|
44
53
|
### For Plugin Injection
|
|
@@ -99,6 +108,19 @@ cd obsidian-plugin-config
|
|
|
99
108
|
yarn install
|
|
100
109
|
```
|
|
101
110
|
|
|
111
|
+
### As a Plugin (for testing NPM exports)
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# Setup vault paths in .env
|
|
115
|
+
echo "TEST_VAULT=C:/path/to/test/vault" >> .env
|
|
116
|
+
echo "REAL_VAULT=C:/path/to/real/vault" >> .env
|
|
117
|
+
|
|
118
|
+
# Development mode
|
|
119
|
+
yarn start # Start development mode
|
|
120
|
+
yarn dev # Watch mode for development
|
|
121
|
+
yarn real # Install to real vault
|
|
122
|
+
```
|
|
123
|
+
|
|
102
124
|
### Local injection test
|
|
103
125
|
|
|
104
126
|
```bash
|
|
@@ -109,27 +131,36 @@ yarn inject ../my-plugin --yes
|
|
|
109
131
|
yarn inject-prompt "../my-plugin"
|
|
110
132
|
```
|
|
111
133
|
|
|
112
|
-
###
|
|
134
|
+
### Development Workflow
|
|
113
135
|
|
|
114
136
|
```bash
|
|
115
|
-
#
|
|
137
|
+
# Standard workflow
|
|
138
|
+
1. yarn i # Install dependencies
|
|
139
|
+
2. Make changes to obsidian-plugin-config
|
|
140
|
+
3. yarn update-exports # Update exports if needed
|
|
141
|
+
4. yarn lint:fix # Fix any linting issues
|
|
142
|
+
5. yarn v # Update version + commit + push GitHub
|
|
143
|
+
6. yarn npm-publish # Complete NPM workflow
|
|
144
|
+
|
|
145
|
+
# Testing as plugin (optional)
|
|
146
|
+
yarn dev # Watch mode for development
|
|
147
|
+
yarn real # Install to real vault
|
|
148
|
+
|
|
149
|
+
# Injection testing (development phase)
|
|
116
150
|
yarn inject ../test-plugin --yes
|
|
117
|
-
|
|
118
|
-
# 2. Fix ESM imports if necessary
|
|
119
|
-
# Example: "./utils.ts" → "./utils.js"
|
|
120
|
-
|
|
121
|
-
# 3. Build and publish to NPM
|
|
122
|
-
yarn build-npm
|
|
123
|
-
yarn update-version
|
|
124
|
-
npm login
|
|
125
|
-
npm publish
|
|
126
151
|
```
|
|
127
152
|
|
|
128
|
-
###
|
|
153
|
+
### Key Commands Summary
|
|
129
154
|
|
|
130
155
|
```bash
|
|
131
|
-
|
|
132
|
-
yarn
|
|
133
|
-
yarn
|
|
156
|
+
# Essential workflow
|
|
157
|
+
yarn i # Install dependencies
|
|
158
|
+
yarn update-exports # Update exports
|
|
159
|
+
yarn v # Update version + commit + push
|
|
160
|
+
yarn npm-publish # Complete NPM workflow
|
|
161
|
+
|
|
162
|
+
# Development & testing
|
|
163
|
+
yarn dev # Test as plugin (watch mode)
|
|
164
|
+
yarn lint:fix # Fix code issues
|
|
134
165
|
yarn help # Full help
|
|
135
166
|
```
|
package/bin/obsidian-inject.js
CHANGED
package/manifest.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "obsidian-plugin-config",
|
|
3
|
+
"name": "Obsidian Plugin Config",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"minAppVersion": "0.15.0",
|
|
6
|
+
"description": "Development and testing environment for obsidian-plugin-config NPM exports and injection system",
|
|
7
|
+
"author": "Your Name",
|
|
8
|
+
"authorUrl": "",
|
|
9
|
+
"fundingUrl": "",
|
|
10
|
+
"isDesktopOnly": false
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "obsidian-plugin-config",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13",
|
|
4
4
|
"description": "Système d'injection pour plugins Obsidian autonomes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -19,14 +19,13 @@
|
|
|
19
19
|
"plugin-utilities"
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
|
-
"
|
|
23
|
-
"i": "yarn install && yarn run update-exports",
|
|
24
|
-
"update-exports": "node scripts/update-exports.js",
|
|
25
|
-
"ue": "node scripts/update-exports.js",
|
|
22
|
+
"i": "yarn install",
|
|
26
23
|
"acp": "tsx scripts/acp.ts",
|
|
27
24
|
"bacp": "tsx scripts/acp.ts -b",
|
|
28
25
|
"update-version": "tsx scripts/update-version-config.ts",
|
|
29
26
|
"v": "tsx scripts/update-version-config.ts",
|
|
27
|
+
"update-exports": "node scripts/update-exports.js",
|
|
28
|
+
"ue": "node scripts/update-exports.js",
|
|
30
29
|
"build": "tsc -noEmit -skipLibCheck",
|
|
31
30
|
"dev": "tsx scripts/esbuild.config.ts",
|
|
32
31
|
"real": "tsx scripts/esbuild.config.ts production real",
|
|
@@ -31,40 +31,7 @@ async function promptForVaultPath(envKey: string): Promise<string> {
|
|
|
31
31
|
return path;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
async function promptForBothVaults(): Promise<void> {
|
|
35
|
-
console.log(`❓ Both vault paths are required for external development`);
|
|
36
|
-
console.log(` TEST_VAULT: for development and testing (yarn dev)`);
|
|
37
|
-
console.log(` REAL_VAULT: for final plugin installation (yarn real)`);
|
|
38
|
-
|
|
39
|
-
let confirmed = false;
|
|
40
|
-
while (!confirmed) {
|
|
41
|
-
const testPath = await askQuestion(`📝 Enter your test vault path: `, rl);
|
|
42
|
-
if (!testPath) {
|
|
43
|
-
console.log('❌ No test vault path provided, exiting...');
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const realPath = await askQuestion(`📝 Enter your real vault path: `, rl);
|
|
48
|
-
if (!realPath) {
|
|
49
|
-
console.log('❌ No real vault path provided, exiting...');
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
34
|
|
|
53
|
-
// Show confirmation
|
|
54
|
-
console.log(`\n📋 Vault paths entered:`);
|
|
55
|
-
console.log(` TEST_VAULT: ${testPath}`);
|
|
56
|
-
console.log(` REAL_VAULT: ${realPath}`);
|
|
57
|
-
|
|
58
|
-
const confirm = await askQuestion(`✅ Are these paths correct? (y/n): `, rl);
|
|
59
|
-
if (confirm.toLowerCase() === 'y' || confirm.toLowerCase() === 'yes') {
|
|
60
|
-
await updateEnvFile("TEST_VAULT", testPath);
|
|
61
|
-
await updateEnvFile("REAL_VAULT", realPath);
|
|
62
|
-
confirmed = true;
|
|
63
|
-
} else {
|
|
64
|
-
console.log(`🔄 Let's try again...\n`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
35
|
|
|
69
36
|
async function updateEnvFile(envKey: string, vaultPath: string): Promise<void> {
|
|
70
37
|
const envPath = path.join(pluginDir, '.env');
|
|
@@ -93,7 +60,23 @@ async function updateEnvFile(envKey: string, vaultPath: string): Promise<void> {
|
|
|
93
60
|
console.log(`✅ Updated ${envKey} in .env file`);
|
|
94
61
|
}
|
|
95
62
|
|
|
63
|
+
function validateVaultPath(vaultPath: string): boolean {
|
|
64
|
+
// Check if the path contains .obsidian directory
|
|
65
|
+
const obsidianPath = path.join(vaultPath, ".obsidian");
|
|
66
|
+
const pluginsPath = path.join(vaultPath, ".obsidian", "plugins");
|
|
67
|
+
|
|
68
|
+
return fs.existsSync(obsidianPath) && fs.existsSync(pluginsPath);
|
|
69
|
+
}
|
|
70
|
+
|
|
96
71
|
function getVaultPath(vaultPath: string): string {
|
|
72
|
+
// Validate that this is a proper vault path
|
|
73
|
+
if (!validateVaultPath(vaultPath)) {
|
|
74
|
+
console.error(`❌ Invalid vault path: ${vaultPath}`);
|
|
75
|
+
console.error(` The path must contain a .obsidian/plugins directory`);
|
|
76
|
+
console.error(` Please enter a valid Obsidian vault path`);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
|
|
97
80
|
// Check if the path already contains the plugins directory path
|
|
98
81
|
const pluginsPath = path.join(".obsidian", "plugins");
|
|
99
82
|
if (vaultPath.includes(pluginsPath)) {
|
|
@@ -160,69 +143,28 @@ async function getBuildPath(isProd: boolean): Promise<string> {
|
|
|
160
143
|
const envKey = useRealVault ? "REAL_VAULT" : "TEST_VAULT";
|
|
161
144
|
const vaultPath = process.env[envKey]?.trim();
|
|
162
145
|
|
|
163
|
-
//
|
|
146
|
+
// If empty or undefined, we're already in the plugin folder
|
|
164
147
|
if (!vaultPath) {
|
|
165
148
|
// Check if we're in Obsidian plugins folder
|
|
166
149
|
const currentPath = process.cwd();
|
|
167
150
|
const isInObsidianPlugins = currentPath.includes('.obsidian/plugins') ||
|
|
168
151
|
currentPath.includes('.obsidian\\plugins');
|
|
169
152
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
// After updating both, get the REAL_VAULT path directly
|
|
181
|
-
const updatedRealVault = process.env.REAL_VAULT?.trim();
|
|
182
|
-
if (updatedRealVault) {
|
|
183
|
-
return getVaultPath(updatedRealVault);
|
|
184
|
-
}
|
|
185
|
-
} else {
|
|
186
|
-
const newPath = await promptForVaultPath(envKey);
|
|
187
|
-
await updateEnvFile(envKey, newPath);
|
|
188
|
-
config();
|
|
189
|
-
return getVaultPath(newPath);
|
|
190
|
-
}
|
|
191
|
-
} else {
|
|
192
|
-
// In obsidian/plugins: ask only for REAL_VAULT
|
|
193
|
-
const newPath = await promptForVaultPath(envKey);
|
|
194
|
-
await updateEnvFile(envKey, newPath);
|
|
195
|
-
return getVaultPath(newPath);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// YARN DEV/START logic
|
|
200
|
-
if (envKey === "TEST_VAULT") {
|
|
201
|
-
if (!isInObsidianPlugins) {
|
|
202
|
-
// External development: ask for both if missing
|
|
203
|
-
if (!testVault || !realVault) {
|
|
204
|
-
await promptForBothVaults();
|
|
205
|
-
config();
|
|
206
|
-
// After updating both, get the TEST_VAULT path directly
|
|
207
|
-
const updatedTestVault = process.env.TEST_VAULT?.trim();
|
|
208
|
-
if (updatedTestVault) {
|
|
209
|
-
return getVaultPath(updatedTestVault);
|
|
210
|
-
}
|
|
211
|
-
} else {
|
|
212
|
-
const newPath = await promptForVaultPath(envKey);
|
|
213
|
-
await updateEnvFile(envKey, newPath);
|
|
214
|
-
return getVaultPath(newPath);
|
|
215
|
-
}
|
|
216
|
-
} else {
|
|
217
|
-
// In obsidian/plugins: allow in-place development
|
|
218
|
-
console.log(`ℹ️ Building in Obsidian plugins folder (in-place development)`);
|
|
219
|
-
return pluginDir;
|
|
220
|
-
}
|
|
153
|
+
if (isInObsidianPlugins) {
|
|
154
|
+
// In obsidian/plugins: allow in-place development
|
|
155
|
+
console.log(`ℹ️ Building in Obsidian plugins folder (in-place development)`);
|
|
156
|
+
return pluginDir;
|
|
157
|
+
} else {
|
|
158
|
+
// External development: prompt for missing vault path
|
|
159
|
+
const newPath = await promptForVaultPath(envKey);
|
|
160
|
+
await updateEnvFile(envKey, newPath);
|
|
161
|
+
config();
|
|
162
|
+
return getVaultPath(newPath);
|
|
221
163
|
}
|
|
222
164
|
}
|
|
223
165
|
|
|
224
166
|
// If we reach here, use the vault path directly
|
|
225
|
-
return
|
|
167
|
+
return getVaultPath(vaultPath);
|
|
226
168
|
}
|
|
227
169
|
|
|
228
170
|
async function createBuildContext(buildPath: string, isProd: boolean, entryPoints: string[]): Promise<esbuild.BuildContext> {
|
|
@@ -266,7 +208,7 @@ async function createBuildContext(buildPath: string, isProd: boolean, entryPoint
|
|
|
266
208
|
build.onEnd(async () => {
|
|
267
209
|
// if real or build
|
|
268
210
|
if (isProd) {
|
|
269
|
-
if (process.argv.includes("-r")) {
|
|
211
|
+
if (process.argv.includes("-r") || process.argv.includes("real")) {
|
|
270
212
|
await copyFilesToTargetDir(buildPath);
|
|
271
213
|
console.log(`Successfully installed in ${buildPath}`);
|
|
272
214
|
} else {
|
package/scripts/help.ts
CHANGED
|
@@ -8,59 +8,71 @@ Injection system for autonomous Obsidian plugins
|
|
|
8
8
|
|
|
9
9
|
📋 PLUGIN CONFIG COMMANDS
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
yarn
|
|
11
|
+
INSTALLATION & SETUP:
|
|
12
|
+
yarn i # Install dependencies
|
|
13
13
|
yarn update-exports, ue # Update package.json exports
|
|
14
|
+
|
|
15
|
+
GIT & VERSION MANAGEMENT:
|
|
16
|
+
yarn acp # Add, commit, push (with Git sync)
|
|
17
|
+
yarn bacp # Build + add, commit, push
|
|
18
|
+
yarn v, update-version # Update version (package.json + versions.json)
|
|
19
|
+
|
|
20
|
+
BUILD & TESTING:
|
|
14
21
|
yarn build # TypeScript check (no build needed)
|
|
22
|
+
yarn dev # Start development mode (watch)
|
|
23
|
+
yarn real # Build for production to real vault
|
|
15
24
|
yarn lint, lint:fix # ESLint verification/correction
|
|
16
25
|
|
|
17
|
-
INJECTION:
|
|
26
|
+
INJECTION (Development phase):
|
|
18
27
|
yarn inject-prompt <path> # Interactive injection (recommended)
|
|
19
28
|
yarn inject-path <path> --yes # Direct injection with auto-confirm
|
|
20
|
-
yarn check-plugin
|
|
21
|
-
|
|
22
|
-
GIT & VERSION:
|
|
23
|
-
yarn acp # Add, commit, push (with Git sync)
|
|
24
|
-
yarn bacp # Build + add, commit, push
|
|
25
|
-
yarn v, update-version # Update version (package.json + versions.json)
|
|
29
|
+
yarn inject, check-plugin # Injection shortcuts
|
|
26
30
|
|
|
27
31
|
NPM PUBLISHING:
|
|
28
32
|
yarn npm-publish # Complete NPM workflow (exports + bin + publish)
|
|
29
33
|
yarn build-npm # Alias for npm-publish
|
|
30
34
|
|
|
31
35
|
HELP:
|
|
32
|
-
yarn
|
|
36
|
+
yarn help, h # This help
|
|
33
37
|
|
|
34
38
|
═══════════════════════════════════════════════════════════════════
|
|
35
39
|
|
|
36
|
-
🔧
|
|
40
|
+
🔧 DEVELOPMENT WORKFLOWS
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
Plugin Config Development:
|
|
43
|
+
1. yarn i # Install dependencies
|
|
44
|
+
2. yarn update-exports # Update exports
|
|
45
|
+
3. yarn dev # Test as plugin (optional)
|
|
46
|
+
4. yarn lint:fix # Fix code issues
|
|
47
|
+
5. yarn v # Update version + commit + push
|
|
48
|
+
6. yarn npm-publish # Publish to NPM
|
|
43
49
|
|
|
44
|
-
Usage:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
Injection Usage (Development phase):
|
|
51
|
+
Recommended structure:
|
|
52
|
+
my-plugins/
|
|
53
|
+
├── obsidian-plugin-config/ # This repo
|
|
54
|
+
├── my-plugin-1/
|
|
55
|
+
└── my-plugin-2/
|
|
56
|
+
|
|
57
|
+
Usage:
|
|
58
|
+
yarn inject-prompt ../my-plugin # Interactive (recommended)
|
|
59
|
+
yarn inject-path ../my-plugin # Direct injection
|
|
60
|
+
yarn check-plugin ../my-plugin # Verification only
|
|
48
61
|
|
|
49
62
|
═══════════════════════════════════════════════════════════════════
|
|
50
63
|
|
|
51
64
|
🚀 COMPLETE WORKFLOWS
|
|
52
65
|
|
|
53
|
-
DEVELOPMENT WORKFLOW
|
|
54
|
-
1.
|
|
55
|
-
2.
|
|
56
|
-
3. yarn
|
|
57
|
-
4. yarn
|
|
58
|
-
5. yarn
|
|
66
|
+
STANDARD DEVELOPMENT WORKFLOW:
|
|
67
|
+
1. yarn i # Install dependencies
|
|
68
|
+
2. Make changes to obsidian-plugin-config
|
|
69
|
+
3. yarn update-exports # Update exports if needed
|
|
70
|
+
4. yarn lint:fix # Fix any linting issues
|
|
71
|
+
5. yarn v # Update version + commit + push GitHub
|
|
72
|
+
6. yarn npm-publish # Complete NPM workflow
|
|
59
73
|
|
|
60
74
|
AUTOMATED WORKFLOW (One command):
|
|
61
75
|
yarn npm-publish # Does EVERYTHING automatically:
|
|
62
|
-
# → Update version (patch)
|
|
63
|
-
# → Commit and push to GitHub
|
|
64
76
|
# → Update exports
|
|
65
77
|
# → Generate bin/obsidian-inject.js
|
|
66
78
|
# → Verify package
|
|
@@ -70,6 +82,11 @@ AFTER NPM PUBLISH:
|
|
|
70
82
|
npm install -g obsidian-plugin-config # Update global package
|
|
71
83
|
Test injection: cd any-plugin && obsidian-inject
|
|
72
84
|
|
|
85
|
+
TESTING AS PLUGIN (Optional):
|
|
86
|
+
1. Configure .env with TEST_VAULT and REAL_VAULT paths
|
|
87
|
+
2. yarn dev # Watch mode for development
|
|
88
|
+
3. yarn real # Install to real vault
|
|
89
|
+
|
|
73
90
|
═══════════════════════════════════════════════════════════════════
|
|
74
91
|
|
|
75
92
|
`);
|
package/scripts/utils.ts
CHANGED
|
@@ -68,12 +68,14 @@ export const isValidPath = async (pathToCheck: string): Promise<boolean> => {
|
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
export async function copyFilesToTargetDir(buildPath: string): Promise<void> {
|
|
71
|
+
const pluginDir = process.cwd();
|
|
72
|
+
const manifestSrc = path.join(pluginDir, "manifest.json");
|
|
71
73
|
const manifestDest = path.join(buildPath, "manifest.json");
|
|
72
74
|
const cssDest = path.join(buildPath, "styles.css");
|
|
73
75
|
const folderToRemove = path.join(buildPath, "_.._");
|
|
74
76
|
|
|
75
77
|
try {
|
|
76
|
-
await mkdir(buildPath);
|
|
78
|
+
await mkdir(buildPath, { recursive: true });
|
|
77
79
|
} catch (error: any) {
|
|
78
80
|
if (error.code !== "EEXIST") {
|
|
79
81
|
console.error(`Error creating directory: ${error.message}`);
|
|
@@ -82,20 +84,23 @@ export async function copyFilesToTargetDir(buildPath: string): Promise<void> {
|
|
|
82
84
|
|
|
83
85
|
// Copy manifest
|
|
84
86
|
try {
|
|
85
|
-
await copyFile(
|
|
87
|
+
await copyFile(manifestSrc, manifestDest);
|
|
86
88
|
} catch (error: any) {
|
|
87
89
|
console.error(`Error copying manifest: ${error.message}`);
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
// Copy CSS
|
|
91
93
|
try {
|
|
94
|
+
const srcStylesPath = path.join(pluginDir, "src/styles.css");
|
|
95
|
+
const rootStylesPath = path.join(pluginDir, "styles.css");
|
|
96
|
+
|
|
92
97
|
// First check if CSS exists in src/styles.css
|
|
93
|
-
if (await isValidPath(
|
|
94
|
-
await copyFile(
|
|
98
|
+
if (await isValidPath(srcStylesPath)) {
|
|
99
|
+
await copyFile(srcStylesPath, cssDest);
|
|
95
100
|
}
|
|
96
101
|
// Otherwise, check if it exists in the root
|
|
97
|
-
else if (await isValidPath(
|
|
98
|
-
await copyFile(
|
|
102
|
+
else if (await isValidPath(rootStylesPath)) {
|
|
103
|
+
await copyFile(rootStylesPath, cssDest);
|
|
99
104
|
if (await isValidPath(folderToRemove)) {
|
|
100
105
|
await rm(folderToRemove, { recursive: true });
|
|
101
106
|
}
|
package/src/main.ts
CHANGED
|
@@ -16,22 +16,22 @@ const DEFAULT_SETTINGS: MyPluginSettings = {
|
|
|
16
16
|
mySetting: "default"
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export default class
|
|
19
|
+
export default class ObsidianPluginConfigPlugin extends Plugin {
|
|
20
20
|
settings: MyPluginSettings;
|
|
21
21
|
|
|
22
22
|
async onload(): Promise<void> {
|
|
23
|
-
console.log("
|
|
23
|
+
console.log("Loading obsidian-plugin-config plugin for testing NPM exports");
|
|
24
24
|
await this.loadSettings();
|
|
25
25
|
|
|
26
26
|
this.addCommand({
|
|
27
27
|
id: 'show-confirmation-modal',
|
|
28
|
-
name: '
|
|
28
|
+
name: 'Test Confirmation Modal (Local)',
|
|
29
29
|
callback: () => this.showConfirmationModal()
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
this.addCommand({
|
|
33
33
|
id: 'show-centralized-modal',
|
|
34
|
-
name: '
|
|
34
|
+
name: 'Test Confirmation Modal (Centralized)',
|
|
35
35
|
callback: () => this.showCentralizedModal()
|
|
36
36
|
});
|
|
37
37
|
|
|
@@ -45,7 +45,7 @@ export default class MyPlugin extends Plugin {
|
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
this.addSettingTab(new
|
|
48
|
+
this.addSettingTab(new PluginConfigSettingTab(this.app, this));
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
private showConfirmationModal(): void {
|
|
@@ -89,10 +89,10 @@ export default class MyPlugin extends Plugin {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
class
|
|
93
|
-
plugin:
|
|
92
|
+
class PluginConfigSettingTab extends PluginSettingTab {
|
|
93
|
+
plugin: ObsidianPluginConfigPlugin;
|
|
94
94
|
|
|
95
|
-
constructor(app: App, plugin:
|
|
95
|
+
constructor(app: App, plugin: ObsidianPluginConfigPlugin) {
|
|
96
96
|
super(app, plugin);
|
|
97
97
|
this.plugin = plugin;
|
|
98
98
|
}
|
|
@@ -100,7 +100,22 @@ class SampleSettingTab extends PluginSettingTab {
|
|
|
100
100
|
display(): void {
|
|
101
101
|
const { containerEl } = this;
|
|
102
102
|
containerEl.empty();
|
|
103
|
-
|
|
103
|
+
|
|
104
|
+
containerEl.createEl('h2', { text: 'Obsidian Plugin Config Settings' });
|
|
105
|
+
containerEl.createEl('p', {
|
|
106
|
+
text: 'This plugin is used for testing NPM exports and development of the obsidian-plugin-config system.'
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
new Setting(containerEl)
|
|
110
|
+
.setName('Test Setting')
|
|
111
|
+
.setDesc('A test setting for development purposes')
|
|
112
|
+
.addText(text => text
|
|
113
|
+
.setPlaceholder('Enter test value')
|
|
114
|
+
.setValue(this.plugin.settings.mySetting)
|
|
115
|
+
.onChange(async (value) => {
|
|
116
|
+
this.plugin.settings.mySetting = value;
|
|
117
|
+
await this.plugin.saveSettings();
|
|
118
|
+
}));
|
|
104
119
|
}
|
|
105
120
|
}
|
|
106
121
|
|
|
@@ -31,40 +31,7 @@ async function promptForVaultPath(envKey: string): Promise<string> {
|
|
|
31
31
|
return path;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
async function promptForBothVaults(): Promise<void> {
|
|
35
|
-
console.log(`❓ Both vault paths are required for external development`);
|
|
36
|
-
console.log(` TEST_VAULT: for development and testing (yarn dev)`);
|
|
37
|
-
console.log(` REAL_VAULT: for final plugin installation (yarn real)`);
|
|
38
|
-
|
|
39
|
-
let confirmed = false;
|
|
40
|
-
while (!confirmed) {
|
|
41
|
-
const testPath = await askQuestion(`📝 Enter your test vault path: `, rl);
|
|
42
|
-
if (!testPath) {
|
|
43
|
-
console.log('❌ No test vault path provided, exiting...');
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const realPath = await askQuestion(`📝 Enter your real vault path: `, rl);
|
|
48
|
-
if (!realPath) {
|
|
49
|
-
console.log('❌ No real vault path provided, exiting...');
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Show confirmation
|
|
54
|
-
console.log(`\n📋 Vault paths entered:`);
|
|
55
|
-
console.log(` TEST_VAULT: ${testPath}`);
|
|
56
|
-
console.log(` REAL_VAULT: ${realPath}`);
|
|
57
34
|
|
|
58
|
-
const confirm = await askQuestion(`✅ Are these paths correct? (y/n): `, rl);
|
|
59
|
-
if (confirm.toLowerCase() === 'y' || confirm.toLowerCase() === 'yes') {
|
|
60
|
-
await updateEnvFile("TEST_VAULT", testPath);
|
|
61
|
-
await updateEnvFile("REAL_VAULT", realPath);
|
|
62
|
-
confirmed = true;
|
|
63
|
-
} else {
|
|
64
|
-
console.log(`🔄 Let's try again...\n`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
35
|
|
|
69
36
|
async function updateEnvFile(envKey: string, vaultPath: string): Promise<void> {
|
|
70
37
|
const envPath = path.join(pluginDir, '.env');
|
|
@@ -176,69 +143,28 @@ async function getBuildPath(isProd: boolean): Promise<string> {
|
|
|
176
143
|
const envKey = useRealVault ? "REAL_VAULT" : "TEST_VAULT";
|
|
177
144
|
const vaultPath = process.env[envKey]?.trim();
|
|
178
145
|
|
|
179
|
-
//
|
|
146
|
+
// If empty or undefined, we're already in the plugin folder
|
|
180
147
|
if (!vaultPath) {
|
|
181
148
|
// Check if we're in Obsidian plugins folder
|
|
182
149
|
const currentPath = process.cwd();
|
|
183
150
|
const isInObsidianPlugins = currentPath.includes('.obsidian/plugins') ||
|
|
184
151
|
currentPath.includes('.obsidian\\plugins');
|
|
185
152
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
// After updating both, get the REAL_VAULT path directly
|
|
197
|
-
const updatedRealVault = process.env.REAL_VAULT?.trim();
|
|
198
|
-
if (updatedRealVault) {
|
|
199
|
-
return getVaultPath(updatedRealVault);
|
|
200
|
-
}
|
|
201
|
-
} else {
|
|
202
|
-
const newPath = await promptForVaultPath(envKey);
|
|
203
|
-
await updateEnvFile(envKey, newPath);
|
|
204
|
-
config();
|
|
205
|
-
return getVaultPath(newPath);
|
|
206
|
-
}
|
|
207
|
-
} else {
|
|
208
|
-
// In obsidian/plugins: ask only for REAL_VAULT
|
|
209
|
-
const newPath = await promptForVaultPath(envKey);
|
|
210
|
-
await updateEnvFile(envKey, newPath);
|
|
211
|
-
return getVaultPath(newPath);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// YARN DEV/START logic
|
|
216
|
-
if (envKey === "TEST_VAULT") {
|
|
217
|
-
if (!isInObsidianPlugins) {
|
|
218
|
-
// External development: ask for both if missing
|
|
219
|
-
if (!testVault || !realVault) {
|
|
220
|
-
await promptForBothVaults();
|
|
221
|
-
config();
|
|
222
|
-
// After updating both, get the TEST_VAULT path directly
|
|
223
|
-
const updatedTestVault = process.env.TEST_VAULT?.trim();
|
|
224
|
-
if (updatedTestVault) {
|
|
225
|
-
return getVaultPath(updatedTestVault);
|
|
226
|
-
}
|
|
227
|
-
} else {
|
|
228
|
-
const newPath = await promptForVaultPath(envKey);
|
|
229
|
-
await updateEnvFile(envKey, newPath);
|
|
230
|
-
return getVaultPath(newPath);
|
|
231
|
-
}
|
|
232
|
-
} else {
|
|
233
|
-
// In obsidian/plugins: allow in-place development
|
|
234
|
-
console.log(`ℹ️ Building in Obsidian plugins folder (in-place development)`);
|
|
235
|
-
return pluginDir;
|
|
236
|
-
}
|
|
153
|
+
if (isInObsidianPlugins) {
|
|
154
|
+
// In obsidian/plugins: allow in-place development
|
|
155
|
+
console.log(`ℹ️ Building in Obsidian plugins folder (in-place development)`);
|
|
156
|
+
return pluginDir;
|
|
157
|
+
} else {
|
|
158
|
+
// External development: prompt for missing vault path
|
|
159
|
+
const newPath = await promptForVaultPath(envKey);
|
|
160
|
+
await updateEnvFile(envKey, newPath);
|
|
161
|
+
config();
|
|
162
|
+
return getVaultPath(newPath);
|
|
237
163
|
}
|
|
238
164
|
}
|
|
239
165
|
|
|
240
166
|
// If we reach here, use the vault path directly
|
|
241
|
-
return
|
|
167
|
+
return getVaultPath(vaultPath);
|
|
242
168
|
}
|
|
243
169
|
|
|
244
170
|
async function createBuildContext(buildPath: string, isProd: boolean, entryPoints: string[]): Promise<esbuild.BuildContext> {
|
|
@@ -282,7 +208,7 @@ async function createBuildContext(buildPath: string, isProd: boolean, entryPoint
|
|
|
282
208
|
build.onEnd(async () => {
|
|
283
209
|
// if real or build
|
|
284
210
|
if (isProd) {
|
|
285
|
-
if (process.argv.includes("-r")) {
|
|
211
|
+
if (process.argv.includes("-r") || process.argv.includes("real")) {
|
|
286
212
|
await copyFilesToTargetDir(buildPath);
|
|
287
213
|
console.log(`Successfully installed in ${buildPath}`);
|
|
288
214
|
} else {
|
|
@@ -68,12 +68,14 @@ export const isValidPath = async (pathToCheck: string): Promise<boolean> => {
|
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
export async function copyFilesToTargetDir(buildPath: string): Promise<void> {
|
|
71
|
+
const pluginDir = process.cwd();
|
|
72
|
+
const manifestSrc = path.join(pluginDir, "manifest.json");
|
|
71
73
|
const manifestDest = path.join(buildPath, "manifest.json");
|
|
72
74
|
const cssDest = path.join(buildPath, "styles.css");
|
|
73
75
|
const folderToRemove = path.join(buildPath, "_.._");
|
|
74
76
|
|
|
75
77
|
try {
|
|
76
|
-
await mkdir(buildPath);
|
|
78
|
+
await mkdir(buildPath, { recursive: true });
|
|
77
79
|
} catch (error: any) {
|
|
78
80
|
if (error.code !== "EEXIST") {
|
|
79
81
|
console.error(`Error creating directory: ${error.message}`);
|
|
@@ -82,20 +84,23 @@ export async function copyFilesToTargetDir(buildPath: string): Promise<void> {
|
|
|
82
84
|
|
|
83
85
|
// Copy manifest
|
|
84
86
|
try {
|
|
85
|
-
await copyFile(
|
|
87
|
+
await copyFile(manifestSrc, manifestDest);
|
|
86
88
|
} catch (error: any) {
|
|
87
89
|
console.error(`Error copying manifest: ${error.message}`);
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
// Copy CSS
|
|
91
93
|
try {
|
|
94
|
+
const srcStylesPath = path.join(pluginDir, "src/styles.css");
|
|
95
|
+
const rootStylesPath = path.join(pluginDir, "styles.css");
|
|
96
|
+
|
|
92
97
|
// First check if CSS exists in src/styles.css
|
|
93
|
-
if (await isValidPath(
|
|
94
|
-
await copyFile(
|
|
98
|
+
if (await isValidPath(srcStylesPath)) {
|
|
99
|
+
await copyFile(srcStylesPath, cssDest);
|
|
95
100
|
}
|
|
96
101
|
// Otherwise, check if it exists in the root
|
|
97
|
-
else if (await isValidPath(
|
|
98
|
-
await copyFile(
|
|
102
|
+
else if (await isValidPath(rootStylesPath)) {
|
|
103
|
+
await copyFile(rootStylesPath, cssDest);
|
|
99
104
|
if (await isValidPath(folderToRemove)) {
|
|
100
105
|
await rm(folderToRemove, { recursive: true });
|
|
101
106
|
}
|