Created
January 26, 2024 20:49
-
-
Save kewalaka/df38f98e710ca53f863ec367f7f96ac4 to your computer and use it in GitHub Desktop.
Move packages for various languages to a Dev Drive & configure environment vars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define the Dev Drive path | |
$DevDrive = "D:\packages" | |
# Function to display progress message | |
function Show-Progress($message, $color) { | |
Write-Host -ForegroundColor $color "Progress: $message" | |
} | |
# Create npm cache directory and set environment variable | |
$npmCacheDir = Join-Path $DevDrive "npm" | |
Show-Progress "Creating npm cache directory..." Yellow | |
New-Item -ItemType Directory -Force -Path $npmCacheDir | |
[Environment]::SetEnvironmentVariable("npm_config_cache", $npmCacheDir, [System.EnvironmentVariableTarget]::Machine) | |
# Move existing npm cache if it exists | |
if (Test-Path "$env:APPDATA\npm-cache") { | |
Show-Progress "Moving existing npm cache..." Yellow | |
Move-Item "$env:APPDATA\npm-cache\*" -Destination $npmCacheDir -Force | |
} | |
# Create NuGet global-packages folder and set environment variable | |
$nugetPackagesDir = Join-Path $DevDrive ".nuget\packages" | |
Show-Progress "Creating NuGet global-packages folder..." Yellow | |
New-Item -ItemType Directory -Force -Path $nugetPackagesDir | |
[Environment]::SetEnvironmentVariable("NUGET_PACKAGES", $nugetPackagesDir, [System.EnvironmentVariableTarget]::Machine) | |
# Set NuGet global-packages folder for MSBuild | |
[Environment]::SetEnvironmentVariable("RestorePackagesPath", $nugetPackagesDir, [System.EnvironmentVariableTarget]::Machine) | |
# Create vcpkg cache directory and set environment variable | |
$vcpkgCacheDir = Join-Path $DevDrive "vcpkg" | |
Show-Progress "Creating vcpkg cache directory..." Yellow | |
New-Item -ItemType Directory -Force -Path $vcpkgCacheDir | |
[Environment]::SetEnvironmentVariable("VCPKG_DEFAULT_BINARY_CACHE", $vcpkgCacheDir, [System.EnvironmentVariableTarget]::Machine) | |
# Move existing vcpkg archives if they exist | |
if (Test-Path "$env:LOCALAPPDATA\vcpkg\archives" -or Test-Path "$env:APPDATA\vcpkg\archives") { | |
Show-Progress "Moving existing vcpkg archives..." Yellow | |
$sourcePath = "$env:LOCALAPPDATA\vcpkg\archives" | |
if (-not (Test-Path $sourcePath)) { | |
$sourcePath = "$env:APPDATA\vcpkg\archives" | |
} | |
Move-Item "$sourcePath\*" -Destination $vcpkgCacheDir -Force | |
} | |
# Create pip cache directory and set environment variable | |
$pipCacheDir = Join-Path $DevDrive "pip" | |
Show-Progress "Creating pip cache directory..." Yellow | |
New-Item -ItemType Directory -Force -Path $pipCacheDir | |
[Environment]::SetEnvironmentVariable("PIP_CACHE_DIR", $pipCacheDir, [System.EnvironmentVariableTarget]::Machine) | |
# Move existing pip cache if it exists | |
if (Test-Path "$env:LocalAppData\pip\Cache") { | |
Show-Progress "Moving existing pip cache..." Yellow | |
Move-Item "$env:LocalAppData\pip\Cache\*" -Destination $pipCacheDir -Force | |
} | |
# Create Cargo cache directory and set environment variable | |
$cargoCacheDir = Join-Path $DevDrive "cargo" | |
Show-Progress "Creating Cargo cache directory..." Yellow | |
New-Item -ItemType Directory -Force -Path $cargoCacheDir | |
[Environment]::SetEnvironmentVariable("CARGO_HOME", $cargoCacheDir, [System.EnvironmentVariableTarget]::Machine) | |
# Move existing Cargo cache if it exists | |
if (Test-Path "$env:USERPROFILE\.cargo") { | |
Show-Progress "Moving existing Cargo cache..." Yellow | |
Move-Item "$env:USERPROFILE\.cargo\*" -Destination $cargoCacheDir -Force | |
} | |
# Print completion message | |
Show-Progress "Package caches have been configured and moved to the Dev Drive." Green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment