diff options
| author | ertopogo <erwin.t.pombett@gmail.com> | 2025-11-20 00:37:40 +0100 |
|---|---|---|
| committer | ertopogo <erwin.t.pombett@gmail.com> | 2025-11-20 00:37:40 +0100 |
| commit | 0f1ba5af1684cfc64b3ff5374ef95c70df1caac0 (patch) | |
| tree | 5b428d0333eb55c575e058215fa8fed5a5ca3352 /scripts/sync-from-project.ps1 | |
| parent | 622cb16f89c7a5dddaba5e96a11c0da63abde21a (diff) | |
Amélioration des scripts avec chemin Windows direct vers WSL et ajout du fichier Cursor
Diffstat (limited to 'scripts/sync-from-project.ps1')
| -rw-r--r-- | scripts/sync-from-project.ps1 | 291 |
1 files changed, 154 insertions, 137 deletions
diff --git a/scripts/sync-from-project.ps1 b/scripts/sync-from-project.ps1 index 45ff258..73ba1c5 100644 --- a/scripts/sync-from-project.ps1 +++ b/scripts/sync-from-project.ps1 @@ -1,137 +1,154 @@ -# Script pour restaurer les fichiers de configuration depuis le projet -# Lit path-mapping.json et copie chaque fichier vers son emplacement original - -param( - [string]$MappingFile = "path-mapping.json" -) - -$ErrorActionPreference = "Stop" - -# Vérifier que le fichier de mapping existe -if (-not (Test-Path $MappingFile)) { - Write-Error "Le fichier de mapping '$MappingFile' n'existe pas. Exécutez d'abord sync-to-project.ps1" - exit 1 -} - -# Charger le mapping -try { - $mapping = Get-Content $MappingFile -Raw | ConvertFrom-Json -} catch { - Write-Error "Impossible de charger le fichier de mapping: $_" - exit 1 -} - -$restoredCount = 0 -$skippedCount = 0 -$errorCount = 0 - -# Fonction pour résoudre un chemin Windows -function Resolve-WindowsPath { - param([string]$path) - - # Remplacer les variables d'environnement - $resolved = $path - $resolved = $resolved -replace '%USERPROFILE%', $env:USERPROFILE - $resolved = $resolved -replace '%APPDATA%', $env:APPDATA - $resolved = $resolved -replace '%LOCALAPPDATA%', $env:LOCALAPPDATA - $resolved = $resolved -replace '%HOME%', $env:HOME - - # Remplacer les autres variables d'environnement - $resolved = [System.Environment]::ExpandEnvironmentVariables($resolved) - - return $resolved -} - -# Traiter les fichiers Windows -if ($mapping.windows) { - $mapping.windows.PSObject.Properties | ForEach-Object { - $originalPath = $_.Name - $projectPath = $_.Value - - try { - # Vérifier que le fichier source existe dans le projet - if (-not (Test-Path $projectPath)) { - Write-Warning "Fichier source introuvable dans le projet: $projectPath" - $skippedCount++ - return - } - - # Résoudre le chemin de destination - $destinationPath = Resolve-WindowsPath $originalPath - - # Créer le répertoire parent si nécessaire - $destinationDir = Split-Path $destinationPath -Parent - if ($destinationDir -and -not (Test-Path $destinationDir)) { - New-Item -ItemType Directory -Path $destinationDir -Force | Out-Null - Write-Host "Créé le répertoire: $destinationDir" - } - - # Copier le fichier - Copy-Item -Path $projectPath -Destination $destinationPath -Force - - Write-Host "Restauré: $projectPath -> $destinationPath" - $restoredCount++ - - } catch { - Write-Error "Erreur lors de la restauration de '$originalPath': $_" - $errorCount++ - } - } -} - -# Traiter les fichiers WSL -if ($mapping.wsl) { - $mapping.wsl.PSObject.Properties | ForEach-Object { - $originalPath = $_.Name - $projectPath = $_.Value - - try { - # Vérifier que le fichier source existe dans le projet - if (-not (Test-Path $projectPath)) { - Write-Warning "Fichier source introuvable dans le projet: $projectPath" - $skippedCount++ - return - } - - # Résoudre le chemin de destination WSL - $wslDestination = $originalPath - if ($wslDestination -match '^~') { - $wslDestination = wsl bash -c "echo $wslDestination" - } - - # Créer le répertoire parent si nécessaire - $wslDir = Split-Path $wslDestination -Parent - if ($wslDir) { - wsl mkdir -p "$wslDir" 2>$null - } - - # Copier le fichier vers WSL - # Convertir le chemin Windows en chemin WSL - $wslSource = (wsl wslpath -a $projectPath) - wsl cp "$wslSource" "$wslDestination" - - if ($LASTEXITCODE -ne 0) { - # Fallback: utiliser PowerShell pour copier vers WSL - $content = Get-Content $projectPath -Raw -Encoding UTF8 - $tempFile = [System.IO.Path]::GetTempFileName() - Set-Content -Path $tempFile -Value $content -Encoding UTF8 - $wslTemp = (wsl wslpath -a $tempFile) - wsl cp "$wslTemp" "$wslDestination" - Remove-Item $tempFile - } - - Write-Host "Restauré (WSL): $projectPath -> $wslDestination" - $restoredCount++ - - } catch { - Write-Error "Erreur lors de la restauration WSL de '$originalPath': $_" - $errorCount++ - } - } -} - -Write-Host "`nRésumé:" -Write-Host " Fichiers restaurés: $restoredCount" -Write-Host " Fichiers ignorés: $skippedCount" -Write-Host " Erreurs: $errorCount" - +# Script pour restaurer les fichiers de configuration depuis le projet
+# Lit path-mapping.json et copie chaque fichier vers son emplacement original
+
+param(
+ [string]$MappingFile = "path-mapping.json"
+)
+
+$ErrorActionPreference = "Stop"
+
+# Vérifier que le fichier de mapping existe
+if (-not (Test-Path $MappingFile)) {
+ Write-Error "Le fichier de mapping '$MappingFile' n'existe pas. Exécutez d'abord sync-to-project.ps1"
+ exit 1
+}
+
+# Charger le mapping
+try {
+ $mapping = Get-Content $MappingFile -Raw | ConvertFrom-Json
+} catch {
+ Write-Error "Impossible de charger le fichier de mapping: $_"
+ exit 1
+}
+
+$restoredCount = 0
+$skippedCount = 0
+$errorCount = 0
+
+# Fonction pour résoudre un chemin Windows
+function Resolve-WindowsPath {
+ param([string]$path)
+
+ # Remplacer les variables d'environnement
+ $resolved = $path
+ $resolved = $resolved -replace '%USERPROFILE%', $env:USERPROFILE
+ $resolved = $resolved -replace '%APPDATA%', $env:APPDATA
+ $resolved = $resolved -replace '%LOCALAPPDATA%', $env:LOCALAPPDATA
+ $resolved = $resolved -replace '%HOME%', $env:HOME
+
+ # Remplacer les autres variables d'environnement
+ $resolved = [System.Environment]::ExpandEnvironmentVariables($resolved)
+
+ return $resolved
+}
+
+# Fonction pour résoudre un chemin WSL vers un chemin Windows accessible
+function Resolve-WSLPath {
+ param([string]$path)
+
+ # Détecter la distribution WSL (par défaut Ubuntu)
+ $wslDistro = "Ubuntu"
+
+ # Expansion de ~ vers /home/toshiro (ou autre utilisateur)
+ if ($path -match '^~') {
+ $homePath = wsl bash -c "echo ~" 2>$null
+ if ($LASTEXITCODE -eq 0 -and $homePath) {
+ $path = $path -replace '^~', $homePath
+ } else {
+ # Fallback: utiliser toshiro
+ $path = $path -replace '^~', "/home/toshiro"
+ }
+ }
+
+ # Convertir le chemin WSL en chemin Windows accessible
+ # Format: /home/toshiro/.bashrc -> \\wsl.localhost\Ubuntu\home\toshiro\.bashrc
+ if ($path -match '^/') {
+ # Enlever le slash initial
+ $relativePath = $path.Substring(1)
+ # Convertir en chemin Windows
+ $windowsPath = "\\wsl.localhost\$wslDistro\$relativePath" -replace '/', '\'
+ return $windowsPath
+ }
+
+ return $path
+}
+
+# Traiter les fichiers Windows
+if ($mapping.windows) {
+ $mapping.windows.PSObject.Properties | ForEach-Object {
+ $originalPath = $_.Name
+ $projectPath = $_.Value
+
+ try {
+ # Vérifier que le fichier source existe dans le projet
+ if (-not (Test-Path $projectPath)) {
+ Write-Warning "Fichier source introuvable dans le projet: $projectPath"
+ $skippedCount++
+ return
+ }
+
+ # Résoudre le chemin de destination
+ $destinationPath = Resolve-WindowsPath $originalPath
+
+ # Créer le répertoire parent si nécessaire
+ $destinationDir = Split-Path $destinationPath -Parent
+ if ($destinationDir -and -not (Test-Path $destinationDir)) {
+ New-Item -ItemType Directory -Path $destinationDir -Force | Out-Null
+ Write-Host "Créé le répertoire: $destinationDir"
+ }
+
+ # Copier le fichier
+ Copy-Item -Path $projectPath -Destination $destinationPath -Force
+
+ Write-Host "Restauré: $projectPath -> $destinationPath"
+ $restoredCount++
+
+ } catch {
+ Write-Error "Erreur lors de la restauration de '$originalPath': $_"
+ $errorCount++
+ }
+ }
+}
+
+# Traiter les fichiers WSL
+if ($mapping.wsl) {
+ $mapping.wsl.PSObject.Properties | ForEach-Object {
+ $originalPath = $_.Name
+ $projectPath = $_.Value
+
+ try {
+ # Vérifier que le fichier source existe dans le projet
+ if (-not (Test-Path $projectPath)) {
+ Write-Warning "Fichier source introuvable dans le projet: $projectPath"
+ $skippedCount++
+ return
+ }
+
+ # Résoudre le chemin de destination WSL en chemin Windows accessible
+ $destinationPath = Resolve-WSLPath $originalPath
+
+ # Créer le répertoire parent si nécessaire
+ $destinationDir = Split-Path $destinationPath -Parent
+ if ($destinationDir -and -not (Test-Path $destinationDir)) {
+ New-Item -ItemType Directory -Path $destinationDir -Force | Out-Null
+ Write-Host "Créé le répertoire: $destinationDir"
+ }
+
+ # Copier le fichier directement (maintenant que le chemin WSL est converti en chemin Windows)
+ Copy-Item -Path $projectPath -Destination $destinationPath -Force
+
+ Write-Host "Restauré (WSL): $projectPath -> $destinationPath"
+ $restoredCount++
+
+ } catch {
+ Write-Error "Erreur lors de la restauration WSL de '$originalPath': $_"
+ $errorCount++
+ }
+ }
+}
+
+Write-Host "`nRésumé:"
+Write-Host " Fichiers restaurés: $restoredCount"
+Write-Host " Fichiers ignorés: $skippedCount"
+Write-Host " Erreurs: $errorCount"
+
|
