@ezetgalaxy/titan 26.8.3 → 26.9.1

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.
Files changed (106) hide show
  1. package/README.md +76 -17
  2. package/index.js +118 -29
  3. package/package.json +1 -2
  4. package/templates/extension/README.md +104 -104
  5. package/templates/extension/index.js +27 -27
  6. package/templates/extension/jsconfig.json +12 -12
  7. package/templates/extension/native/Cargo.toml +9 -9
  8. package/templates/extension/native/src/lib.rs +5 -5
  9. package/templates/extension/package.json +20 -20
  10. package/templates/extension/titan.json +17 -17
  11. package/templates/js/Dockerfile +66 -66
  12. package/templates/js/_dockerignore +3 -3
  13. package/templates/js/_gitignore +1 -0
  14. package/templates/js/app/actions/hello.js +5 -5
  15. package/templates/js/app/titan.d.ts +87 -87
  16. package/templates/js/jsconfig.json +18 -18
  17. package/templates/js/server/src/action_management.rs +131 -131
  18. package/templates/js/server/src/errors.rs +10 -10
  19. package/templates/js/server/src/extensions.rs +989 -989
  20. package/templates/js/server/src/utils.rs +33 -33
  21. package/templates/js/titan/bundle.js +78 -78
  22. package/templates/js/titan/dev.js +9 -1
  23. package/templates/js/titan/titan.js +122 -122
  24. package/templates/{rust → rust-js}/Dockerfile +66 -66
  25. package/templates/{rust → rust-js}/_dockerignore +3 -3
  26. package/templates/{rust → rust-js}/_gitignore +1 -0
  27. package/templates/{rust → rust-js}/app/actions/hello.js +5 -5
  28. package/templates/{rust → rust-js}/app/actions/rust_hello.rs +14 -14
  29. package/templates/{rust → rust-js}/app/titan.d.ts +101 -101
  30. package/templates/{rust → rust-js}/jsconfig.json +18 -18
  31. package/templates/{rust → rust-js}/package.json +1 -1
  32. package/templates/{rust → rust-js}/server/src/action_management.rs +131 -131
  33. package/templates/{rust → rust-js}/server/src/errors.rs +10 -10
  34. package/templates/{rust → rust-js}/server/src/extensions.rs +989 -989
  35. package/templates/{rust → rust-js}/server/src/utils.rs +33 -33
  36. package/templates/{rust → rust-js}/titan/dev.js +9 -1
  37. package/templates/rust-ts/Dockerfile +66 -0
  38. package/templates/rust-ts/_dockerignore +3 -0
  39. package/templates/rust-ts/_gitignore +38 -0
  40. package/templates/rust-ts/app/actions/hello.ts +11 -0
  41. package/templates/rust-ts/app/actions/rust_hello.rs +14 -0
  42. package/templates/rust-ts/app/app.ts +11 -0
  43. package/templates/rust-ts/package.json +14 -0
  44. package/templates/rust-ts/server/Cargo.lock +2869 -0
  45. package/templates/rust-ts/server/Cargo.toml +39 -0
  46. package/templates/rust-ts/server/src/action_management.rs +131 -0
  47. package/templates/rust-ts/server/src/errors.rs +51 -0
  48. package/templates/rust-ts/server/src/extensions.rs +989 -0
  49. package/templates/rust-ts/server/src/main.rs +468 -0
  50. package/templates/rust-ts/server/src/utils.rs +33 -0
  51. package/templates/rust-ts/titan/bundle.js +163 -0
  52. package/templates/rust-ts/titan/dev.js +402 -0
  53. package/templates/rust-ts/titan/titan.d.ts +117 -0
  54. package/templates/rust-ts/titan/titan.js +122 -0
  55. package/templates/rust-ts/tsconfig.json +21 -0
  56. package/templates/ts/Dockerfile +40 -0
  57. package/templates/ts/_dockerignore +3 -0
  58. package/templates/ts/_gitignore +38 -0
  59. package/templates/ts/app/actions/hello.ts +11 -0
  60. package/templates/ts/app/app.ts +10 -0
  61. package/templates/ts/package.json +26 -0
  62. package/templates/ts/server/Cargo.lock +2869 -0
  63. package/templates/ts/server/Cargo.toml +27 -0
  64. package/templates/ts/server/src/action_management.rs +131 -0
  65. package/templates/ts/server/src/errors.rs +51 -0
  66. package/templates/ts/server/src/extensions.rs +989 -0
  67. package/templates/ts/server/src/main.rs +437 -0
  68. package/templates/ts/server/src/utils.rs +33 -0
  69. package/templates/ts/titan/builder.js +121 -0
  70. package/templates/ts/titan/bundle.js +76 -0
  71. package/templates/ts/titan/dev.js +402 -0
  72. package/templates/ts/titan/runtime.js +1 -0
  73. package/templates/ts/titan/titan.d.ts +117 -0
  74. package/templates/ts/titan/titan.js +122 -0
  75. package/templates/ts/tsconfig.json +16 -0
  76. package/titanpl-sdk/README.md +109 -109
  77. package/titanpl-sdk/bin/run.js +251 -254
  78. package/titanpl-sdk/index.d.ts +46 -46
  79. package/titanpl-sdk/index.js +5 -5
  80. package/titanpl-sdk/package.json +32 -32
  81. package/titanpl-sdk/templates/.dockerignore +3 -3
  82. package/titanpl-sdk/templates/Dockerfile +53 -53
  83. package/titanpl-sdk/templates/app/actions/hello.js +5 -5
  84. package/titanpl-sdk/templates/app/titan.d.ts +87 -87
  85. package/titanpl-sdk/templates/jsconfig.json +18 -18
  86. package/titanpl-sdk/templates/server/src/action_management.rs +131 -131
  87. package/titanpl-sdk/templates/server/src/errors.rs +10 -10
  88. package/titanpl-sdk/templates/server/src/extensions.rs +640 -640
  89. package/titanpl-sdk/templates/server/src/utils.rs +33 -33
  90. package/titanpl-sdk/templates/titan/bundle.js +65 -65
  91. package/titanpl-sdk/templates/titan/dev.js +113 -113
  92. package/titanpl-sdk/templates/titan/titan.js +98 -98
  93. package/templates/js/server/action_map.json +0 -3
  94. package/templates/js/server/actions/hello.jsbundle +0 -48
  95. package/templates/js/server/routes.json +0 -16
  96. package/templates/rust/server/action_map.json +0 -3
  97. package/templates/rust/server/actions/hello.jsbundle +0 -47
  98. package/templates/rust/server/routes.json +0 -22
  99. package/templates/rust/server/src/actions_rust/mod.rs +0 -19
  100. package/templates/rust/server/src/actions_rust/rust_hello.rs +0 -14
  101. /package/templates/{rust → rust-js}/app/app.js +0 -0
  102. /package/templates/{rust → rust-js}/server/Cargo.lock +0 -0
  103. /package/templates/{rust → rust-js}/server/Cargo.toml +0 -0
  104. /package/templates/{rust → rust-js}/server/src/main.rs +0 -0
  105. /package/templates/{rust → rust-js}/titan/bundle.js +0 -0
  106. /package/templates/{rust → rust-js}/titan/titan.js +0 -0
package/README.md CHANGED
@@ -13,6 +13,7 @@
13
13
  💙 **Enjoy development mode `titan dev`**
14
14
  💟 **Titan Planet docs:** https://titan-docs-ez.vercel.app/docs
15
15
  🚀 **CLI: `titan` is now the canonical command. `tit` remains supported as an alias.**
16
+ 🛡️ **Strict Mode:** Titan now enforces zero type errors before running.
16
17
 
17
18
  ---
18
19
 
@@ -21,15 +22,15 @@
21
22
  [![npm version](https://img.shields.io/npm/v/@ezetgalaxy/titan.svg?style=flat-square)](https://www.npmjs.com/package/@ezetgalaxy/titan)
22
23
 
23
24
 
24
- **JavaScript Simplicity. Native Rust Power. Zero Configuration.**
25
+ **TypeScript Precision. JavaScript Simplicity. Native Rust Power. Zero Configuration.**
25
26
 
26
- Titan Planet is a **JavaScript-first Backend Framework** that compiles your application into a single, high-performance native binary. It embeds a V8 JavaScript runtime directly into a specialized Rust + Axum server.
27
+ Titan Planet is a **JavaScript/TypeScript-first Backend Framework** that compiles your application into a single, high-performance native binary. It embeds a V8 JavaScript runtime directly into a specialized Rust + Axum server.
27
28
 
28
- **Start with pure JavaScript.**
29
+ **Start with pure TypeScript/JavaScript.**
29
30
  **Need raw power? Add Rust actions seamlessly.**
30
31
  Titan handles the compilation, bundling, and routing automatically for both.
31
32
 
32
- Titan = **JavaScript productivity × Rust performance × Zero DevOps**
33
+ Titan = **TS/JS productivity × Rust performance × Zero DevOps**
33
34
 
34
35
  ---
35
36
 
@@ -38,8 +39,8 @@ Titan = **JavaScript productivity × Rust performance × Zero DevOps**
38
39
  | Feature | Titan | Express/Nest | FastAPI | Bun |
39
40
  | ------------------------------------ | ----- | ------------ | ------- | --------- |
40
41
  | Native binary output | ✅ Yes | ❌ No | ❌ No | ❌ No |
41
- | Hybrid Rust + JS Actions | ✅ Yes | ❌ No | ❌ No | ❌ No |
42
- | Pure JavaScript developer experience | ✅ Yes | Yes | ❌ No | ❌ Partial |
42
+ | Hybrid Rust + JS/TS Actions | ✅ Yes | ❌ No | ❌ No | ❌ No |
43
+ | Strict TypeScript Enforcement | ✅ Yes | Setup Req. | ❌ No | ❌ Partial |
43
44
  | Zero-config Docker deploy | ✅ Yes | ❌ No | ❌ No | ❌ No |
44
45
  | Action-based architecture | ✅ Yes | ❌ No | ❌ No | ❌ No |
45
46
  | Hot reload dev server | ✅ Yes | ❌ No | ❌ No | ❌ No |
@@ -62,7 +63,9 @@ npm install -g @ezetgalaxy/titan
62
63
  titan init my-app
63
64
  # Follow the interactive prompt to choose:
64
65
  # - JavaScript (Standard)
66
+ # - TypeScript (Strict)
65
67
  # - Rust + JavaScript (Beta)
68
+ # - Rust + TypeScript (Beta)
66
69
  ```
67
70
 
68
71
  Inside your project:
@@ -73,10 +76,11 @@ titan dev
73
76
 
74
77
  You'll see the Titan Dev Server spin up:
75
78
  ```
76
- Titan Planet v26.8.0 [ Dev Mode ]
79
+ Titan Planet v26.9.1 [ Dev Mode ]
77
80
 
78
- Type: Rust + JS Actions
81
+ Type: Rust + TS Actions
79
82
  Hot Reload: Enabled
83
+ Strict Mode: Active 🛡️
80
84
 
81
85
  • Preparing runtime... Done
82
86
  • A new orbit is ready for your app in 0.9s
@@ -87,18 +91,47 @@ You'll see the Titan Dev Server spin up:
87
91
 
88
92
  # ⚡ Hybrid Action System
89
93
 
90
- Titan is unique because it allows you to write endpoints in **both** JavaScript and Rust within the same project.
94
+ Titan is unique because it allows you to write endpoints in **JavaScript, TypeScript, and Rust** within the same project.
95
+
96
+ | Feature | Status | Notes |
97
+ | :--- | :--- | :--- |
98
+ | **Standard JavaScript** | ✅ Stable | Production Ready |
99
+ | **Standard TypeScript** | 🚧 Beta | **Ready for Dev**, Production Under Testing |
100
+ | **Rust + JS (Hybrid)** | 🧪 Experimental | **Dev Only**, Production Under Testing |
101
+ | **Rust + TS (Hybrid)** | 🧪 Experimental | **Dev Only**, Production Under Testing |
102
+
103
+ ### 🔵 TypeScript Actions (`app/actions/hello.ts`)
104
+ Fully typed, strict, and auto-compiled.
105
+
106
+ ```typescript
107
+ import { defineAction } from "../../titan/titan";
108
+
109
+ interface HelloResponse {
110
+ message: string;
111
+ user_name: string;
112
+ }
113
+
114
+ // "defineAction" provides automatic type inference for "req"
115
+ export const hello = defineAction((req): HelloResponse => {
116
+ t.log("Handling request with strict types...");
117
+
118
+ return {
119
+ message: "Hello from TypeScript!",
120
+ user_name: req.body.name || "Guest"
121
+ };
122
+ });
123
+ ```
91
124
 
92
125
  ### 🟡 JavaScript Actions (`app/actions/hello.js`)
93
126
  Perfect for business logic, rapid prototyping, and IO-bound tasks.
94
127
  ```javascript
95
- export function run(req) {
128
+ export const hello = defineAction((req) => {
96
129
  t.log("Handling user request...");
97
130
  return {
98
131
  message: "Hello from JavaScript!",
99
132
  user_id: req.params.id
100
133
  };
101
- }
134
+ });
102
135
  ```
103
136
 
104
137
  ### 🔴 Rust Actions (Beta)
@@ -115,17 +148,43 @@ pub async fn run(req: Request<Body>) -> impl IntoResponse {
115
148
  }
116
149
  ```
117
150
 
118
- **Titan automatically detects, compiles, and routes both types.**
151
+ **Titan automatically detects, compiles, and routes all types.**
152
+ * `.ts` files are type-checked and compiled with esbuild.
119
153
  * `.js` files are bundled with esbuild.
120
154
  * `.rs` files are compiled into the native binary.
121
- * Both share the same `routes.json` configuration.
155
+ * All share the same `routes.json` configuration.
156
+
157
+ ---
158
+
159
+ # 🛡️ Strict Type Safety & Error Logs
160
+
161
+ Titan prioritizes code quality by enforcing **Strict TypeScript** logic during development.
162
+
163
+ If `titan dev` detects a type error, the server **will not run**. This ensures you never ship or test broken code.
164
+
165
+ ### Sample Error Output
166
+ When a type error occurs, Titan pauses execution and provides a clear, actionable log:
167
+
168
+ ```text
169
+ [Titan] ❌ TypeScript Error:
170
+ app/actions/payment.ts(12,5): error TS2322: Type 'string' is not assignable to type 'number'.
171
+
172
+ 10 | const amount: number = req.body.amount;
173
+ 11 |
174
+ > 12 | processPayment( "100" ); // Error here
175
+ | ^^^^^^^^^^^^^^^^^^^^^^^
176
+
177
+ [Titan] 🛑 Server paused due to type errors. Fix them to resume.
178
+ ```
179
+
180
+ Once fixed, the server automatically resumes.
122
181
 
123
182
  ---
124
183
 
125
184
  # ✨ Core Capabilities
126
185
 
127
186
  ### 🔌 Unified Runtime API (`t`)
128
- Both JS and Rust actions have access to the powerful `t` namespace:
187
+ All actions (JS/TS/Rust) have access to the powerful `t` namespace:
129
188
 
130
189
  * `t.fetch(url, options)` — High-performance HTTP client
131
190
  * `t.log(msg)` — Sandboxed, structured logging
@@ -143,7 +202,7 @@ Extend the runtime with custom Rust engines using **Titan Extensions**.
143
202
 
144
203
  # 📦 Deployment
145
204
 
146
- Titan compiles your entire app—JS code, Rust code, and server logic—into a **single executable**.
205
+ Titan compiles your entire app—JS/TS code, Rust code, and server logic—into a **single executable**.
147
206
 
148
207
  * **Tiny Docker Images**: Alpine-based, ~20MB compressed.
149
208
  * **Instant Startup**: No node_modules overhead.
@@ -152,7 +211,7 @@ Titan compiles your entire app—JS code, Rust code, and server logic—into a *
152
211
  ---
153
212
 
154
213
  # 🧱 Architecture Note
155
- Titan is **not** a Node.js framework. It is a Rust server that speaks JavaScript.
214
+ Titan is **not** a Node.js framework. It is a Rust server that speaks JavaScript/TypeScript.
156
215
  * **No Event Loop** for JS (Request/Response model).
157
216
  * **No `require`** (Use raw imports or bundled dependencies).
158
217
  * **True Isolation** per request.
@@ -161,6 +220,6 @@ Titan is **not** a Node.js framework. It is a Rust server that speaks JavaScript
161
220
 
162
221
  **Titan v26 — Stable**
163
222
  * Production-ready Hybrid Runtime
223
+ * Strict TypeScript Support
164
224
  * Native Rust Performance
165
225
  * Zero-Config Cloud Deployment
166
-
package/index.js CHANGED
@@ -107,7 +107,7 @@ function help() {
107
107
  console.log(`
108
108
  ${bold(cyan("Titan Planet"))} v${TITAN_VERSION}
109
109
 
110
- ${green("titan init <project>")} Create new Titan project
110
+ ${green("titan init <project> [-t <template>]")} Create new Titan project
111
111
  ${green("titan create ext <name>")} Create new Titan extension
112
112
  ${green("titan dev")} Dev mode (hot reload)
113
113
  ${green("titan build")} Build production Rust server
@@ -123,37 +123,82 @@ ${yellow("Note: `tit` is supported as a legacy alias.")}
123
123
  * INIT
124
124
  * ----------------------------------------------------- */
125
125
  async function initProject(name, templateName) {
126
- if (!name) {
127
- console.log(red("Usage: titan init <project> [--template <js|rust>]"));
128
- return;
126
+ let projName = name;
127
+
128
+ if (!projName) {
129
+ const response = await prompts({
130
+ type: 'text',
131
+ name: 'value',
132
+ message: 'Project name:',
133
+ initial: 'my-titan-app'
134
+ });
135
+
136
+ if (!response.value) {
137
+ console.log(red("✖ Operation cancelled"));
138
+ return;
139
+ }
140
+ projName = response.value;
129
141
  }
130
142
 
131
143
  let selectedTemplate = templateName;
132
144
 
133
145
  if (!selectedTemplate) {
134
- const response = await prompts({
146
+ // 1. Language Selection
147
+ const langRes = await prompts({
135
148
  type: 'select',
136
149
  name: 'value',
137
- message: 'Select a template:',
150
+ message: 'Select language:',
138
151
  choices: [
139
- { title: 'JavaScript', description: 'Standard Titan app with JS actions', value: 'js' },
140
- { title: `Rust + JavaScript ${yellow('(Beta)')}`, description: 'High-performance Rust actions + JS flexibility', value: 'rust' }
152
+ { title: 'JavaScript', value: 'js' },
153
+ { title: 'TypeScript', value: 'ts' }
141
154
  ],
142
155
  initial: 0
143
156
  });
144
157
 
145
- if (!response.value) {
158
+ if (!langRes.value) {
159
+ console.log(red("✖ Operation cancelled"));
160
+ return;
161
+ }
162
+ const lang = langRes.value;
163
+
164
+ // 2. Template Selection
165
+ const archRes = await prompts({
166
+ type: 'select',
167
+ name: 'value',
168
+ message: 'Select template:',
169
+ choices: [
170
+ {
171
+ title: `Standard (${lang.toUpperCase()})`,
172
+ description: `Standard Titan app with ${lang.toUpperCase()} actions`,
173
+ value: 'standard'
174
+ },
175
+ {
176
+ title: `Rust + ${lang.toUpperCase()} (Hybrid)`,
177
+ description: `High-performance Rust actions + ${lang.toUpperCase()} flexibility`,
178
+ value: 'hybrid'
179
+ }
180
+ ],
181
+ initial: 0
182
+ });
183
+
184
+ if (!archRes.value) {
146
185
  console.log(red("✖ Operation cancelled"));
147
186
  return;
148
187
  }
149
- selectedTemplate = response.value;
188
+ const arch = archRes.value;
189
+
190
+ if (lang === 'js') {
191
+ selectedTemplate = arch === 'standard' ? 'js' : 'rust-js';
192
+ } else {
193
+ selectedTemplate = arch === 'standard' ? 'ts' : 'rust-ts';
194
+ }
150
195
  }
151
196
 
152
- const target = path.join(process.cwd(), name);
197
+ const target = path.join(process.cwd(), projName);
153
198
  const templateDir = path.join(__dirname, "templates", selectedTemplate);
154
199
 
155
200
  if (!fs.existsSync(templateDir)) {
156
- console.log(red(`Template '${selectedTemplate}' not found. Available: js, rust`));
201
+ console.log(red(`Template '${selectedTemplate}' not found.`));
157
202
  return;
158
203
  }
159
204
 
@@ -164,7 +209,7 @@ async function initProject(name, templateName) {
164
209
 
165
210
  console.log("\n" + bold(cyan("🚀 Initializing Titan Project...")));
166
211
  console.log(gray(` Target: ${target}`));
167
- console.log(gray(` Template: ${selectedTemplate === 'rust' ? 'Rust + JS (Native Perf)' : 'JavaScript (Standard)'}`));
212
+ console.log(gray(` Template: ${selectedTemplate}`));
168
213
 
169
214
  // ----------------------------------------------------------
170
215
  // 1. Copy full template directory
@@ -198,7 +243,7 @@ async function initProject(name, templateName) {
198
243
  console.log(cyan("📦 Installing dependencies..."));
199
244
 
200
245
  try {
201
- execSync(`npm install esbuild chokidar --silent`, {
246
+ execSync(`npm install --silent`, {
202
247
  cwd: target,
203
248
  stdio: "inherit",
204
249
  });
@@ -210,7 +255,7 @@ async function initProject(name, templateName) {
210
255
  console.log("\n" + bold(green("🎉 You're all set!")));
211
256
  console.log(`
212
257
  ${gray("Next steps:")}
213
- ${cyan(`cd ${name}`)}
258
+ ${cyan(`cd ${projName}`)}
214
259
  ${cyan("titan dev")}
215
260
  `);
216
261
  }
@@ -244,7 +289,7 @@ async function devServer() {
244
289
  /* -------------------------------------------------------
245
290
  * BUILD
246
291
  * ----------------------------------------------------- */
247
- function buildProd() {
292
+ async function buildProd() {
248
293
  console.log(cyan("Titan: Building production output..."));
249
294
 
250
295
  const root = process.cwd();
@@ -253,11 +298,34 @@ function buildProd() {
253
298
  const actionsOut = path.join(serverDir, "actions");
254
299
 
255
300
  // BASIC CHECKS
256
- if (!fs.existsSync(appJs)) {
257
- console.log(red("ERROR: app/app.js not found."));
301
+ if (!fs.existsSync(appJs) && !fs.existsSync(path.join(root, "app", "app.ts"))) {
302
+ console.log(red("ERROR: app/app.js or app/app.ts not found."));
258
303
  process.exit(1);
259
304
  }
260
305
 
306
+ // COMPILE TYPESCRIPT IF NEEDED
307
+ if (fs.existsSync(path.join(root, "tsconfig.json"))) {
308
+ console.log(cyan("→ Compiling TypeScript..."));
309
+ try {
310
+ // We use esbuild for speed and consistency with dev mode
311
+ const { buildSync } = await import("esbuild");
312
+ buildSync({
313
+ entryPoints: [path.join(root, "app", "app.ts")],
314
+ outfile: appJs,
315
+ bundle: true,
316
+ platform: "node",
317
+ format: "esm",
318
+ external: ["fs", "path", "esbuild", "chokidar", "typescript"],
319
+ packages: "external",
320
+ });
321
+ console.log(green("✔ TypeScript compiled"));
322
+ } catch (e) {
323
+ console.log(red("ERROR: Failed to compile TypeScript."));
324
+ console.error(e);
325
+ process.exit(1);
326
+ }
327
+ }
328
+
261
329
  // ----------------------------------------------------
262
330
  // 1) BUILD METADATA + BUNDLE ACTIONS (ONE TIME ONLY)
263
331
  // ----------------------------------------------------
@@ -285,23 +353,42 @@ function buildProd() {
285
353
  // 2) BUILD RUST BINARY
286
354
  // ----------------------------------------------------
287
355
  console.log(cyan("→ Building Rust release binary..."));
288
- execSync("cargo build --release", {
289
- cwd: serverDir,
290
- stdio: "inherit"
291
- });
292
356
 
293
- console.log(green("✔ Titan production build complete!"));
357
+ // Only build rust if it's a rust project (check Cargo.toml)
358
+ if (fs.existsSync(path.join(serverDir, "Cargo.toml"))) {
359
+ execSync("cargo build --release", {
360
+ cwd: serverDir,
361
+ stdio: "inherit"
362
+ });
363
+ console.log(green("✔ Titan production build complete!"));
364
+ } else {
365
+ console.log(green("✔ Titan production build complete (pure JS/TS)!"));
366
+ }
294
367
  }
295
368
 
296
369
  /* -------------------------------------------------------
297
370
  * START
298
371
  * ----------------------------------------------------- */
299
- function startProd() {
372
+ async function startProd() {
300
373
  const isWin = process.platform === "win32";
301
374
  const bin = isWin ? "titan-server.exe" : "titan-server";
375
+ const root = process.cwd();
376
+
377
+ const exe = path.join(root, "server", "target", "release", bin);
378
+
379
+ if (fs.existsSync(exe)) {
380
+ execSync(`"${exe}"`, { stdio: "inherit" });
381
+ } else {
382
+ // Fallback to pure node start if no rust binary
383
+ const appJs = path.join(root, "app", "app.js");
384
+ // Actually, typically we run the bundled/compiled app if we don't have rust server?
385
+ // But wait, the pure TS template runs `node .titan/app.js` in Docker.
386
+ // But locally `titan start` relies on `app/app.js` being compiled?
387
+ // In `buildProd` above we compiled to `app/app.js`.
388
+ // Let's check for `.titan/app.js` which is dev artifact? No, use the prod build artifact.
389
+ execSync(`node "${appJs}"`, { stdio: "inherit" });
390
+ }
302
391
 
303
- const exe = path.join(process.cwd(), "server", "target", "release", bin);
304
- execSync(`"${exe}"`, { stdio: "inherit" });
305
392
  }
306
393
 
307
394
  /* -------------------------------------------------------
@@ -335,7 +422,9 @@ function updateTitan() {
335
422
  }
336
423
 
337
424
  if (!fs.existsSync(templateServer)) {
338
- console.log(red("CLI is corrupted server template missing."));
425
+ console.log(red(`CLI seems corrupted or incomplete.`));
426
+ console.log(red(`Expected server template at: ${templateServer}`));
427
+ console.log(yellow(`If you are running from npx, try clearing cache or installing a specific version.`));
339
428
  return;
340
429
  }
341
430
 
@@ -539,8 +628,8 @@ if (cmd === "create" && args[1] === "ext") {
539
628
  break;
540
629
  }
541
630
  case "dev": devServer(); break;
542
- case "build": buildProd(); break;
543
- case "start": startProd(); break;
631
+ case "build": await buildProd(); break;
632
+ case "start": await startProd(); break;
544
633
  case "update": updateTitan(); break;
545
634
  case "--version":
546
635
  case "-v":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ezetgalaxy/titan",
3
- "version": "26.8.3",
3
+ "version": "26.9.1",
4
4
  "description": "Titan Planet is a JavaScript-first backend framework that embeds JS actions into a Rust + Axum server and ships as a single native binary. Routes are compiled to static metadata; only actions run in the embedded JS runtime. No Node.js. No event loop in production.",
5
5
  "license": "ISC",
6
6
  "author": "ezetgalaxy",
@@ -13,7 +13,6 @@
13
13
  "files": [
14
14
  "index.js",
15
15
  "templates/",
16
- "titan",
17
16
  "titanpl-sdk",
18
17
  "README.md"
19
18
  ],
@@ -1,104 +1,104 @@
1
- # 🪐 Titan Extension: {{name}}
2
-
3
- > Elevate Titan Planet with custom JavaScript and high-performance Native Rust logic.
4
-
5
- Welcome to your new Titan extension! This template provides everything you need to build, test, and deploy powerful additions to the Titan project.
6
-
7
- ---
8
-
9
- ## 🛠 Project Structure
10
-
11
- - `index.js`: The JavaScript entry point where you define your extension's API on the global `t` object.
12
- - `titan.json`: Manifest file defining extension metadata and Native module mappings.
13
- - `native/`: Directory for Rust source code.
14
- - `src/lib.rs`: Your Native function implementations.
15
- - `Cargo.toml`: Rust package and dependency configuration.
16
- - `jsconfig.json`: Enables full IntelliSense for the Titan Runtime API.
17
-
18
- ---
19
-
20
- ## 🚀 Quick Start
21
-
22
- ### 1. Install Dependencies
23
- Get full type support in your IDE:
24
- ```bash
25
- npm install
26
- ```
27
-
28
- ### 2. Build Native Module (Optional)
29
- If your extension uses Rust, compile it to a dynamic library:
30
- ```bash
31
- cd native
32
- cargo build --release
33
- cd ..
34
- ```
35
-
36
- ### 3. Test the Extension
37
- Use the Titan SDK to run a local test harness:
38
- ```bash
39
- titan run ext
40
- ```
41
- *Tip: Visit `http://localhost:3000/test` after starting the runner to see your extension in action!*
42
-
43
- ---
44
-
45
- ## 💻 Development Guide
46
-
47
- ### Writing JavaScript
48
- Extensions interact with the global `t` object. It's best practice to namespace your extension:
49
-
50
- ```javascript
51
- t.{{name}} = {
52
- myMethod: (val) => {
53
- t.log("{{name}}", "Doing something...");
54
- return val * 2;
55
- }
56
- };
57
- ```
58
-
59
- ### Writing Native Rust Functions
60
- Native functions should be marked with `#[unsafe(no_mangle)]` and use `extern "C"`:
61
-
62
- ```rust
63
- #[unsafe(no_mangle)]
64
- pub extern "C" fn multiply(a: f64, b: f64) -> f64 {
65
- a * b
66
- }
67
- ```
68
-
69
- ### Mapping Native Functions in `titan.json`
70
- Expose your Rust functions to JavaScript by adding them to the `native.functions` section:
71
-
72
- ```json
73
- "functions": {
74
- "add": {
75
- "symbol": "add",
76
- "parameters": ["f64", "f64"],
77
- "result": "f64"
78
- }
79
- }
80
- ```
81
-
82
- ---
83
-
84
- ## 🧪 Testing with Titan SDK
85
-
86
- The `titan run ext` command automates the testing workflow:
87
- 1. It builds your native code.
88
- 2. It sets up a temporary Titan project environment.
89
- 3. It links your extension into `node_modules`.
90
- 4. It starts the Titan Runtime at `http://localhost:3000`.
91
-
92
- You can modify the test harness or add custom test cases by exploring the generated `.titan_test_run` directory (it is git-ignored).
93
-
94
- ---
95
-
96
- ## 📦 Deployment
97
- To use your extension in a Titan project:
98
- 1. Publish your extension to npm or link it locally.
99
- 2. In your Titan project: `npm install my-extension`.
100
- 3. The Titan Runtime will automatically detect and load your extension if it contains a `titan.json`.
101
-
102
- ---
103
-
104
- Happy coding on Titan Planet! 🚀
1
+ # 🪐 Titan Extension: {{name}}
2
+
3
+ > Elevate Titan Planet with custom JavaScript and high-performance Native Rust logic.
4
+
5
+ Welcome to your new Titan extension! This template provides everything you need to build, test, and deploy powerful additions to the Titan project.
6
+
7
+ ---
8
+
9
+ ## 🛠 Project Structure
10
+
11
+ - `index.js`: The JavaScript entry point where you define your extension's API on the global `t` object.
12
+ - `titan.json`: Manifest file defining extension metadata and Native module mappings.
13
+ - `native/`: Directory for Rust source code.
14
+ - `src/lib.rs`: Your Native function implementations.
15
+ - `Cargo.toml`: Rust package and dependency configuration.
16
+ - `jsconfig.json`: Enables full IntelliSense for the Titan Runtime API.
17
+
18
+ ---
19
+
20
+ ## 🚀 Quick Start
21
+
22
+ ### 1. Install Dependencies
23
+ Get full type support in your IDE:
24
+ ```bash
25
+ npm install
26
+ ```
27
+
28
+ ### 2. Build Native Module (Optional)
29
+ If your extension uses Rust, compile it to a dynamic library:
30
+ ```bash
31
+ cd native
32
+ cargo build --release
33
+ cd ..
34
+ ```
35
+
36
+ ### 3. Test the Extension
37
+ Use the Titan SDK to run a local test harness:
38
+ ```bash
39
+ titan run ext
40
+ ```
41
+ *Tip: Visit `http://localhost:3000/test` after starting the runner to see your extension in action!*
42
+
43
+ ---
44
+
45
+ ## 💻 Development Guide
46
+
47
+ ### Writing JavaScript
48
+ Extensions interact with the global `t` object. It's best practice to namespace your extension:
49
+
50
+ ```javascript
51
+ t.{{name}} = {
52
+ myMethod: (val) => {
53
+ t.log("{{name}}", "Doing something...");
54
+ return val * 2;
55
+ }
56
+ };
57
+ ```
58
+
59
+ ### Writing Native Rust Functions
60
+ Native functions should be marked with `#[unsafe(no_mangle)]` and use `extern "C"`:
61
+
62
+ ```rust
63
+ #[unsafe(no_mangle)]
64
+ pub extern "C" fn multiply(a: f64, b: f64) -> f64 {
65
+ a * b
66
+ }
67
+ ```
68
+
69
+ ### Mapping Native Functions in `titan.json`
70
+ Expose your Rust functions to JavaScript by adding them to the `native.functions` section:
71
+
72
+ ```json
73
+ "functions": {
74
+ "add": {
75
+ "symbol": "add",
76
+ "parameters": ["f64", "f64"],
77
+ "result": "f64"
78
+ }
79
+ }
80
+ ```
81
+
82
+ ---
83
+
84
+ ## 🧪 Testing with Titan SDK
85
+
86
+ The `titan run ext` command automates the testing workflow:
87
+ 1. It builds your native code.
88
+ 2. It sets up a temporary Titan project environment.
89
+ 3. It links your extension into `node_modules`.
90
+ 4. It starts the Titan Runtime at `http://localhost:3000`.
91
+
92
+ You can modify the test harness or add custom test cases by exploring the generated `.titan_test_run` directory (it is git-ignored).
93
+
94
+ ---
95
+
96
+ ## 📦 Deployment
97
+ To use your extension in a Titan project:
98
+ 1. Publish your extension to npm or link it locally.
99
+ 2. In your Titan project: `npm install my-extension`.
100
+ 3. The Titan Runtime will automatically detect and load your extension if it contains a `titan.json`.
101
+
102
+ ---
103
+
104
+ Happy coding on Titan Planet! 🚀