@powerhousedao/ph-cli 6.0.0-dev.40 → 6.0.0-dev.41

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,45 @@
1
+ import { writeCliDocsMarkdownFile } from "@powerhousedao/codegen/file-builders";
2
+ import { accessToken } from "../src/commands/access-token.js";
3
+ import { build, connect, preview, studio } from "../src/commands/connect.js";
4
+ import { generate } from "../src/commands/generate.js";
5
+ import { inspect } from "../src/commands/inspect.js";
6
+ import { install } from "../src/commands/install.js";
7
+ import { list } from "../src/commands/list.js";
8
+ import { login } from "../src/commands/login.js";
9
+ import { migrate } from "../src/commands/migrate.js";
10
+ import { phCli } from "../src/commands/ph-cli.js";
11
+ import { switchboard } from "../src/commands/switchboard.js";
12
+ import { uninstall } from "../src/commands/uninstall.js";
13
+ import { vetra } from "../src/commands/vetra.js";
14
+
15
+ const commands = [
16
+ { name: "generate", command: generate },
17
+ { name: "vetra", command: vetra },
18
+ { name: "connect", command: connect },
19
+ { name: "connect studio", command: studio },
20
+ { name: "connect build", command: build },
21
+ { name: "connect preview", command: preview },
22
+ { name: "access token", command: accessToken },
23
+ { name: "inspect", command: inspect },
24
+ { name: "list", command: list },
25
+ { name: "migrate", command: migrate },
26
+ { name: "switchboard", command: switchboard },
27
+ { name: "login", command: login },
28
+ { name: "install", command: install },
29
+ { name: "uninstall", command: uninstall },
30
+ ];
31
+
32
+ const cliDescription = phCli.description ?? "";
33
+
34
+ async function main() {
35
+ await writeCliDocsMarkdownFile({
36
+ filePath: "COMMANDS.md",
37
+ docsTitle: `Powerhouse CLI Commands (${process.env.WORKSPACE_VERSION || process.env.npm_package_version})`,
38
+ docsIntroduction:
39
+ "This document provides detailed information about the available commands in the Powerhouse CLI.",
40
+ cliDescription,
41
+ entries: commands,
42
+ });
43
+ }
44
+
45
+ await main();
@@ -0,0 +1,84 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import { fileURLToPath } from "url";
4
+
5
+ /**
6
+ * Generate COMMANDS.md file from the help texts in help.ts
7
+ */
8
+ async function generateCommandsMd() {
9
+ try {
10
+ // Define paths for ES modules
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = path.dirname(__filename);
13
+ const rootDir = path.resolve(__dirname, "..");
14
+ const helpFilePath = path.join(rootDir, "src", "help.ts");
15
+ const outputPath = path.join(rootDir, "COMMANDS-LEGACY.md");
16
+
17
+ // Read the help.ts file
18
+ const helpFileContent = fs.readFileSync(helpFilePath, "utf8");
19
+
20
+ // Extract all help text constants using regex
21
+ const helpTextRegex = /export const (\w+)Help = `([\s\S]+?)`;/g;
22
+ const commands: { name: string; content: string }[] = [];
23
+
24
+ let match;
25
+ while ((match = helpTextRegex.exec(helpFileContent)) !== null) {
26
+ const commandName = match[1];
27
+ const helpContent = match[2];
28
+ commands.push({ name: commandName, content: helpContent });
29
+ }
30
+
31
+ // Sort commands alphabetically
32
+ commands.sort((a, b) => a.name.localeCompare(b.name));
33
+
34
+ // Generate the markdown content
35
+ let markdown = "# Powerhouse CLI Commands\n\n";
36
+ markdown +=
37
+ "This document provides detailed information about the available commands in the Powerhouse CLI.\n\n";
38
+ markdown += "## Table of Contents\n\n";
39
+
40
+ // Add table of contents
41
+ commands.forEach((command) => {
42
+ const displayName = formatCommandName(command.name);
43
+ const anchor = displayName.toLowerCase().replace(/\s+/g, "-");
44
+ markdown += `- [${displayName}](#${anchor})\n`;
45
+ });
46
+
47
+ markdown += "\n";
48
+
49
+ // Add command details
50
+ commands.forEach((command) => {
51
+ const displayName = formatCommandName(command.name);
52
+ markdown += `## ${displayName}\n\n`;
53
+ markdown += "```\n";
54
+ markdown += command.content.trim();
55
+ markdown += "\n```\n\n";
56
+ });
57
+
58
+ // Add footer
59
+ markdown += "---\n\n";
60
+ markdown +=
61
+ "*This document was automatically generated from the help text in the codebase.*\n";
62
+
63
+ // Write to COMMANDS.md
64
+ fs.writeFileSync(outputPath, markdown);
65
+
66
+ console.log(`✅ COMMANDS.md has been generated at ${outputPath}`);
67
+ } catch (error) {
68
+ console.error("Failed to generate COMMANDS.md:", error);
69
+ process.exit(1);
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Format command name for display (e.g., "setupGlobals" -> "Setup Globals")
75
+ */
76
+ function formatCommandName(commandName: string): string {
77
+ // Convert camelCase to separate words with spaces
78
+ const name = commandName.replace(/([A-Z])/g, " $1").trim();
79
+ // Capitalize first letter and convert the rest to lowercase
80
+ return name.charAt(0).toUpperCase() + name.slice(1);
81
+ }
82
+
83
+ // Run the script
84
+ generateCommandsMd();
@@ -0,0 +1,22 @@
1
+ import { readFileSync, writeFileSync } from "fs";
2
+ import { join } from "path";
3
+ import { fileURLToPath } from "url";
4
+
5
+ interface PackageJson {
6
+ version: string;
7
+ }
8
+
9
+ const __dirname = fileURLToPath(new URL(".", import.meta.url));
10
+
11
+ // Read package.json
12
+ const packageJson = JSON.parse(
13
+ readFileSync(join(__dirname, "../package.json"), "utf-8"),
14
+ ) as PackageJson;
15
+
16
+ // Generate version.ts content
17
+ const versionFileContent = `// This file is auto-generated. DO NOT EDIT.
18
+ export const version = "${packageJson.version}";
19
+ `;
20
+
21
+ // Write version.ts
22
+ writeFileSync(join(__dirname, "../src/version.ts"), versionFileContent);
@@ -0,0 +1,199 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # =============================================================================
4
+ # Configuration
5
+ # =============================================================================
6
+ PROJECT_NAME=${1:-"global"}
7
+ ACTION=${2:-"status"}
8
+
9
+ # Nginx config file name - remove leading dot to avoid hidden file issues
10
+ # (nginx's include directive with * glob doesn't match hidden files)
11
+ NGINX_CONFIG_NAME="${PROJECT_NAME#.}"
12
+ if [ "$NGINX_CONFIG_NAME" = "" ]; then
13
+ NGINX_CONFIG_NAME="default-ph"
14
+ fi
15
+
16
+ # Get Switchboard port from .env or use default
17
+ if [ -f ".env" ]; then
18
+ SWITCHBOARD_PORT=$(grep "SWITCHBOARD_PORT=" .env | cut -d'=' -f2)
19
+ fi
20
+ SWITCHBOARD_PORT=${SWITCHBOARD_PORT:-4001}
21
+
22
+ # =============================================================================
23
+ # OS Detection and Windows Handling
24
+ # =============================================================================
25
+ if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
26
+ if [ -f "$0.ps1" ]; then
27
+ powershell -ExecutionPolicy Bypass -File "$0.ps1" -PROJECT_NAME "$PROJECT_NAME" -ACTION "$ACTION"
28
+ else
29
+ echo "Error: Windows management script (manage-environment.ps1) not found"
30
+ exit 1
31
+ fi
32
+ else
33
+ # =============================================================================
34
+ # Service Management
35
+ # =============================================================================
36
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
37
+ echo " Managing project: $PROJECT_NAME"
38
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
39
+
40
+ # Function to check if service is properly set up
41
+ check_setup() {
42
+ local project_name=$1
43
+ local error=0
44
+
45
+ # Check if .env file exists
46
+ if [ ! -f ".env" ]; then
47
+ echo "Error: .env file not found in project directory"
48
+ error=1
49
+ fi
50
+
51
+ # Check if Nginx configuration exists
52
+ if [ ! -f "/etc/nginx/sites-available/$NGINX_CONFIG_NAME" ]; then
53
+ echo "Error: Nginx configuration not found at /etc/nginx/sites-available/$NGINX_CONFIG_NAME"
54
+ error=1
55
+ fi
56
+
57
+ # Check if database is configured
58
+ if ! grep -q "DATABASE_URL" ".env"; then
59
+ echo "Error: Database configuration not found in .env file"
60
+ error=1
61
+ fi
62
+
63
+ if [ $error -eq 1 ]; then
64
+ echo "Please run 'ph setup-environment' first to set up the service"
65
+ exit 1
66
+ fi
67
+ }
68
+
69
+ # Function to enable/disable Nginx site
70
+ manage_nginx_site() {
71
+ local action=$1
72
+ local site_path="/etc/nginx/sites-available/$NGINX_CONFIG_NAME"
73
+ local enabled_path="/etc/nginx/sites-enabled/$NGINX_CONFIG_NAME"
74
+
75
+ if [ ! -f "$site_path" ]; then
76
+ echo "Error: Nginx site configuration for $NGINX_CONFIG_NAME not found"
77
+ return 1
78
+ fi
79
+
80
+ case "$action" in
81
+ "enable")
82
+ if [ ! -L "$enabled_path" ]; then
83
+ sudo ln -sf "$site_path" "$enabled_path"
84
+ sudo nginx -t && sudo nginx -s reload
85
+ fi
86
+ ;;
87
+ "disable")
88
+ if [ -L "$enabled_path" ]; then
89
+ sudo rm -f "$enabled_path"
90
+ sudo nginx -t && sudo nginx -s reload
91
+ fi
92
+ ;;
93
+ esac
94
+ }
95
+
96
+ # Function to start services
97
+ start_services() {
98
+ check_setup "$PROJECT_NAME"
99
+ echo "Starting services..."
100
+ # Build Connect
101
+ echo "Building Connect..."
102
+ ph connect build
103
+ sudo rm -rf /var/www/html/${PROJECT_NAME}
104
+ sudo mkdir -p /var/www/html/${PROJECT_NAME}
105
+ sudo cp -r .ph/connect-build/dist/* /var/www/html/${PROJECT_NAME}/
106
+
107
+ # Enable Nginx site
108
+ manage_nginx_site "enable"
109
+
110
+ # Start Switchboard via PM2
111
+ if ! pm2 list | grep -q "switchboard_${PROJECT_NAME}"; then
112
+ cd $PROJECT_NAME
113
+ pm2 start "pnpm switchboard --port $SWITCHBOARD_PORT" --name "switchboard_${PROJECT_NAME}"
114
+ pm2 save
115
+ else
116
+ pm2 start "switchboard_${PROJECT_NAME}"
117
+ fi
118
+ }
119
+
120
+ # Function to stop services
121
+ stop_services() {
122
+ check_setup "$PROJECT_NAME"
123
+ echo "Stopping services..."
124
+ # Stop Switchboard via PM2
125
+ if pm2 list | grep -q "switchboard_${PROJECT_NAME}"; then
126
+ pm2 stop "switchboard_${PROJECT_NAME}"
127
+ fi
128
+
129
+ # Disable Nginx site
130
+ manage_nginx_site "disable"
131
+ }
132
+
133
+ case "$ACTION" in
134
+ "start")
135
+ start_services
136
+ ;;
137
+
138
+ "stop")
139
+ stop_services
140
+ ;;
141
+
142
+ "restart")
143
+ echo "Restarting services..."
144
+ stop_services
145
+ start_services
146
+ ;;
147
+
148
+ "status")
149
+ check_setup "$PROJECT_NAME"
150
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
151
+ echo " Service Status for $PROJECT_NAME"
152
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
153
+
154
+ # Create table header
155
+ printf "%-15s %-10s %-15s %-10s %-10s\n" "Service" "Status" "Memory" "Uptime" "Health"
156
+ echo "────────────────────────────────────────────────────────────────────"
157
+
158
+ # Check Connect status
159
+ connect_status="Disabled"
160
+ connect_health="❌"
161
+ connect_memory="N/A"
162
+ connect_uptime="N/A"
163
+ if [ -L "/etc/nginx/sites-enabled/$NGINX_CONFIG_NAME" ]; then
164
+ connect_status="Enabled"
165
+ # Check if Connect is reachable
166
+ if curl -s -f "http://localhost/$PROJECT_NAME" > /dev/null; then
167
+ connect_health="✅"
168
+ fi
169
+ # Get Nginx memory usage for the site
170
+ nginx_pid=$(pgrep -f "nginx.*$PROJECT_NAME" | head -n 1)
171
+ if [ -n "$nginx_pid" ]; then
172
+ connect_memory=$(ps -o rss= -p "$nginx_pid" 2>/dev/null | awk '{printf "%.1fmb", $1/1024}')
173
+ connect_uptime=$(ps -o etime= -p "$nginx_pid" 2>/dev/null)
174
+ fi
175
+ fi
176
+ printf "%-15s %-10s %-15s %-10s %-10s\n" "Connect" "$connect_status" "$connect_memory" "$connect_uptime" "$connect_health"
177
+
178
+ # Check Switchboard status
179
+ switchboard_info=$(pm2 list | grep "switchboard_${PROJECT_NAME}")
180
+ if [ -n "$switchboard_info" ]; then
181
+ switchboard_status="Enabled"
182
+ switchboard_memory=$(echo "$switchboard_info" | awk '{print $12}')
183
+ switchboard_uptime=$(echo "$switchboard_info" | awk '{print $7}')
184
+ switchboard_health="✅"
185
+ printf "%-15s %-10s %-15s %-10s %-10s\n" "Switchboard" "$switchboard_status" "$switchboard_memory" "$switchboard_uptime" "$switchboard_health"
186
+ else
187
+ printf "%-15s %-10s %-15s %-10s %-10s\n" "Switchboard" "Disabled" "N/A" "N/A" "❌"
188
+ fi
189
+ echo "────────────────────────────────────────────────────────────────────"
190
+ ;;
191
+
192
+ *)
193
+ echo "Usage: $0 [project_name] {start|stop|restart|status}"
194
+ echo "Default project_name: global"
195
+ echo "Default action: status"
196
+ exit 1
197
+ ;;
198
+ esac
199
+ fi