From b33ff5f1fa86a8989ef1be65fd636b0458c0e9d1 Mon Sep 17 00:00:00 2001 From: ertopogo Date: Wed, 26 Nov 2025 19:52:23 +0100 Subject: Chore: Normalisation des fin de ligne (LF) via .gittattributs --- scripts/sync-from-project.ps1 | 308 ++++++++++++++--------------- scripts/sync-to-project.ps1 | 440 +++++++++++++++++++++--------------------- 2 files changed, 374 insertions(+), 374 deletions(-) (limited to 'scripts') diff --git a/scripts/sync-from-project.ps1 b/scripts/sync-from-project.ps1 index 73ba1c5..7ad43a7 100644 --- a/scripts/sync-from-project.ps1 +++ b/scripts/sync-from-project.ps1 @@ -1,154 +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 -} - -# 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" - +# 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" + diff --git a/scripts/sync-to-project.ps1 b/scripts/sync-to-project.ps1 index dc7423a..09cade6 100644 --- a/scripts/sync-to-project.ps1 +++ b/scripts/sync-to-project.ps1 @@ -1,220 +1,220 @@ -# Script pour copier les fichiers de configuration vers le projet -# Lit files-config.txt et copie chaque fichier vers configs/{system}/ - -param( - [string]$ConfigFile = "files-config.txt", - [string]$MappingFile = "path-mapping.json" -) - -$ErrorActionPreference = "Stop" - -# Vérifier que le fichier de configuration existe -if (-not (Test-Path $ConfigFile)) { - Write-Error "Le fichier de configuration '$ConfigFile' n'existe pas." - exit 1 -} - -# Créer les répertoires de destination -$configsDir = "configs" -$windowsDir = Join-Path $configsDir "windows" -$wslDir = Join-Path $configsDir "wsl" - -foreach ($dir in @($configsDir, $windowsDir, $wslDir)) { - if (-not (Test-Path $dir)) { - New-Item -ItemType Directory -Path $dir -Force | Out-Null - Write-Host "Créé le répertoire: $dir" - } -} - -# Charger le mapping existant ou créer un nouveau -$mapping = @{ - windows = @{} - wsl = @{} -} - -if (Test-Path $MappingFile) { - try { - $existingMapping = Get-Content $MappingFile -Raw | ConvertFrom-Json - if ($existingMapping.windows) { - $mapping.windows = @{} - $existingMapping.windows.PSObject.Properties | ForEach-Object { - $mapping.windows[$_.Name] = $_.Value - } - } - if ($existingMapping.wsl) { - $mapping.wsl = @{} - $existingMapping.wsl.PSObject.Properties | ForEach-Object { - $mapping.wsl[$_.Name] = $_.Value - } - } - } catch { - Write-Warning "Impossible de charger le mapping existant, création d'un nouveau mapping." - } -} - -# 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 - $resolved = $resolved -replace '%USERPROFILE%', $env:USERPROFILE - - # 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 -} - -# Fonction pour obtenir le chemin relatif dans le projet -function Get-ProjectPath { - param( - [string]$system, - [string]$originalPath - ) - - # Nettoyer chaque partie du chemin - $parts = $originalPath -split '[\\/]' - $safeParts = @() - - foreach ($part in $parts) { - # Nettoyer chaque partie : remplacer les caractères invalides et les variables - $safePart = $part -replace '[\\/:*?"<>|]', '_' - $safePart = $safePart -replace '^%', 'var_' -replace '%$', '' -replace '%', '_' - $safePart = $safePart -replace '^~', 'home' - - # Si la partie est vide après nettoyage, utiliser un nom par défaut - if ([string]::IsNullOrWhiteSpace($safePart)) { - $safePart = "root" - } - - $safeParts += $safePart - } - - # Rejoindre toutes les parties avec des underscores - $safeName = $safeParts -join '_' - - # Construire le chemin final - $basePath = Join-Path "configs" $system - return Join-Path $basePath $safeName -} - -# Lire et traiter le fichier de configuration -$lines = Get-Content $ConfigFile | Where-Object { - $_ -notmatch '^\s*#' -and $_.Trim() -ne '' -} - -$copiedCount = 0 -$skippedCount = 0 -$errorCount = 0 - -foreach ($line in $lines) { - $line = $line.Trim() - if ($line -eq '' -or $line -match '^\s*#') { - continue - } - - # Parser la ligne: système|chemin - if ($line -notmatch '^(\w+)\|(.+)$') { - Write-Warning "Ligne ignorée (format invalide): $line" - continue - } - - $system = $matches[1] - $originalPath = $matches[2] - - if ($system -notin @('windows', 'wsl')) { - Write-Warning "Système invalide '$system' dans la ligne: $line" - continue - } - - try { - # Résoudre le chemin selon le système - if ($system -eq 'windows') { - $resolvedPath = Resolve-WindowsPath $originalPath - } else { - # Pour WSL, convertir en chemin Windows accessible - $resolvedPath = Resolve-WSLPath $originalPath - } - - # Vérifier que le fichier existe - if (-not (Test-Path $resolvedPath)) { - Write-Warning "Fichier introuvable: $resolvedPath (original: $originalPath)" - $skippedCount++ - continue - } - - # Obtenir le chemin de destination dans le projet - $projectPath = Get-ProjectPath $system $originalPath - - # Créer le répertoire parent si nécessaire - $projectDir = Split-Path $projectPath -Parent - if (-not (Test-Path $projectDir)) { - New-Item -ItemType Directory -Path $projectDir -Force | Out-Null - } - - # Copier le fichier - # Maintenant que les chemins WSL sont convertis en chemins Windows, on peut utiliser Copy-Item pour les deux - Copy-Item -Path $resolvedPath -Destination $projectPath -Force - - # Enregistrer le mapping - $mapping[$system][$originalPath] = $projectPath - - Write-Host "Copié: $originalPath -> $projectPath" - $copiedCount++ - - } catch { - Write-Error "Erreur lors du traitement de '$line': $_" - $errorCount++ - } -} - -# Sauvegarder le mapping -$mappingJson = @{ - windows = $mapping.windows - wsl = $mapping.wsl -} | ConvertTo-Json -Depth 10 - -Set-Content -Path $MappingFile -Value $mappingJson -Encoding UTF8 - -Write-Host "`nRésumé:" -Write-Host " Fichiers copiés: $copiedCount" -Write-Host " Fichiers ignorés: $skippedCount" -Write-Host " Erreurs: $errorCount" -Write-Host " Mapping sauvegardé dans: $MappingFile" - +# Script pour copier les fichiers de configuration vers le projet +# Lit files-config.txt et copie chaque fichier vers configs/{system}/ + +param( + [string]$ConfigFile = "files-config.txt", + [string]$MappingFile = "path-mapping.json" +) + +$ErrorActionPreference = "Stop" + +# Vérifier que le fichier de configuration existe +if (-not (Test-Path $ConfigFile)) { + Write-Error "Le fichier de configuration '$ConfigFile' n'existe pas." + exit 1 +} + +# Créer les répertoires de destination +$configsDir = "configs" +$windowsDir = Join-Path $configsDir "windows" +$wslDir = Join-Path $configsDir "wsl" + +foreach ($dir in @($configsDir, $windowsDir, $wslDir)) { + if (-not (Test-Path $dir)) { + New-Item -ItemType Directory -Path $dir -Force | Out-Null + Write-Host "Créé le répertoire: $dir" + } +} + +# Charger le mapping existant ou créer un nouveau +$mapping = @{ + windows = @{} + wsl = @{} +} + +if (Test-Path $MappingFile) { + try { + $existingMapping = Get-Content $MappingFile -Raw | ConvertFrom-Json + if ($existingMapping.windows) { + $mapping.windows = @{} + $existingMapping.windows.PSObject.Properties | ForEach-Object { + $mapping.windows[$_.Name] = $_.Value + } + } + if ($existingMapping.wsl) { + $mapping.wsl = @{} + $existingMapping.wsl.PSObject.Properties | ForEach-Object { + $mapping.wsl[$_.Name] = $_.Value + } + } + } catch { + Write-Warning "Impossible de charger le mapping existant, création d'un nouveau mapping." + } +} + +# 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 + $resolved = $resolved -replace '%USERPROFILE%', $env:USERPROFILE + + # 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 +} + +# Fonction pour obtenir le chemin relatif dans le projet +function Get-ProjectPath { + param( + [string]$system, + [string]$originalPath + ) + + # Nettoyer chaque partie du chemin + $parts = $originalPath -split '[\\/]' + $safeParts = @() + + foreach ($part in $parts) { + # Nettoyer chaque partie : remplacer les caractères invalides et les variables + $safePart = $part -replace '[\\/:*?"<>|]', '_' + $safePart = $safePart -replace '^%', 'var_' -replace '%$', '' -replace '%', '_' + $safePart = $safePart -replace '^~', 'home' + + # Si la partie est vide après nettoyage, utiliser un nom par défaut + if ([string]::IsNullOrWhiteSpace($safePart)) { + $safePart = "root" + } + + $safeParts += $safePart + } + + # Rejoindre toutes les parties avec des underscores + $safeName = $safeParts -join '_' + + # Construire le chemin final + $basePath = Join-Path "configs" $system + return Join-Path $basePath $safeName +} + +# Lire et traiter le fichier de configuration +$lines = Get-Content $ConfigFile | Where-Object { + $_ -notmatch '^\s*#' -and $_.Trim() -ne '' +} + +$copiedCount = 0 +$skippedCount = 0 +$errorCount = 0 + +foreach ($line in $lines) { + $line = $line.Trim() + if ($line -eq '' -or $line -match '^\s*#') { + continue + } + + # Parser la ligne: système|chemin + if ($line -notmatch '^(\w+)\|(.+)$') { + Write-Warning "Ligne ignorée (format invalide): $line" + continue + } + + $system = $matches[1] + $originalPath = $matches[2] + + if ($system -notin @('windows', 'wsl')) { + Write-Warning "Système invalide '$system' dans la ligne: $line" + continue + } + + try { + # Résoudre le chemin selon le système + if ($system -eq 'windows') { + $resolvedPath = Resolve-WindowsPath $originalPath + } else { + # Pour WSL, convertir en chemin Windows accessible + $resolvedPath = Resolve-WSLPath $originalPath + } + + # Vérifier que le fichier existe + if (-not (Test-Path $resolvedPath)) { + Write-Warning "Fichier introuvable: $resolvedPath (original: $originalPath)" + $skippedCount++ + continue + } + + # Obtenir le chemin de destination dans le projet + $projectPath = Get-ProjectPath $system $originalPath + + # Créer le répertoire parent si nécessaire + $projectDir = Split-Path $projectPath -Parent + if (-not (Test-Path $projectDir)) { + New-Item -ItemType Directory -Path $projectDir -Force | Out-Null + } + + # Copier le fichier + # Maintenant que les chemins WSL sont convertis en chemins Windows, on peut utiliser Copy-Item pour les deux + Copy-Item -Path $resolvedPath -Destination $projectPath -Force + + # Enregistrer le mapping + $mapping[$system][$originalPath] = $projectPath + + Write-Host "Copié: $originalPath -> $projectPath" + $copiedCount++ + + } catch { + Write-Error "Erreur lors du traitement de '$line': $_" + $errorCount++ + } +} + +# Sauvegarder le mapping +$mappingJson = @{ + windows = $mapping.windows + wsl = $mapping.wsl +} | ConvertTo-Json -Depth 10 + +Set-Content -Path $MappingFile -Value $mappingJson -Encoding UTF8 + +Write-Host "`nRésumé:" +Write-Host " Fichiers copiés: $copiedCount" +Write-Host " Fichiers ignorés: $skippedCount" +Write-Host " Erreurs: $errorCount" +Write-Host " Mapping sauvegardé dans: $MappingFile" + -- cgit v1.2.3