@aravinthan_p/appnest-engine 1.0.12 → 1.0.13
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.
- package/README.md +145 -0
- package/appnest-proxy/server.js +2 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Appnest Engine
|
|
2
|
+
|
|
3
|
+
Development CLI and runtime for Appnest apps. It wires your **app-backend**, **app-frontend**, and optional **app-installation-frontend** behind a single proxy, runs checks, and helps you bundle and zip the app for distribution.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
Appnest Engine runs in the **developer’s project directory** (where `app-backend`, `app-frontend`, etc. live). It provides:
|
|
10
|
+
|
|
11
|
+
- **CLI** – Commands for setup, precheck, install, run, lint, bundle, and zip.
|
|
12
|
+
- **Proxy** – One server on port **3000** that routes traffic to your app’s backend and frontends.
|
|
13
|
+
- **Engine packages** – Shared runtime pieces (proxy, backend layer, frontend dev servers) that load your app code from the current directory.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Flow
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
┌─────────────────────────────────────────────────────────────────────────┐
|
|
21
|
+
│ Developer runs: appnest-engine run run-all │
|
|
22
|
+
│ (from their app project directory: app-backend, app-frontend, etc.) │
|
|
23
|
+
└─────────────────────────────────────────────────────────────────────────┘
|
|
24
|
+
│
|
|
25
|
+
▼
|
|
26
|
+
┌─────────────────────────────────────────────────────────────────────────┐
|
|
27
|
+
│ CLI (cli.js) │
|
|
28
|
+
│ • Parses "run run-all" → appnestAction("run-all") │
|
|
29
|
+
│ • runtimeUtils.runApp() starts only: appnest-proxy │
|
|
30
|
+
└─────────────────────────────────────────────────────────────────────────┘
|
|
31
|
+
│
|
|
32
|
+
▼
|
|
33
|
+
┌─────────────────────────────────────────────────────────────────────────┐
|
|
34
|
+
│ appnest-proxy (port 3000) │
|
|
35
|
+
│ • Reads .env from ORIGINAL_CWD (developer’s project) │
|
|
36
|
+
│ • Allocates ports for app-backend, app-frontend, app-installation-* │
|
|
37
|
+
│ • Starts appnest-backend (loads user’s app-backend/server.js) │
|
|
38
|
+
│ • Starts appnest-frontend (Vite dev server for app-frontend) │
|
|
39
|
+
│ • Starts appnest-installation-frontend if folder exists │
|
|
40
|
+
│ • Proxies: │
|
|
41
|
+
│ /app-backend/* → app-backend │
|
|
42
|
+
│ /app-frontend/* → app-frontend │
|
|
43
|
+
│ /app-installation-frontend/* → app-installation-frontend │
|
|
44
|
+
│ • Watches app-backend / app-frontend and restarts on change (backend) │
|
|
45
|
+
│ or on config change (frontends); HMR for normal frontend edits │
|
|
46
|
+
└─────────────────────────────────────────────────────────────────────────┘
|
|
47
|
+
│
|
|
48
|
+
┌───────────────────────────┼───────────────────────────┐
|
|
49
|
+
▼ ▼ ▼
|
|
50
|
+
┌──────────────────┐ ┌────────────────────┐ ┌────────────────────────────┐
|
|
51
|
+
│ appnest-backend │ │ appnest-frontend │ │ appnest-installation- │
|
|
52
|
+
│ (Express layer) │ │ (Vite dev server) │ │ frontend (Vite dev server) │
|
|
53
|
+
│ Loads user’s │ │ Serves user’s │ │ Serves user’s │
|
|
54
|
+
│ app-backend/ │ │ app-frontend/ │ │ app-installation-frontend/ │
|
|
55
|
+
│ server.js │ │ │ │ │
|
|
56
|
+
└──────────────────┘ └────────────────────┘ └────────────────────────────┘
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- **User directory** = where the developer runs the CLI (`process.cwd()` → `ORIGINAL_CWD` for child processes).
|
|
60
|
+
- **Engine packages** = `appnest-backend`, `appnest-frontend`, `appnest-installation-frontend`, `appnest-proxy` (inside this repo). They are the runtime that loads and serves the **app** folders from the user directory.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Project structure
|
|
65
|
+
|
|
66
|
+
| Path | Role |
|
|
67
|
+
|------|------|
|
|
68
|
+
| `cli.js` | Entry point for `appnest-engine` CLI; uses Commander, delegates to `appnest-command-line`. |
|
|
69
|
+
| `index.js` | Exports `appnestAction` for programmatic use. |
|
|
70
|
+
| `package.json` | Root package; `bin.appnest-engine` → `cli.js`; version is read by CLI. |
|
|
71
|
+
| **appnest-command-line/** | Implements all CLI actions (setup, precheck, install, run, lint, bundle, zip). |
|
|
72
|
+
| **appnest-proxy/** | Express server on port 3000; env from user `.env`; starts backend + frontends; proxies and file watching. |
|
|
73
|
+
| **appnest-backend/** | Express app that loads the user’s `app-backend/server.js` and exposes it under `/app-backend`. |
|
|
74
|
+
| **appnest-frontend/** | Vite dev server for the user’s `app-frontend`. |
|
|
75
|
+
| **appnest-installation-frontend/** | Vite dev server for the user’s `app-installation-frontend` (optional). |
|
|
76
|
+
|
|
77
|
+
The developer’s project (user directory) is expected to have:
|
|
78
|
+
|
|
79
|
+
- `app-backend/` (e.g. `server.js`)
|
|
80
|
+
- `app-frontend/` (e.g. Vite/React app)
|
|
81
|
+
- Optional: `app-installation-frontend/`
|
|
82
|
+
- `.env` (read by the proxy for ports, `CLIENT_SCRIPT_URL`, `PROXY_DEBUG_LOGS`, etc.)
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Installation
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
cd appnest-engine
|
|
90
|
+
npm install
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
If this repo uses **npm workspaces**, a single `npm install` at the root also installs dependencies for `appnest-backend`, `appnest-frontend`, `appnest-installation-frontend`, and `appnest-proxy`.
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## CLI usage
|
|
98
|
+
|
|
99
|
+
From the **appnest-engine** directory, or with the `appnest-engine` binary on `PATH`:
|
|
100
|
+
|
|
101
|
+
| Command | Description |
|
|
102
|
+
|---------|-------------|
|
|
103
|
+
| `appnest-engine --version` | Print version (from root `package.json`). |
|
|
104
|
+
| `appnest-engine run setup-app` | Download appnest-basecode from GitHub and extract into current directory (`app-backend`, `app-frontend`, etc.). |
|
|
105
|
+
| `appnest-engine run precheck` | Check Node.js (≥22), ngrok, and that engine + app paths exist. |
|
|
106
|
+
| `appnest-engine run install-packages` | Run `npm install` in engine packages (appnest-backend, -frontend, -installation-frontend, -proxy). |
|
|
107
|
+
| `appnest-engine run run-all` | Start **appnest-proxy** only; the proxy then starts backend + frontends and proxies traffic. |
|
|
108
|
+
| `appnest-engine run zip-app` | Bundle frontends, then zip `app-frontend`, `app-backend`, `app-installation-frontend` into `appnest-app-pack/`. |
|
|
109
|
+
| `appnest-engine run lint` | Lint `app-backend` and `app-frontend` (and fix manifest checks). |
|
|
110
|
+
| `appnest-engine run lint-fix` | Same as lint with auto-fix where possible. |
|
|
111
|
+
| `appnest-engine help` | Show help. |
|
|
112
|
+
|
|
113
|
+
**Typical developer flow:**
|
|
114
|
+
|
|
115
|
+
1. In the **app project** directory: `appnest-engine run setup-app` (if not already set up).
|
|
116
|
+
2. `appnest-engine run precheck` (optional).
|
|
117
|
+
3. From **appnest-engine** (or with global/linked binary): `appnest-engine run install-packages`.
|
|
118
|
+
4. From the **app project** directory: `appnest-engine run run-all` → proxy on port 3000, app at e.g. `http://localhost:3000/app-frontend/`, API at `http://localhost:3000/app-backend/`.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Runtime flow (when `run-all` is used)
|
|
123
|
+
|
|
124
|
+
1. **CLI** runs `runApp()`, which starts **appnest-proxy** with `ORIGINAL_CWD` set to the current working directory.
|
|
125
|
+
2. **Proxy** reads `.env` from `ORIGINAL_CWD`, allocates ports for backend and frontends, then:
|
|
126
|
+
- Starts **appnest-backend** (which loads the user’s `app-backend/server.js`).
|
|
127
|
+
- Starts **appnest-frontend** (Vite for `app-frontend`).
|
|
128
|
+
- If `app-installation-frontend` exists, starts **appnest-installation-frontend**.
|
|
129
|
+
3. Proxy mounts:
|
|
130
|
+
- `/app-backend` → app-backend
|
|
131
|
+
- `/app-frontend` → app-frontend
|
|
132
|
+
- `/app-installation-frontend` → app-installation-frontend
|
|
133
|
+
4. **File watching**: Changes in `app-backend` restart the backend; changes in `app-frontend` / `app-installation-frontend` trigger restart only for config (e.g. `vite.config.js`, `.env`); other frontend changes use Vite HMR.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Zip / bundle flow
|
|
138
|
+
|
|
139
|
+
- **`run zip-app`** runs **bundle-frontend** first (builds appnest-frontend and appnest-installation-frontend), then zips the **user’s** `app-frontend`, `app-backend`, and `app-installation-frontend` into **appnest-app-pack** (and updates paths in `app-frontend/dist/index.html` as needed). Use this to produce a single pack for deployment or distribution.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
ISC
|
package/appnest-proxy/server.js
CHANGED
|
@@ -7,7 +7,6 @@ const chokidar = require('chokidar');
|
|
|
7
7
|
const fs = require('fs');
|
|
8
8
|
|
|
9
9
|
const app = express();
|
|
10
|
-
const PROXY_PORT = 3000;
|
|
11
10
|
|
|
12
11
|
console.log('📂 User Directory from appnest-proxy', process.env.ORIGINAL_CWD);
|
|
13
12
|
|
|
@@ -177,6 +176,8 @@ const startAppServers = () => {
|
|
|
177
176
|
async function startServers() {
|
|
178
177
|
appInjectedEnv = getAppEnv();
|
|
179
178
|
console.log('📂 App Injected Environment Variables:', appInjectedEnv);
|
|
179
|
+
const PROXY_PORT = appInjectedEnv.APPNEST_ENGINE_PORT || 3000;
|
|
180
|
+
console.log('📂 Proxy Port:', PROXY_PORT);
|
|
180
181
|
await allocateAndVerifyAppUniquePorts();
|
|
181
182
|
startAppServers();
|
|
182
183
|
|