WuYongJie 9859afc4aa 初始化3D家具展示系统项目
- 完整的Next.js 14 + TypeScript项目架构
- 集成Three.js和GSAP用于3D渲染和动画
- Prisma ORM + PostgreSQL数据库
- Docker容器化部署支持
- 本地缓存优化系统
- 中文界面和注释
- 移动端响应式设计
- 健康检查和监控功能
2025-12-11 16:42:59 +08:00

198 lines
6.6 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 一键设置本地缓存系统
# 作者: Kiro AI Assistant
# 用途: 自动设置完整的本地依赖包缓存系统
param(
[string]$FlnxiPath = "..\..\flnxi_sucai",
[switch]$SkipFlnxi = $false,
[switch]$Force = $false
)
Write-Host "=== 设置本地缓存系统 ===" -ForegroundColor Green
$ScriptDir = $PSScriptRoot
$LocalPackagesDir = Split-Path -Parent $ScriptDir
# 步骤 1: 从 flnxi_sucai 复制基础包
if (-not $SkipFlnxi) {
Write-Host "`n步骤 1: 从 flnxi_sucai 项目复制基础包" -ForegroundColor Cyan
$CopyScript = Join-Path $ScriptDir "copy-from-flnxi.ps1"
if (Test-Path $CopyScript) {
$CopyArgs = @("-FlnxiPath", $FlnxiPath)
if ($Force) { $CopyArgs += "-Force" }
& $CopyScript @CopyArgs
if ($LASTEXITCODE -ne 0) {
Write-Host "警告: 从 flnxi_sucai 复制失败,将跳过此步骤" -ForegroundColor Yellow
}
} else {
Write-Host "警告: 找不到 copy-from-flnxi.ps1 脚本" -ForegroundColor Yellow
}
} else {
Write-Host "跳过从 flnxi_sucai 复制基础包" -ForegroundColor Yellow
}
# 步骤 2: 下载项目特定的依赖包
Write-Host "`n步骤 2: 下载项目特定的依赖包" -ForegroundColor Cyan
$DownloadScript = Join-Path $ScriptDir "download-packages.ps1"
if (Test-Path $DownloadScript) {
$DownloadArgs = @()
if ($Force) { $DownloadArgs += "-Force" }
& $DownloadScript @DownloadArgs
if ($LASTEXITCODE -ne 0) {
Write-Host "错误: 下载依赖包失败" -ForegroundColor Red
exit 1
}
} else {
Write-Host "错误: 找不到 download-packages.ps1 脚本" -ForegroundColor Red
exit 1
}
# 步骤 3: 加载 Docker 镜像
Write-Host "`n步骤 3: 加载 Docker 镜像到本地" -ForegroundColor Cyan
$LoadScript = Join-Path $ScriptDir "load-images.ps1"
if (Test-Path $LoadScript) {
$LoadArgs = @()
if ($Force) { $LoadArgs += "-Force" }
& $LoadScript @LoadArgs
if ($LASTEXITCODE -ne 0) {
Write-Host "警告: 加载 Docker 镜像失败" -ForegroundColor Yellow
}
} else {
Write-Host "警告: 找不到 load-images.ps1 脚本" -ForegroundColor Yellow
}
# 步骤 4: 验证缓存设置
Write-Host "`n步骤 4: 验证缓存设置" -ForegroundColor Cyan
$ValidationResults = @{
dockerImages = 0
npmCache = $false
prismaEngines = $false
totalSize = 0
}
# 检查 Docker 镜像
$DockerImagesDir = Join-Path $LocalPackagesDir "docker-images"
if (Test-Path $DockerImagesDir) {
$ImageDirs = Get-ChildItem -Path $DockerImagesDir -Directory
foreach ($dir in $ImageDirs) {
$TarFiles = Get-ChildItem -Path $dir.FullName -Filter "*.tar"
$ValidationResults.dockerImages += $TarFiles.Count
}
}
# 检查 npm 缓存
$NpmCacheDir = Join-Path $LocalPackagesDir "npm-cache"
$CachedNodeModules = Join-Path $NpmCacheDir "node_modules"
$ValidationResults.npmCache = Test-Path $CachedNodeModules
# 检查 Prisma 引擎
$PrismaEnginesDir = Join-Path $LocalPackagesDir "prisma-engines"
$ValidationResults.prismaEngines = Test-Path $PrismaEnginesDir
# 计算总大小
if (Test-Path $LocalPackagesDir) {
Get-ChildItem -Path $LocalPackagesDir -Recurse -File | ForEach-Object {
$ValidationResults.totalSize += $_.Length
}
}
$TotalSizeGB = [math]::Round($ValidationResults.totalSize / 1GB, 2)
# 显示验证结果
Write-Host "验证结果:" -ForegroundColor White
Write-Host " Docker 镜像: $($ValidationResults.dockerImages) 个" -ForegroundColor $(if ($ValidationResults.dockerImages -gt 0) { "Green" } else { "Red" })
Write-Host " npm 缓存: $(if ($ValidationResults.npmCache) { "✓" } else { "✗" })" -ForegroundColor $(if ($ValidationResults.npmCache) { "Green" } else { "Red" })
Write-Host " Prisma 引擎: $(if ($ValidationResults.prismaEngines) { "✓" } else { "✗" })" -ForegroundColor $(if ($ValidationResults.prismaEngines) { "Green" } else { "Red" })
Write-Host " 总缓存大小: $TotalSizeGB GB" -ForegroundColor Cyan
# 步骤 5: 创建使用说明
Write-Host "`n步骤 5: 创建使用说明" -ForegroundColor Cyan
$UsageGuide = @"
# 本地缓存系统使用说明
## 缓存状态
- Docker 镜像: $($ValidationResults.dockerImages) 个
- npm 缓存: $(if ($ValidationResults.npmCache) { "已设置" } else { "未设置" })
- Prisma 引擎: $(if ($ValidationResults.prismaEngines) { "已缓存" } else { "未缓存" })
- 总大小: $TotalSizeGB GB
## 使用方法
### 1. 构建项目
```powershell
# 使用本地缓存构建 Docker 镜像
docker-compose build
# 或者直接启动(会自动构建)
docker-compose up --build
```
### 2. 更新缓存
```powershell
# 更新所有缓存
.\local-packages\scripts\setup-local-cache.ps1 -Force
# 只更新特定部分
.\local-packages\scripts\download-packages.ps1 -Force
.\local-packages\scripts\load-images.ps1 -Force
```
### 3. 清理缓存
```powershell
# 清理所有本地缓存
Remove-Item -Path "local-packages" -Recurse -Force
# 重新设置
.\local-packages\scripts\setup-local-cache.ps1
```
## 注意事项
1. 本地缓存会占用约 $TotalSizeGB GB 磁盘空间
2. 定期更新缓存以获取最新版本
3. 构建时会优先使用本地缓存,提高构建速度
4. 如果本地缓存不可用,会自动回退到网络下载
生成时间: $(Get-Date -Format "yyyy-MM-dd HH:mm:ss")
"@
$UsageGuidePath = Join-Path $LocalPackagesDir "USAGE.md"
$UsageGuide | Set-Content $UsageGuidePath -Encoding UTF8
Write-Host "使用说明已保存到: $UsageGuidePath" -ForegroundColor Green
# 完成
Write-Host "`n=== 本地缓存系统设置完成 ===" -ForegroundColor Green
if ($ValidationResults.dockerImages -gt 0 -and $ValidationResults.npmCache) {
Write-Host "✓ 缓存系统设置成功,可以开始构建项目" -ForegroundColor Green
Write-Host "`n下一步: 运行 'docker-compose up --build' 开始构建" -ForegroundColor Yellow
} else {
Write-Host "⚠ 缓存系统设置不完整,建议检查网络连接后重试" -ForegroundColor Yellow
Write-Host "可以运行 'setup-local-cache.ps1 -Force' 强制重新设置" -ForegroundColor Gray
}
# 显示磁盘使用情况
Write-Host "`n磁盘使用情况:" -ForegroundColor Cyan
Write-Host "本地缓存: $TotalSizeGB GB" -ForegroundColor White
try {
$DiskInfo = Get-WmiObject -Class Win32_LogicalDisk | Where-Object { $_.DriveType -eq 3 }
foreach ($disk in $DiskInfo) {
$FreeSpaceGB = [math]::Round($disk.FreeSpace / 1GB, 2)
$TotalSpaceGB = [math]::Round($disk.Size / 1GB, 2)
Write-Host "$($disk.DeviceID) 可用空间: $FreeSpaceGB GB / $TotalSpaceGB GB" -ForegroundColor Gray
}
} catch {
Write-Host "无法获取磁盘信息" -ForegroundColor Gray
}