@ezetgalaxy/titan 25.14.2 → 25.14.5

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/index.js CHANGED
@@ -187,66 +187,41 @@ function buildProd() {
187
187
 
188
188
  const root = process.cwd();
189
189
  const appJs = path.join(root, "app", "app.js");
190
- const bundler = path.join(root, "titan", "bundle.js");
191
190
  const serverDir = path.join(root, "server");
192
- const builtActionsDir = path.join(serverDir, "actions"); // REAL output
193
- const actionsOut = builtActionsDir; // final output
191
+ const actionsOut = path.join(serverDir, "actions");
194
192
 
195
- // --------------------------------------------
196
- // 0) Basic validation
197
- // --------------------------------------------
193
+ // BASIC CHECKS
198
194
  if (!fs.existsSync(appJs)) {
199
195
  console.log(red("ERROR: app/app.js not found."));
200
196
  process.exit(1);
201
197
  }
202
198
 
203
- if (!fs.existsSync(bundler)) {
204
- console.log(red("ERROR: titan/bundle.js not found."));
205
- process.exit(1);
206
- }
207
-
208
- // --------------------------------------------
209
- // 1) Generate routes + action_map via DSL
210
- // --------------------------------------------
211
- console.log(cyan("→ Generating Titan metadata..."));
199
+ // ----------------------------------------------------
200
+ // 1) BUILD METADATA + BUNDLE ACTIONS (ONE TIME ONLY)
201
+ // ----------------------------------------------------
202
+ console.log(cyan("→ Building Titan metadata + bundling actions..."));
212
203
  execSync("node app/app.js --build", { stdio: "inherit" });
213
204
 
214
- // --------------------------------------------
215
- // 2) Bundle JS actions
216
- // --------------------------------------------
217
- console.log(cyan("→ Bundling Titan actions..."));
218
- execSync("node titan/bundle.js", { stdio: "inherit" });
219
-
220
- // --------------------------------------------
221
- // 3) Ensure server/actions exists
222
- // --------------------------------------------
205
+ // ensure actions directory exists
223
206
  fs.mkdirSync(actionsOut, { recursive: true });
224
207
 
225
- // --------------------------------------------
226
- // 4) List & verify bundles
227
- // --------------------------------------------
228
- if (!fs.existsSync(builtActionsDir)) {
229
- console.log(red("ERROR: Titan bundler did NOT generate server/actions directory."));
230
- console.log(red("This means titan/bundle.js output path is incorrect."));
208
+ // verify bundled actions exist
209
+ const bundles = fs.readdirSync(actionsOut).filter(f => f.endsWith(".jsbundle"));
210
+ if (bundles.length === 0) {
211
+ console.log(red("ERROR: No actions bundled."));
212
+ console.log(red("Make sure your DSL outputs to server/actions."));
231
213
  process.exit(1);
232
214
  }
233
215
 
234
- const bundles = fs.readdirSync(builtActionsDir)
235
- .filter(f => f.endsWith(".jsbundle"));
236
-
237
- if (bundles.length === 0) {
238
- console.log(yellow("Warning: No actions bundled."));
239
- } else {
240
- for (const file of bundles) {
241
- console.log(cyan(`→ Found bundle: ${file}`));
242
- }
243
- }
216
+ bundles.forEach(file => {
217
+ console.log(cyan(`→ Found action bundle: ${file}`));
218
+ });
244
219
 
245
- console.log(green("✔ Actions copied to server/actions"));
220
+ console.log(green("✔ Actions ready in server/actions"));
246
221
 
247
- // --------------------------------------------
248
- // 5) Build Rust server
249
- // --------------------------------------------
222
+ // ----------------------------------------------------
223
+ // 2) BUILD RUST BINARY
224
+ // ----------------------------------------------------
250
225
  console.log(cyan("→ Building Rust release binary..."));
251
226
  execSync("cargo build --release", {
252
227
  cwd: serverDir,
@@ -257,6 +232,7 @@ function buildProd() {
257
232
  }
258
233
 
259
234
 
235
+
260
236
  /* START PRODUCTION BINARY */
261
237
  function startProd() {
262
238
  const isWin = process.platform === "win32";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ezetgalaxy/titan",
3
- "version": "25.14.2",
3
+ "version": "25.14.5",
4
4
  "description": "JavaScript backend framework that compiles your JS into a Rust + Axum server.",
5
5
  "license": "ISC",
6
6
  "author": "ezetgalaxy",
@@ -10,6 +10,8 @@ use axum::{
10
10
  Router,
11
11
  };
12
12
 
13
+ use std::path::Path;
14
+
13
15
  use boa_engine::{
14
16
  js_string,
15
17
  native_function::NativeFunction,
@@ -36,8 +38,6 @@ struct RouteVal {
36
38
  #[derive(Clone)]
37
39
  struct AppState {
38
40
  routes: Arc<HashMap<String, RouteVal>>,
39
- /// Project root — used only in dev mode
40
- project_root: PathBuf,
41
41
  }
42
42
 
43
43
  fn inject_t_fetch(ctx: &mut Context) {
@@ -130,20 +130,30 @@ fn detect_project_root() -> PathBuf {
130
130
  }
131
131
 
132
132
 
133
- fn resolve_actions_dir(project_root: &PathBuf) -> PathBuf {
134
- let exe = std::env::current_exe().unwrap();
135
- let exe_dir = exe.parent().unwrap();
133
+ fn resolve_actions_dir() -> PathBuf {
134
+ let exe = std::env::current_exe().unwrap_or_else(|_| PathBuf::from("."));
135
+ let exe_dir = exe.parent().unwrap_or(Path::new("/app")).to_path_buf();
136
+
137
+ // Detect production if running from Docker binary location
136
138
  let is_prod = exe_dir.to_string_lossy().contains("/app")
137
- || exe_dir.ends_with("release");
139
+ || exe.file_name().unwrap_or_default() == "titan-server";
138
140
 
139
141
  if is_prod {
140
- PathBuf::from("/app/actions")
141
- } else {
142
- project_root.join("server").join("actions")
142
+ // Final production directory
143
+ return PathBuf::from("/app/actions");
143
144
  }
145
+
146
+ // DEV: exe = <root>/server/target/debug/server(.exe)
147
+ exe_dir
148
+ .parent() // target
149
+ .unwrap_or(Path::new("."))
150
+ .parent() // server
151
+ .unwrap_or(Path::new("."))
152
+ .join("actions")
144
153
  }
145
154
 
146
155
 
156
+
147
157
  async fn dynamic_handler(
148
158
  State(state): State<AppState>,
149
159
  req: Request<Body>,
@@ -179,7 +189,7 @@ async fn dynamic_handler(
179
189
  .into_response();
180
190
  }
181
191
 
182
- let actions_dir = resolve_actions_dir(&state.project_root);
192
+ let actions_dir = resolve_actions_dir();
183
193
  let action_path = actions_dir.join(format!("{}.jsbundle", action_name));
184
194
 
185
195
  if !action_path.exists() {
@@ -243,11 +253,10 @@ async fn main() -> Result<()> {
243
253
  let routes_map: HashMap<String, RouteVal> =
244
254
  serde_json::from_value(json["routes"].clone()).unwrap_or_default();
245
255
 
246
- let project_root = detect_project_root();
256
+ let _project_root = detect_project_root();
247
257
 
248
258
  let state = AppState {
249
259
  routes: Arc::new(routes_map),
250
- project_root,
251
260
  };
252
261
 
253
262
 
@@ -258,7 +267,16 @@ let state = AppState {
258
267
  .with_state(state);
259
268
 
260
269
  let listener = TcpListener::bind(format!("0.0.0.0:{}", port)).await?;
261
- println!("Titan server running on {}", port);
270
+ // TITAN BANNER
271
+ println!("\n\x1b[38;5;208m████████╗██╗████████╗ █████╗ ███╗ ██╗");
272
+ println!("╚══██╔══╝██║╚══██╔══╝██╔══██╗████╗ ██║");
273
+ println!(" ██║ ██║ ██║ ███████║██╔██╗ ██║");
274
+ println!(" ██║ ██║ ██║ ██╔══██║██║╚██╗██║");
275
+ println!(" ██║ ██║ ██║ ██║ ██║██║ ╚████║");
276
+ println!(" ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝\x1b[0m\n");
277
+
278
+
279
+ println!("\x1b[38;5;39mTitan server running at:\x1b[0m http://localhost:{}", port);
262
280
 
263
281
  axum::serve(listener, app).await?;
264
282
  Ok(())