deploy-to-openclaw.ps1 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.0.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) -or -not (Test-Path $ac)) { $skipped++; continue }
  29. try { $null = Get-Content $ac -Raw -Encoding UTF8 | ConvertFrom-Json } catch { $errors++; continue }
  30. $dest = Join-Path $SkillsRoot $n
  31. if ($DryRun) {
  32. if (Test-Path $dest) { $tag = 'UPDATE' } else { $tag = 'NEW' }
  33. Write-Host " [$tag] $n"
  34. } else {
  35. if (Test-Path $dest) { Remove-Item -Recurse -Force $dest }
  36. New-Item -ItemType Directory -Path $dest -Force | Out-Null
  37. Get-ChildItem -File -Path $skillDir.FullName | ForEach-Object { Copy-Item $_.FullName -Destination $dest }
  38. Write-Host " [OK] $n" -ForegroundColor Green
  39. }
  40. $deployed++
  41. }
  42. }
  43. Write-Host "Result: $deployed deployed, $skipped skipped, $errors errors"
  44. # Deploy workflows
  45. $wfSource = Join-Path $SourceRoot "workflows"
  46. $wfTarget = Join-Path (Split-Path $SkillsRoot -Parent) "workflows"
  47. if (Test-Path $wfSource) {
  48. Write-Host "--- workflows ---" -ForegroundColor Cyan
  49. if (-not $DryRun) {
  50. if (-not (Test-Path $wfTarget)) { New-Item -ItemType Directory -Path $wfTarget -Force | Out-Null }
  51. Get-ChildItem -File -Path $wfSource | ForEach-Object {
  52. Copy-Item $_.FullName -Destination $wfTarget -Force
  53. Write-Host " [OK] $($_.Name)" -ForegroundColor Green
  54. }
  55. } else {
  56. Get-ChildItem -File -Path $wfSource | ForEach-Object { Write-Host " [WORKFLOW] $($_.Name)" }
  57. }
  58. }
  59. if (-not $DryRun) {
  60. # Copy credentials template
  61. $tpl = Join-Path (Join-Path $SourceRoot "__config") "wechat-credentials.template.json"
  62. $dst = Join-Path (Split-Path $SkillsRoot -Parent) "wechat-credentials.template.json"
  63. if (Test-Path $tpl) { Copy-Item $tpl -Destination $dst -Force; Write-Host "Template: $dst" }
  64. # Create default credentials if not exists
  65. $credFile = Join-Path (Split-Path $SkillsRoot -Parent) "wechat-credentials.json"
  66. if (-not (Test-Path $credFile)) {
  67. Copy-Item $tpl -Destination $credFile -Force
  68. Write-Host "[!] Created $credFile - please edit wechatApiBase to your server address" -ForegroundColor Yellow
  69. }
  70. Write-Host "Done!" -ForegroundColor Green
  71. }