更新 Init-DeveloperDrive.ps1

This commit is contained in:
2025-12-20 13:25:24 +00:00
parent 59a7b76b68
commit 399d594024

View File

@@ -1,67 +1,37 @@
# ========================================================================= # 1_Map_Dev_Caches.ps1
# 程序员 D 盘生产力开发环境初始化脚本 $TargetBase = "D:\Data\Symlink_Storage"
# =========================================================================
$DriveLetter = "D:\" # 定义映射关系C盘路径 = D盘子路径
$Mappings = @{
# 1. 检查 D 盘是否存在 "$HOME\.m2" = "$TargetBase\.m2"
if (!(Test-Path $DriveLetter)) { "$HOME\.gradle" = "$TargetBase\.gradle"
Write-Error "错误:未检测到 D 盘,请检查驱动器盘符。" "$HOME\.npm" = "$TargetBase\npm-cache"
return "$env:LOCALAPPDATA\pip\cache" = "$TargetBase\pip-cache"
} }
# 2. 定义要创建的目录结构 foreach ($Source in $Mappings.Keys) {
$Directories = @( $Destination = $Mappings[$Source]
"Workspace\Github",
"Workspace\Company",
"Workspace\Lab",
"Environment\Java",
"Environment\Python",
"Environment\Nodejs",
"Environment\Go",
"Software\Portable",
"Software\Installers",
"DevTools\JetBrains",
"DevTools\VSCode",
"DevTools\Databases",
"Data\Docker",
"Data\VMs",
"Data\DB_Storage",
"Data\Symlink_Storage\.m2", # 用于映射 C 盘 Maven 仓库
"Data\Symlink_Storage\.gradle", # 用于映射 C 盘 Gradle 缓存
"Data\Symlink_Storage\npm-cache", # 用于映射 C 盘 npm 缓存
"Document\Wiki",
"Document\eBooks",
"Document\Assets",
"Temp"
)
Write-Host "--- 开始初始化 $DriveLetter 目录结构 ---" -ForegroundColor Cyan # 如果 D 盘目标目录不存在,则创建
if (!(Test-Path $Destination)) {
# 3. 循环创建目录 New-Item -Path $Destination -ItemType Directory -Force | Out-Null
foreach ($Dir in $Directories) {
$FullPath = Join-Path $DriveLetter $Dir
if (!(Test-Path $FullPath)) {
New-Item -Path $FullPath -ItemType Directory | Out-Null
Write-Host "[成功] 已创建: $FullPath" -ForegroundColor Green
} else {
Write-Host "[跳过] 已存在: $FullPath" -ForegroundColor Yellow
} }
}
# 4. 在根目录生成一个结构说明文件 if (Test-Path $Source) {
$ReadmeContent = @" # 如果 C 盘已经是符号链接,跳过
# D $folder = Get-Item $Source
- Workspace: Git if ($folder.Attributes -match "ReparsePoint") {
- Environment: SDK Write-Host "[跳过] $Source 已经是映射状态" -ForegroundColor Yellow
- Software: 绿 continue
- DevTools: IDE }
- Data: Docker C
- Document:
- Temp:
"@
$ReadmePath = Join-Path $DriveLetter "README_Layout.md" # 移动现有文件到 D 盘
$ReadmeContent | Out-File -FilePath $ReadmePath -Encoding utf8 Write-Host "[处理] 正在搬移 $Source -> $Destination" -ForegroundColor Cyan
Move-Item -Path "$Source\*" -Destination $Destination -Force -ErrorAction SilentlyContinue
Remove-Item -Path $Source -Recurse -Force
}
Write-Host "--- 初始化完成!说明文件已生成在 $DriveLetter ---" -ForegroundColor Cyan # 创建符号链接 (Junction)
New-Item -Path $Source -ItemType Junction -Value $Destination
Write-Host "[成功] 已建立链接: $Source" -ForegroundColor Green
}