@ezetgalaxy/titan 25.12.2 β†’ 25.12.4

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,30 +64,61 @@ rustc -V
34
64
 
35
65
  ---
36
66
 
37
- ## New Features
38
- To get new features:
39
- ```bash
40
- tit update
41
- ```
42
-
43
- ## ✨ Features
44
-
45
- - Write your backend in **pure JavaScript**
46
- - Compile into a **native Rust HTTP server**
47
- - Titan DSL: `t.get()`, `t.post()`, `t.start()`
48
- - Automatic **route generation**
49
- - Automatic **JS action bundling**
50
- - Fast **Rust Axum runtime**
51
- - JavaScript execution via **Boa engine**
52
- - **Hot Reload Dev Server** (edit β†’ rebuild β†’ restart automatically)
53
- - Production output: **single binary**
54
- - Zero-config deployment
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
- ## πŸ“¦ Installation
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
- Install the Titan CLI globally:
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
- ## πŸš€ Create a New Titan Project
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 automatically:
137
+ Titan will:
77
138
 
78
- - Create project structure
79
- - Generate routes from `/app/app.js`
80
- - Bundle JS actions into `.jsbundle` files
81
- - 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
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 # Titan routes (DSL)
91
- β”‚ └── actions/
92
- β”‚ └── hello.js # Titan action
93
- β”‚
94
- β”œβ”€β”€ titan/
95
- β”‚ β”œβ”€β”€ titan.js # Titan DSL
96
- β”‚ β”œβ”€β”€ bundle.js # Bundler (esbuild)
97
- β”‚ └── 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
98
164
  β”‚
99
- β”œβ”€β”€ server/ # Rust backend (auto generated)
100
- β”‚ β”œβ”€β”€ src/
101
- β”‚ β”œβ”€β”€ actions/ # JS β†’ .jsbundle compiled actions
102
- β”‚ β”œβ”€β”€ titan/ # internal runtime files
103
- β”‚ β”œβ”€β”€ target/ # Cargo build output
104
- β”‚ β”œβ”€β”€ routes.json
105
- β”‚ β”œβ”€β”€ action_map.json
106
- β”‚ └── 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
107
173
  β”‚
108
- └── package.json
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
- This is the complete Titan architecture:
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: Titan Routes (DSL)
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 will:
218
+ Titan Dev Mode:
164
219
 
165
- - Regenerate routes on every save
166
- - Rebundle actions automatically
167
- - **Kill and restart the Rust server safely**
168
- - 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
169
224
 
170
- Full DX flow:
225
+ Flow:
171
226
 
172
227
  ```
173
- Save file β†’ auto rebuild β†’ auto restart β†’ updated API
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 goes into:
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
- # ☁ Deploying Titan
251
+ # ☁ Uploading Titan to GitHub
205
252
 
206
- After `tit build`, deploy the `server/` folder anywhere:
253
+ Titan projects are designed for **direct repository upload**.
207
254
 
208
- - Railway
209
- - Fly.io
210
- - Docker
211
- - VPS
212
- - Render
213
- - 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
+ ```
214
266
 
215
- Start command:
267
+ Push to GitHub:
216
268
 
217
269
  ```bash
218
- ./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
219
276
  ```
220
277
 
221
- No Node.js needed in production β€” Titan runs as a pure Rust binary.
278
+ Your repo is now fully deployable with Docker.
222
279
 
223
280
  ---
224
281
 
225
- # 🧠 How Titan Works (Internals)
282
+ # ☁ Zero-Config Deployment with Docker
226
283
 
227
- ### 1. JavaScript DSL
228
- You write backend logic using Titan’s intuitive DSL.
284
+ Once pushed to GitHub, you can deploy anywhere.
229
285
 
230
- ### 2. Bundler
231
- Titan uses esbuild to compile JS actions into `.jsbundle`.
286
+ ## Deploy to Railway
232
287
 
233
- ### 3. Metadata
234
- `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
235
293
 
236
- - `routes.json`
237
- - `action_map.json`
294
+ Railway will:
238
295
 
239
- ### 4. Rust Server
240
- Axum server:
296
+ * Build your Rust server
297
+ * Copy JS bundles
298
+ * Start the `titan-server` binary
299
+ * Expose the correct port
241
300
 
242
- - Loads `.jsbundle` actions
243
- - Injects request data
244
- - Executes JS via Boa
245
- - Returns JSON response to user
301
+ No configuration required.
246
302
 
247
- ### 5. Production Output
248
- 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`
249
321
 
250
- - A **native binary**
251
- - JS bundles
252
- - Route maps
253
- - 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
254
339
 
255
340
  ---
256
341
 
257
342
  # 🎯 Why Titan Exists
258
343
 
259
- Titan exists for developers who want:
344
+ Titan is for developers who want:
260
345
 
261
- - Rust performance
262
- - JavaScript simplicity
263
- - Zero Rust learning curve
264
- - Zero config deployment
265
- - 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
266
352
 
267
- Titan bridges two worlds:
353
+ Titan merges two worlds:
268
354
 
269
- **JavaScript Productivity Γ— Rust Performance**
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
- - JS β†’ Rust server compiler
278
- - Action Engine
279
- - Axum Runtime
280
- - Titan DSL
281
- - Hot Reload Dev Mode
282
- - 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
283
373
 
284
374
  ---
285
375
 
286
376
  # 🀝 Contributing
287
377
 
288
- PRs, issues, suggestions, and feature discussions are welcome.
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
- 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.2",
3
+ "version": "25.12.4",
4
4
  "description": "JavaScript backend framework that compiles your JS into a Rust + Axum server.",
5
5
  "license": "ISC",
6
6
  "author": "ezetgalaxy",
@@ -6,7 +6,7 @@ RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
6
6
  && apt-get install -y nodejs
7
7
 
8
8
  # Install Titan CLI AND its required dependencies
9
- RUN npm install -g @ezetgalaxy/titan esbuild chokidar
9
+ RUN npm install -g @ezetgalaxy/titan
10
10
 
11
11
  WORKDIR /app
12
12
 
@@ -14,7 +14,7 @@ WORKDIR /app
14
14
  COPY . .
15
15
 
16
16
  # Install Titan dependencies LOCALLY
17
- RUN npm install esbuild chokidar
17
+ RUN npm install
18
18
 
19
19
  # Build Titan metadata (routes + bundles)
20
20
  RUN tit build
@@ -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();