obsidian-plugin-config 1.1.4 → 1.1.5
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/package.json +1 -1
- package/scripts/inject-path.ts +12 -113
- package/scripts/inject-prompt.ts +4 -4
- package/src/main_test.ts +0 -0
- package/src/utils/SettingsHelper.ts +1 -1
package/package.json
CHANGED
package/scripts/inject-path.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { execSync } from "child_process";
|
|
6
|
-
import dotenv from "dotenv";
|
|
7
6
|
import {
|
|
8
7
|
askConfirmation,
|
|
9
8
|
createReadlineInterface,
|
|
@@ -11,9 +10,6 @@ import {
|
|
|
11
10
|
gitExec
|
|
12
11
|
} from "./utils.js";
|
|
13
12
|
|
|
14
|
-
// Load environment variables from .env file
|
|
15
|
-
dotenv.config();
|
|
16
|
-
|
|
17
13
|
const rl = createReadlineInterface();
|
|
18
14
|
|
|
19
15
|
interface InjectionPlan {
|
|
@@ -133,7 +129,7 @@ async function ensurePluginConfigClean(): Promise<void> {
|
|
|
133
129
|
const currentBranch = execSync("git rev-parse --abbrev-ref HEAD", { encoding: "utf8" }).trim();
|
|
134
130
|
gitExec(`git push --set-upstream origin ${currentBranch}`);
|
|
135
131
|
console.log(`✅ New branch pushed with upstream set`);
|
|
136
|
-
} catch
|
|
132
|
+
} catch {
|
|
137
133
|
console.log(`⚠️ Changes committed locally but push failed. Continue with injection.`);
|
|
138
134
|
}
|
|
139
135
|
}
|
|
@@ -150,34 +146,13 @@ async function ensurePluginConfigClean(): Promise<void> {
|
|
|
150
146
|
* Find plugin-config root directory
|
|
151
147
|
*/
|
|
152
148
|
function findPluginConfigRoot(): string {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
// Option 1: local - check parent directory
|
|
156
|
-
if (envPath === "local") {
|
|
157
|
-
const parentPath = path.resolve(process.cwd(), "../obsidian-plugin-config");
|
|
158
|
-
if (fs.existsSync(parentPath)) {
|
|
159
|
-
return parentPath;
|
|
160
|
-
}
|
|
161
|
-
throw new Error("obsidian-plugin-config not found in parent directory");
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Option 2: prompt - skip auto-detection
|
|
165
|
-
if (envPath === "prompt") {
|
|
166
|
-
throw new Error("PROMPT_REQUIRED");
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Option 3: specific path
|
|
170
|
-
if (envPath && fs.existsSync(envPath)) {
|
|
171
|
-
return envPath;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Option 4: auto-detect parent, fallback to current
|
|
149
|
+
// Option 1: auto-detect parent directory
|
|
175
150
|
const parentPath = path.resolve(process.cwd(), "../obsidian-plugin-config");
|
|
176
151
|
if (fs.existsSync(parentPath)) {
|
|
177
152
|
return parentPath;
|
|
178
153
|
}
|
|
179
154
|
|
|
180
|
-
// Option
|
|
155
|
+
// Option 2: Check if we're running from NPM package (global installation)
|
|
181
156
|
// Get the directory of this script file
|
|
182
157
|
const scriptDir = path.dirname(new URL(import.meta.url).pathname);
|
|
183
158
|
const npmPackageRoot = path.resolve(scriptDir, "..");
|
|
@@ -214,21 +189,20 @@ function copyFromLocal(filePath: string): string {
|
|
|
214
189
|
}
|
|
215
190
|
|
|
216
191
|
/**
|
|
217
|
-
* Clean old script files (remove
|
|
192
|
+
* Clean old script files (remove existing scripts to ensure clean injection)
|
|
218
193
|
*/
|
|
219
194
|
async function cleanOldScripts(scriptsPath: string): Promise<void> {
|
|
220
195
|
const scriptNames = ["utils", "esbuild.config", "acp", "update-version", "release", "help"];
|
|
196
|
+
const extensions = [".ts", ".mts", ".js", ".mjs"];
|
|
221
197
|
|
|
222
|
-
// Remove
|
|
198
|
+
// Remove all existing script files with any extension
|
|
223
199
|
for (const scriptName of scriptNames) {
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
} else if (await isValidPath(mtsFile)) {
|
|
231
|
-
console.log(`ℹ️ Found old ${scriptName}.mts file (will be replaced by ${scriptName}.ts)`);
|
|
200
|
+
for (const ext of extensions) {
|
|
201
|
+
const scriptFile = path.join(scriptsPath, `${scriptName}${ext}`);
|
|
202
|
+
if (await isValidPath(scriptFile)) {
|
|
203
|
+
fs.unlinkSync(scriptFile);
|
|
204
|
+
console.log(`🗑️ Removed existing ${scriptName}${ext} (will be replaced)`);
|
|
205
|
+
}
|
|
232
206
|
}
|
|
233
207
|
}
|
|
234
208
|
|
|
@@ -605,82 +579,7 @@ function readInjectionInfo(targetPath: string): any | null {
|
|
|
605
579
|
}
|
|
606
580
|
}
|
|
607
581
|
|
|
608
|
-
/**
|
|
609
|
-
* Check if tsx is available and install it if needed
|
|
610
|
-
*/
|
|
611
|
-
async function ensureTsxAvailable(targetPath: string): Promise<void> {
|
|
612
|
-
console.log(`\n🔍 Checking tsx availability...`);
|
|
613
582
|
|
|
614
|
-
try {
|
|
615
|
-
// Check if tsx is available globally
|
|
616
|
-
try {
|
|
617
|
-
execSync('tsx --version', { stdio: 'pipe' });
|
|
618
|
-
console.log(` ✅ tsx is available globally`);
|
|
619
|
-
return;
|
|
620
|
-
} catch {
|
|
621
|
-
// tsx not available globally, continue to check locally
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
// Check if tsx is available locally in target
|
|
625
|
-
try {
|
|
626
|
-
execSync('npx tsx --version', {
|
|
627
|
-
cwd: targetPath,
|
|
628
|
-
stdio: 'pipe'
|
|
629
|
-
});
|
|
630
|
-
console.log(` ✅ tsx is available locally`);
|
|
631
|
-
return;
|
|
632
|
-
} catch {
|
|
633
|
-
// tsx not available locally, need to install
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
console.log(` ⚠️ tsx not found, installing as dev dependency...`);
|
|
637
|
-
|
|
638
|
-
// Install tsx as dev dependency
|
|
639
|
-
execSync('yarn add -D tsx', {
|
|
640
|
-
cwd: targetPath,
|
|
641
|
-
stdio: 'inherit'
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
console.log(` ✅ tsx installed successfully`);
|
|
645
|
-
|
|
646
|
-
} catch (error) {
|
|
647
|
-
console.error(` ❌ Failed to install tsx: ${error}`);
|
|
648
|
-
console.log(` 💡 You may need to install tsx manually: yarn add -D tsx`);
|
|
649
|
-
throw new Error('tsx installation failed');
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
/**
|
|
654
|
-
* Clean NPM artifacts to avoid conflicts with Yarn
|
|
655
|
-
*/
|
|
656
|
-
async function cleanNpmArtifacts(targetPath: string): Promise<void> {
|
|
657
|
-
console.log(`\n🧹 Cleaning NPM artifacts...`);
|
|
658
|
-
|
|
659
|
-
const packageLockPath = path.join(targetPath, "package-lock.json");
|
|
660
|
-
const nodeModulesPath = path.join(targetPath, "node_modules");
|
|
661
|
-
|
|
662
|
-
try {
|
|
663
|
-
// Remove package-lock.json if it exists
|
|
664
|
-
if (fs.existsSync(packageLockPath)) {
|
|
665
|
-
fs.unlinkSync(packageLockPath);
|
|
666
|
-
console.log(` 🗑️ Removed package-lock.json (NPM lock file)`);
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
// Remove node_modules if it exists
|
|
670
|
-
if (fs.existsSync(nodeModulesPath)) {
|
|
671
|
-
fs.rmSync(nodeModulesPath, { recursive: true, force: true });
|
|
672
|
-
console.log(` 🗑️ Removed node_modules (will be reinstalled with Yarn)`);
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
if (!fs.existsSync(packageLockPath) && !fs.existsSync(nodeModulesPath)) {
|
|
676
|
-
console.log(` ✅ No NPM artifacts found`);
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
} catch (error) {
|
|
680
|
-
console.error(` ❌ Failed to clean NPM artifacts: ${error}`);
|
|
681
|
-
console.log(` 💡 You may need to manually remove package-lock.json and node_modules`);
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
583
|
|
|
685
584
|
/**
|
|
686
585
|
* Clean NPM artifacts if package-lock.json is found (evidence of NPM usage)
|
package/scripts/inject-prompt.ts
CHANGED
|
@@ -44,7 +44,7 @@ async function analyzePlugin(pluginPath: string): Promise<InjectionPlan> {
|
|
|
44
44
|
try {
|
|
45
45
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
46
46
|
plan.isObsidianPlugin = !!(manifest.id && manifest.name && manifest.version);
|
|
47
|
-
} catch
|
|
47
|
+
} catch {
|
|
48
48
|
console.warn("Warning: Could not parse manifest.json");
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -57,7 +57,7 @@ async function analyzePlugin(pluginPath: string): Promise<InjectionPlan> {
|
|
|
57
57
|
...Object.keys(packageJson.dependencies || {}),
|
|
58
58
|
...Object.keys(packageJson.devDependencies || {})
|
|
59
59
|
];
|
|
60
|
-
} catch
|
|
60
|
+
} catch {
|
|
61
61
|
console.warn("Warning: Could not parse package.json");
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -125,7 +125,7 @@ async function ensurePluginConfigClean(): Promise<void> {
|
|
|
125
125
|
const currentBranch = execSync("git rev-parse --abbrev-ref HEAD", { encoding: "utf8" }).trim();
|
|
126
126
|
gitExec(`git push --set-upstream origin ${currentBranch}`);
|
|
127
127
|
console.log(`✅ New branch pushed with upstream set`);
|
|
128
|
-
} catch
|
|
128
|
+
} catch {
|
|
129
129
|
console.log(`⚠️ Changes committed locally but push failed. Continue with injection.`);
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -370,7 +370,7 @@ async function createInjectionInfo(targetPath: string): Promise<void> {
|
|
|
370
370
|
try {
|
|
371
371
|
const configPackageJson = JSON.parse(fs.readFileSync(configPackageJsonPath, "utf8"));
|
|
372
372
|
injectorVersion = configPackageJson.version || "unknown";
|
|
373
|
-
} catch
|
|
373
|
+
} catch {
|
|
374
374
|
console.warn("Warning: Could not read injector version");
|
|
375
375
|
}
|
|
376
376
|
|
package/src/main_test.ts
ADDED
|
File without changes
|
|
@@ -167,7 +167,7 @@ export class SettingsHelper {
|
|
|
167
167
|
arrow.style.marginRight = "8px";
|
|
168
168
|
arrow.style.fontSize = "0.8em";
|
|
169
169
|
|
|
170
|
-
const toggle = () => {
|
|
170
|
+
const toggle = () : void => {
|
|
171
171
|
const isCurrentlyOpen = contentEl.style.display !== "none";
|
|
172
172
|
contentEl.style.display = isCurrentlyOpen ? "none" : "block";
|
|
173
173
|
arrow.setText(isCurrentlyOpen ? "▶" : "▼");
|