bookworm-boot/prepare-repo.ps1
bookworm 5e0ff18aa1 feat: Bookworm Portable v1.5 — 8 fixes (P0 NDA + P1 banners + P2 perf)
- P1: Banner v1.3→v1.5, Hooks 29→34
- P1: 卸载脚本补删 更新Bookworm.lnk
- P1: git stash pop 安全检查
- P2: Playwright 检测改用 npm list
- P2: 代理端口扫描 500ms async 超时

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

207 lines
5.9 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.

<#
.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
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$templateSrc = Join-Path $ScriptDir "settings.template.json"
$templateDst = Join-Path $ClaudeDir "settings.template.json"
if (Test-Path $templateSrc) {
Copy-Item $templateSrc $templateDst -Force
Write-Host "[1/6] settings.template.json 已放入 .claude/" -ForegroundColor Green
}
else {
Write-Host "[1/6] [WARN] settings.template.json 不在脚本目录,请手动创建" -ForegroundColor Yellow
}
# 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, settings.template.json
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