obsidian-plugin-config 1.1.1 → 1.1.3
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 +61 -3
- package/package.json +1 -1
- package/scripts/inject-path.ts +72 -6
package/bin/obsidian-inject.js
CHANGED
|
@@ -78,16 +78,74 @@ function main() {
|
|
|
78
78
|
console.log(`📦 Depuis: ${packageRoot}\n`);
|
|
79
79
|
|
|
80
80
|
try {
|
|
81
|
+
// Check if target directory has package.json
|
|
82
|
+
const targetPackageJson = join(targetPath, 'package.json');
|
|
83
|
+
if (!fs.existsSync(targetPackageJson)) {
|
|
84
|
+
console.error(`❌ Erreur: package.json non trouvé dans ${targetPath}`);
|
|
85
|
+
console.error(` Assurez-vous que c'est un projet Node.js valide.`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
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
|
+
|
|
114
|
+
// Check if tsx is available locally in target
|
|
115
|
+
let tsxCommand = 'npx tsx';
|
|
116
|
+
try {
|
|
117
|
+
execSync('npx tsx --version', {
|
|
118
|
+
cwd: targetPath,
|
|
119
|
+
stdio: 'pipe'
|
|
120
|
+
});
|
|
121
|
+
console.log(`✅ tsx disponible localement`);
|
|
122
|
+
} catch {
|
|
123
|
+
console.log(`⚠️ tsx non trouvé, installation en cours...`);
|
|
124
|
+
|
|
125
|
+
// Install tsx locally in target directory
|
|
126
|
+
try {
|
|
127
|
+
execSync('yarn add -D tsx', {
|
|
128
|
+
cwd: targetPath,
|
|
129
|
+
stdio: 'inherit'
|
|
130
|
+
});
|
|
131
|
+
console.log(`✅ tsx installé avec succès`);
|
|
132
|
+
} catch (installError) {
|
|
133
|
+
console.error(`❌ Échec de l'installation de tsx:`, installError.message);
|
|
134
|
+
console.error(` Essayez d'installer tsx manuellement: cd "${targetPath}" && yarn add -D tsx`);
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
81
139
|
// Execute the injection script with tsx
|
|
82
140
|
const command = `npx tsx "${injectScriptPath}" "${targetPath}"`;
|
|
83
141
|
|
|
84
142
|
execSync(command, {
|
|
85
143
|
stdio: 'inherit',
|
|
86
|
-
cwd:
|
|
144
|
+
cwd: targetPath // Use target directory to ensure tsx is available
|
|
87
145
|
});
|
|
88
|
-
|
|
146
|
+
|
|
89
147
|
console.log(`\n✅ Injection terminée avec succès !`);
|
|
90
|
-
|
|
148
|
+
|
|
91
149
|
} catch (error) {
|
|
92
150
|
console.error(`\n❌ Erreur lors de l'injection:`, error.message);
|
|
93
151
|
process.exit(1);
|
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
|