deploy-to-openclaw.ps1 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. param(
  2. [string]$SkillsRoot = "$env:USERPROFILE\.openclaw\skills",
  3. [string]$SourceRoot = $PSScriptRoot,
  4. [switch]$DryRun
  5. )
  6. $ErrorActionPreference = "Stop"
  7. $categories = @("wechat")
  8. Write-Host "=== OpenClaw WeChat Skill Deploy v1.0.0 ==="
  9. Write-Host "Source: $SourceRoot"
  10. Write-Host "Target: $SkillsRoot"
  11. if ($DryRun) { Write-Host "[DRY RUN]" -ForegroundColor Yellow }
  12. if (-not $DryRun -and -not (Test-Path $SkillsRoot)) {
  13. New-Item -ItemType Directory -Path $SkillsRoot -Force | Out-Null
  14. }
  15. $deployed = 0; $skipped = 0; $errors = 0
  16. foreach ($cat in $categories) {
  17. $catPath = Join-Path $SourceRoot $cat
  18. if (-not (Test-Path $catPath)) { continue }
  19. Write-Host "--- $cat ---" -ForegroundColor Cyan
  20. foreach ($skillDir in (Get-ChildItem -Directory -Path $catPath)) {
  21. $n = $skillDir.Name
  22. $sm = Join-Path $skillDir.FullName "SKILL.md"
  23. $ac = Join-Path $skillDir.FullName "api-config.json"
  24. if (-not (Test-Path $sm) -or -not (Test-Path $ac)) { $skipped++; continue }
  25. try { $null = Get-Content $ac -Raw -Encoding UTF8 | ConvertFrom-Json } catch { $errors++; continue }
  26. $dest = Join-Path $SkillsRoot $n
  27. if ($DryRun) {
  28. Write-Host " [$( if (Test-Path $dest){'UPDATE'}else{'NEW'} )] $n"
  29. } else {
  30. if (Test-Path $dest) { Remove-Item -Recurse -Force $dest }
  31. New-Item -ItemType Directory -Path $dest -Force | Out-Null
  32. Get-ChildItem -File -Path $skillDir.FullName | ForEach-Object { Copy-Item $_.FullName -Destination $dest }
  33. Write-Host " [OK] $n" -ForegroundColor Green
  34. }
  35. $deployed++
  36. }
  37. }
  38. Write-Host "Result: $deployed deployed, $skipped skipped, $errors errors"
  39. # Deploy workflows
  40. $wfSource = Join-Path $SourceRoot "workflows"
  41. $wfTarget = Join-Path (Split-Path $SkillsRoot -Parent) "workflows"
  42. if (Test-Path $wfSource) {
  43. Write-Host "--- workflows ---" -ForegroundColor Cyan
  44. if (-not $DryRun) {
  45. if (-not (Test-Path $wfTarget)) { New-Item -ItemType Directory -Path $wfTarget -Force | Out-Null }
  46. Get-ChildItem -File -Path $wfSource | ForEach-Object {
  47. Copy-Item $_.FullName -Destination $wfTarget -Force
  48. Write-Host " [OK] $($_.Name)" -ForegroundColor Green
  49. }
  50. } else {
  51. Get-ChildItem -File -Path $wfSource | ForEach-Object { Write-Host " [WORKFLOW] $($_.Name)" }
  52. }
  53. }
  54. if (-not $DryRun) {
  55. # Copy credentials template
  56. $tpl = Join-Path $SourceRoot "__config\wechat-credentials.template.json"
  57. $dst = Join-Path (Split-Path $SkillsRoot -Parent) "wechat-credentials.template.json"
  58. if (Test-Path $tpl) { Copy-Item $tpl -Destination $dst -Force; Write-Host "Template: $dst" }
  59. # Create default credentials if not exists
  60. $credFile = Join-Path (Split-Path $SkillsRoot -Parent) "wechat-credentials.json"
  61. if (-not (Test-Path $credFile)) {
  62. Copy-Item $tpl -Destination $credFile -Force
  63. Write-Host "[!] Created $credFile - please edit wechatApiBase to your server address" -ForegroundColor Yellow
  64. }
  65. Write-Host "Done!" -ForegroundColor Green
  66. }