deploy-to-openclaw.ps1 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. param(
  2. [string]$SkillsRoot,
  3. [string]$SourceRoot = $PSScriptRoot,
  4. [switch]$DryRun
  5. )
  6. $ErrorActionPreference = "Stop"
  7. # Cross-platform home dir: $HOME works on Windows PowerShell 5+ and PowerShell 7 (Linux/Mac)
  8. if (-not $SkillsRoot) {
  9. $SkillsRoot = Join-Path (Join-Path $HOME ".openclaw") "skills"
  10. }
  11. $categories = @("wechat")
  12. Write-Host "=== OpenClaw WeChat Skill Deploy v1.2.0 ==="
  13. Write-Host "Source: $SourceRoot"
  14. Write-Host "Target: $SkillsRoot"
  15. if ($DryRun) { Write-Host "[DRY RUN]" -ForegroundColor Yellow }
  16. if (-not $DryRun -and -not (Test-Path $SkillsRoot)) {
  17. New-Item -ItemType Directory -Path $SkillsRoot -Force | Out-Null
  18. }
  19. $deployed = 0; $skipped = 0; $errors = 0
  20. foreach ($cat in $categories) {
  21. $catPath = Join-Path $SourceRoot $cat
  22. if (-not (Test-Path $catPath)) { continue }
  23. Write-Host "--- $cat ---" -ForegroundColor Cyan
  24. foreach ($skillDir in (Get-ChildItem -Directory -Path $catPath)) {
  25. $n = $skillDir.Name
  26. $sm = Join-Path $skillDir.FullName "SKILL.md"
  27. $ac = Join-Path $skillDir.FullName "api-config.json"
  28. if (-not (Test-Path $sm)) { $skipped++; continue }
  29. # api-config.json is optional reference material in v1.1.0+
  30. if (Test-Path $ac) {
  31. try { $null = Get-Content $ac -Raw -Encoding UTF8 | ConvertFrom-Json } catch { $errors++; continue }
  32. }
  33. $dest = Join-Path $SkillsRoot $n
  34. if ($DryRun) {
  35. if (Test-Path $dest) { $tag = 'UPDATE' } else { $tag = 'NEW' }
  36. Write-Host " [$tag] $n"
  37. } else {
  38. if (Test-Path $dest) { Remove-Item -Recurse -Force $dest }
  39. New-Item -ItemType Directory -Path $dest -Force | Out-Null
  40. Get-ChildItem -File -Path $skillDir.FullName | ForEach-Object { Copy-Item $_.FullName -Destination $dest }
  41. Write-Host " [OK] $n" -ForegroundColor Green
  42. }
  43. $deployed++
  44. }
  45. }
  46. Write-Host "Result: $deployed deployed, $skipped skipped, $errors errors"
  47. # Deploy workflows
  48. $wfSource = Join-Path $SourceRoot "workflows"
  49. $wfTarget = Join-Path (Split-Path $SkillsRoot -Parent) "workflows"
  50. if (Test-Path $wfSource) {
  51. Write-Host "--- workflows ---" -ForegroundColor Cyan
  52. if (-not $DryRun) {
  53. if (-not (Test-Path $wfTarget)) { New-Item -ItemType Directory -Path $wfTarget -Force | Out-Null }
  54. Get-ChildItem -File -Path $wfSource | ForEach-Object {
  55. Copy-Item $_.FullName -Destination $wfTarget -Force
  56. Write-Host " [OK] $($_.Name)" -ForegroundColor Green
  57. }
  58. } else {
  59. Get-ChildItem -File -Path $wfSource | ForEach-Object { Write-Host " [WORKFLOW] $($_.Name)" }
  60. }
  61. }
  62. $openclawDir = Split-Path $SkillsRoot -Parent
  63. if (-not $DryRun) {
  64. # Copy credentials template
  65. $tpl = Join-Path (Join-Path $SourceRoot "__config") "wechat-credentials.template.json"
  66. $dst = Join-Path $openclawDir "wechat-credentials.template.json"
  67. if (Test-Path $tpl) { Copy-Item $tpl -Destination $dst -Force; Write-Host "Template: $dst" }
  68. # Create default credentials if not exists
  69. $credFile = Join-Path $openclawDir "wechat-credentials.json"
  70. if (-not (Test-Path $credFile)) {
  71. Copy-Item $tpl -Destination $credFile -Force
  72. Write-Host "[!] Created $credFile - please edit wechatApiBase to your server address" -ForegroundColor Yellow
  73. }
  74. }
  75. # ---- Auto-reply daemon + config ----
  76. $daemonSrc = Join-Path (Join-Path $SourceRoot "daemon") "auto-reply-daemon.js"
  77. $daemonDst = Join-Path $openclawDir "auto-reply-daemon.js"
  78. $cfgTplSrc = Join-Path (Join-Path $SourceRoot "daemon") "wechat-auto-reply-config.template.json"
  79. $cfgTplDst = Join-Path $openclawDir "wechat-auto-reply-config.template.json"
  80. $cfgDst = Join-Path $openclawDir "wechat-auto-reply-config.json"
  81. if (Test-Path $daemonSrc) {
  82. Write-Host "--- auto-reply daemon ---" -ForegroundColor Cyan
  83. if ($DryRun) {
  84. Write-Host " [DAEMON] $daemonDst"
  85. Write-Host " [CONFIG-TEMPLATE] $cfgTplDst"
  86. if (-not (Test-Path $cfgDst)) { Write-Host " [CONFIG-DEFAULT] $cfgDst" }
  87. } else {
  88. Copy-Item $daemonSrc -Destination $daemonDst -Force
  89. Write-Host " [OK] $daemonDst" -ForegroundColor Green
  90. if (Test-Path $cfgTplSrc) {
  91. Copy-Item $cfgTplSrc -Destination $cfgTplDst -Force
  92. Write-Host " [OK] $cfgTplDst" -ForegroundColor Green
  93. if (-not (Test-Path $cfgDst)) {
  94. Copy-Item $cfgTplSrc -Destination $cfgDst -Force
  95. Write-Host " [!] Created default config: $cfgDst (edit to customize reply rules)" -ForegroundColor Yellow
  96. }
  97. }
  98. }
  99. }
  100. if (-not $DryRun) { Write-Host "Done!" -ForegroundColor Green }