# 一键安装 script-to-doodle-animation skill 到 Claude Code
# 用法：双击 install.cmd，或 pwsh -File install.ps1 [-Target <skills目录>]
param(
    # 默认装到用户级 skills（全部项目可用）；装到某项目则传 <项目>\.claude\skills
    [string]$Target = "$env:USERPROFILE\.claude\skills"
)
$ErrorActionPreference = 'Stop'
$name = 'script-to-doodle-animation'
$src = Join-Path $PSScriptRoot $name
$dst = Join-Path $Target $name

if (-not (Test-Path (Join-Path $src 'SKILL.md'))) {
    Write-Host "[X] 找不到 skill 源目录: $src" -ForegroundColor Red
    exit 1
}

New-Item -ItemType Directory -Force -Path $Target | Out-Null

# 已有旧版则先备份，不覆盖丢数据
if (Test-Path $dst) {
    $bak = "$dst.bak-$(Get-Date -Format 'yyyyMMdd-HHmmss')"
    Write-Host "检测到已安装旧版，备份到 $bak"
    Move-Item $dst $bak
}

Copy-Item $src $dst -Recurse
Write-Host ""
Write-Host "[OK] 已安装到 $dst" -ForegroundColor Green

# ---- 依赖体检（仅提示，不阻塞安装）----
Write-Host ""
Write-Host "依赖体检：" -ForegroundColor Cyan

function Check($label, $script, $hint) {
    try {
        $null = & $script 2>$null
        if ($LASTEXITCODE -eq 0 -or $?) { Write-Host "  [OK] $label" -ForegroundColor Green; return }
    } catch {}
    Write-Host "  [--] $label  → $hint" -ForegroundColor Yellow
}

Check 'Python 3.10+'        { python -V }                          '安装 Python 并加入 PATH'
Check 'edge-tts（配音）'     { python -c 'import edge_tts' }        'pip install edge-tts'
Check 'fonttools+brotli'    { python -c 'import fontTools, brotli' } 'pip install fonttools brotli'
Check 'Node 18+'            { node -v }                            '安装 Node.js'
Check 'playwright（渲mp4）' { node -e "require('playwright')" }    '技能根目录 npm i playwright && npx playwright install chromium'
Check 'ffmpeg'              { ffmpeg -version }                    '安装 ffmpeg 并加入 PATH'

Write-Host ""
Write-Host "完成。重启 Claude Code（或新开会话）后，把一段中文文稿发给 agent，" -ForegroundColor Cyan
Write-Host "说「做成简笔画讲解动画」即可自动触发本技能。" -ForegroundColor Cyan
Write-Host "卸载：删除 $dst"
