-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGoClaw-OneClickStart.ps1
More file actions
172 lines (138 loc) · 4.9 KB
/
Copy pathGoClaw-OneClickStart.ps1
File metadata and controls
172 lines (138 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
param(
[ValidateSet("launcher", "dev", "petclaw")]
[string]$Mode = "petclaw",
[switch]$NoBrowser,
[switch]$SkipNpmInstall,
[switch]$NoTerminalWindows
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
function Require-Command {
param([Parameter(Mandatory = $true)][string]$Name)
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
throw "Required command not found: $Name"
}
}
function Resolve-CommandPath {
param(
[Parameter(Mandatory = $true)][string]$Name,
[string[]]$Fallbacks = @()
)
$cmd = Get-Command $Name -ErrorAction SilentlyContinue
if ($cmd -and $cmd.Source) {
return $cmd.Source
}
foreach ($candidate in $Fallbacks) {
if (Test-Path $candidate) {
return $candidate
}
}
throw "Required command not found: $Name"
}
function Escape-SingleQuote {
param([Parameter(Mandatory = $true)][string]$Value)
return $Value -replace "'", "''"
}
function Get-ExitCodeOrDefault {
param([int]$Default = 0)
$lastExit = Get-Variable -Name LASTEXITCODE -Scope Global -ErrorAction SilentlyContinue
if ($null -ne $lastExit) {
return [int]$lastExit.Value
}
if (-not $?) {
return 1
}
return $Default
}
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
$FrontendRoot = Join-Path $Root "clawpet-frontend"
$Frontend = Join-Path $FrontendRoot "clawpet"
$PetClaw = Join-Path $FrontendRoot "clawpet"
$LauncherExe = Join-Path $Root "picoclaw-web.exe"
Write-Host "Project root: $Root"
Write-Host "Start mode: $Mode"
$runGoclawDev = Join-Path $Root "scripts\run-goclaw-dev.ps1"
if ($Mode -ne "launcher") {
if (-not (Test-Path $runGoclawDev)) {
throw "Startup script not found: $runGoclawDev"
}
if ($SkipNpmInstall) {
Write-Warning "-SkipNpmInstall is ignored when delegating to scripts\\run-goclaw-dev.ps1"
}
$delegateArgs = @(
"-ExecutionPolicy", "Bypass",
"-File", $runGoclawDev,
"-Restart",
"-PetclawMode", "prod"
)
if ($NoTerminalWindows) {
$delegateArgs += "-NoTerminalWindows"
}
if ($NoBrowser) {
Write-Warning "-NoBrowser is not used by scripts\\run-goclaw-dev.ps1 and will be ignored"
}
& powershell @delegateArgs
exit (Get-ExitCodeOrDefault)
}
if ($Mode -eq "launcher") {
if (-not (Test-Path $LauncherExe)) {
throw "Launcher not found: $LauncherExe"
}
$launcherArgs = @()
if ($NoBrowser) {
$launcherArgs += "-no-browser"
}
Write-Host "Launching Web UI launcher..."
& $LauncherExe @launcherArgs
exit (Get-ExitCodeOrDefault)
}
$goCmd = Resolve-CommandPath -Name "go" -Fallbacks @(
"C:\Program Files\Go\bin\go.exe"
)
$npmCmd = Resolve-CommandPath -Name "npm" -Fallbacks @(
"C:\Program Files\nodejs\npm.cmd",
"C:\Program Files (x86)\nodejs\npm.cmd"
)
if (-not (Test-Path $Frontend)) {
throw "Frontend folder not found: $Frontend"
}
if (-not (Test-Path $PetClaw)) {
throw "PetClaw folder not found: $PetClaw"
}
$rootEscaped = Escape-SingleQuote -Value $Root
$frontendEscaped = Escape-SingleQuote -Value $Frontend
$petclawEscaped = Escape-SingleQuote -Value $PetClaw
if (-not $SkipNpmInstall) {
$nodeModules = Join-Path $Frontend "node_modules"
if (-not (Test-Path $nodeModules)) {
Write-Host "Installing frontend dependencies..."
& "$npmCmd" install --prefix "$Frontend"
}
$petclawNodeModules = Join-Path $PetClaw "node_modules"
if (-not (Test-Path $petclawNodeModules)) {
Write-Host "Installing PetClaw dependencies..."
& "$npmCmd" install --prefix "$PetClaw"
}
}
$goEscaped = Escape-SingleQuote -Value $goCmd
$npmEscaped = Escape-SingleQuote -Value $npmCmd
$backendCommand = "Set-Location '$rootEscaped'; & '$goEscaped' run -tags 'goolm,stdjson' ./cmd/picoclaw gateway"
$frontendCommand = "Set-Location '$frontendEscaped'; & '$npmEscaped' run start"
$petclawCommand = "Set-Location '$petclawEscaped'; & '$npmEscaped' run dev"
if ($Mode -eq "petclaw") {
Write-Host "Starting backend in a new PowerShell window..."
Start-Process powershell -ArgumentList @("-NoExit", "-Command", $backendCommand) | Out-Null
Write-Host "Starting PetClaw frontend in a new PowerShell window..."
Start-Process powershell -ArgumentList @("-NoExit", "-Command", $petclawCommand) | Out-Null
if (-not $NoBrowser) {
Start-Sleep -Seconds 2
Start-Process "http://localhost:3000/onboarding"
}
Write-Host "Done. Keep both windows open while using the app."
exit 0
}
Write-Host "Starting backend in a new PowerShell window..."
Start-Process powershell -ArgumentList @("-NoExit", "-Command", $backendCommand) | Out-Null
Write-Host "Starting frontend in a new PowerShell window..."
Start-Process powershell -ArgumentList @("-NoExit", "-Command", $frontendCommand) | Out-Null
Write-Host "Done. Keep both windows open while using the app."