@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 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 JS routes and actions into a production-grade **Rust + Axum native server**.
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 excellent DX (developer experience).
7
+ Developers write **zero Rust**, yet deploy a high-performance, safe, fully native backend with modern DX.
9
8
 
10
- Titan = Next.js DX Γ— Rust performance Γ— JavaScript simplicity
9
+ Titan = Rust performance Γ— JavaScript simplicity
11
10
 
12
11
  ---
13
12
 
14
- ## βš™ Requirements
13
+ # 🐳 Production Docker Support (Pre-built by Titan CLI)
15
14
 
16
- Before using Titan, ensure your system has:
15
+ Titan provides **first-class Docker support automatically**.
17
16
 
18
- ### **1. Rust (latest stable)**
19
- Install from:
20
- https://rust-lang.org/tools/install/
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
- Check version:
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
- ## ✨ Features
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
- - Write your backend in **pure JavaScript**
40
- - Compile into a **native Rust HTTP server**
41
- - Titan DSL: `t.get()`, `t.post()`, `t.start()`
42
- - Automatic **route generation**
43
- - Automatic **JS action bundling**
44
- - Fast **Rust Axum runtime**
45
- - JavaScript execution via **Boa engine**
46
- - **Hot Reload Dev Server** (edit β†’ rebuild β†’ restart automatically)
47
- - Production output: **single binary**
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
- ## πŸ“¦ Installation
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
- Install the Titan CLI globally:
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
- ## πŸš€ Create a New Titan Project
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 automatically:
137
+ Titan will:
71
138
 
72
- - Create project structure
73
- - Generate routes from `/app/app.js`
74
- - Bundle JS actions into `.jsbundle` files
75
- - Start the **Rust Axum dev server with Hot Reload**
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 # Titan routes (DSL)
85
- β”‚ └── actions/
86
- β”‚ └── hello.js # Titan action
87
- β”‚
88
- β”œβ”€β”€ titan/
89
- β”‚ β”œβ”€β”€ titan.js # Titan DSL
90
- β”‚ β”œβ”€β”€ bundle.js # Bundler (esbuild)
91
- β”‚ └── dev.js # Hot reload engine
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/ # Rust backend (auto generated)
94
- β”‚ β”œβ”€β”€ src/
95
- β”‚ β”œβ”€β”€ actions/ # JS β†’ .jsbundle compiled actions
96
- β”‚ β”œβ”€β”€ titan/ # internal runtime files
97
- β”‚ β”œβ”€β”€ target/ # Cargo build output
98
- β”‚ β”œβ”€β”€ routes.json
99
- β”‚ β”œβ”€β”€ action_map.json
100
- β”‚ └── titan-server # Final Rust binary
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
- └── package.json
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
- This is the complete Titan architecture:
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: Titan Routes (DSL)
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 will:
218
+ Titan Dev Mode:
158
219
 
159
- - Regenerate routes on every save
160
- - Rebundle actions automatically
161
- - **Kill and restart the Rust server safely**
162
- - Give full hot reload like modern JS frameworks
220
+ * Rebuilds routes automatically
221
+ * Rebundles actions
222
+ * Restarts Rust server safely
223
+ * Provides instant backend hot reload
163
224
 
164
- Full DX flow:
225
+ Flow:
165
226
 
166
227
  ```
167
- Save file β†’ auto rebuild β†’ auto restart β†’ updated API
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 goes into:
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
- # ☁ Deploying Titan
251
+ # ☁ Uploading Titan to GitHub
199
252
 
200
- After `tit build`, deploy the `server/` folder anywhere:
253
+ Titan projects are designed for **direct repository upload**.
201
254
 
202
- - Railway
203
- - Fly.io
204
- - Docker
205
- - VPS
206
- - Render
207
- - Bare metal
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
- Start command:
267
+ Push to GitHub:
210
268
 
211
269
  ```bash
212
- ./titan-server
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
- No Node.js needed in production β€” Titan runs as a pure Rust binary.
278
+ Your repo is now fully deployable with Docker.
216
279
 
217
280
  ---
218
281
 
219
- # 🧠 How Titan Works (Internals)
282
+ # ☁ Zero-Config Deployment with Docker
220
283
 
221
- ### 1. JavaScript DSL
222
- You write backend logic using Titan’s intuitive DSL.
284
+ Once pushed to GitHub, you can deploy anywhere.
223
285
 
224
- ### 2. Bundler
225
- Titan uses esbuild to compile JS actions into `.jsbundle`.
286
+ ## Deploy to Railway
226
287
 
227
- ### 3. Metadata
228
- `t.start()` writes:
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
- - `routes.json`
231
- - `action_map.json`
294
+ Railway will:
232
295
 
233
- ### 4. Rust Server
234
- Axum server:
296
+ * Build your Rust server
297
+ * Copy JS bundles
298
+ * Start the `titan-server` binary
299
+ * Expose the correct port
235
300
 
236
- - Loads `.jsbundle` actions
237
- - Injects request data
238
- - Executes JS via Boa
239
- - Returns JSON response to user
301
+ No configuration required.
240
302
 
241
- ### 5. Production Output
242
- Titan produces:
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
- - A **native binary**
245
- - JS bundles
246
- - Route maps
247
- - Entire backend in one folder
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 exists for developers who want:
344
+ Titan is for developers who want:
254
345
 
255
- - Rust performance
256
- - JavaScript simplicity
257
- - Zero Rust learning curve
258
- - Zero config deployment
259
- - Modern DX + native speed
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 bridges two worlds:
353
+ Titan merges two worlds:
262
354
 
263
- **JavaScript Productivity Γ— Rust Performance**
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
- - JS β†’ Rust server compiler
272
- - Action Engine
273
- - Axum Runtime
274
- - Titan DSL
275
- - Hot Reload Dev Mode
276
- - Railway/Fly.io Deployment
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
- PRs, issues, suggestions, and feature discussions are welcome.
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
- const cliTitan = path.join(__dirname, "templates", "titan");
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
- const backupDir = path.join(projectRoot, `titan_backup_${Date.now()}`);
235
- fs.renameSync(projectTitan, backupDir);
236
- console.log(green(`βœ” Backup created β†’ ${backupDir}`));
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
- const projectTemplateRoot = path.join(__dirname, "templates");
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(projectTemplateRoot, file);
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(green("βœ” Titan runtime updated successfully!"));
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@ezetgalaxy/titan",
3
- "version": "25.12.1",
3
+ "version": "25.12.3",
4
4
  "description": "JavaScript backend framework that compiles your JS into a Rust + Axum server.",
5
5
  "license": "ISC",
6
6
  "author": "ezetgalaxy",
@@ -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
+ }
@@ -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();