|
| 1 | +# This script organizes your Svelte project files and automatically updates import paths. |
| 2 | +# It is safe to run on a partially-organized project. |
| 3 | + |
| 4 | +Write-Host "Starting complete project organization and path updates..." -ForegroundColor Green |
| 5 | + |
| 6 | +$basePath = Resolve-Path "src/lib" |
| 7 | + |
| 8 | +# --- Define the new structure and file moves --- |
| 9 | +# This list contains all components, including those already moved. |
| 10 | +$moves = @{ |
| 11 | + # Layout Components |
| 12 | + "$basePath/components/Header.svelte" = "$basePath/components/layout/Header.svelte"; |
| 13 | + "$basePath/components/Footer.svelte" = "$basePath/components/layout/Footer.svelte"; |
| 14 | + "$basePath/components/Nav.svelte" = "$basePath/components/layout/Nav.svelte"; |
| 15 | + "$basePath/components/ScrollToTop.svelte" = "$basePath/components/layout/ScrollToTop.svelte"; |
| 16 | + |
| 17 | + # UI Components |
| 18 | + "$basePath/components/GlitchText.svelte" = "$basePath/components/ui/GlitchText.svelte"; |
| 19 | + "$basePath/components/Section.svelte" = "$basePath/components/ui/Section.svelte"; |
| 20 | + "$basePath/components/CRTFilter.svelte" = "$basePath/components/ui/CRTFilter.svelte"; |
| 21 | + "$basePath/components/CRTControl.svelte" = "$basePath/components/ui/CRTControl.svelte"; |
| 22 | + "$basePath/components/Typewriter.svelte" = "$basePath/components/ui/Typewriter.svelte"; |
| 23 | + "$basePath/components/Timeline.svelte" = "$basePath/components/ui/Timeline.svelte"; |
| 24 | + "$basePath/components/ThemeSwitch.svelte" = "$basePath/components/ui/ThemeSwitch.svelte"; |
| 25 | + "$basePath/components/ProjectCard.svelte" = "$basePath/components/ui/ProjectCard.svelte"; |
| 26 | + "$basePath/components/SkillCard.svelte" = "$basePath/components/ui/SkillCard.svelte"; |
| 27 | + "$basePath/components/SkillIcon.svelte" = "$basePath/components/ui/SkillIcon.svelte"; |
| 28 | + "$basePath/components/BlinkingCursor.svelte" = "$basePath/components/ui/BlinkingCursor.svelte"; |
| 29 | + "$basePath/components/Kirby.svelte" = "$basePath/components/ui/Kirby.svelte"; |
| 30 | + |
| 31 | + # Feature Components & Folders |
| 32 | + "$basePath/components/AboutSection.svelte" = "$basePath/components/features/AboutSection.svelte"; |
| 33 | + "$basePath/components/SkillsSection.svelte" = "$basePath/components/features/SkillsSection.svelte"; |
| 34 | + "$basePath/components/ProjectsSection.svelte" = "$basePath/components/features/ProjectsSection.svelte"; |
| 35 | + "$basePath/components/ExperienceSection.svelte" = "$basePath/components/features/ExperienceSection.svelte"; |
| 36 | + "$basePath/components/EducationSection.svelte" = "$basePath/components/features/EducationSection.svelte"; |
| 37 | + "$basePath/components/terminal" = "$basePath/components/features/terminal"; |
| 38 | + "$basePath/components/skills" = "$basePath/components/features/skills"; |
| 39 | + |
| 40 | + # Other Lib Files |
| 41 | + "$basePath/i18n.js" = "$basePath/utils/i18n.js"; |
| 42 | + "$basePath/transitions/print.ts" = "$basePath/transitions/transitions.ts"; |
| 43 | +} |
| 44 | + |
| 45 | +# --- Create new directories --- |
| 46 | +$moves.Values | ForEach-Object { |
| 47 | + $dir = Split-Path $_ -Parent |
| 48 | + if (-not (Test-Path $dir)) { |
| 49 | + New-Item -ItemType Directory -Path $dir -Force | Out-Null |
| 50 | + Write-Host "Created directory: $dir" |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +# --- Move remaining files and folders --- |
| 55 | +Write-Host "Checking for files to move..." |
| 56 | +$moves.GetEnumerator() | ForEach-Object { |
| 57 | + # THE FIX: This `if` statement makes the script robust. |
| 58 | + # It checks if the file exists at the *original* source location before trying to move it. |
| 59 | + # If a file was already moved by the previous script, this check will fail and the script |
| 60 | + # will safely skip it without causing an error. |
| 61 | + if (Test-Path $_.Name) { |
| 62 | + Move-Item -Path $_.Name -Destination $_.Value -Force |
| 63 | + Write-Host "Moved: $($_.Name) -> $($_.Value)" |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +# --- Update import paths --- |
| 68 | +# This section will run over all files and fix any remaining incorrect import paths. |
| 69 | +Write-Host "Updating all import paths in project files..." |
| 70 | +$filesToUpdate = Get-ChildItem -Path "src" -Recurse -Include *.svelte, *.ts, *.js |
| 71 | + |
| 72 | +# Define all possible path replacements, from old to new. |
| 73 | +$pathUpdates = @{ |
| 74 | + # Layout |
| 75 | + "from '$lib/components/Header.svelte'" = "from '$lib/components/layout/Header.svelte'"; |
| 76 | + "from '$lib/components/Footer.svelte'" = "from '$lib/components/layout/Footer.svelte'"; |
| 77 | + "from '$lib/components/Nav.svelte'" = "from '$lib/components/layout/Nav.svelte'"; |
| 78 | + "from '$lib/components/ScrollToTop.svelte'" = "from '$lib/components/layout/ScrollToTop.svelte'"; |
| 79 | + # UI |
| 80 | + "from '$lib/components/GlitchText.svelte'" = "from '$lib/components/ui/GlitchText.svelte'"; |
| 81 | + "from '../GlitchText.svelte'" = "from '$lib/components/ui/GlitchText.svelte'"; |
| 82 | + "from '$lib/components/Section.svelte'" = "from '$lib/components/ui/Section.svelte'"; |
| 83 | + "from '$lib/components/CRTFilter.svelte'" = "from '$lib/components/ui/CRTFilter.svelte'"; |
| 84 | + "from '$lib/components/CRTControl.svelte'" = "from '$lib/components/ui/CRTControl.svelte'"; |
| 85 | + "from '$lib/components/Typewriter.svelte'" = "from '$lib/components/ui/Typewriter.svelte'"; |
| 86 | + "from '$lib/components/Timeline.svelte'" = "from '$lib/components/ui/Timeline.svelte'"; |
| 87 | + "from '$lib/components/ThemeSwitch.svelte'" = "from '$lib/components/ui/ThemeSwitch.svelte'"; |
| 88 | + "from '$lib/components/ProjectCard.svelte'" = "from '$lib/components/ui/ProjectCard.svelte'"; |
| 89 | + "from '$lib/components/SkillCard.svelte'" = "from '$lib/components/ui/SkillCard.svelte'"; |
| 90 | + "from '$lib/components/SkillIcon.svelte'" = "from '$lib/components/ui/SkillIcon.svelte'"; |
| 91 | + "from '$lib/components/skills/SkillIcon.svelte'" = "from '$lib/components/ui/SkillIcon.svelte'"; |
| 92 | + "from '$lib/components/BlinkingCursor.svelte'" = "from '$lib/components/ui/BlinkingCursor.svelte'"; |
| 93 | + "from './BlinkingCursor.svelte'" = "from '$lib/components/ui/BlinkingCursor.svelte'"; |
| 94 | + # Features |
| 95 | + "from '$lib/components/terminal/Terminal.svelte'" = "from '$lib/components/features/terminal/Terminal.svelte'"; |
| 96 | + "from './BootSequence.svelte'" = "from '$lib/components/features/terminal/BootSequence.svelte'"; |
| 97 | + "from './FileExplorer.svelte'" = "from '$lib/components/features/terminal/FileExplorer.svelte'"; |
| 98 | + "from './ProjectView.svelte'" = "from '$lib/components/features/terminal/ProjectView.svelte'"; |
| 99 | + "from './ProjectFile.svelte'" = "from '$lib/components/features/terminal/ProjectFile.svelte'"; |
| 100 | + # Utils, Transitions, etc. |
| 101 | + "from '$lib/i18n'" = "from '$lib/utils/i18n'"; |
| 102 | + "from '$lib/transitions/print'" = "from '$lib/transitions/transitions'"; |
| 103 | + "from '$lib/transitions/transitions'" = "from '$lib/transitions/transitions'"; |
| 104 | +} |
| 105 | + |
| 106 | +foreach ($file in $filesToUpdate) { |
| 107 | + $content = Get-Content $file.FullName -Raw |
| 108 | + $originalContent = $content |
| 109 | + |
| 110 | + $pathUpdates.GetEnumerator() | ForEach-Object { |
| 111 | + $content = $content -replace [regex]::Escape($_.Name), $_.Value |
| 112 | + } |
| 113 | + |
| 114 | + if ($content -ne $originalContent) { |
| 115 | + Set-Content -Path $file.FullName -Value $content |
| 116 | + Write-Host "Updated paths in: $($file.FullName)" -ForegroundColor Cyan |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +Write-Host "----------------------------------------------------" -ForegroundColor Green |
| 121 | +Write-Host "Project successfully organized and paths updated!" -ForegroundColor Green |
| 122 | +Write-Host "----------------------------------------------------" -ForegroundColor Green |
0 commit comments