@t8n/ui 1.0.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 +276 -0
- package/index.d.ts +65 -0
- package/index.js +131 -0
- package/jsconfig.json +13 -0
- package/package.json +32 -0
- package/test-app/.dockerignore +3 -0
- package/test-app/Dockerfile +66 -0
- package/test-app/app/actions/hello.js +7 -0
- package/test-app/app/app.js +10 -0
- package/test-app/app/static/app.html +9 -0
- package/test-app/app/static/styles.css +9 -0
- package/test-app/app/titan.d.ts +249 -0
- package/test-app/eslint.config.js +8 -0
- package/test-app/jsconfig.json +20 -0
- package/test-app/package.json +25 -0
- package/test-app/server/Cargo.toml +32 -0
- package/test-app/server/src/action_management.rs +171 -0
- package/test-app/server/src/errors.rs +10 -0
- package/test-app/server/src/extensions/builtin.rs +828 -0
- package/test-app/server/src/extensions/external.rs +309 -0
- package/test-app/server/src/extensions/mod.rs +430 -0
- package/test-app/server/src/extensions/titan_core.js +178 -0
- package/test-app/server/src/main.rs +433 -0
- package/test-app/server/src/runtime.rs +314 -0
- package/test-app/server/src/utils.rs +33 -0
- package/test-app/server/titan_storage.json +5 -0
- package/test-app/titan/bundle.js +264 -0
- package/test-app/titan/dev.js +350 -0
- package/test-app/titan/error-box.js +268 -0
- package/test-app/titan/titan.js +129 -0
- package/titan.json +20 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Titan.js
|
|
3
|
+
* Main Titan runtime builder
|
|
4
|
+
* RULE: This file does NOT handle esbuild errors - bundle.js handles those
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from "fs";
|
|
8
|
+
import path from "path";
|
|
9
|
+
import { bundle } from "./bundle.js";
|
|
10
|
+
|
|
11
|
+
const cyan = (t) => `\x1b[36m${t}\x1b[0m`;
|
|
12
|
+
const green = (t) => `\x1b[32m${t}\x1b[0m`;
|
|
13
|
+
|
|
14
|
+
const routes = {};
|
|
15
|
+
const dynamicRoutes = {};
|
|
16
|
+
const actionMap = {};
|
|
17
|
+
|
|
18
|
+
function addRoute(method, route) {
|
|
19
|
+
const key = `${method.toUpperCase()}:${route}`;
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
reply(value) {
|
|
23
|
+
routes[key] = {
|
|
24
|
+
type: typeof value === "object" ? "json" : "text",
|
|
25
|
+
value
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
action(name) {
|
|
30
|
+
if (route.includes(":")) {
|
|
31
|
+
if (!dynamicRoutes[method]) dynamicRoutes[method] = [];
|
|
32
|
+
dynamicRoutes[method].push({
|
|
33
|
+
method: method.toUpperCase(),
|
|
34
|
+
pattern: route,
|
|
35
|
+
action: name
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
routes[key] = {
|
|
39
|
+
type: "action",
|
|
40
|
+
value: name
|
|
41
|
+
};
|
|
42
|
+
actionMap[key] = name;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Titan App Builder
|
|
50
|
+
*/
|
|
51
|
+
const t = {
|
|
52
|
+
/**
|
|
53
|
+
* Define a GET route
|
|
54
|
+
*/
|
|
55
|
+
get(route) {
|
|
56
|
+
return addRoute("GET", route);
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Define a POST route
|
|
61
|
+
*/
|
|
62
|
+
post(route) {
|
|
63
|
+
return addRoute("POST", route);
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
log(module, msg) {
|
|
67
|
+
console.log(`[\x1b[35m${module}\x1b[0m] ${msg}`);
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Start the Titan Server
|
|
72
|
+
* RULE: Only calls bundle() - does NOT handle esbuild errors
|
|
73
|
+
* RULE: If bundle throws __TITAN_BUNDLE_FAILED__, stop immediately without printing
|
|
74
|
+
*/
|
|
75
|
+
async start(port = 3000, msg = "", threads) {
|
|
76
|
+
try {
|
|
77
|
+
console.log(cyan("[Titan] Preparing runtime..."));
|
|
78
|
+
|
|
79
|
+
// RULE: Just call bundle() - it handles its own errors
|
|
80
|
+
await bundle();
|
|
81
|
+
|
|
82
|
+
const base = path.join(process.cwd(), "server");
|
|
83
|
+
if (!fs.existsSync(base)) {
|
|
84
|
+
fs.mkdirSync(base, { recursive: true });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const routesPath = path.join(base, "routes.json");
|
|
88
|
+
const actionMapPath = path.join(base, "action_map.json");
|
|
89
|
+
|
|
90
|
+
fs.writeFileSync(
|
|
91
|
+
routesPath,
|
|
92
|
+
JSON.stringify(
|
|
93
|
+
{
|
|
94
|
+
__config: { port, threads },
|
|
95
|
+
routes,
|
|
96
|
+
__dynamic_routes: Object.values(dynamicRoutes).flat()
|
|
97
|
+
},
|
|
98
|
+
null,
|
|
99
|
+
2
|
|
100
|
+
)
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
fs.writeFileSync(
|
|
104
|
+
actionMapPath,
|
|
105
|
+
JSON.stringify(actionMap, null, 2)
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
console.log(green("✔ Titan metadata written successfully"));
|
|
109
|
+
if (msg) console.log(cyan(msg));
|
|
110
|
+
|
|
111
|
+
} catch (e) {
|
|
112
|
+
// RULE: If bundle threw __TITAN_BUNDLE_FAILED__, just re-throw it
|
|
113
|
+
// The error box was already printed by bundle.js
|
|
114
|
+
if (e.message === '__TITAN_BUNDLE_FAILED__') {
|
|
115
|
+
throw e;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Other unexpected errors (not from bundle)
|
|
119
|
+
console.error(`\x1b[31m[Titan] Unexpected error: ${e.message}\x1b[0m`);
|
|
120
|
+
throw e;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Titan App Builder (Alias for t)
|
|
127
|
+
*/
|
|
128
|
+
export const Titan = t;
|
|
129
|
+
export default t;
|
package/titan.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@t8n/ui",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"description": "A lightweight HTML templating engine for TitanPL with file caching and variable interpolation.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"titanpl",
|
|
8
|
+
"t8n",
|
|
9
|
+
"titan",
|
|
10
|
+
"titan planet",
|
|
11
|
+
"templating",
|
|
12
|
+
"html",
|
|
13
|
+
"template",
|
|
14
|
+
"engine",
|
|
15
|
+
"gravity",
|
|
16
|
+
"@titanpl/core"
|
|
17
|
+
],
|
|
18
|
+
"author": "Shoya"
|
|
19
|
+
}
|
|
20
|
+
|