obsidian-plugin-config 1.1.2 → 1.1.4
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
CHANGED
|
@@ -86,6 +86,31 @@ function main() {
|
|
|
86
86
|
process.exit(1);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
// Clean NPM artifacts if package-lock.json exists
|
|
90
|
+
const packageLockPath = join(targetPath, 'package-lock.json');
|
|
91
|
+
if (fs.existsSync(packageLockPath)) {
|
|
92
|
+
console.log(`🧹 Installation NPM détectée, nettoyage...`);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
// Remove package-lock.json
|
|
96
|
+
fs.unlinkSync(packageLockPath);
|
|
97
|
+
console.log(` 🗑️ package-lock.json supprimé`);
|
|
98
|
+
|
|
99
|
+
// Remove node_modules if it exists
|
|
100
|
+
const nodeModulesPath = join(targetPath, 'node_modules');
|
|
101
|
+
if (fs.existsSync(nodeModulesPath)) {
|
|
102
|
+
fs.rmSync(nodeModulesPath, { recursive: true, force: true });
|
|
103
|
+
console.log(` 🗑️ node_modules supprimé (sera réinstallé avec Yarn)`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
console.log(` ✅ Artefacts NPM nettoyés pour éviter les conflits Yarn`);
|
|
107
|
+
|
|
108
|
+
} catch (cleanError) {
|
|
109
|
+
console.error(` ❌ Échec du nettoyage:`, cleanError.message);
|
|
110
|
+
console.log(` 💡 Supprimez manuellement package-lock.json et node_modules`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
89
114
|
// Check if tsx is available locally in target
|
|
90
115
|
let tsxCommand = 'npx tsx';
|
|
91
116
|
try {
|
package/package.json
CHANGED
package/scripts/inject-path.ts
CHANGED
|
@@ -650,6 +650,69 @@ async function ensureTsxAvailable(targetPath: string): Promise<void> {
|
|
|
650
650
|
}
|
|
651
651
|
}
|
|
652
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
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Clean NPM artifacts if package-lock.json is found (evidence of NPM usage)
|
|
687
|
+
*/
|
|
688
|
+
async function cleanNpmArtifactsIfNeeded(targetPath: string): Promise<void> {
|
|
689
|
+
const packageLockPath = path.join(targetPath, "package-lock.json");
|
|
690
|
+
|
|
691
|
+
// Only clean if package-lock.json exists (proof of NPM installation)
|
|
692
|
+
if (fs.existsSync(packageLockPath)) {
|
|
693
|
+
console.log(`\n🧹 NPM installation detected, cleaning artifacts...`);
|
|
694
|
+
|
|
695
|
+
try {
|
|
696
|
+
// Remove package-lock.json
|
|
697
|
+
fs.unlinkSync(packageLockPath);
|
|
698
|
+
console.log(` 🗑️ Removed package-lock.json`);
|
|
699
|
+
|
|
700
|
+
// Remove node_modules if it exists
|
|
701
|
+
const nodeModulesPath = path.join(targetPath, "node_modules");
|
|
702
|
+
if (fs.existsSync(nodeModulesPath)) {
|
|
703
|
+
fs.rmSync(nodeModulesPath, { recursive: true, force: true });
|
|
704
|
+
console.log(` 🗑️ Removed node_modules (will be reinstalled with Yarn)`);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
console.log(` ✅ NPM artifacts cleaned to avoid Yarn conflicts`);
|
|
708
|
+
|
|
709
|
+
} catch (error) {
|
|
710
|
+
console.error(` ❌ Failed to clean NPM artifacts: ${error}`);
|
|
711
|
+
console.log(` 💡 You may need to manually remove package-lock.json and node_modules`);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
653
716
|
/**
|
|
654
717
|
* Check if tsx is installed locally and install it if needed
|
|
655
718
|
*/
|
|
@@ -711,24 +774,27 @@ export async function performInjection(targetPath: string): Promise<void> {
|
|
|
711
774
|
console.log(`\n🚀 Starting injection process...`);
|
|
712
775
|
|
|
713
776
|
try {
|
|
714
|
-
// Step 1:
|
|
777
|
+
// Step 1: Clean NPM artifacts if needed
|
|
778
|
+
await cleanNpmArtifactsIfNeeded(targetPath);
|
|
779
|
+
|
|
780
|
+
// Step 2: Ensure tsx is installed
|
|
715
781
|
await ensureTsxInstalled(targetPath);
|
|
716
782
|
|
|
717
|
-
// Step
|
|
783
|
+
// Step 3: Inject scripts
|
|
718
784
|
await injectScripts(targetPath);
|
|
719
785
|
|
|
720
|
-
// Step
|
|
786
|
+
// Step 4: Update package.json
|
|
721
787
|
console.log(`\n📦 Updating package.json...`);
|
|
722
788
|
await updatePackageJson(targetPath);
|
|
723
789
|
|
|
724
|
-
// Step
|
|
790
|
+
// Step 5: Analyze centralized imports (without modifying)
|
|
725
791
|
await analyzeCentralizedImports(targetPath);
|
|
726
792
|
|
|
727
|
-
// Step
|
|
793
|
+
// Step 6: Create required directories
|
|
728
794
|
console.log(`\n📁 Creating required directories...`);
|
|
729
795
|
await createRequiredDirectories(targetPath);
|
|
730
796
|
|
|
731
|
-
// Step
|
|
797
|
+
// Step 7: Install dependencies
|
|
732
798
|
await runYarnInstall(targetPath);
|
|
733
799
|
|
|
734
800
|
// Step 6: Create injection info file
|
|
@@ -93,7 +93,23 @@ async function updateEnvFile(envKey: string, vaultPath: string): Promise<void> {
|
|
|
93
93
|
console.log(`✅ Updated ${envKey} in .env file`);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
function validateVaultPath(vaultPath: string): boolean {
|
|
97
|
+
// Check if the path contains .obsidian directory
|
|
98
|
+
const obsidianPath = path.join(vaultPath, ".obsidian");
|
|
99
|
+
const pluginsPath = path.join(vaultPath, ".obsidian", "plugins");
|
|
100
|
+
|
|
101
|
+
return fs.existsSync(obsidianPath) && fs.existsSync(pluginsPath);
|
|
102
|
+
}
|
|
103
|
+
|
|
96
104
|
function getVaultPath(vaultPath: string): string {
|
|
105
|
+
// Validate that this is a proper vault path
|
|
106
|
+
if (!validateVaultPath(vaultPath)) {
|
|
107
|
+
console.error(`❌ Invalid vault path: ${vaultPath}`);
|
|
108
|
+
console.error(` The path must contain a .obsidian/plugins directory`);
|
|
109
|
+
console.error(` Please enter a valid Obsidian vault path`);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
|
|
97
113
|
// Check if the path already contains the plugins directory path
|
|
98
114
|
const pluginsPath = path.join(".obsidian", "plugins");
|
|
99
115
|
if (vaultPath.includes(pluginsPath)) {
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import { readFile, writeFile } from "fs/promises";
|
|
2
2
|
import dedent from "dedent";
|
|
3
|
-
import { inc, valid } from "semver";
|
|
4
3
|
import { askQuestion, createReadlineInterface, gitExec, ensureGitSync } from "./utils.js";
|
|
5
4
|
|
|
5
|
+
// Simple version increment functions to avoid semver compatibility issues
|
|
6
|
+
function incrementVersion(version: string, type: 'patch' | 'minor' | 'major'): string {
|
|
7
|
+
const parts = version.split('.').map(Number);
|
|
8
|
+
if (parts.length !== 3) return '';
|
|
9
|
+
|
|
10
|
+
switch (type) {
|
|
11
|
+
case 'patch':
|
|
12
|
+
parts[2]++;
|
|
13
|
+
break;
|
|
14
|
+
case 'minor':
|
|
15
|
+
parts[1]++;
|
|
16
|
+
parts[2] = 0;
|
|
17
|
+
break;
|
|
18
|
+
case 'major':
|
|
19
|
+
parts[0]++;
|
|
20
|
+
parts[1] = 0;
|
|
21
|
+
parts[2] = 0;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return parts.join('.');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isValidVersion(version: string): boolean {
|
|
29
|
+
const versionRegex = /^\d+\.\d+\.\d+$/;
|
|
30
|
+
return versionRegex.test(version);
|
|
31
|
+
}
|
|
32
|
+
|
|
6
33
|
const rl = createReadlineInterface();
|
|
7
34
|
|
|
8
35
|
async function getTargetVersion(currentVersion: string): Promise<string> {
|
|
@@ -18,15 +45,16 @@ async function getTargetVersion(currentVersion: string): Promise<string> {
|
|
|
18
45
|
switch (updateType.trim()) {
|
|
19
46
|
case "p":
|
|
20
47
|
case "1":
|
|
21
|
-
return
|
|
48
|
+
return incrementVersion(currentVersion, "patch");
|
|
22
49
|
case "min":
|
|
23
50
|
case "2":
|
|
24
|
-
return
|
|
51
|
+
return incrementVersion(currentVersion, "minor");
|
|
25
52
|
case "maj":
|
|
26
53
|
case "3":
|
|
27
|
-
return
|
|
54
|
+
return incrementVersion(currentVersion, "major");
|
|
28
55
|
default:
|
|
29
|
-
|
|
56
|
+
const trimmed = updateType.trim();
|
|
57
|
+
return isValidVersion(trimmed) ? trimmed : "";
|
|
30
58
|
}
|
|
31
59
|
}
|
|
32
60
|
|