@powerhousedao/ph-cli 0.41.2 → 2.5.0-dev.0

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.
Files changed (76) hide show
  1. package/README.md +122 -18
  2. package/dist/package.json +13 -1
  3. package/dist/scripts/generate-commands-md.ts +84 -0
  4. package/dist/scripts/generate-version.ts +22 -0
  5. package/dist/scripts/manage-environment +190 -0
  6. package/dist/scripts/setup-environment +380 -0
  7. package/dist/scripts/setup-environment.ps1 +313 -0
  8. package/dist/scripts/setup.sh +24 -0
  9. package/dist/src/cli.js +17 -2
  10. package/dist/src/cli.js.map +1 -1
  11. package/dist/src/commands/connect.d.ts +1 -1
  12. package/dist/src/commands/connect.d.ts.map +1 -1
  13. package/dist/src/commands/connect.js +39 -9
  14. package/dist/src/commands/connect.js.map +1 -1
  15. package/dist/src/commands/index.d.ts.map +1 -1
  16. package/dist/src/commands/index.js +3 -1
  17. package/dist/src/commands/index.js.map +1 -1
  18. package/dist/src/commands/install.d.ts +2 -1
  19. package/dist/src/commands/install.d.ts.map +1 -1
  20. package/dist/src/commands/install.js +39 -10
  21. package/dist/src/commands/install.js.map +1 -1
  22. package/dist/src/commands/list.d.ts.map +1 -1
  23. package/dist/src/commands/list.js +2 -2
  24. package/dist/src/commands/list.js.map +1 -1
  25. package/dist/src/commands/reactor.d.ts +9 -0
  26. package/dist/src/commands/reactor.d.ts.map +1 -0
  27. package/dist/src/commands/reactor.js +39 -0
  28. package/dist/src/commands/reactor.js.map +1 -0
  29. package/dist/src/commands/service.d.ts +1 -1
  30. package/dist/src/commands/service.d.ts.map +1 -1
  31. package/dist/src/commands/service.js +48 -126
  32. package/dist/src/commands/service.js.map +1 -1
  33. package/dist/src/commands/switchboard.d.ts +5 -5
  34. package/dist/src/commands/switchboard.d.ts.map +1 -1
  35. package/dist/src/commands/switchboard.js +18 -12
  36. package/dist/src/commands/switchboard.js.map +1 -1
  37. package/dist/src/commands/uninstall.d.ts.map +1 -1
  38. package/dist/src/commands/uninstall.js +10 -1
  39. package/dist/src/commands/uninstall.js.map +1 -1
  40. package/dist/src/help.d.ts +15 -3
  41. package/dist/src/help.d.ts.map +1 -1
  42. package/dist/src/help.js +80 -15
  43. package/dist/src/help.js.map +1 -1
  44. package/dist/src/services/connect.js +1 -1
  45. package/dist/src/services/connect.js.map +1 -1
  46. package/dist/src/services/dev.d.ts.map +1 -1
  47. package/dist/src/services/dev.js +2 -2
  48. package/dist/src/services/dev.js.map +1 -1
  49. package/dist/src/services/generate.js +1 -1
  50. package/dist/src/services/generate.js.map +1 -1
  51. package/dist/src/services/inspect.d.ts.map +1 -1
  52. package/dist/src/services/inspect.js +3 -2
  53. package/dist/src/services/inspect.js.map +1 -1
  54. package/dist/src/services/reactor.d.ts +32 -0
  55. package/dist/src/services/reactor.d.ts.map +1 -0
  56. package/dist/src/services/reactor.js +66 -0
  57. package/dist/src/services/reactor.js.map +1 -0
  58. package/dist/src/services/switchboard.d.ts +2 -31
  59. package/dist/src/services/switchboard.d.ts.map +1 -1
  60. package/dist/src/services/switchboard.js +24 -58
  61. package/dist/src/services/switchboard.js.map +1 -1
  62. package/dist/src/utils.d.ts +11 -3
  63. package/dist/src/utils.d.ts.map +1 -1
  64. package/dist/src/utils.js +8 -7
  65. package/dist/src/utils.js.map +1 -1
  66. package/dist/src/version.d.ts +1 -1
  67. package/dist/src/version.d.ts.map +1 -1
  68. package/dist/src/version.js +1 -1
  69. package/dist/src/version.js.map +1 -1
  70. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  71. package/dist/vitest.config.d.ts +3 -0
  72. package/dist/vitest.config.d.ts.map +1 -0
  73. package/dist/vitest.config.js +7 -0
  74. package/dist/vitest.config.js.map +1 -0
  75. package/package.json +20 -8
  76. package/dist/tsconfig.tsbuildinfo +0 -1
package/README.md CHANGED
@@ -1,18 +1,72 @@
1
1
  # Powerhouse CLI (ph-cli)
2
2
 
3
- A command-line interface tool for Powerhouse DAO that helps you manage and interact with Powerhouse packages and services.
3
+ [![npm version](https://img.shields.io/npm/v/ph-cli.svg)](https://www.npmjs.com/package/ph-cli)
4
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
6
+
7
+ A powerful command-line interface tool for Powerhouse DAO that streamlines the development and management of Powerhouse packages and services. The CLI provides a unified interface for common development tasks, package management, and service operations.
8
+
9
+ ## Table of Contents
10
+
11
+ - [Features](#features)
12
+ - [Installation](#installation)
13
+ - [Quick Start](#quick-start)
14
+ - [Commands](#commands)
15
+ - [Connect](#ph-connect)
16
+ - [Generate](#ph-generate)
17
+ - [Install](#ph-install)
18
+ - [Uninstall](#ph-uninstall)
19
+ - [List](#ph-list)
20
+ - [Inspect](#ph-inspect)
21
+ - [Service](#ph-service)
22
+ - [Version](#ph-version)
23
+ - [Help](#ph-help)
24
+ - [Configuration](#configuration)
25
+ - [Troubleshooting](#troubleshooting)
26
+ - [Contributing](#contributing)
27
+ - [License](#license)
28
+
29
+ ## Features
30
+
31
+ - 🚀 Fast and efficient package management
32
+ - 🔧 Powerful code generation capabilities
33
+ - 🌐 Connect Studio development environment
34
+ - 📦 Workspace-aware package operations
35
+ - 🔍 Package inspection and dependency management
36
+ - 🛠 Service management and monitoring
37
+ - 📝 Comprehensive documentation and help system
4
38
 
5
39
  ## Installation
6
40
 
7
41
  ```bash
8
- npm install ph-cli
42
+ # Install globally
43
+ npm install -g ph-cli
44
+
45
+ # Install as a dev dependency
46
+ npm install --save-dev ph-cli
47
+ ```
48
+
49
+ ## Quick Start
50
+
51
+ ```bash
52
+ # Initialize a new Powerhouse project
53
+ ph init
54
+
55
+ # Start the development environment
56
+ ph connect
57
+
58
+ # Install required dependencies
59
+ ph install @powerhousedao/core
60
+
61
+ # Generate code from models
62
+ ph generate --interactive
9
63
  ```
10
64
 
11
- ## Available Commands
65
+ ## Commands
12
66
 
13
67
  ### `ph connect`
14
68
 
15
- Starts Connect Studio, a development environment for Powerhouse.
69
+ Starts Connect Studio, a development environment for Powerhouse. This command launches a local development server with hot-reloading and debugging capabilities.
16
70
 
17
71
  #### Options:
18
72
  - `-p, --port <port>`: Port to run the server on (default: 3000)
@@ -21,6 +75,7 @@ Starts Connect Studio, a development environment for Powerhouse.
21
75
  - `--open`: Open the browser automatically
22
76
  - `--config-file <configFile>`: Path to the powerhouse.config.js file
23
77
 
78
+ #### Examples:
24
79
  ```bash
25
80
  # Start Connect Studio on default port (3000)
26
81
  ph connect
@@ -40,7 +95,7 @@ ph connect --config-file ./my-config.js
40
95
 
41
96
  ### `ph generate`
42
97
 
43
- Generate code from document models with various options.
98
+ Generate code from document models with various options. This command supports multiple generation types including editors, processors, subgraphs, and import scripts.
44
99
 
45
100
  #### Options:
46
101
  - `-i, --interactive`: Run the command in interactive mode
@@ -58,6 +113,7 @@ Generate code from document models with various options.
58
113
  - `-w, --watch`: Watch the generated code
59
114
  - `-d, --drive-editor <name>`: Generate a drive editor with the specified name
60
115
 
116
+ #### Examples:
61
117
  ```bash
62
118
  # Generate code from a specific file
63
119
  ph generate path/to/model.json
@@ -86,7 +142,7 @@ ph generate --watch
86
142
 
87
143
  ### `ph install` (or `ph add`, `ph i`)
88
144
 
89
- Install Powerhouse dependencies.
145
+ Install Powerhouse dependencies with support for global and workspace-specific installations.
90
146
 
91
147
  #### Options:
92
148
  - `-g, --global`: Install the dependency globally
@@ -94,6 +150,7 @@ Install Powerhouse dependencies.
94
150
  - `-w, --workspace`: Install the dependency in the workspace (use this option for monorepos)
95
151
  - `--package-manager <packageManager>`: Force package manager to use
96
152
 
153
+ #### Examples:
97
154
  ```bash
98
155
  # Install a package
99
156
  ph install @powerhousedao/package-name
@@ -110,7 +167,7 @@ ph install @powerhousedao/package1 @powerhousedao/package2
110
167
 
111
168
  ### `ph uninstall` (or `ph remove`)
112
169
 
113
- Remove Powerhouse dependencies.
170
+ Remove Powerhouse dependencies from your project.
114
171
 
115
172
  #### Options:
116
173
  - `-g, --global`: Remove the dependency globally
@@ -118,6 +175,7 @@ Remove Powerhouse dependencies.
118
175
  - `-w, --workspace`: Remove the dependency in the workspace (use this option for monorepos)
119
176
  - `--package-manager <packageManager>`: Force package manager to use
120
177
 
178
+ #### Examples:
121
179
  ```bash
122
180
  # Remove a package
123
181
  ph uninstall @powerhousedao/package-name
@@ -131,11 +189,12 @@ ph uninstall -w @powerhousedao/package-name
131
189
 
132
190
  ### `ph list` (or `ph l`)
133
191
 
134
- List all installed Powerhouse packages in your project.
192
+ List all installed Powerhouse packages in your project with detailed information.
135
193
 
136
194
  #### Options:
137
195
  - `--debug`: Show additional logs
138
196
 
197
+ #### Examples:
139
198
  ```bash
140
199
  # List packages
141
200
  ph list
@@ -146,11 +205,12 @@ ph list --debug
146
205
 
147
206
  ### `ph inspect` (or `ph is`)
148
207
 
149
- Inspect a specific package.
208
+ Inspect a specific package for detailed information about its dependencies, configuration, and usage.
150
209
 
151
210
  #### Options:
152
211
  - `--debug`: Show additional logs
153
212
 
213
+ #### Examples:
154
214
  ```bash
155
215
  # Inspect a package
156
216
  ph inspect @powerhousedao/package-name
@@ -161,12 +221,13 @@ ph inspect --debug @powerhousedao/package-name
161
221
 
162
222
  ### `ph service`
163
223
 
164
- Manage Powerhouse services.
224
+ Manage Powerhouse services with various operations.
165
225
 
166
226
  #### Options:
167
227
  - `action`: The action to perform (default: "list")
168
228
  - `service`: The service to manage (default: "all")
169
229
 
230
+ #### Examples:
170
231
  ```bash
171
232
  # List all services
172
233
  ph service list
@@ -177,19 +238,21 @@ ph service list service-name
177
238
 
178
239
  ### `ph version` (or `ph v`)
179
240
 
180
- Display the current version of the PH CLI.
241
+ Display the current version of the PH CLI and related information.
181
242
 
182
243
  #### Options:
183
244
  - `--debug`: Show additional logs
184
245
 
246
+ #### Examples:
185
247
  ```bash
186
248
  ph version
187
249
  ```
188
250
 
189
251
  ### `ph help`
190
252
 
191
- Display help information about the CLI and its commands.
253
+ Display comprehensive help information about the CLI and its commands.
192
254
 
255
+ #### Examples:
193
256
  ```bash
194
257
  # Show general help
195
258
  ph help
@@ -198,17 +261,58 @@ ph help
198
261
  ph help <command>
199
262
  ```
200
263
 
201
- ## Global Options
264
+ ## Configuration
265
+
266
+ The CLI can be configured using a `powerhouse.config.js` file in your project root. Here's an example configuration:
267
+
268
+ ```javascript
269
+ module.exports = {
270
+ port: 3000,
271
+ host: false,
272
+ https: false,
273
+ packageManager: 'npm',
274
+ workspace: {
275
+ enabled: true,
276
+ root: './packages'
277
+ }
278
+ };
279
+ ```
280
+
281
+ ## Troubleshooting
282
+
283
+ ### Common Issues
284
+
285
+ 1. **Command not found**
286
+ - Ensure ph-cli is installed globally or locally
287
+ - Check your PATH environment variable
288
+
289
+ 2. **Permission errors**
290
+ - Use sudo for global installations
291
+ - Check directory permissions
202
292
 
203
- Most commands support the following global options:
293
+ 3. **Package installation failures**
294
+ - Clear npm cache: `npm cache clean --force`
295
+ - Check network connectivity
296
+ - Verify package name and version
204
297
 
205
- - `--debug`: Show additional debug logs
206
- - `--package-manager <manager>`: Force the use of a specific package manager
298
+ ### Debug Mode
299
+
300
+ Most commands support a `--debug` flag for additional logging:
301
+
302
+ ```bash
303
+ ph install --debug @powerhousedao/package-name
304
+ ```
207
305
 
208
306
  ## Contributing
209
307
 
210
- Please refer to the project's contribution guidelines for details on our code of conduct and the process for submitting pull requests.
308
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details on:
309
+
310
+ - Code of Conduct
311
+ - Development Process
312
+ - Pull Request Process
313
+ - Style Guide
314
+ - Testing Requirements
211
315
 
212
316
  ## License
213
317
 
214
- This project is licensed under the terms specified in the LICENSE file.
318
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
package/dist/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@powerhousedao/ph-cli",
3
- "version": "0.41.2",
3
+ "version": "2.5.0-dev.0",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0-only",
6
6
  "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/powerhouse-inc/powerhouse"
10
+ },
7
11
  "publishConfig": {
8
12
  "access": "public"
9
13
  },
@@ -14,6 +18,11 @@
14
18
  "dist"
15
19
  ],
16
20
  "scripts": {
21
+ "generate-commands-md": "tsx scripts/generate-commands-md.ts",
22
+ "generate-version": "tsx scripts/generate-version.ts",
23
+ "prebuild": "npm run clean && npm run generate-commands-md && npm run generate-version",
24
+ "postbuild": "npm run copy-scripts",
25
+ "copy-scripts": "copyfiles scripts/* dist/",
17
26
  "build": "tsc --build",
18
27
  "dev": "concurrently -P 'pnpm -w run build:tsc --watch' 'nodemon --watch \"../..\" -e ts,tsx,js,json dist/src/cli.js -- {@}' --",
19
28
  "prepublishOnly": "npm run build",
@@ -27,7 +36,9 @@
27
36
  "keywords": [],
28
37
  "author": "",
29
38
  "devDependencies": {
39
+ "@types/node": "^22.15.17",
30
40
  "concurrently": "^9.1.2",
41
+ "copyfiles": "^2.4.1",
31
42
  "nodemon": "^3.1.9",
32
43
  "vitest": "^3.1.2"
33
44
  },
@@ -37,6 +48,7 @@
37
48
  "@powerhousedao/config": "workspace:*",
38
49
  "@powerhousedao/connect": "workspace:*",
39
50
  "@powerhousedao/reactor-local": "workspace:*",
51
+ "@powerhousedao/switchboard": "workspace:*",
40
52
  "colorette": "^2.0.20",
41
53
  "commander": "^12.1.0",
42
54
  "document-drive": "workspace:*",
@@ -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.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,190 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # =============================================================================
4
+ # Configuration
5
+ # =============================================================================
6
+ PROJECT_NAME=${1:-"global"}
7
+ ACTION=${2:-"status"}
8
+
9
+ # =============================================================================
10
+ # OS Detection and Windows Handling
11
+ # =============================================================================
12
+ if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
13
+ if [ -f "$0.ps1" ]; then
14
+ powershell -ExecutionPolicy Bypass -File "$0.ps1" -PROJECT_NAME "$PROJECT_NAME" -ACTION "$ACTION"
15
+ else
16
+ echo "Error: Windows management script (manage-environment.ps1) not found"
17
+ exit 1
18
+ fi
19
+ else
20
+ # =============================================================================
21
+ # Service Management
22
+ # =============================================================================
23
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
24
+ echo " Managing project: $PROJECT_NAME"
25
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
26
+
27
+ # Function to check if service is properly set up
28
+ check_setup() {
29
+ local project_name=$1
30
+ local error=0
31
+
32
+ # Check if .env file exists
33
+ if [ ! -f ".env" ]; then
34
+ echo "Error: .env file not found in project directory"
35
+ error=1
36
+ fi
37
+
38
+ # Check if Nginx configuration exists
39
+ if [ ! -f "/etc/nginx/sites-available/$project_name" ]; then
40
+ echo "Error: Nginx configuration not found"
41
+ error=1
42
+ fi
43
+
44
+ # Check if database is configured
45
+ if ! grep -q "DATABASE_URL" ".env"; then
46
+ echo "Error: Database configuration not found in .env file"
47
+ error=1
48
+ fi
49
+
50
+ if [ $error -eq 1 ]; then
51
+ echo "Please run 'ph setup-environment' first to set up the service"
52
+ exit 1
53
+ fi
54
+ }
55
+
56
+ # Function to enable/disable Nginx site
57
+ manage_nginx_site() {
58
+ local action=$1
59
+ local site_path="/etc/nginx/sites-available/$PROJECT_NAME"
60
+ local enabled_path="/etc/nginx/sites-enabled/$PROJECT_NAME"
61
+
62
+ if [ ! -f "$site_path" ]; then
63
+ echo "Error: Nginx site configuration for $PROJECT_NAME not found"
64
+ return 1
65
+ fi
66
+
67
+ case "$action" in
68
+ "enable")
69
+ if [ ! -L "$enabled_path" ]; then
70
+ sudo ln -sf "$site_path" "$enabled_path"
71
+ sudo nginx -t && sudo nginx -s reload
72
+ fi
73
+ ;;
74
+ "disable")
75
+ if [ -L "$enabled_path" ]; then
76
+ sudo rm -f "$enabled_path"
77
+ sudo nginx -t && sudo nginx -s reload
78
+ fi
79
+ ;;
80
+ esac
81
+ }
82
+
83
+ case "$ACTION" in
84
+ "start")
85
+ check_setup "$PROJECT_NAME"
86
+ echo "Starting services..."
87
+ # Build Connect
88
+ echo "Building Connect..."
89
+ ph connect build
90
+ sudo cp -r .ph/connect-build/dist /var/www/html/${PROJECT_NAME}
91
+
92
+ # Enable Nginx site
93
+ manage_nginx_site "enable"
94
+
95
+ # Start Switchboard via PM2
96
+ if ! pm2 list | grep -q "switchboard_${PROJECT_NAME}"; then
97
+ cd $PROJECT_NAME
98
+ pm2 start "pnpm switchboard" --name "switchboard_${PROJECT_NAME}"
99
+ pm2 save
100
+ else
101
+ pm2 start "switchboard_${PROJECT_NAME}"
102
+ fi
103
+ ;;
104
+
105
+ "stop")
106
+ check_setup "$PROJECT_NAME"
107
+ echo "Stopping services..."
108
+ # Stop Switchboard via PM2
109
+ if pm2 list | grep -q "switchboard_${PROJECT_NAME}"; then
110
+ pm2 stop "switchboard_${PROJECT_NAME}"
111
+ fi
112
+
113
+ # Disable Nginx site
114
+ manage_nginx_site "disable"
115
+ ;;
116
+
117
+ "restart")
118
+ check_setup "$PROJECT_NAME"
119
+ echo "Restarting services..."
120
+ # Build Connect
121
+ echo "Building Connect..."
122
+ ph connect build
123
+ sudo cp -r .ph/connect-build/dist /var/www/html/${PROJECT_NAME}
124
+
125
+ # Restart Nginx site
126
+ manage_nginx_site "disable"
127
+ manage_nginx_site "enable"
128
+
129
+ # Restart Switchboard via PM2
130
+ if pm2 list | grep -q "switchboard_${PROJECT_NAME}"; then
131
+ pm2 restart "switchboard_${PROJECT_NAME}"
132
+ else
133
+ cd $PROJECT_NAME
134
+ pm2 start "pnpm switchboard" --name "switchboard_${PROJECT_NAME}"
135
+ pm2 save
136
+ fi
137
+ ;;
138
+
139
+ "status")
140
+ check_setup "$PROJECT_NAME"
141
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
142
+ echo " Service Status for $PROJECT_NAME"
143
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
144
+
145
+ # Create table header
146
+ printf "%-15s %-10s %-15s %-10s %-10s\n" "Service" "Status" "Memory" "Uptime" "Health"
147
+ echo "────────────────────────────────────────────────────────────────────"
148
+
149
+ # Check Connect status
150
+ connect_status="Disabled"
151
+ connect_health="❌"
152
+ connect_memory="N/A"
153
+ connect_uptime="N/A"
154
+ if [ -L "/etc/nginx/sites-enabled/$PROJECT_NAME" ]; then
155
+ connect_status="Enabled"
156
+ # Check if Connect is reachable
157
+ if curl -s -f "http://localhost/$PROJECT_NAME" > /dev/null; then
158
+ connect_health="✅"
159
+ fi
160
+ # Get Nginx memory usage for the site
161
+ nginx_pid=$(pgrep -f "nginx.*$PROJECT_NAME" | head -n 1)
162
+ if [ -n "$nginx_pid" ]; then
163
+ connect_memory=$(ps -o rss= -p "$nginx_pid" 2>/dev/null | awk '{printf "%.1fmb", $1/1024}')
164
+ connect_uptime=$(ps -o etime= -p "$nginx_pid" 2>/dev/null)
165
+ fi
166
+ fi
167
+ printf "%-15s %-10s %-15s %-10s %-10s\n" "Connect" "$connect_status" "$connect_memory" "$connect_uptime" "$connect_health"
168
+
169
+ # Check Switchboard status
170
+ switchboard_info=$(pm2 list | grep "switchboard_${PROJECT_NAME}")
171
+ if [ -n "$switchboard_info" ]; then
172
+ switchboard_status="Enabled"
173
+ switchboard_memory=$(echo "$switchboard_info" | awk '{print $12}')
174
+ switchboard_uptime=$(echo "$switchboard_info" | awk '{print $7}')
175
+ switchboard_health="✅"
176
+ printf "%-15s %-10s %-15s %-10s %-10s\n" "Switchboard" "$switchboard_status" "$switchboard_memory" "$switchboard_uptime" "$switchboard_health"
177
+ else
178
+ printf "%-15s %-10s %-15s %-10s %-10s\n" "Switchboard" "Disabled" "N/A" "N/A" "❌"
179
+ fi
180
+ echo "────────────────────────────────────────────────────────────────────"
181
+ ;;
182
+
183
+ *)
184
+ echo "Usage: $0 [project_name] {start|stop|restart|status}"
185
+ echo "Default project_name: global"
186
+ echo "Default action: status"
187
+ exit 1
188
+ ;;
189
+ esac
190
+ fi