@powerhousedao/ph-cli 4.1.0-dev.63 → 4.1.0-dev.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,313 @@
1
+ # PowerShell script for setting up Powerhouse environment on Windows
2
+ param(
3
+ [string]$TARGET_TAG = "latest"
4
+ )
5
+
6
+ # Function to check if running as administrator
7
+ function Test-Administrator {
8
+ $user = [Security.Principal.WindowsIdentity]::GetCurrent()
9
+ $principal = New-Object Security.Principal.WindowsPrincipal $user
10
+ $principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
11
+ }
12
+
13
+ # Check if running as administrator
14
+ if (-not (Test-Administrator)) {
15
+ Write-Host "Please run this script as Administrator" -ForegroundColor Red
16
+ exit 1
17
+ }
18
+
19
+ # Install required packages using winget
20
+ Write-Host "Installing required packages..."
21
+ winget install -e --id PostgreSQL.PostgreSQL
22
+ winget install -e --id NGINX.NGINX
23
+
24
+ Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
25
+ Write-Host " Setting up global project"
26
+ Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
27
+
28
+ # Create installation directory if it doesn't exist
29
+ $installPath = "C:\www"
30
+ if (-not (Test-Path $installPath)) {
31
+ New-Item -ItemType Directory -Path $installPath
32
+ }
33
+ Set-Location $installPath
34
+
35
+ # Initialize Powerhouse project
36
+ ph init powerhouse --$TARGET_TAG
37
+ Set-Location powerhouse
38
+
39
+ # Interactive package installation loop
40
+ Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
41
+ Write-Host " Package Installation"
42
+ Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
43
+ while ($true) {
44
+ $package_name = Read-Host "Enter package name to install (or press Enter to skip)"
45
+ if ([string]::IsNullOrEmpty($package_name)) {
46
+ break
47
+ }
48
+ ph install $package_name
49
+ }
50
+
51
+ # Build Connect
52
+ ph connect build
53
+
54
+ # Database Configuration
55
+ Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
56
+ Write-Host " Database Configuration"
57
+ Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
58
+ Write-Host "Choose database type:"
59
+ Write-Host "1) Local PostgreSQL database"
60
+ Write-Host "2) Remote PostgreSQL database"
61
+ $db_choice = Read-Host "Enter your choice (1 or 2)"
62
+
63
+ if ($db_choice -eq "1") {
64
+ Write-Host "Setting up local PostgreSQL database..."
65
+
66
+ # Generate database credentials
67
+ $DB_PASSWORD = "powerhouse"
68
+ $DB_USER = "powerhouse"
69
+ $DB_NAME = "powerhouse"
70
+
71
+ # Create database and user using psql
72
+ $env:PGPASSWORD = "postgres" # Default PostgreSQL password
73
+ psql -U postgres -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASSWORD';"
74
+ psql -U postgres -c "CREATE DATABASE $DB_NAME OWNER $DB_USER;"
75
+ psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;"
76
+
77
+ # Set DATABASE_URL for local database
78
+ $DATABASE_URL = "postgresql://$DB_USER`:$DB_PASSWORD@localhost:5432/$DB_NAME"
79
+
80
+ Write-Host "Local database configured successfully!"
81
+ Write-Host "Database URL: $DATABASE_URL"
82
+ Write-Host "Please save these credentials securely!"
83
+ } else {
84
+ Write-Host "Enter remote PostgreSQL URL (format: postgresql://user:password@host:port/db)"
85
+ Write-Host "Example: postgresql://powerhouse:password@db.example.com:5432/powerhouse"
86
+ $DATABASE_URL = Read-Host "DATABASE_URL"
87
+ }
88
+
89
+ # Save DATABASE_URL to .env file
90
+ Add-Content -Path "$installPath\powerhouse\.env" -Value "DATABASE_URL=$DATABASE_URL"
91
+
92
+ # SSL Configuration choice
93
+ Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
94
+ Write-Host " SSL Configuration"
95
+ Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
96
+ Write-Host "Choose SSL configuration:"
97
+ Write-Host "1) Let's Encrypt certificates for domains"
98
+ Write-Host "2) Self-signed certificate for machine hostname"
99
+ $ssl_choice = Read-Host "Enter your choice (1 or 2)"
100
+
101
+ if ($ssl_choice -eq "1") {
102
+ # Install certbot for Let's Encrypt
103
+ winget install -e --id Certbot.Certbot
104
+
105
+ # Domain setup
106
+ Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
107
+ Write-Host " Domain Setup"
108
+ Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
109
+ $base_domain = Read-Host "Enter base domain (e.g. powerhouse.xyz)"
110
+ $connect_subdomain = Read-Host "Enter subdomain for Connect service (default: connect)"
111
+ $switchboard_subdomain = Read-Host "Enter subdomain for Switchboard service (default: switchboard)"
112
+
113
+ # Set default subdomains if not provided
114
+ if ([string]::IsNullOrEmpty($connect_subdomain)) { $connect_subdomain = "connect" }
115
+ if ([string]::IsNullOrEmpty($switchboard_subdomain)) { $switchboard_subdomain = "switchboard" }
116
+
117
+ # Construct full domains
118
+ $connect_domain = "$connect_subdomain.$base_domain"
119
+ $switchboard_domain = "$switchboard_subdomain.$base_domain"
120
+
121
+ Write-Host "Using domains:"
122
+ Write-Host "Connect: $connect_domain"
123
+ Write-Host "Switchboard: $switchboard_domain"
124
+
125
+ # Generate temporary SSL certificates
126
+ Write-Host "Generating temporary SSL certificates..."
127
+ $sslPath = "C:\nginx\ssl"
128
+ if (-not (Test-Path $sslPath)) {
129
+ New-Item -ItemType Directory -Path $sslPath
130
+ }
131
+
132
+ # Create Nginx configuration for domains
133
+ $nginxConfig = @"
134
+ # Security headers
135
+ add_header Strict-Transport-Security "max-age=63072000" always;
136
+ add_header X-Frame-Options DENY;
137
+ add_header X-Content-Type-Options nosniff;
138
+ add_header X-XSS-Protection "1; mode=block";
139
+
140
+ server {
141
+ listen 80;
142
+ server_name $connect_domain $switchboard_domain;
143
+ return 301 https://`$host`$request_uri;
144
+ }
145
+
146
+ server {
147
+ listen 443 ssl http2;
148
+ server_name $connect_domain;
149
+
150
+ ssl_certificate $sslPath\temp.crt;
151
+ ssl_certificate_key $sslPath\temp.key;
152
+
153
+ # SSL configuration
154
+ ssl_protocols TLSv1.2 TLSv1.3;
155
+ ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
156
+ ssl_prefer_server_ciphers off;
157
+ ssl_session_timeout 1d;
158
+ ssl_session_cache shared:SSL:50m;
159
+ ssl_session_tickets off;
160
+ ssl_stapling on;
161
+ ssl_stapling_verify on;
162
+
163
+ if (`$http_x_forwarded_proto = "http") {
164
+ return 301 https://`$server_name`$request_uri;
165
+ }
166
+
167
+ location / {
168
+ root C:/www/powerhouse/.ph/connect-build/dist;
169
+ try_files `$uri `$uri/ /index.html;
170
+ add_header Cache-Control "no-cache";
171
+ add_header X-Forwarded-Proto `$scheme;
172
+ add_header X-Forwarded-Host `$host;
173
+ add_header X-Forwarded-Port `$server_port;
174
+ }
175
+ }
176
+
177
+ server {
178
+ listen 443 ssl http2;
179
+ server_name $switchboard_domain;
180
+
181
+ ssl_certificate $sslPath\temp.crt;
182
+ ssl_certificate_key $sslPath\temp.key;
183
+
184
+ location / {
185
+ proxy_pass http://localhost:4001;
186
+ proxy_http_version 1.1;
187
+ proxy_set_header Upgrade `$http_upgrade;
188
+ proxy_set_header Connection 'upgrade';
189
+ proxy_set_header Host `$host;
190
+ proxy_cache_bypass `$http_upgrade;
191
+ proxy_set_header X-Real-IP `$remote_addr;
192
+ proxy_set_header X-Forwarded-For `$proxy_add_x_forwarded_for;
193
+ proxy_set_header X-Forwarded-Proto `$scheme;
194
+ }
195
+ }
196
+ "@
197
+
198
+ # Save Nginx configuration
199
+ $nginxConfig | Out-File -FilePath "C:\nginx\conf\sites-available\powerhouse.conf" -Encoding UTF8
200
+
201
+ # Create symbolic link to enable the site
202
+ if (-not (Test-Path "C:\nginx\conf\sites-enabled")) {
203
+ New-Item -ItemType Directory -Path "C:\nginx\conf\sites-enabled"
204
+ }
205
+ New-Item -ItemType SymbolicLink -Path "C:\nginx\conf\sites-enabled\powerhouse.conf" -Target "C:\nginx\conf\sites-available\powerhouse.conf" -Force
206
+
207
+ # Test Nginx configuration
208
+ nginx -t
209
+
210
+ # Restart Nginx
211
+ Stop-Service nginx
212
+ Start-Service nginx
213
+
214
+ # Obtain SSL certificates
215
+ Write-Host "Obtaining SSL certificates..."
216
+ certbot --nginx -d $connect_domain -d $switchboard_domain --non-interactive --agree-tos --email "admin@$base_domain"
217
+
218
+ } else {
219
+ # Get machine hostname
220
+ $hostname = [System.Net.Dns]::GetHostName()
221
+
222
+ # Generate self-signed certificate
223
+ Write-Host "Generating self-signed certificate for $hostname..."
224
+ $sslPath = "C:\nginx\ssl"
225
+ if (-not (Test-Path $sslPath)) {
226
+ New-Item -ItemType Directory -Path $sslPath
227
+ }
228
+
229
+ # Create Nginx configuration for self-signed
230
+ $nginxConfig = @"
231
+ # Security headers
232
+ add_header Strict-Transport-Security "max-age=63072000" always;
233
+ add_header X-Frame-Options DENY;
234
+ add_header X-Content-Type-Options nosniff;
235
+ add_header X-XSS-Protection "1; mode=block";
236
+
237
+ server {
238
+ listen 80;
239
+ server_name $hostname;
240
+ return 301 https://`$host`$request_uri;
241
+ }
242
+
243
+ server {
244
+ listen 443 ssl http2;
245
+ server_name $hostname;
246
+
247
+ ssl_certificate $sslPath\$hostname.crt;
248
+ ssl_certificate_key $sslPath\$hostname.key;
249
+
250
+ location /connect {
251
+ proxy_pass http://localhost:3000;
252
+ proxy_http_version 1.1;
253
+ proxy_set_header Upgrade `$http_upgrade;
254
+ proxy_set_header Connection 'upgrade';
255
+ proxy_set_header Host `$host;
256
+ proxy_cache_bypass `$http_upgrade;
257
+ proxy_set_header X-Real-IP `$remote_addr;
258
+ proxy_set_header X-Forwarded-For `$proxy_add_x_forwarded_for;
259
+ proxy_set_header X-Forwarded-Proto `$scheme;
260
+ }
261
+
262
+ location /switchboard {
263
+ proxy_pass http://localhost:4001;
264
+ proxy_http_version 1.1;
265
+ proxy_set_header Upgrade `$http_upgrade;
266
+ proxy_set_header Connection 'upgrade';
267
+ proxy_set_header Host `$host;
268
+ proxy_cache_bypass `$http_upgrade;
269
+ proxy_set_header X-Real-IP `$remote_addr;
270
+ proxy_set_header X-Forwarded-For `$proxy_add_x_forwarded_for;
271
+ proxy_set_header X-Forwarded-Proto `$scheme;
272
+ }
273
+ }
274
+ "@
275
+
276
+ # Save Nginx configuration
277
+ $nginxConfig | Out-File -FilePath "C:\nginx\conf\sites-available\powerhouse.conf" -Encoding UTF8
278
+
279
+ # Create symbolic link to enable the site
280
+ if (-not (Test-Path "C:\nginx\conf\sites-enabled")) {
281
+ New-Item -ItemType Directory -Path "C:\nginx\conf\sites-enabled"
282
+ }
283
+ New-Item -ItemType SymbolicLink -Path "C:\nginx\conf\sites-enabled\powerhouse.conf" -Target "C:\nginx\conf\sites-available\powerhouse.conf" -Force
284
+
285
+ # Test Nginx configuration
286
+ nginx -t
287
+
288
+ # Restart Nginx
289
+ Stop-Service nginx
290
+ Start-Service nginx
291
+ }
292
+
293
+ # Install PM2 globally if not already installed
294
+ if (-not (Get-Command pm2 -ErrorAction SilentlyContinue)) {
295
+ pnpm install -g pm2
296
+ }
297
+
298
+ # Run database migrations
299
+ pnpm prisma db push --schema node_modules/document-drive/dist/prisma/schema.prisma
300
+
301
+ # Start services with PM2
302
+ Write-Host "Starting services with PM2..."
303
+ if ($ssl_choice -eq "2") {
304
+ # Self-signed certificate - use base paths
305
+ pm2 start pnpm switchboard --name "switchboard" -- --base-path /switchboard
306
+ } else {
307
+ # Let's Encrypt - no base paths needed
308
+ pm2 start "pnpm switchboard" --name "switchboard"
309
+ }
310
+
311
+ # Save PM2 process list and setup startup script
312
+ pm2 save
313
+ pm2 startup
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env bash
2
+ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
3
+ \. ~/.nvm/nvm.sh
4
+ export NVM_DIR="$HOME/.nvm"
5
+ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
6
+ [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
7
+ nvm --version
8
+ nvm install 22
9
+ curl -fsSL https://get.pnpm.io/install.sh | sh -
10
+ export PNPM_HOME="/home/$USER/.local/share/pnpm"
11
+ export PATH="$PNPM_HOME:$PATH"
12
+ pnpm install -g ph-cmd
13
+ echo ""
14
+ echo " 🎉 Setup Complete! 🎉"
15
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
16
+ echo " To complete installation:"
17
+ echo " 1. Restart your terminal"
18
+ echo " OR"
19
+ echo " Run: source ~/.bashrc"
20
+ echo ""
21
+ echo " 2. Start using Powerhouse by typing:"
22
+ echo " ph"
23
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
24
+ echo ""
@@ -0,0 +1,2 @@
1
+ export declare const version = "4.1.0-dev.64";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ // This file is auto-generated. DO NOT EDIT.
2
+ export const version = "4.1.0-dev.64";
3
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,CAAC,MAAM,OAAO,GAAG,cAAc,CAAC"}