@ezetgalaxy/titan 25.12.1 β 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 +228 -133
- 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,24 +64,61 @@ rustc -V
|
|
|
34
64
|
|
|
35
65
|
---
|
|
36
66
|
|
|
37
|
-
|
|
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
|
+
```
|
|
38
75
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- Zero-config deployment
|
|
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.
|
|
49
85
|
|
|
50
86
|
---
|
|
51
87
|
|
|
52
|
-
|
|
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.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
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
|
|
109
|
+
|
|
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
|
+
|
|
53
118
|
|
|
54
|
-
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
# π¦ Installation
|
|
55
122
|
|
|
56
123
|
```bash
|
|
57
124
|
npm install -g @ezetgalaxy/titan
|
|
@@ -59,7 +126,7 @@ npm install -g @ezetgalaxy/titan
|
|
|
59
126
|
|
|
60
127
|
---
|
|
61
128
|
|
|
62
|
-
|
|
129
|
+
# π Create a New Titan Project
|
|
63
130
|
|
|
64
131
|
```bash
|
|
65
132
|
tit init my-app
|
|
@@ -67,12 +134,12 @@ cd my-app
|
|
|
67
134
|
tit dev
|
|
68
135
|
```
|
|
69
136
|
|
|
70
|
-
Titan will
|
|
137
|
+
Titan will:
|
|
71
138
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
139
|
+
* Create the project structure
|
|
140
|
+
* Generate routing metadata
|
|
141
|
+
* Bundle JS actions
|
|
142
|
+
* Start the Rust dev server with hot reload
|
|
76
143
|
|
|
77
144
|
---
|
|
78
145
|
|
|
@@ -80,30 +147,36 @@ Titan will automatically:
|
|
|
80
147
|
|
|
81
148
|
```
|
|
82
149
|
my-app/
|
|
83
|
-
βββ app/
|
|
84
|
-
β βββ app.js
|
|
85
|
-
β βββ actions/
|
|
86
|
-
β βββ hello.js
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
92
164
|
β
|
|
93
|
-
βββ server/
|
|
94
|
-
β βββ
|
|
95
|
-
β βββ
|
|
96
|
-
β βββ
|
|
97
|
-
β βββ
|
|
98
|
-
β βββ routes.json
|
|
99
|
-
β βββ action_map.json
|
|
100
|
-
β βββ 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
|
|
101
173
|
β
|
|
102
|
-
|
|
103
|
-
|
|
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`
|
|
104
178
|
|
|
105
|
-
|
|
106
|
-
**JS input β Rust server output β Native production binary.**
|
|
179
|
+
```
|
|
107
180
|
|
|
108
181
|
---
|
|
109
182
|
|
|
@@ -121,58 +194,40 @@ globalThis.hello = hello;
|
|
|
121
194
|
|
|
122
195
|
---
|
|
123
196
|
|
|
124
|
-
# π£ Example:
|
|
197
|
+
# π£ Example: Routes (Titan DSL)
|
|
125
198
|
|
|
126
199
|
**app/app.js**
|
|
127
200
|
|
|
128
201
|
```js
|
|
129
202
|
import t from "../titan/titan.js";
|
|
130
203
|
|
|
131
|
-
// POST /hello β hello action
|
|
132
204
|
t.post("/hello").action("hello");
|
|
133
|
-
|
|
134
|
-
// GET / β reply text
|
|
135
205
|
t.get("/").reply("Welcome to Titan");
|
|
136
206
|
|
|
137
207
|
t.start(3000, "Ready to land on Titan Planet π");
|
|
138
208
|
```
|
|
139
209
|
|
|
140
|
-
Titan generates:
|
|
141
|
-
|
|
142
|
-
- `server/routes.json`
|
|
143
|
-
- `server/action_map.json`
|
|
144
|
-
|
|
145
|
-
Used by the Rust runtime to dispatch requests.
|
|
146
|
-
|
|
147
210
|
---
|
|
148
211
|
|
|
149
212
|
# π₯ Hot Reload Dev Mode
|
|
150
213
|
|
|
151
|
-
Start development mode:
|
|
152
|
-
|
|
153
214
|
```bash
|
|
154
215
|
tit dev
|
|
155
216
|
```
|
|
156
217
|
|
|
157
|
-
Titan Dev Mode
|
|
218
|
+
Titan Dev Mode:
|
|
158
219
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
220
|
+
* Rebuilds routes automatically
|
|
221
|
+
* Rebundles actions
|
|
222
|
+
* Restarts Rust server safely
|
|
223
|
+
* Provides instant backend hot reload
|
|
163
224
|
|
|
164
|
-
|
|
225
|
+
Flow:
|
|
165
226
|
|
|
166
227
|
```
|
|
167
|
-
Save
|
|
228
|
+
Save β Rebuild β Restart β Updated API
|
|
168
229
|
```
|
|
169
230
|
|
|
170
|
-
Supports:
|
|
171
|
-
|
|
172
|
-
- Editing `app/app.js`
|
|
173
|
-
- Editing `app/actions/*.js`
|
|
174
|
-
- Fast rebuilds via esbuild
|
|
175
|
-
|
|
176
231
|
---
|
|
177
232
|
|
|
178
233
|
# π Production Build
|
|
@@ -181,7 +236,7 @@ Supports:
|
|
|
181
236
|
tit build
|
|
182
237
|
```
|
|
183
238
|
|
|
184
|
-
Production output
|
|
239
|
+
Production output:
|
|
185
240
|
|
|
186
241
|
```
|
|
187
242
|
server/
|
|
@@ -191,76 +246,113 @@ server/
|
|
|
191
246
|
actions/*.jsbundle
|
|
192
247
|
```
|
|
193
248
|
|
|
194
|
-
You deploy **only the server folder**.
|
|
195
|
-
|
|
196
249
|
---
|
|
197
250
|
|
|
198
|
-
# β
|
|
251
|
+
# β Uploading Titan to GitHub
|
|
199
252
|
|
|
200
|
-
|
|
253
|
+
Titan projects are designed for **direct repository upload**.
|
|
201
254
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
+
```
|
|
208
266
|
|
|
209
|
-
|
|
267
|
+
Push to GitHub:
|
|
210
268
|
|
|
211
269
|
```bash
|
|
212
|
-
|
|
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
|
|
213
276
|
```
|
|
214
277
|
|
|
215
|
-
|
|
278
|
+
Your repo is now fully deployable with Docker.
|
|
216
279
|
|
|
217
280
|
---
|
|
218
281
|
|
|
219
|
-
#
|
|
282
|
+
# β Zero-Config Deployment with Docker
|
|
220
283
|
|
|
221
|
-
|
|
222
|
-
You write backend logic using Titanβs intuitive DSL.
|
|
284
|
+
Once pushed to GitHub, you can deploy anywhere.
|
|
223
285
|
|
|
224
|
-
|
|
225
|
-
Titan uses esbuild to compile JS actions into `.jsbundle`.
|
|
286
|
+
## Deploy to Railway
|
|
226
287
|
|
|
227
|
-
|
|
228
|
-
|
|
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
|
|
229
293
|
|
|
230
|
-
|
|
231
|
-
- `action_map.json`
|
|
294
|
+
Railway will:
|
|
232
295
|
|
|
233
|
-
|
|
234
|
-
|
|
296
|
+
* Build your Rust server
|
|
297
|
+
* Copy JS bundles
|
|
298
|
+
* Start the `titan-server` binary
|
|
299
|
+
* Expose the correct port
|
|
235
300
|
|
|
236
|
-
|
|
237
|
-
- Injects request data
|
|
238
|
-
- Executes JS via Boa
|
|
239
|
-
- Returns JSON response to user
|
|
301
|
+
No configuration required.
|
|
240
302
|
|
|
241
|
-
|
|
242
|
-
|
|
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`
|
|
243
321
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
-
|
|
247
|
-
|
|
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
|
|
248
339
|
|
|
249
340
|
---
|
|
250
341
|
|
|
251
342
|
# π― Why Titan Exists
|
|
252
343
|
|
|
253
|
-
Titan
|
|
344
|
+
Titan is for developers who want:
|
|
254
345
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
346
|
+
* Rust performance
|
|
347
|
+
* JavaScript simplicity
|
|
348
|
+
* Zero Rust learning curve
|
|
349
|
+
* Modern DX
|
|
350
|
+
* Fast deployment
|
|
351
|
+
* Native backend speed
|
|
260
352
|
|
|
261
|
-
Titan
|
|
353
|
+
Titan merges two worlds:
|
|
262
354
|
|
|
263
|
-
|
|
355
|
+
JavaScript productivity Γ Rust performance.
|
|
264
356
|
|
|
265
357
|
---
|
|
266
358
|
|
|
@@ -268,18 +360,21 @@ Titan bridges two worlds:
|
|
|
268
360
|
|
|
269
361
|
**Titan v1 β Stable**
|
|
270
362
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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
|
|
277
373
|
|
|
278
374
|
---
|
|
279
375
|
|
|
280
376
|
# π€ Contributing
|
|
281
377
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
***
|
|
378
|
+
Issues, discussions, and pull requests are welcome.
|
|
285
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();
|