@ezetgalaxy/titan 25.12.2 β 25.12.3
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 +229 -140
- package/index.js +37 -10
- package/package.json +1 -1
- package/templates/titan/bundle.js +40 -40
- package/templates/titan/dev.js +67 -67
package/README.md
CHANGED
|
@@ -1,31 +1,61 @@
|
|
|
1
|
-
|
|
1
|
+
# TITAN PLANET π
|
|
2
2
|
|
|
3
|
-
## TITAN PLANET π
|
|
4
3
|
JavaScript Simplicity. Rust Power.
|
|
5
4
|
|
|
6
|
-
Titan is a JavaScript-first backend framework that compiles your
|
|
5
|
+
Titan is a JavaScript-first backend framework that compiles your JavaScript routes and actions into a production-grade **Rust + Axum native server**.
|
|
7
6
|
|
|
8
|
-
Developers write **zero Rust**, yet deploy a high-performance, safe, fully native backend with
|
|
7
|
+
Developers write **zero Rust**, yet deploy a high-performance, safe, fully native backend with modern DX.
|
|
9
8
|
|
|
10
|
-
Titan =
|
|
9
|
+
Titan = Rust performance Γ JavaScript simplicity
|
|
11
10
|
|
|
12
11
|
---
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
# π³ Production Docker Support (Pre-built by Titan CLI)
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
Titan provides **first-class Docker support automatically**.
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
When you create a project with:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
tit init my-app
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Titan generates:
|
|
24
|
+
|
|
25
|
+
* A **pre-configured Dockerfile** (production-ready)
|
|
26
|
+
* A **pre-configured .dockerignore**
|
|
27
|
+
* A **Git-ready .gitignore**
|
|
28
|
+
* A **safe, no-spaces directory structure** ideal for cloud builds
|
|
29
|
+
|
|
30
|
+
You do **not** need to modify the Dockerfile. It is optimized for:
|
|
31
|
+
|
|
32
|
+
* Native Rust builds
|
|
33
|
+
* Fast multi-stage compilation
|
|
34
|
+
* Minimal final image size
|
|
35
|
+
* Railway, Fly.io, Render, Docker Hub, VPS deployments
|
|
36
|
+
|
|
37
|
+
This ensures **zero-config deployment** anywhere.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
# β Requirements
|
|
42
|
+
|
|
43
|
+
Install before using Titan:
|
|
44
|
+
|
|
45
|
+
### 1. Rust (latest stable)
|
|
46
|
+
|
|
47
|
+
[https://rust-lang.org/tools/install/](https://rust-lang.org/tools/install/)
|
|
48
|
+
|
|
49
|
+
### 2. Node.js (v18+)
|
|
21
50
|
|
|
22
|
-
### **2. Node.js (v18+)**
|
|
23
51
|
Required for:
|
|
24
|
-
- Titan CLI
|
|
25
|
-
- esbuild
|
|
26
|
-
- JS β Rust compilation process
|
|
27
52
|
|
|
28
|
-
|
|
53
|
+
* Titan CLI
|
|
54
|
+
* esbuild
|
|
55
|
+
* JS β Rust compilation pipeline
|
|
56
|
+
|
|
57
|
+
Verify:
|
|
58
|
+
|
|
29
59
|
```bash
|
|
30
60
|
node -v
|
|
31
61
|
npm -v
|
|
@@ -34,30 +64,61 @@ rustc -V
|
|
|
34
64
|
|
|
35
65
|
---
|
|
36
66
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
67
|
+
# π Updating Titan CLI
|
|
68
|
+
|
|
69
|
+
Titan ships with a built-in updater.
|
|
70
|
+
To upgrade to the latest CLI, features, and patches:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
tit update
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
This updates:
|
|
77
|
+
|
|
78
|
+
* Titan CLI
|
|
79
|
+
* DSL components
|
|
80
|
+
* Bundler + Dev server
|
|
81
|
+
* Rust server templates
|
|
82
|
+
* Dockerfile (if version bump requires)
|
|
83
|
+
|
|
84
|
+
Backwards compatibility is maintained automatically.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
# β¨ Features
|
|
89
|
+
|
|
90
|
+
Here is the updated **Features** block with your new environment-variable feature added cleanly and professionally, matching the style of your documentation.
|
|
91
|
+
|
|
92
|
+
You can copyβpaste it directly into the README.
|
|
55
93
|
|
|
56
94
|
---
|
|
57
95
|
|
|
58
|
-
|
|
96
|
+
# β¨ Features
|
|
97
|
+
|
|
98
|
+
* Write backend logic in **pure JavaScript**
|
|
99
|
+
* Compile into a **native Rust Axum server**
|
|
100
|
+
* Titan DSL: `t.get()`, `t.post()`, `t.start()`
|
|
101
|
+
* Automatic **route generation**
|
|
102
|
+
* Automatic **JS action bundling**
|
|
103
|
+
* High-performance **Rust Axum runtime**
|
|
104
|
+
* JavaScript execution via **Boa engine**
|
|
105
|
+
* Full **Hot Reload Dev Server**
|
|
106
|
+
* **Single binary** production output
|
|
107
|
+
* Zero-config deployment
|
|
108
|
+
* Built-in **environment variable support** β create a `.env` file in the project root and access values directly via `process.env.KEY_NAME` inside your Titan actions and app logic
|
|
59
109
|
|
|
60
|
-
|
|
110
|
+
With `.env` support, Titan loads environment variables automatically during:
|
|
111
|
+
|
|
112
|
+
* `tit dev`
|
|
113
|
+
* `tit build`
|
|
114
|
+
* Production runtime inside the Rust server
|
|
115
|
+
|
|
116
|
+
No additional configuration is required.
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
# π¦ Installation
|
|
61
122
|
|
|
62
123
|
```bash
|
|
63
124
|
npm install -g @ezetgalaxy/titan
|
|
@@ -65,7 +126,7 @@ npm install -g @ezetgalaxy/titan
|
|
|
65
126
|
|
|
66
127
|
---
|
|
67
128
|
|
|
68
|
-
|
|
129
|
+
# π Create a New Titan Project
|
|
69
130
|
|
|
70
131
|
```bash
|
|
71
132
|
tit init my-app
|
|
@@ -73,12 +134,12 @@ cd my-app
|
|
|
73
134
|
tit dev
|
|
74
135
|
```
|
|
75
136
|
|
|
76
|
-
Titan will
|
|
137
|
+
Titan will:
|
|
77
138
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
139
|
+
* Create the project structure
|
|
140
|
+
* Generate routing metadata
|
|
141
|
+
* Bundle JS actions
|
|
142
|
+
* Start the Rust dev server with hot reload
|
|
82
143
|
|
|
83
144
|
---
|
|
84
145
|
|
|
@@ -86,30 +147,36 @@ Titan will automatically:
|
|
|
86
147
|
|
|
87
148
|
```
|
|
88
149
|
my-app/
|
|
89
|
-
βββ app/
|
|
90
|
-
β βββ app.js
|
|
91
|
-
β βββ actions/
|
|
92
|
-
β βββ hello.js
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
150
|
+
βββ app/ # You develop ONLY this folder
|
|
151
|
+
β βββ app.js # Titan routes (DSL)
|
|
152
|
+
β βββ actions/ # Your custom JS actions
|
|
153
|
+
β βββ hello.js # Example Titan action
|
|
154
|
+
|
|
155
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
156
|
+
Everything below is auto-generated by `tit init`
|
|
157
|
+
You never modify these folders manually
|
|
158
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
159
|
+
|
|
160
|
+
βββ titan/ # Titan's internal JS engine
|
|
161
|
+
β βββ titan.js # Titan DSL runtime
|
|
162
|
+
β βββ bundle.js # JS β .jsbundle bundler
|
|
163
|
+
β βββ dev.js # Hot Reload system
|
|
98
164
|
β
|
|
99
|
-
βββ server/
|
|
100
|
-
β βββ
|
|
101
|
-
β βββ
|
|
102
|
-
β βββ
|
|
103
|
-
β βββ
|
|
104
|
-
β βββ routes.json
|
|
105
|
-
β βββ action_map.json
|
|
106
|
-
β βββ titan-server
|
|
165
|
+
βββ server/ # Auto-generated Rust backend
|
|
166
|
+
β βββ Cargo.toml # Rust project config
|
|
167
|
+
β βββ src/ # Rust source code
|
|
168
|
+
β βββ actions/ # Compiled .jsbundle actions
|
|
169
|
+
β βββ titan/ # Internal Rust runtime files
|
|
170
|
+
β βββ routes.json # Generated route metadata
|
|
171
|
+
β βββ action_map.json # Maps actions to bundles
|
|
172
|
+
β βββ titan-server # Final production Rust binary
|
|
107
173
|
β
|
|
108
|
-
|
|
109
|
-
|
|
174
|
+
βββ Dockerfile # Auto-generated production Dockerfile
|
|
175
|
+
βββ .dockerignore # Auto-generated Docker ignore rules
|
|
176
|
+
βββ package.json # JS project config (auto)
|
|
177
|
+
βββ .gitignore # Auto-generated by `tit init`
|
|
110
178
|
|
|
111
|
-
|
|
112
|
-
**JS input β Rust server output β Native production binary.**
|
|
179
|
+
```
|
|
113
180
|
|
|
114
181
|
---
|
|
115
182
|
|
|
@@ -127,58 +194,40 @@ globalThis.hello = hello;
|
|
|
127
194
|
|
|
128
195
|
---
|
|
129
196
|
|
|
130
|
-
# π£ Example:
|
|
197
|
+
# π£ Example: Routes (Titan DSL)
|
|
131
198
|
|
|
132
199
|
**app/app.js**
|
|
133
200
|
|
|
134
201
|
```js
|
|
135
202
|
import t from "../titan/titan.js";
|
|
136
203
|
|
|
137
|
-
// POST /hello β hello action
|
|
138
204
|
t.post("/hello").action("hello");
|
|
139
|
-
|
|
140
|
-
// GET / β reply text
|
|
141
205
|
t.get("/").reply("Welcome to Titan");
|
|
142
206
|
|
|
143
207
|
t.start(3000, "Ready to land on Titan Planet π");
|
|
144
208
|
```
|
|
145
209
|
|
|
146
|
-
Titan generates:
|
|
147
|
-
|
|
148
|
-
- `server/routes.json`
|
|
149
|
-
- `server/action_map.json`
|
|
150
|
-
|
|
151
|
-
Used by the Rust runtime to dispatch requests.
|
|
152
|
-
|
|
153
210
|
---
|
|
154
211
|
|
|
155
212
|
# π₯ Hot Reload Dev Mode
|
|
156
213
|
|
|
157
|
-
Start development mode:
|
|
158
|
-
|
|
159
214
|
```bash
|
|
160
215
|
tit dev
|
|
161
216
|
```
|
|
162
217
|
|
|
163
|
-
Titan Dev Mode
|
|
218
|
+
Titan Dev Mode:
|
|
164
219
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
220
|
+
* Rebuilds routes automatically
|
|
221
|
+
* Rebundles actions
|
|
222
|
+
* Restarts Rust server safely
|
|
223
|
+
* Provides instant backend hot reload
|
|
169
224
|
|
|
170
|
-
|
|
225
|
+
Flow:
|
|
171
226
|
|
|
172
227
|
```
|
|
173
|
-
Save
|
|
228
|
+
Save β Rebuild β Restart β Updated API
|
|
174
229
|
```
|
|
175
230
|
|
|
176
|
-
Supports:
|
|
177
|
-
|
|
178
|
-
- Editing `app/app.js`
|
|
179
|
-
- Editing `app/actions/*.js`
|
|
180
|
-
- Fast rebuilds via esbuild
|
|
181
|
-
|
|
182
231
|
---
|
|
183
232
|
|
|
184
233
|
# π Production Build
|
|
@@ -187,7 +236,7 @@ Supports:
|
|
|
187
236
|
tit build
|
|
188
237
|
```
|
|
189
238
|
|
|
190
|
-
Production output
|
|
239
|
+
Production output:
|
|
191
240
|
|
|
192
241
|
```
|
|
193
242
|
server/
|
|
@@ -197,76 +246,113 @@ server/
|
|
|
197
246
|
actions/*.jsbundle
|
|
198
247
|
```
|
|
199
248
|
|
|
200
|
-
You deploy **only the server folder**.
|
|
201
|
-
|
|
202
249
|
---
|
|
203
250
|
|
|
204
|
-
# β
|
|
251
|
+
# β Uploading Titan to GitHub
|
|
205
252
|
|
|
206
|
-
|
|
253
|
+
Titan projects are designed for **direct repository upload**.
|
|
207
254
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
255
|
+
Include everything generated by `tit init`:
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
app/
|
|
259
|
+
titan/
|
|
260
|
+
server/
|
|
261
|
+
Cargo.toml
|
|
262
|
+
Dockerfile
|
|
263
|
+
.gitignore
|
|
264
|
+
package.json
|
|
265
|
+
```
|
|
214
266
|
|
|
215
|
-
|
|
267
|
+
Push to GitHub:
|
|
216
268
|
|
|
217
269
|
```bash
|
|
218
|
-
|
|
270
|
+
git init
|
|
271
|
+
git add .
|
|
272
|
+
git commit -m "Initial Titan project"
|
|
273
|
+
git branch -M main
|
|
274
|
+
git remote add origin <your_repo_url>
|
|
275
|
+
git push -u origin main
|
|
219
276
|
```
|
|
220
277
|
|
|
221
|
-
|
|
278
|
+
Your repo is now fully deployable with Docker.
|
|
222
279
|
|
|
223
280
|
---
|
|
224
281
|
|
|
225
|
-
#
|
|
282
|
+
# β Zero-Config Deployment with Docker
|
|
226
283
|
|
|
227
|
-
|
|
228
|
-
You write backend logic using Titanβs intuitive DSL.
|
|
284
|
+
Once pushed to GitHub, you can deploy anywhere.
|
|
229
285
|
|
|
230
|
-
|
|
231
|
-
Titan uses esbuild to compile JS actions into `.jsbundle`.
|
|
286
|
+
## Deploy to Railway
|
|
232
287
|
|
|
233
|
-
|
|
234
|
-
|
|
288
|
+
1. Go to Railway
|
|
289
|
+
2. Create New Project β Deploy from GitHub
|
|
290
|
+
3. Select your Titan repo
|
|
291
|
+
4. Railway auto-detects the Dockerfile
|
|
292
|
+
5. It builds + deploys automatically
|
|
235
293
|
|
|
236
|
-
|
|
237
|
-
- `action_map.json`
|
|
294
|
+
Railway will:
|
|
238
295
|
|
|
239
|
-
|
|
240
|
-
|
|
296
|
+
* Build your Rust server
|
|
297
|
+
* Copy JS bundles
|
|
298
|
+
* Start the `titan-server` binary
|
|
299
|
+
* Expose the correct port
|
|
241
300
|
|
|
242
|
-
|
|
243
|
-
- Injects request data
|
|
244
|
-
- Executes JS via Boa
|
|
245
|
-
- Returns JSON response to user
|
|
301
|
+
No configuration required.
|
|
246
302
|
|
|
247
|
-
|
|
248
|
-
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
# π§ Internal Architecture
|
|
306
|
+
|
|
307
|
+
### 1. Titan DSL
|
|
308
|
+
|
|
309
|
+
Simple JavaScript syntax for writing routes and actions.
|
|
310
|
+
|
|
311
|
+
### 2. Bundler (esbuild)
|
|
312
|
+
|
|
313
|
+
Compiles actions into `.jsbundle` format.
|
|
314
|
+
|
|
315
|
+
### 3. Metadata
|
|
316
|
+
|
|
317
|
+
`t.start()` generates:
|
|
318
|
+
|
|
319
|
+
* `routes.json`
|
|
320
|
+
* `action_map.json`
|
|
249
321
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
-
|
|
253
|
-
|
|
322
|
+
### 4. Rust Server
|
|
323
|
+
|
|
324
|
+
Axum-based runtime:
|
|
325
|
+
|
|
326
|
+
* Loads JS bundles
|
|
327
|
+
* Injects request objects
|
|
328
|
+
* Executes JS via Boa
|
|
329
|
+
* Returns JSON
|
|
330
|
+
|
|
331
|
+
### 5. Production Output
|
|
332
|
+
|
|
333
|
+
Titan emits:
|
|
334
|
+
|
|
335
|
+
* Native Rust binary
|
|
336
|
+
* JS bundles
|
|
337
|
+
* Routing metadata
|
|
338
|
+
* Fully deployable directory
|
|
254
339
|
|
|
255
340
|
---
|
|
256
341
|
|
|
257
342
|
# π― Why Titan Exists
|
|
258
343
|
|
|
259
|
-
Titan
|
|
344
|
+
Titan is for developers who want:
|
|
260
345
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
346
|
+
* Rust performance
|
|
347
|
+
* JavaScript simplicity
|
|
348
|
+
* Zero Rust learning curve
|
|
349
|
+
* Modern DX
|
|
350
|
+
* Fast deployment
|
|
351
|
+
* Native backend speed
|
|
266
352
|
|
|
267
|
-
Titan
|
|
353
|
+
Titan merges two worlds:
|
|
268
354
|
|
|
269
|
-
|
|
355
|
+
JavaScript productivity Γ Rust performance.
|
|
270
356
|
|
|
271
357
|
---
|
|
272
358
|
|
|
@@ -274,18 +360,21 @@ Titan bridges two worlds:
|
|
|
274
360
|
|
|
275
361
|
**Titan v1 β Stable**
|
|
276
362
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
363
|
+
Includes:
|
|
364
|
+
|
|
365
|
+
* JS β Rust compiler
|
|
366
|
+
* Action Engine
|
|
367
|
+
* Axum Runtime
|
|
368
|
+
* Titan DSL
|
|
369
|
+
* Hot Reload Dev Server
|
|
370
|
+
* Docker Deployments
|
|
371
|
+
* Railway/Fly.io Support
|
|
372
|
+
* `tit update` CLI Upgrader
|
|
283
373
|
|
|
284
374
|
---
|
|
285
375
|
|
|
286
376
|
# π€ Contributing
|
|
287
377
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
***
|
|
378
|
+
Issues, discussions, and pull requests are welcome.
|
|
291
379
|
|
|
380
|
+
---
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { execSync, spawn } from "child_process";
|
|
@@ -221,7 +221,9 @@ function startProd() {
|
|
|
221
221
|
function updateTitan() {
|
|
222
222
|
const projectRoot = process.cwd();
|
|
223
223
|
const projectTitan = path.join(projectRoot, "titan");
|
|
224
|
-
|
|
224
|
+
|
|
225
|
+
const cliTemplatesRoot = path.join(__dirname, "templates");
|
|
226
|
+
const cliTitan = path.join(cliTemplatesRoot, "titan");
|
|
225
227
|
|
|
226
228
|
if (!fs.existsSync(projectTitan)) {
|
|
227
229
|
console.log(red("No titan/ folder found in this project."));
|
|
@@ -229,18 +231,41 @@ function updateTitan() {
|
|
|
229
231
|
return;
|
|
230
232
|
}
|
|
231
233
|
|
|
232
|
-
console.log(cyan("Titan: Updating runtime files..."));
|
|
233
234
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
//
|
|
236
|
+
// 2. Replace titan/ runtime folder
|
|
237
|
+
//
|
|
238
|
+
fs.rmSync(projectTitan, { recursive: true, force: true });
|
|
239
|
+
console.log(green("β Old titan/ runtime removed"));
|
|
237
240
|
|
|
238
241
|
copyDir(cliTitan, projectTitan);
|
|
242
|
+
console.log(green("β titan/ runtime updated"));
|
|
243
|
+
|
|
244
|
+
//
|
|
245
|
+
// 3. Update server/Cargo.toml
|
|
246
|
+
//
|
|
247
|
+
const srcToml = path.join(cliTemplatesRoot, "server", "Cargo.toml");
|
|
248
|
+
const destToml = path.join(projectRoot, "server", "Cargo.toml");
|
|
249
|
+
if (fs.existsSync(srcToml)) {
|
|
250
|
+
fs.copyFileSync(srcToml, destToml);
|
|
251
|
+
console.log(green("β Updated server/Cargo.toml"));
|
|
252
|
+
}
|
|
239
253
|
|
|
240
|
-
|
|
254
|
+
//
|
|
255
|
+
// 4. Update ONLY server/src/main.rs
|
|
256
|
+
//
|
|
257
|
+
const srcMain = path.join(cliTemplatesRoot, "server", "src", "main.rs");
|
|
258
|
+
const destMain = path.join(projectRoot, "server", "src", "main.rs");
|
|
259
|
+
if (fs.existsSync(srcMain)) {
|
|
260
|
+
fs.copyFileSync(srcMain, destMain);
|
|
261
|
+
console.log(green("β Updated server/src/main.rs"));
|
|
262
|
+
}
|
|
241
263
|
|
|
264
|
+
//
|
|
265
|
+
// 5. Update root-level config files
|
|
266
|
+
//
|
|
242
267
|
[".gitignore", ".dockerignore", "Dockerfile"].forEach((file) => {
|
|
243
|
-
const src = path.join(
|
|
268
|
+
const src = path.join(cliTemplatesRoot, file);
|
|
244
269
|
const dest = path.join(projectRoot, file);
|
|
245
270
|
|
|
246
271
|
if (fs.existsSync(src)) {
|
|
@@ -249,12 +274,14 @@ function updateTitan() {
|
|
|
249
274
|
}
|
|
250
275
|
});
|
|
251
276
|
|
|
252
|
-
console.log(
|
|
253
|
-
console.log(cyan("Your project now has the latest Titan features."));
|
|
277
|
+
console.log(cyan("β Titan forced update complete"));
|
|
254
278
|
}
|
|
255
279
|
|
|
256
280
|
|
|
257
281
|
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
258
285
|
// ROUTER
|
|
259
286
|
switch (cmd) {
|
|
260
287
|
case "init":
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import esbuild from "esbuild";
|
|
4
|
-
|
|
5
|
-
const root = process.cwd();
|
|
6
|
-
const actionsDir = path.join(root, "app", "actions");
|
|
7
|
-
const outDir = path.join(root, "server", "actions");
|
|
8
|
-
|
|
9
|
-
export async function bundle() {
|
|
10
|
-
console.log("[Titan] Bundling actions...");
|
|
11
|
-
|
|
12
|
-
fs.mkdirSync(outDir, { recursive: true });
|
|
13
|
-
|
|
14
|
-
// Clean old bundles
|
|
15
|
-
for (const file of fs.readdirSync(outDir)) {
|
|
16
|
-
fs.unlinkSync(path.join(outDir, file));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const files = fs.readdirSync(actionsDir).filter(f => f.endsWith(".js"));
|
|
20
|
-
|
|
21
|
-
for (const file of files) {
|
|
22
|
-
const entry = path.join(actionsDir, file);
|
|
23
|
-
|
|
24
|
-
// Rust runtime expects `.jsbundle` extension β consistent with previous design
|
|
25
|
-
const outfile = path.join(outDir, file.replace(".js", ".jsbundle"));
|
|
26
|
-
|
|
27
|
-
console.log(`[Titan] Bundling ${entry} β ${outfile}`);
|
|
28
|
-
|
|
29
|
-
await esbuild.build({
|
|
30
|
-
entryPoints: [entry],
|
|
31
|
-
bundle: true,
|
|
32
|
-
format: "cjs",
|
|
33
|
-
platform: "neutral",
|
|
34
|
-
outfile,
|
|
35
|
-
minify: false,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
console.log("[Titan] Bundling finished.");
|
|
40
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import esbuild from "esbuild";
|
|
4
|
+
|
|
5
|
+
const root = process.cwd();
|
|
6
|
+
const actionsDir = path.join(root, "app", "actions");
|
|
7
|
+
const outDir = path.join(root, "server", "actions");
|
|
8
|
+
|
|
9
|
+
export async function bundle() {
|
|
10
|
+
console.log("[Titan] Bundling actions...");
|
|
11
|
+
|
|
12
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
13
|
+
|
|
14
|
+
// Clean old bundles
|
|
15
|
+
for (const file of fs.readdirSync(outDir)) {
|
|
16
|
+
fs.unlinkSync(path.join(outDir, file));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const files = fs.readdirSync(actionsDir).filter(f => f.endsWith(".js"));
|
|
20
|
+
|
|
21
|
+
for (const file of files) {
|
|
22
|
+
const entry = path.join(actionsDir, file);
|
|
23
|
+
|
|
24
|
+
// Rust runtime expects `.jsbundle` extension β consistent with previous design
|
|
25
|
+
const outfile = path.join(outDir, file.replace(".js", ".jsbundle"));
|
|
26
|
+
|
|
27
|
+
console.log(`[Titan] Bundling ${entry} β ${outfile}`);
|
|
28
|
+
|
|
29
|
+
await esbuild.build({
|
|
30
|
+
entryPoints: [entry],
|
|
31
|
+
bundle: true,
|
|
32
|
+
format: "cjs",
|
|
33
|
+
platform: "neutral",
|
|
34
|
+
outfile,
|
|
35
|
+
minify: false,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log("[Titan] Bundling finished.");
|
|
40
|
+
}
|
package/templates/titan/dev.js
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import chokidar from "chokidar";
|
|
2
|
-
import { spawn, execSync } from "child_process";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { fileURLToPath } from "url";
|
|
5
|
-
import { bundle } from "./bundle.js";
|
|
6
|
-
|
|
7
|
-
// Required for __dirname in ES modules
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
const __dirname = path.dirname(__filename);
|
|
10
|
-
|
|
11
|
-
let serverProcess = null;
|
|
12
|
-
|
|
13
|
-
function startRustServer() {
|
|
14
|
-
if (serverProcess) {
|
|
15
|
-
serverProcess.kill();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const serverPath = path.join(process.cwd(), "server");
|
|
19
|
-
|
|
20
|
-
serverProcess = spawn("cargo", ["run"], {
|
|
21
|
-
cwd: serverPath,
|
|
22
|
-
stdio: "inherit",
|
|
23
|
-
shell: true
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
serverProcess.on("close", (code) => {
|
|
27
|
-
console.log(`[Titan] Rust server exited: ${code}`);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function rebuild() {
|
|
32
|
-
console.log("[Titan] Regenerating routes.json & action_map.json...");
|
|
33
|
-
execSync("node app/app.js", { stdio: "inherit" });
|
|
34
|
-
|
|
35
|
-
console.log("[Titan] Bundling JS actions...");
|
|
36
|
-
await bundle();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function startDev() {
|
|
40
|
-
console.log("[Titan] Dev mode starting...");
|
|
41
|
-
|
|
42
|
-
// FIRST BUILD
|
|
43
|
-
await rebuild();
|
|
44
|
-
startRustServer();
|
|
45
|
-
|
|
46
|
-
const watcher = chokidar.watch("app", {
|
|
47
|
-
ignoreInitial: true
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
let timer = null;
|
|
51
|
-
|
|
52
|
-
watcher.on("all", async (event, file) => {
|
|
53
|
-
if (timer) clearTimeout(timer);
|
|
54
|
-
|
|
55
|
-
timer = setTimeout(async () => {
|
|
56
|
-
console.log(`[Titan] Change detected: ${file}`);
|
|
57
|
-
|
|
58
|
-
await rebuild();
|
|
59
|
-
|
|
60
|
-
console.log("[Titan] Restarting Rust server...");
|
|
61
|
-
startRustServer();
|
|
62
|
-
|
|
63
|
-
}, 200);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
startDev();
|
|
1
|
+
import chokidar from "chokidar";
|
|
2
|
+
import { spawn, execSync } from "child_process";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { bundle } from "./bundle.js";
|
|
6
|
+
|
|
7
|
+
// Required for __dirname in ES modules
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
|
|
11
|
+
let serverProcess = null;
|
|
12
|
+
|
|
13
|
+
function startRustServer() {
|
|
14
|
+
if (serverProcess) {
|
|
15
|
+
serverProcess.kill();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const serverPath = path.join(process.cwd(), "server");
|
|
19
|
+
|
|
20
|
+
serverProcess = spawn("cargo", ["run"], {
|
|
21
|
+
cwd: serverPath,
|
|
22
|
+
stdio: "inherit",
|
|
23
|
+
shell: true
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
serverProcess.on("close", (code) => {
|
|
27
|
+
console.log(`[Titan] Rust server exited: ${code}`);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function rebuild() {
|
|
32
|
+
console.log("[Titan] Regenerating routes.json & action_map.json...");
|
|
33
|
+
execSync("node app/app.js", { stdio: "inherit" });
|
|
34
|
+
|
|
35
|
+
console.log("[Titan] Bundling JS actions...");
|
|
36
|
+
await bundle();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function startDev() {
|
|
40
|
+
console.log("[Titan] Dev mode starting...");
|
|
41
|
+
|
|
42
|
+
// FIRST BUILD
|
|
43
|
+
await rebuild();
|
|
44
|
+
startRustServer();
|
|
45
|
+
|
|
46
|
+
const watcher = chokidar.watch("app", {
|
|
47
|
+
ignoreInitial: true
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
let timer = null;
|
|
51
|
+
|
|
52
|
+
watcher.on("all", async (event, file) => {
|
|
53
|
+
if (timer) clearTimeout(timer);
|
|
54
|
+
|
|
55
|
+
timer = setTimeout(async () => {
|
|
56
|
+
console.log(`[Titan] Change detected: ${file}`);
|
|
57
|
+
|
|
58
|
+
await rebuild();
|
|
59
|
+
|
|
60
|
+
console.log("[Titan] Restarting Rust server...");
|
|
61
|
+
startRustServer();
|
|
62
|
+
|
|
63
|
+
}, 200);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
startDev();
|