@ezetgalaxy/titan 26.8.2 → 26.9.0
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 +65 -25
- package/index.js +62 -15
- package/package.json +2 -2
- package/templates/extension/README.md +104 -104
- package/templates/extension/index.js +27 -27
- package/templates/extension/jsconfig.json +12 -12
- package/templates/extension/native/Cargo.toml +9 -9
- package/templates/extension/native/src/lib.rs +5 -5
- package/templates/extension/package.json +20 -20
- package/templates/extension/titan.json +17 -17
- package/templates/js/Dockerfile +66 -66
- package/templates/js/_dockerignore +3 -3
- package/templates/js/_gitignore +1 -0
- package/templates/js/app/actions/hello.js +5 -5
- package/templates/js/app/titan.d.ts +87 -87
- package/templates/js/jsconfig.json +18 -18
- package/templates/js/server/src/action_management.rs +131 -131
- package/templates/js/server/src/errors.rs +10 -10
- package/templates/js/server/src/extensions.rs +989 -989
- package/templates/js/server/src/utils.rs +33 -33
- package/templates/js/titan/bundle.js +78 -78
- package/templates/js/titan/dev.js +35 -3
- package/templates/js/titan/titan.js +122 -122
- package/templates/rust/Dockerfile +66 -66
- package/templates/rust/_dockerignore +3 -3
- package/templates/rust/_gitignore +1 -0
- package/templates/rust/app/actions/hello.js +5 -5
- package/templates/rust/app/actions/rust_hello.rs +14 -14
- package/templates/rust/app/titan.d.ts +101 -101
- package/templates/rust/jsconfig.json +18 -18
- package/templates/rust/server/src/action_management.rs +131 -131
- package/templates/rust/server/src/errors.rs +10 -10
- package/templates/rust/server/src/extensions.rs +989 -989
- package/templates/rust/server/src/utils.rs +33 -33
- package/templates/rust/titan/dev.js +36 -12
- package/templates/rust-ts/Dockerfile +66 -0
- package/templates/rust-ts/_dockerignore +3 -0
- package/templates/rust-ts/_gitignore +38 -0
- package/templates/rust-ts/app/actions/hello.ts +5 -0
- package/templates/rust-ts/app/actions/rust_hello.rs +14 -0
- package/templates/rust-ts/app/app.ts +11 -0
- package/templates/rust-ts/app/titan.d.ts +101 -0
- package/templates/rust-ts/package.json +14 -0
- package/templates/rust-ts/server/Cargo.lock +2869 -0
- package/templates/rust-ts/server/Cargo.toml +39 -0
- package/templates/rust-ts/server/src/action_management.rs +131 -0
- package/templates/rust-ts/server/src/errors.rs +51 -0
- package/templates/rust-ts/server/src/extensions.rs +989 -0
- package/templates/rust-ts/server/src/main.rs +468 -0
- package/templates/rust-ts/server/src/utils.rs +33 -0
- package/templates/rust-ts/titan/bundle.js +157 -0
- package/templates/rust-ts/titan/dev.js +402 -0
- package/templates/rust-ts/titan/titan.js +122 -0
- package/templates/rust-ts/tsconfig.json +21 -0
- package/templates/ts/Dockerfile +66 -0
- package/templates/ts/_dockerignore +3 -0
- package/templates/ts/_gitignore +38 -0
- package/templates/ts/app/actions/hello.ts +9 -0
- package/templates/ts/app/app.ts +10 -0
- package/templates/ts/app/titan.d.ts +102 -0
- package/templates/ts/package.json +26 -0
- package/templates/ts/server/Cargo.lock +2869 -0
- package/templates/ts/server/Cargo.toml +27 -0
- package/templates/ts/server/src/action_management.rs +131 -0
- package/templates/ts/server/src/errors.rs +51 -0
- package/templates/ts/server/src/extensions.rs +989 -0
- package/templates/ts/server/src/main.rs +437 -0
- package/templates/ts/server/src/utils.rs +33 -0
- package/templates/ts/titan/bundle.js +78 -0
- package/templates/ts/titan/dev.js +402 -0
- package/templates/ts/titan/titan.js +122 -0
- package/templates/ts/tsconfig.json +16 -0
- package/titanpl-sdk/README.md +109 -109
- package/titanpl-sdk/bin/run.js +254 -254
- package/titanpl-sdk/index.d.ts +46 -46
- package/titanpl-sdk/index.js +5 -5
- package/titanpl-sdk/package.json +32 -32
- package/titanpl-sdk/templates/.dockerignore +3 -3
- package/titanpl-sdk/templates/Dockerfile +53 -53
- package/titanpl-sdk/templates/app/actions/hello.js +5 -5
- package/titanpl-sdk/templates/app/titan.d.ts +87 -87
- package/titanpl-sdk/templates/jsconfig.json +18 -18
- package/titanpl-sdk/templates/server/src/action_management.rs +131 -131
- package/titanpl-sdk/templates/server/src/errors.rs +10 -10
- package/titanpl-sdk/templates/server/src/extensions.rs +640 -640
- package/titanpl-sdk/templates/server/src/utils.rs +33 -33
- package/titanpl-sdk/templates/titan/bundle.js +65 -65
- package/titanpl-sdk/templates/titan/dev.js +113 -113
- package/titanpl-sdk/templates/titan/titan.js +98 -98
- package/templates/js/server/action_map.json +0 -3
- package/templates/js/server/actions/hello.jsbundle +0 -48
- package/templates/js/server/routes.json +0 -16
- package/templates/rust/server/action_map.json +0 -3
- package/templates/rust/server/actions/hello.jsbundle +0 -47
- package/templates/rust/server/routes.json +0 -22
- package/templates/rust/server/src/actions_rust/mod.rs +0 -19
- package/templates/rust/server/src/actions_rust/rust_hello.rs +0 -14
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
pub fn blue(s: &str) -> String {
|
|
2
|
-
format!("\x1b[38;5;39m{}\x1b[0m", s)
|
|
3
|
-
}
|
|
4
|
-
pub fn white(s: &str) -> String {
|
|
5
|
-
format!("\x1b[39m{}\x1b[0m", s)
|
|
6
|
-
}
|
|
7
|
-
pub fn yellow(s: &str) -> String {
|
|
8
|
-
format!("\x1b[33m{}\x1b[0m", s)
|
|
9
|
-
}
|
|
10
|
-
pub fn green(s: &str) -> String {
|
|
11
|
-
format!("\x1b[32m{}\x1b[0m", s)
|
|
12
|
-
}
|
|
13
|
-
pub fn gray(s: &str) -> String {
|
|
14
|
-
format!("\x1b[90m{}\x1b[0m", s)
|
|
15
|
-
}
|
|
16
|
-
pub fn red(s: &str) -> String {
|
|
17
|
-
format!("\x1b[31m{}\x1b[0m", s)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
pub fn parse_expires_in(value: &str) -> Option<u64> {
|
|
21
|
-
let (num, unit) = value.split_at(value.len() - 1);
|
|
22
|
-
let n: u64 = num.parse().ok()?;
|
|
23
|
-
|
|
24
|
-
match unit {
|
|
25
|
-
"s" => Some(n),
|
|
26
|
-
"m" => Some(n * 60),
|
|
27
|
-
"h" => Some(n * 60 * 60),
|
|
28
|
-
"d" => Some(n * 60 * 60 * 24),
|
|
29
|
-
_ => None,
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
pub fn blue(s: &str) -> String {
|
|
2
|
+
format!("\x1b[38;5;39m{}\x1b[0m", s)
|
|
3
|
+
}
|
|
4
|
+
pub fn white(s: &str) -> String {
|
|
5
|
+
format!("\x1b[39m{}\x1b[0m", s)
|
|
6
|
+
}
|
|
7
|
+
pub fn yellow(s: &str) -> String {
|
|
8
|
+
format!("\x1b[33m{}\x1b[0m", s)
|
|
9
|
+
}
|
|
10
|
+
pub fn green(s: &str) -> String {
|
|
11
|
+
format!("\x1b[32m{}\x1b[0m", s)
|
|
12
|
+
}
|
|
13
|
+
pub fn gray(s: &str) -> String {
|
|
14
|
+
format!("\x1b[90m{}\x1b[0m", s)
|
|
15
|
+
}
|
|
16
|
+
pub fn red(s: &str) -> String {
|
|
17
|
+
format!("\x1b[31m{}\x1b[0m", s)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
pub fn parse_expires_in(value: &str) -> Option<u64> {
|
|
21
|
+
let (num, unit) = value.split_at(value.len() - 1);
|
|
22
|
+
let n: u64 = num.parse().ok()?;
|
|
23
|
+
|
|
24
|
+
match unit {
|
|
25
|
+
"s" => Some(n),
|
|
26
|
+
"m" => Some(n * 60),
|
|
27
|
+
"h" => Some(n * 60 * 60),
|
|
28
|
+
"d" => Some(n * 60 * 60 * 24),
|
|
29
|
+
_ => None,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
@@ -1,65 +1,65 @@
|
|
|
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") || f.endsWith(".ts"));
|
|
20
|
-
|
|
21
|
-
for (const file of files) {
|
|
22
|
-
const actionName = path.basename(file, path.extname(file));
|
|
23
|
-
|
|
24
|
-
const entry = path.join(actionsDir, file);
|
|
25
|
-
|
|
26
|
-
// Rust runtime expects `.jsbundle` extension — consistent with previous design
|
|
27
|
-
const outfile = path.join(outDir, actionName + ".jsbundle");
|
|
28
|
-
|
|
29
|
-
console.log(`[Titan] Bundling ${entry} → ${outfile}`);
|
|
30
|
-
|
|
31
|
-
await esbuild.build({
|
|
32
|
-
entryPoints: [entry],
|
|
33
|
-
outfile,
|
|
34
|
-
bundle: true,
|
|
35
|
-
format: "iife",
|
|
36
|
-
globalName: "__titan_exports",
|
|
37
|
-
platform: "neutral",
|
|
38
|
-
target: "es2020",
|
|
39
|
-
banner: {
|
|
40
|
-
js: "const defineAction = (fn) => fn;"
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
footer: {
|
|
44
|
-
js: `
|
|
45
|
-
(function () {
|
|
46
|
-
const fn =
|
|
47
|
-
__titan_exports["${actionName}"] ||
|
|
48
|
-
__titan_exports.default;
|
|
49
|
-
|
|
50
|
-
if (typeof fn !== "function") {
|
|
51
|
-
throw new Error("[Titan] Action '${actionName}' not found or not a function");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
globalThis["${actionName}"] = fn;
|
|
55
|
-
})();
|
|
56
|
-
`
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
console.log("[Titan] Bundling finished.");
|
|
65
|
-
}
|
|
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") || f.endsWith(".ts"));
|
|
20
|
+
|
|
21
|
+
for (const file of files) {
|
|
22
|
+
const actionName = path.basename(file, path.extname(file));
|
|
23
|
+
|
|
24
|
+
const entry = path.join(actionsDir, file);
|
|
25
|
+
|
|
26
|
+
// Rust runtime expects `.jsbundle` extension — consistent with previous design
|
|
27
|
+
const outfile = path.join(outDir, actionName + ".jsbundle");
|
|
28
|
+
|
|
29
|
+
console.log(`[Titan] Bundling ${entry} → ${outfile}`);
|
|
30
|
+
|
|
31
|
+
await esbuild.build({
|
|
32
|
+
entryPoints: [entry],
|
|
33
|
+
outfile,
|
|
34
|
+
bundle: true,
|
|
35
|
+
format: "iife",
|
|
36
|
+
globalName: "__titan_exports",
|
|
37
|
+
platform: "neutral",
|
|
38
|
+
target: "es2020",
|
|
39
|
+
banner: {
|
|
40
|
+
js: "const defineAction = (fn) => fn;"
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
footer: {
|
|
44
|
+
js: `
|
|
45
|
+
(function () {
|
|
46
|
+
const fn =
|
|
47
|
+
__titan_exports["${actionName}"] ||
|
|
48
|
+
__titan_exports.default;
|
|
49
|
+
|
|
50
|
+
if (typeof fn !== "function") {
|
|
51
|
+
throw new Error("[Titan] Action '${actionName}' not found or not a function");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
globalThis["${actionName}"] = fn;
|
|
55
|
+
})();
|
|
56
|
+
`
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
console.log("[Titan] Bundling finished.");
|
|
65
|
+
}
|
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
import chokidar from "chokidar";
|
|
2
|
-
import { spawn, execSync } from "child_process";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { fileURLToPath } from "url";
|
|
5
|
-
import fs from "fs";
|
|
6
|
-
import { bundle } from "./bundle.js";
|
|
7
|
-
|
|
8
|
-
// Required for __dirname in ES modules
|
|
9
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
const __dirname = path.dirname(__filename);
|
|
11
|
-
|
|
12
|
-
let serverProcess = null;
|
|
13
|
-
|
|
14
|
-
async function killServer() {
|
|
15
|
-
if (!serverProcess) return;
|
|
16
|
-
|
|
17
|
-
const pid = serverProcess.pid;
|
|
18
|
-
const killPromise = new Promise((resolve) => {
|
|
19
|
-
if (serverProcess.exitCode !== null) return resolve();
|
|
20
|
-
serverProcess.once("close", resolve);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
if (process.platform === "win32") {
|
|
24
|
-
try {
|
|
25
|
-
execSync(`taskkill /pid ${pid} /f /t`, { stdio: 'ignore' });
|
|
26
|
-
} catch (e) {
|
|
27
|
-
// Ignore errors if process is already dead
|
|
28
|
-
}
|
|
29
|
-
} else {
|
|
30
|
-
serverProcess.kill();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
await killPromise;
|
|
35
|
-
} catch (e) { }
|
|
36
|
-
serverProcess = null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function startRustServer() {
|
|
40
|
-
await killServer();
|
|
41
|
-
|
|
42
|
-
// Give the OS a moment to release file locks on the binary
|
|
43
|
-
await new Promise(r => setTimeout(r, 500));
|
|
44
|
-
|
|
45
|
-
const serverPath = path.join(process.cwd(), "server");
|
|
46
|
-
|
|
47
|
-
serverProcess = spawn("cargo", ["run"], {
|
|
48
|
-
cwd: serverPath,
|
|
49
|
-
stdio: "inherit",
|
|
50
|
-
shell: true
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
serverProcess.on("close", (code) => {
|
|
54
|
-
if (code !== null && code !== 0 && code !== 1) {
|
|
55
|
-
// 1 is often just 'terminated' on windows if forced, but also error.
|
|
56
|
-
// We just log it.
|
|
57
|
-
}
|
|
58
|
-
console.log(`[Titan] Rust server exited: ${code}`);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function rebuild() {
|
|
63
|
-
console.log("[Titan] Regenerating routes.json & action_map.json...");
|
|
64
|
-
execSync("node app/app.js", { stdio: "inherit" });
|
|
65
|
-
|
|
66
|
-
console.log("[Titan] Bundling JS actions...");
|
|
67
|
-
await bundle();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function startDev() {
|
|
71
|
-
console.log("[Titan] Dev mode starting...");
|
|
72
|
-
|
|
73
|
-
if (fs.existsSync(path.join(process.cwd(), ".env"))) {
|
|
74
|
-
console.log("\x1b[33m[Titan] Env Configured\x1b[0m");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// FIRST BUILD
|
|
78
|
-
try {
|
|
79
|
-
await rebuild();
|
|
80
|
-
await startRustServer();
|
|
81
|
-
} catch (e) {
|
|
82
|
-
console.log("\x1b[31m[Titan] Initial build failed. Waiting for changes...\x1b[0m");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const watcher = chokidar.watch(["app", ".env"], {
|
|
86
|
-
ignoreInitial: true
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
let timer = null;
|
|
90
|
-
|
|
91
|
-
watcher.on("all", async (event, file) => {
|
|
92
|
-
if (timer) clearTimeout(timer);
|
|
93
|
-
|
|
94
|
-
timer = setTimeout(async () => {
|
|
95
|
-
if (file.includes(".env")) {
|
|
96
|
-
console.log("\x1b[33m[Titan] Env Refreshed\x1b[0m");
|
|
97
|
-
} else {
|
|
98
|
-
console.log(`[Titan] Change detected: ${file}`);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
await rebuild();
|
|
103
|
-
console.log("[Titan] Restarting Rust server...");
|
|
104
|
-
await startRustServer();
|
|
105
|
-
} catch (e) {
|
|
106
|
-
console.log("\x1b[31m[Titan] Build failed -- waiting for changes...\x1b[0m");
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
}, 200);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
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 fs from "fs";
|
|
6
|
+
import { bundle } from "./bundle.js";
|
|
7
|
+
|
|
8
|
+
// Required for __dirname in ES modules
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
|
|
12
|
+
let serverProcess = null;
|
|
13
|
+
|
|
14
|
+
async function killServer() {
|
|
15
|
+
if (!serverProcess) return;
|
|
16
|
+
|
|
17
|
+
const pid = serverProcess.pid;
|
|
18
|
+
const killPromise = new Promise((resolve) => {
|
|
19
|
+
if (serverProcess.exitCode !== null) return resolve();
|
|
20
|
+
serverProcess.once("close", resolve);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (process.platform === "win32") {
|
|
24
|
+
try {
|
|
25
|
+
execSync(`taskkill /pid ${pid} /f /t`, { stdio: 'ignore' });
|
|
26
|
+
} catch (e) {
|
|
27
|
+
// Ignore errors if process is already dead
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
serverProcess.kill();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
await killPromise;
|
|
35
|
+
} catch (e) { }
|
|
36
|
+
serverProcess = null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function startRustServer() {
|
|
40
|
+
await killServer();
|
|
41
|
+
|
|
42
|
+
// Give the OS a moment to release file locks on the binary
|
|
43
|
+
await new Promise(r => setTimeout(r, 500));
|
|
44
|
+
|
|
45
|
+
const serverPath = path.join(process.cwd(), "server");
|
|
46
|
+
|
|
47
|
+
serverProcess = spawn("cargo", ["run"], {
|
|
48
|
+
cwd: serverPath,
|
|
49
|
+
stdio: "inherit",
|
|
50
|
+
shell: true
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
serverProcess.on("close", (code) => {
|
|
54
|
+
if (code !== null && code !== 0 && code !== 1) {
|
|
55
|
+
// 1 is often just 'terminated' on windows if forced, but also error.
|
|
56
|
+
// We just log it.
|
|
57
|
+
}
|
|
58
|
+
console.log(`[Titan] Rust server exited: ${code}`);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function rebuild() {
|
|
63
|
+
console.log("[Titan] Regenerating routes.json & action_map.json...");
|
|
64
|
+
execSync("node app/app.js", { stdio: "inherit" });
|
|
65
|
+
|
|
66
|
+
console.log("[Titan] Bundling JS actions...");
|
|
67
|
+
await bundle();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function startDev() {
|
|
71
|
+
console.log("[Titan] Dev mode starting...");
|
|
72
|
+
|
|
73
|
+
if (fs.existsSync(path.join(process.cwd(), ".env"))) {
|
|
74
|
+
console.log("\x1b[33m[Titan] Env Configured\x1b[0m");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// FIRST BUILD
|
|
78
|
+
try {
|
|
79
|
+
await rebuild();
|
|
80
|
+
await startRustServer();
|
|
81
|
+
} catch (e) {
|
|
82
|
+
console.log("\x1b[31m[Titan] Initial build failed. Waiting for changes...\x1b[0m");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const watcher = chokidar.watch(["app", ".env"], {
|
|
86
|
+
ignoreInitial: true
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
let timer = null;
|
|
90
|
+
|
|
91
|
+
watcher.on("all", async (event, file) => {
|
|
92
|
+
if (timer) clearTimeout(timer);
|
|
93
|
+
|
|
94
|
+
timer = setTimeout(async () => {
|
|
95
|
+
if (file.includes(".env")) {
|
|
96
|
+
console.log("\x1b[33m[Titan] Env Refreshed\x1b[0m");
|
|
97
|
+
} else {
|
|
98
|
+
console.log(`[Titan] Change detected: ${file}`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
await rebuild();
|
|
103
|
+
console.log("[Titan] Restarting Rust server...");
|
|
104
|
+
await startRustServer();
|
|
105
|
+
} catch (e) {
|
|
106
|
+
console.log("\x1b[31m[Titan] Build failed -- waiting for changes...\x1b[0m");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}, 200);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
startDev();
|
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { bundle } from "./bundle.js";
|
|
4
|
-
|
|
5
|
-
const cyan = (t) => `\x1b[36m${t}\x1b[0m`;
|
|
6
|
-
const green = (t) => `\x1b[32m${t}\x1b[0m`;
|
|
7
|
-
|
|
8
|
-
const routes = {};
|
|
9
|
-
const dynamicRoutes = {};
|
|
10
|
-
const actionMap = {};
|
|
11
|
-
|
|
12
|
-
function addRoute(method, route) {
|
|
13
|
-
const key = `${method.toUpperCase()}:${route}`;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
reply(value) {
|
|
18
|
-
routes[key] = {
|
|
19
|
-
type: typeof value === "object" ? "json" : "text",
|
|
20
|
-
value
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
action(name) {
|
|
25
|
-
if (route.includes(":")) {
|
|
26
|
-
if (!dynamicRoutes[method]) dynamicRoutes[method] = [];
|
|
27
|
-
dynamicRoutes[method].push({
|
|
28
|
-
method: method.toUpperCase(),
|
|
29
|
-
pattern: route,
|
|
30
|
-
action: name
|
|
31
|
-
});
|
|
32
|
-
} else {
|
|
33
|
-
routes[key] = {
|
|
34
|
-
type: "action",
|
|
35
|
-
value: name
|
|
36
|
-
};
|
|
37
|
-
actionMap[key] = name;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const t = {
|
|
44
|
-
get(route) {
|
|
45
|
-
return addRoute("GET", route);
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
post(route) {
|
|
49
|
-
return addRoute("POST", route);
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
log(module, msg) {
|
|
53
|
-
console.log(`[\x1b[35m${module}\x1b[0m] ${msg}`);
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
async start(port = 3000, msg = "") {
|
|
57
|
-
try {
|
|
58
|
-
console.log(cyan("[Titan] Preparing runtime..."));
|
|
59
|
-
await bundle();
|
|
60
|
-
|
|
61
|
-
const base = path.join(process.cwd(), "server");
|
|
62
|
-
if (!fs.existsSync(base)) {
|
|
63
|
-
fs.mkdirSync(base, { recursive: true });
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const routesPath = path.join(base, "routes.json");
|
|
67
|
-
const actionMapPath = path.join(base, "action_map.json");
|
|
68
|
-
|
|
69
|
-
fs.writeFileSync(
|
|
70
|
-
routesPath,
|
|
71
|
-
JSON.stringify(
|
|
72
|
-
{
|
|
73
|
-
__config: { port },
|
|
74
|
-
routes,
|
|
75
|
-
__dynamic_routes: Object.values(dynamicRoutes).flat()
|
|
76
|
-
},
|
|
77
|
-
null,
|
|
78
|
-
2
|
|
79
|
-
)
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
fs.writeFileSync(
|
|
83
|
-
actionMapPath,
|
|
84
|
-
JSON.stringify(actionMap, null, 2)
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
console.log(green("✔ Titan metadata written successfully"));
|
|
88
|
-
if (msg) console.log(cyan(msg));
|
|
89
|
-
|
|
90
|
-
} catch (e) {
|
|
91
|
-
console.error(`\x1b[31m[Titan] Build Error: ${e.message}\x1b[0m`);
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
globalThis.t = t;
|
|
98
|
-
export default t;
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { bundle } from "./bundle.js";
|
|
4
|
+
|
|
5
|
+
const cyan = (t) => `\x1b[36m${t}\x1b[0m`;
|
|
6
|
+
const green = (t) => `\x1b[32m${t}\x1b[0m`;
|
|
7
|
+
|
|
8
|
+
const routes = {};
|
|
9
|
+
const dynamicRoutes = {};
|
|
10
|
+
const actionMap = {};
|
|
11
|
+
|
|
12
|
+
function addRoute(method, route) {
|
|
13
|
+
const key = `${method.toUpperCase()}:${route}`;
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
reply(value) {
|
|
18
|
+
routes[key] = {
|
|
19
|
+
type: typeof value === "object" ? "json" : "text",
|
|
20
|
+
value
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
action(name) {
|
|
25
|
+
if (route.includes(":")) {
|
|
26
|
+
if (!dynamicRoutes[method]) dynamicRoutes[method] = [];
|
|
27
|
+
dynamicRoutes[method].push({
|
|
28
|
+
method: method.toUpperCase(),
|
|
29
|
+
pattern: route,
|
|
30
|
+
action: name
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
routes[key] = {
|
|
34
|
+
type: "action",
|
|
35
|
+
value: name
|
|
36
|
+
};
|
|
37
|
+
actionMap[key] = name;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const t = {
|
|
44
|
+
get(route) {
|
|
45
|
+
return addRoute("GET", route);
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
post(route) {
|
|
49
|
+
return addRoute("POST", route);
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
log(module, msg) {
|
|
53
|
+
console.log(`[\x1b[35m${module}\x1b[0m] ${msg}`);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
async start(port = 3000, msg = "") {
|
|
57
|
+
try {
|
|
58
|
+
console.log(cyan("[Titan] Preparing runtime..."));
|
|
59
|
+
await bundle();
|
|
60
|
+
|
|
61
|
+
const base = path.join(process.cwd(), "server");
|
|
62
|
+
if (!fs.existsSync(base)) {
|
|
63
|
+
fs.mkdirSync(base, { recursive: true });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const routesPath = path.join(base, "routes.json");
|
|
67
|
+
const actionMapPath = path.join(base, "action_map.json");
|
|
68
|
+
|
|
69
|
+
fs.writeFileSync(
|
|
70
|
+
routesPath,
|
|
71
|
+
JSON.stringify(
|
|
72
|
+
{
|
|
73
|
+
__config: { port },
|
|
74
|
+
routes,
|
|
75
|
+
__dynamic_routes: Object.values(dynamicRoutes).flat()
|
|
76
|
+
},
|
|
77
|
+
null,
|
|
78
|
+
2
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
fs.writeFileSync(
|
|
83
|
+
actionMapPath,
|
|
84
|
+
JSON.stringify(actionMap, null, 2)
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
console.log(green("✔ Titan metadata written successfully"));
|
|
88
|
+
if (msg) console.log(cyan(msg));
|
|
89
|
+
|
|
90
|
+
} catch (e) {
|
|
91
|
+
console.error(`\x1b[31m[Titan] Build Error: ${e.message}\x1b[0m`);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
globalThis.t = t;
|
|
98
|
+
export default t;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
const defineAction = (fn) => fn;
|
|
2
|
-
var __titan_exports = (() => {
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// app/actions/hello.js
|
|
22
|
-
var hello_exports = {};
|
|
23
|
-
__export(hello_exports, {
|
|
24
|
-
hello: () => hello
|
|
25
|
-
});
|
|
26
|
-
var hello = (req) => {
|
|
27
|
-
return {
|
|
28
|
-
message: `Hello from Titan ${req.body.name}`
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
return __toCommonJS(hello_exports);
|
|
32
|
-
})();
|
|
33
|
-
|
|
34
|
-
(function () {
|
|
35
|
-
const fn =
|
|
36
|
-
__titan_exports["hello"] ||
|
|
37
|
-
__titan_exports.default;
|
|
38
|
-
|
|
39
|
-
if (typeof fn !== "function") {
|
|
40
|
-
throw new Error("[Titan] Action 'hello' not found or not a function");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
globalThis["hello"] = function(request_arg) {
|
|
44
|
-
globalThis.req = request_arg;
|
|
45
|
-
return fn(request_arg);
|
|
46
|
-
};
|
|
47
|
-
})();
|
|
48
|
-
|