bookworm-boot/prepare-repo.ps1
bookworm d499342271 feat: Mac 支持 v1.5 同步 + 模板清理 + 卸载脚本
- Bookworm-Setup.sh: 重写为完整 Mac 安装器(依赖检测/代理/配置克隆/凭证解密/别名bw)
- install-mac.sh: 新建重定向脚本,消除文档断链
- uninstall-mac.sh: 新建 Mac 卸载脚本(进程/凭证/历史/别名清理)
- guide-mac.html: 修复所有过时引用(install-mac.sh/start-mac.sh/bookworm→bw)
- settings.template.json: 从 boot 仓库移除(由 build-portable.js 管理)
- prepare-repo.ps1/README/quick-reference: 更新模板引用

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 13:48:05 +08:00

198 lines
5.6 KiB
PowerShell
Raw Permalink 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.

<#
.SYNOPSIS
Bookworm Portable - 仓库准备脚本
.DESCRIPTION
将当前 .claude/ 目录初始化为 Git 仓库,
排除敏感文件和大体积依赖, 推送到 Gitea.
.USAGE
# 首次准备 (初始化 + 推送)
.\prepare-repo.ps1 -GitUrl "http://8.138.11.105:3000/bookworm/bookworm-config.git"
#>
param(
[Parameter(Mandatory=$true)]
[string]$GitUrl
)
$ErrorActionPreference = "Stop"
$ClaudeDir = Join-Path $env:USERPROFILE ".claude"
Write-Host ""
Write-Host " Bookworm Portable - 仓库准备" -ForegroundColor Cyan
Write-Host " =============================" -ForegroundColor Cyan
Write-Host ""
if (-not (Test-Path $ClaudeDir)) {
Write-Host "[ERROR] .claude 目录不存在: $ClaudeDir" -ForegroundColor Red
exit 1
}
# 1. settings.template.json (由 build-portable.js 自动生成,无需手动拷贝)
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Write-Host "[1/6] settings.template.json 由 build-portable.js 管理,跳过" -ForegroundColor Gray
# 2. 创建 .gitignore
Write-Host "[2/6] 生成 .gitignore..." -ForegroundColor White
$gitignore = @"
# ===== Bookworm Portable .gitignore =====
# ()
.credentials.json
.hmac-key
secrets.enc
*.key
*.pem
*.token
*.secret
.env
.env.*
# ()
settings.json
settings.local.json
# /
mcp-servers/
node_modules/
file-history/
vendor/
# Skill (/node_modules)
skills/gstack/
skills/browse/
skills/*/dist/
skills/*/.git/
skills/*/node_modules/
# (28MB)
hooks/__tests__/
#
cache/
paste-cache/
sessions/
shell-snapshots/
telemetry/
repos/
plugins/
tasks/
teams/
backups/
# ()
debug/
# ()
projects/
#
memory/
# OS
Thumbs.db
desktop.ini
.DS_Store
#
*.sqlite
*.db
*.test.tmp
"@
Set-Content (Join-Path $ClaudeDir ".gitignore") -Value $gitignore -Encoding UTF8
Write-Host " [OK] .gitignore 已写入" -ForegroundColor Green
# 3. 初始化 Git 仓库
Write-Host "[3/6] 初始化 Git 仓库..." -ForegroundColor White
Push-Location $ClaudeDir
try {
if (-not (Test-Path ".git")) {
git init
git checkout -b main
Write-Host " [OK] Git 仓库已初始化" -ForegroundColor Green
}
else {
Write-Host " [!] 已有 .git跳过初始化" -ForegroundColor Yellow
}
# 4. 暂存文件
Write-Host "[4/6] 暂存文件..." -ForegroundColor White
git add -A
# 人工确认待提交内容
$fileList = git diff --cached --name-only
$fileCount = ($fileList | Measure-Object -Line).Lines
$sizeEstimate = git diff --cached --stat | Select-Object -Last 1
Write-Host " 待提交: $fileCount 个文件" -ForegroundColor Gray
Write-Host " $sizeEstimate" -ForegroundColor DarkGray
# 检查是否有异常大文件
$largeFiles = git diff --cached --numstat | ForEach-Object {
$parts = $_ -split '\t'
if ($parts[2]) { $parts[2] }
} | ForEach-Object {
$item = Get-Item (Join-Path $ClaudeDir $_) -ErrorAction SilentlyContinue
$size = if ($item) { $item.Length } else { 0 }
if ($size -and $size -gt 1MB) {
[PSCustomObject]@{ File = $_; SizeMB = [math]::Round($size / 1MB, 1) }
}
}
if ($largeFiles) {
Write-Host ""
Write-Host " [!] 发现大文件 (>1MB):" -ForegroundColor Yellow
$largeFiles | ForEach-Object { Write-Host " $($_.SizeMB)MB $($_.File)" -ForegroundColor Yellow }
Write-Host ""
}
$confirm = Read-Host " 确认提交以上文件? (y/n)"
if ($confirm -ne 'y') {
Write-Host " 已取消" -ForegroundColor Yellow
exit 0
}
# 5. 提交
Write-Host "[5/6] 提交..." -ForegroundColor White
git commit -m "Bookworm v6.5.1 portable commit
Includes: CLAUDE.md, skills (92), agents (18), hooks (29),
scripts, constitution
Excludes: credentials, mcp-servers, node_modules, cache,
sessions, debug logs, project-specific data, gstack/browse binaries"
Write-Host " [OK] 提交完成" -ForegroundColor Green
# 6. 推送到 Gitea
Write-Host "[6/6] 推送到 Gitea..." -ForegroundColor White
$remoteExists = git remote -v 2>$null | Select-String "origin"
if (-not $remoteExists) {
git remote add origin $GitUrl
}
else {
git remote set-url origin $GitUrl
}
Write-Host " 推送到: $GitUrl" -ForegroundColor Gray
git push -u origin main 2>&1 | ForEach-Object { Write-Host " $_" }
} finally {
Pop-Location
}
# 统计
$repoSize = git -C $ClaudeDir count-objects -vH 2>$null | Select-String "size-pack"
Write-Host ""
Write-Host " ╔══════════════════════════════════════════╗" -ForegroundColor Green
Write-Host " ║ 仓库准备完成! ║" -ForegroundColor Green
Write-Host " ╠══════════════════════════════════════════╣" -ForegroundColor Green
Write-Host " ║ 远程: $GitUrl" -ForegroundColor Green
Write-Host "$repoSize" -ForegroundColor Green
Write-Host " ╚══════════════════════════════════════════╝" -ForegroundColor Green
Write-Host ""
Write-Host " 下一步:" -ForegroundColor Yellow
Write-Host " 1. 运行 .\encrypt-secrets.ps1 创建加密凭证" -ForegroundColor Yellow
Write-Host " 2. 将 USB 内容复制到 U 盘:" -ForegroundColor Yellow
Write-Host " install.ps1 + stop.ps1 + secrets.enc" -ForegroundColor Yellow
Write-Host " 3. 在目标机运行: .\install.ps1" -ForegroundColor Yellow