@ezetgalaxy/titan 26.8.3 → 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 +63 -14
- package/index.js +62 -15
- package/package.json +1 -1
- 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 +9 -1
- 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 +9 -1
- 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
package/titanpl-sdk/bin/run.js
CHANGED
|
@@ -1,254 +1,254 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { execSync } from "child_process";
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
|
-
|
|
7
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
-
const __dirname = path.dirname(__filename);
|
|
9
|
-
|
|
10
|
-
// Helper for colors
|
|
11
|
-
const cyan = (t) => `\x1b[36m${t}\x1b[0m`;
|
|
12
|
-
const green = (t) => `\x1b[32m${t}\x1b[0m`;
|
|
13
|
-
const red = (t) => `\x1b[31m${t}\x1b[0m`;
|
|
14
|
-
const yellow = (t) => `\x1b[33m${t}\x1b[0m`;
|
|
15
|
-
|
|
16
|
-
function copyDir(src, dest) {
|
|
17
|
-
fs.mkdirSync(dest, { recursive: true });
|
|
18
|
-
for (const file of fs.readdirSync(src)) {
|
|
19
|
-
const srcPath = path.join(src, file);
|
|
20
|
-
const destPath = path.join(dest, file);
|
|
21
|
-
if (fs.lstatSync(srcPath).isDirectory()) {
|
|
22
|
-
copyDir(srcPath, destPath);
|
|
23
|
-
} else {
|
|
24
|
-
fs.copyFileSync(srcPath, destPath);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function run() {
|
|
30
|
-
console.log(cyan("Titan SDK: Test Runner"));
|
|
31
|
-
|
|
32
|
-
// 1. Validate we are in an extension directory
|
|
33
|
-
const cwd = process.cwd();
|
|
34
|
-
const manifestPath = path.join(cwd, "titan.json");
|
|
35
|
-
if (!fs.existsSync(manifestPath)) {
|
|
36
|
-
console.log(red("Error: titan.json not found. Run this command inside your extension folder."));
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
41
|
-
const name = manifest.name;
|
|
42
|
-
console.log(green(`Extension: ${name}`));
|
|
43
|
-
|
|
44
|
-
// 2. Build Native Logic (if properly set up)
|
|
45
|
-
const nativeDir = path.join(cwd, "native");
|
|
46
|
-
if (fs.existsSync(nativeDir) && fs.existsSync(path.join(nativeDir, "Cargo.toml"))) {
|
|
47
|
-
console.log(cyan("Building native Rust module..."));
|
|
48
|
-
try {
|
|
49
|
-
execSync("cargo build --release", { cwd: nativeDir, stdio: "inherit" });
|
|
50
|
-
} catch (e) {
|
|
51
|
-
console.log(red("Failed to build native module."));
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 3. Create a Test Harness (Mini Titan Project)
|
|
57
|
-
const runDir = path.join(cwd, ".titan_test_run");
|
|
58
|
-
if (fs.existsSync(runDir)) {
|
|
59
|
-
try {
|
|
60
|
-
fs.rmSync(runDir, {
|
|
61
|
-
recursive: true,
|
|
62
|
-
force: true,
|
|
63
|
-
maxRetries: 10,
|
|
64
|
-
retryDelay: 100
|
|
65
|
-
});
|
|
66
|
-
} catch (e) {
|
|
67
|
-
console.log(yellow(`Warning: Could not fully clean ${runDir}. Proceeding anyway...`));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Ensure runDir exists (sometimes rmSync + mkdirSync fails on Windows due to locks)
|
|
72
|
-
if (!fs.existsSync(runDir)) {
|
|
73
|
-
fs.mkdirSync(runDir, { recursive: true });
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Create app structure
|
|
77
|
-
const appDir = path.join(runDir, "app");
|
|
78
|
-
fs.mkdirSync(appDir);
|
|
79
|
-
|
|
80
|
-
// Create actions folder (required by Titan build)
|
|
81
|
-
const actionsDir = path.join(appDir, "actions");
|
|
82
|
-
fs.mkdirSync(actionsDir);
|
|
83
|
-
|
|
84
|
-
// Copy titan/ and server/ from templates
|
|
85
|
-
const templatesDir = path.join(__dirname, "..", "templates");
|
|
86
|
-
|
|
87
|
-
const titanSrc = path.join(templatesDir, "titan");
|
|
88
|
-
const titanDest = path.join(runDir, "titan");
|
|
89
|
-
if (fs.existsSync(titanSrc)) {
|
|
90
|
-
console.log(cyan("→ Setting up Titan runtime..."));
|
|
91
|
-
copyDir(titanSrc, titanDest);
|
|
92
|
-
// Double check titan.js exists
|
|
93
|
-
if (!fs.existsSync(path.join(titanDest, "titan.js"))) {
|
|
94
|
-
console.log(red(`Error: Failed to copy titan.js to ${titanDest}`));
|
|
95
|
-
process.exit(1);
|
|
96
|
-
}
|
|
97
|
-
} else {
|
|
98
|
-
console.log(red(`Error: Titan templates not found at ${titanSrc}`));
|
|
99
|
-
process.exit(1);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const serverSrc = path.join(templatesDir, "server");
|
|
103
|
-
const serverDest = path.join(runDir, "server");
|
|
104
|
-
if (fs.existsSync(serverSrc)) {
|
|
105
|
-
console.log(cyan("→ Setting up Titan server..."));
|
|
106
|
-
copyDir(serverSrc, serverDest);
|
|
107
|
-
} else {
|
|
108
|
-
console.log(red(`Error: Server templates not found at ${serverSrc}`));
|
|
109
|
-
process.exit(1);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Create package.json for the test harness
|
|
113
|
-
const pkgJson = {
|
|
114
|
-
"type": "module"
|
|
115
|
-
};
|
|
116
|
-
fs.writeFileSync(path.join(runDir, "package.json"), JSON.stringify(pkgJson, null, 2));
|
|
117
|
-
|
|
118
|
-
// Create 'node_modules' to link the extension
|
|
119
|
-
const nmDir = path.join(runDir, "node_modules");
|
|
120
|
-
fs.mkdirSync(nmDir);
|
|
121
|
-
|
|
122
|
-
// Link current extension to node_modules/NAME
|
|
123
|
-
// Use junction for Windows compat without admin rights
|
|
124
|
-
const extDest = path.join(nmDir, name);
|
|
125
|
-
try {
|
|
126
|
-
fs.symlinkSync(cwd, extDest, "junction");
|
|
127
|
-
} catch (e) {
|
|
128
|
-
// Fallback to copy if link fails
|
|
129
|
-
console.log(yellow("Linking failed, copying extension files..."));
|
|
130
|
-
copyDir(cwd, extDest);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Create a test action in app/actions/test.js
|
|
134
|
-
const testAction = `export const test = (req) => {
|
|
135
|
-
const ext = t["${name}"];
|
|
136
|
-
|
|
137
|
-
const results = {
|
|
138
|
-
extension: "${name}",
|
|
139
|
-
loaded: !!ext,
|
|
140
|
-
methods: ext ? Object.keys(ext) : [],
|
|
141
|
-
timestamp: new Date().toISOString()
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
if (ext && ext.hello) {
|
|
145
|
-
try {
|
|
146
|
-
results.hello_test = ext.hello("World");
|
|
147
|
-
} catch(e) {
|
|
148
|
-
results.hello_error = String(e);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (ext && ext.calc) {
|
|
153
|
-
try {
|
|
154
|
-
results.calc_test = ext.calc(15, 25);
|
|
155
|
-
} catch(e) {
|
|
156
|
-
results.calc_error = String(e);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return results;
|
|
161
|
-
};
|
|
162
|
-
`;
|
|
163
|
-
|
|
164
|
-
fs.writeFileSync(path.join(actionsDir, "test.js"), testAction);
|
|
165
|
-
|
|
166
|
-
// Create a simple test script in app/app.js
|
|
167
|
-
// This script will be executed by Titan
|
|
168
|
-
const testScript = `import t from "../titan/titan.js";
|
|
169
|
-
import "${name}";
|
|
170
|
-
|
|
171
|
-
// Extension test harness for: ${name}
|
|
172
|
-
const ext = t["${name}"];
|
|
173
|
-
|
|
174
|
-
console.log("---------------------------------------------------");
|
|
175
|
-
console.log("Testing Extension: ${name}");
|
|
176
|
-
console.log("---------------------------------------------------");
|
|
177
|
-
|
|
178
|
-
if (!ext) {
|
|
179
|
-
console.log("ERROR: Extension '${name}' not found in global 't'.");
|
|
180
|
-
} else {
|
|
181
|
-
console.log("✓ Extension loaded successfully!");
|
|
182
|
-
console.log("✓ Available methods:", Object.keys(ext).join(", "));
|
|
183
|
-
|
|
184
|
-
// Try 'hello' if it exists
|
|
185
|
-
if (typeof ext.hello === 'function') {
|
|
186
|
-
console.log("\\nTesting ext.hello('Titan')...");
|
|
187
|
-
try {
|
|
188
|
-
const res = ext.hello("Titan");
|
|
189
|
-
console.log("✓ Result:", res);
|
|
190
|
-
} catch(e) {
|
|
191
|
-
console.log("✗ Error:", e.message);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Try 'calc' if it exists
|
|
196
|
-
if (typeof ext.calc === 'function') {
|
|
197
|
-
console.log("\\nTesting ext.calc(10, 20)...");
|
|
198
|
-
try {
|
|
199
|
-
const res = ext.calc(10, 20);
|
|
200
|
-
console.log("✓ Result:", res);
|
|
201
|
-
} catch(e) {
|
|
202
|
-
console.log("✗ Error:", e.message);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
console.log("---------------------------------------------------");
|
|
208
|
-
console.log("✓ Test complete!");
|
|
209
|
-
console.log("\\n📍 Routes:");
|
|
210
|
-
console.log(" GET http://localhost:3000/ → Test harness info");
|
|
211
|
-
console.log(" GET http://localhost:3000/test → Extension test results (JSON)");
|
|
212
|
-
console.log("---------------------------------------------------\\n");
|
|
213
|
-
|
|
214
|
-
// Create routes
|
|
215
|
-
t.get("/test").action("test");
|
|
216
|
-
t.get("/").reply("🚀 Extension Test Harness for ${name}\\n\\nVisit /test to see extension test results");
|
|
217
|
-
|
|
218
|
-
await t.start(3000, "Titan Extension Test Running!");
|
|
219
|
-
`;
|
|
220
|
-
|
|
221
|
-
fs.writeFileSync(path.join(appDir, "app.js"), testScript);
|
|
222
|
-
|
|
223
|
-
// Build the app (bundle actions)
|
|
224
|
-
console.log(cyan("Building test app..."));
|
|
225
|
-
try {
|
|
226
|
-
// Ensure we are in runDir and the file exists
|
|
227
|
-
const appJsPath = path.join(runDir, "app", "app.js");
|
|
228
|
-
if (!fs.existsSync(appJsPath)) {
|
|
229
|
-
throw new Error(`app/app.js missing at ${appJsPath}`);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
execSync("node app/app.js --build", {
|
|
233
|
-
cwd: runDir,
|
|
234
|
-
stdio: "inherit",
|
|
235
|
-
env: { ...process.env, NODE_OPTIONS: "--no-warnings" }
|
|
236
|
-
});
|
|
237
|
-
} catch (e) {
|
|
238
|
-
console.log(red("Failed to build test app. This is expected if your extension has errors."));
|
|
239
|
-
// Don't exit here, attempt to continue to show runtime errors if possible
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// 4. Run Titan Server using cargo run (like dev mode)
|
|
243
|
-
console.log(green("\x1b[1m\n>>> STARTING EXTENSION TEST >>>\n\x1b[0m"));
|
|
244
|
-
|
|
245
|
-
const serverDir = path.join(runDir, "server");
|
|
246
|
-
|
|
247
|
-
try {
|
|
248
|
-
execSync("cargo run", { cwd: serverDir, stdio: "inherit" });
|
|
249
|
-
} catch (e) {
|
|
250
|
-
console.log(red("Runtime exited."));
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
run();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { execSync } from "child_process";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
|
+
|
|
10
|
+
// Helper for colors
|
|
11
|
+
const cyan = (t) => `\x1b[36m${t}\x1b[0m`;
|
|
12
|
+
const green = (t) => `\x1b[32m${t}\x1b[0m`;
|
|
13
|
+
const red = (t) => `\x1b[31m${t}\x1b[0m`;
|
|
14
|
+
const yellow = (t) => `\x1b[33m${t}\x1b[0m`;
|
|
15
|
+
|
|
16
|
+
function copyDir(src, dest) {
|
|
17
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
18
|
+
for (const file of fs.readdirSync(src)) {
|
|
19
|
+
const srcPath = path.join(src, file);
|
|
20
|
+
const destPath = path.join(dest, file);
|
|
21
|
+
if (fs.lstatSync(srcPath).isDirectory()) {
|
|
22
|
+
copyDir(srcPath, destPath);
|
|
23
|
+
} else {
|
|
24
|
+
fs.copyFileSync(srcPath, destPath);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function run() {
|
|
30
|
+
console.log(cyan("Titan SDK: Test Runner"));
|
|
31
|
+
|
|
32
|
+
// 1. Validate we are in an extension directory
|
|
33
|
+
const cwd = process.cwd();
|
|
34
|
+
const manifestPath = path.join(cwd, "titan.json");
|
|
35
|
+
if (!fs.existsSync(manifestPath)) {
|
|
36
|
+
console.log(red("Error: titan.json not found. Run this command inside your extension folder."));
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
41
|
+
const name = manifest.name;
|
|
42
|
+
console.log(green(`Extension: ${name}`));
|
|
43
|
+
|
|
44
|
+
// 2. Build Native Logic (if properly set up)
|
|
45
|
+
const nativeDir = path.join(cwd, "native");
|
|
46
|
+
if (fs.existsSync(nativeDir) && fs.existsSync(path.join(nativeDir, "Cargo.toml"))) {
|
|
47
|
+
console.log(cyan("Building native Rust module..."));
|
|
48
|
+
try {
|
|
49
|
+
execSync("cargo build --release", { cwd: nativeDir, stdio: "inherit" });
|
|
50
|
+
} catch (e) {
|
|
51
|
+
console.log(red("Failed to build native module."));
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 3. Create a Test Harness (Mini Titan Project)
|
|
57
|
+
const runDir = path.join(cwd, ".titan_test_run");
|
|
58
|
+
if (fs.existsSync(runDir)) {
|
|
59
|
+
try {
|
|
60
|
+
fs.rmSync(runDir, {
|
|
61
|
+
recursive: true,
|
|
62
|
+
force: true,
|
|
63
|
+
maxRetries: 10,
|
|
64
|
+
retryDelay: 100
|
|
65
|
+
});
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.log(yellow(`Warning: Could not fully clean ${runDir}. Proceeding anyway...`));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Ensure runDir exists (sometimes rmSync + mkdirSync fails on Windows due to locks)
|
|
72
|
+
if (!fs.existsSync(runDir)) {
|
|
73
|
+
fs.mkdirSync(runDir, { recursive: true });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Create app structure
|
|
77
|
+
const appDir = path.join(runDir, "app");
|
|
78
|
+
fs.mkdirSync(appDir);
|
|
79
|
+
|
|
80
|
+
// Create actions folder (required by Titan build)
|
|
81
|
+
const actionsDir = path.join(appDir, "actions");
|
|
82
|
+
fs.mkdirSync(actionsDir);
|
|
83
|
+
|
|
84
|
+
// Copy titan/ and server/ from templates
|
|
85
|
+
const templatesDir = path.join(__dirname, "..", "templates");
|
|
86
|
+
|
|
87
|
+
const titanSrc = path.join(templatesDir, "titan");
|
|
88
|
+
const titanDest = path.join(runDir, "titan");
|
|
89
|
+
if (fs.existsSync(titanSrc)) {
|
|
90
|
+
console.log(cyan("→ Setting up Titan runtime..."));
|
|
91
|
+
copyDir(titanSrc, titanDest);
|
|
92
|
+
// Double check titan.js exists
|
|
93
|
+
if (!fs.existsSync(path.join(titanDest, "titan.js"))) {
|
|
94
|
+
console.log(red(`Error: Failed to copy titan.js to ${titanDest}`));
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
console.log(red(`Error: Titan templates not found at ${titanSrc}`));
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const serverSrc = path.join(templatesDir, "server");
|
|
103
|
+
const serverDest = path.join(runDir, "server");
|
|
104
|
+
if (fs.existsSync(serverSrc)) {
|
|
105
|
+
console.log(cyan("→ Setting up Titan server..."));
|
|
106
|
+
copyDir(serverSrc, serverDest);
|
|
107
|
+
} else {
|
|
108
|
+
console.log(red(`Error: Server templates not found at ${serverSrc}`));
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Create package.json for the test harness
|
|
113
|
+
const pkgJson = {
|
|
114
|
+
"type": "module"
|
|
115
|
+
};
|
|
116
|
+
fs.writeFileSync(path.join(runDir, "package.json"), JSON.stringify(pkgJson, null, 2));
|
|
117
|
+
|
|
118
|
+
// Create 'node_modules' to link the extension
|
|
119
|
+
const nmDir = path.join(runDir, "node_modules");
|
|
120
|
+
fs.mkdirSync(nmDir);
|
|
121
|
+
|
|
122
|
+
// Link current extension to node_modules/NAME
|
|
123
|
+
// Use junction for Windows compat without admin rights
|
|
124
|
+
const extDest = path.join(nmDir, name);
|
|
125
|
+
try {
|
|
126
|
+
fs.symlinkSync(cwd, extDest, "junction");
|
|
127
|
+
} catch (e) {
|
|
128
|
+
// Fallback to copy if link fails
|
|
129
|
+
console.log(yellow("Linking failed, copying extension files..."));
|
|
130
|
+
copyDir(cwd, extDest);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Create a test action in app/actions/test.js
|
|
134
|
+
const testAction = `export const test = (req) => {
|
|
135
|
+
const ext = t["${name}"];
|
|
136
|
+
|
|
137
|
+
const results = {
|
|
138
|
+
extension: "${name}",
|
|
139
|
+
loaded: !!ext,
|
|
140
|
+
methods: ext ? Object.keys(ext) : [],
|
|
141
|
+
timestamp: new Date().toISOString()
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
if (ext && ext.hello) {
|
|
145
|
+
try {
|
|
146
|
+
results.hello_test = ext.hello("World");
|
|
147
|
+
} catch(e) {
|
|
148
|
+
results.hello_error = String(e);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (ext && ext.calc) {
|
|
153
|
+
try {
|
|
154
|
+
results.calc_test = ext.calc(15, 25);
|
|
155
|
+
} catch(e) {
|
|
156
|
+
results.calc_error = String(e);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return results;
|
|
161
|
+
};
|
|
162
|
+
`;
|
|
163
|
+
|
|
164
|
+
fs.writeFileSync(path.join(actionsDir, "test.js"), testAction);
|
|
165
|
+
|
|
166
|
+
// Create a simple test script in app/app.js
|
|
167
|
+
// This script will be executed by Titan
|
|
168
|
+
const testScript = `import t from "../titan/titan.js";
|
|
169
|
+
import "${name}";
|
|
170
|
+
|
|
171
|
+
// Extension test harness for: ${name}
|
|
172
|
+
const ext = t["${name}"];
|
|
173
|
+
|
|
174
|
+
console.log("---------------------------------------------------");
|
|
175
|
+
console.log("Testing Extension: ${name}");
|
|
176
|
+
console.log("---------------------------------------------------");
|
|
177
|
+
|
|
178
|
+
if (!ext) {
|
|
179
|
+
console.log("ERROR: Extension '${name}' not found in global 't'.");
|
|
180
|
+
} else {
|
|
181
|
+
console.log("✓ Extension loaded successfully!");
|
|
182
|
+
console.log("✓ Available methods:", Object.keys(ext).join(", "));
|
|
183
|
+
|
|
184
|
+
// Try 'hello' if it exists
|
|
185
|
+
if (typeof ext.hello === 'function') {
|
|
186
|
+
console.log("\\nTesting ext.hello('Titan')...");
|
|
187
|
+
try {
|
|
188
|
+
const res = ext.hello("Titan");
|
|
189
|
+
console.log("✓ Result:", res);
|
|
190
|
+
} catch(e) {
|
|
191
|
+
console.log("✗ Error:", e.message);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Try 'calc' if it exists
|
|
196
|
+
if (typeof ext.calc === 'function') {
|
|
197
|
+
console.log("\\nTesting ext.calc(10, 20)...");
|
|
198
|
+
try {
|
|
199
|
+
const res = ext.calc(10, 20);
|
|
200
|
+
console.log("✓ Result:", res);
|
|
201
|
+
} catch(e) {
|
|
202
|
+
console.log("✗ Error:", e.message);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
console.log("---------------------------------------------------");
|
|
208
|
+
console.log("✓ Test complete!");
|
|
209
|
+
console.log("\\n📍 Routes:");
|
|
210
|
+
console.log(" GET http://localhost:3000/ → Test harness info");
|
|
211
|
+
console.log(" GET http://localhost:3000/test → Extension test results (JSON)");
|
|
212
|
+
console.log("---------------------------------------------------\\n");
|
|
213
|
+
|
|
214
|
+
// Create routes
|
|
215
|
+
t.get("/test").action("test");
|
|
216
|
+
t.get("/").reply("🚀 Extension Test Harness for ${name}\\n\\nVisit /test to see extension test results");
|
|
217
|
+
|
|
218
|
+
await t.start(3000, "Titan Extension Test Running!");
|
|
219
|
+
`;
|
|
220
|
+
|
|
221
|
+
fs.writeFileSync(path.join(appDir, "app.js"), testScript);
|
|
222
|
+
|
|
223
|
+
// Build the app (bundle actions)
|
|
224
|
+
console.log(cyan("Building test app..."));
|
|
225
|
+
try {
|
|
226
|
+
// Ensure we are in runDir and the file exists
|
|
227
|
+
const appJsPath = path.join(runDir, "app", "app.js");
|
|
228
|
+
if (!fs.existsSync(appJsPath)) {
|
|
229
|
+
throw new Error(`app/app.js missing at ${appJsPath}`);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
execSync("node app/app.js --build", {
|
|
233
|
+
cwd: runDir,
|
|
234
|
+
stdio: "inherit",
|
|
235
|
+
env: { ...process.env, NODE_OPTIONS: "--no-warnings" }
|
|
236
|
+
});
|
|
237
|
+
} catch (e) {
|
|
238
|
+
console.log(red("Failed to build test app. This is expected if your extension has errors."));
|
|
239
|
+
// Don't exit here, attempt to continue to show runtime errors if possible
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// 4. Run Titan Server using cargo run (like dev mode)
|
|
243
|
+
console.log(green("\x1b[1m\n>>> STARTING EXTENSION TEST >>>\n\x1b[0m"));
|
|
244
|
+
|
|
245
|
+
const serverDir = path.join(runDir, "server");
|
|
246
|
+
|
|
247
|
+
try {
|
|
248
|
+
execSync("cargo run", { cwd: serverDir, stdio: "inherit" });
|
|
249
|
+
} catch (e) {
|
|
250
|
+
console.log(red("Runtime exited."));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
run();
|
package/titanpl-sdk/index.d.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
export { };
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
/**
|
|
5
|
-
* Titan Runtime Global Object
|
|
6
|
-
*/
|
|
7
|
-
const t: Titan.Runtime;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export namespace Titan {
|
|
11
|
-
interface Runtime {
|
|
12
|
-
/**
|
|
13
|
-
* Log messages to the Titan console
|
|
14
|
-
*/
|
|
15
|
-
log: LogInterface;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Read file content
|
|
19
|
-
*/
|
|
20
|
-
read(path: string): string;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Fetch API wrapper
|
|
24
|
-
*/
|
|
25
|
-
fetch(url: string, options?: any): Promise<any>;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Database operations
|
|
29
|
-
*/
|
|
30
|
-
db: {
|
|
31
|
-
query(sql: string, params?: any[]): Promise<any>;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Titan Extensions
|
|
36
|
-
*/
|
|
37
|
-
[key: string]: any;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface LogInterface {
|
|
41
|
-
(...args: any[]): void;
|
|
42
|
-
info(...args: any[]): void;
|
|
43
|
-
warn(...args: any[]): void;
|
|
44
|
-
error(...args: any[]): void;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
1
|
+
export { };
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
/**
|
|
5
|
+
* Titan Runtime Global Object
|
|
6
|
+
*/
|
|
7
|
+
const t: Titan.Runtime;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export namespace Titan {
|
|
11
|
+
interface Runtime {
|
|
12
|
+
/**
|
|
13
|
+
* Log messages to the Titan console
|
|
14
|
+
*/
|
|
15
|
+
log: LogInterface;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Read file content
|
|
19
|
+
*/
|
|
20
|
+
read(path: string): string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Fetch API wrapper
|
|
24
|
+
*/
|
|
25
|
+
fetch(url: string, options?: any): Promise<any>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Database operations
|
|
29
|
+
*/
|
|
30
|
+
db: {
|
|
31
|
+
query(sql: string, params?: any[]): Promise<any>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Titan Extensions
|
|
36
|
+
*/
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface LogInterface {
|
|
41
|
+
(...args: any[]): void;
|
|
42
|
+
info(...args: any[]): void;
|
|
43
|
+
warn(...args: any[]): void;
|
|
44
|
+
error(...args: any[]): void;
|
|
45
|
+
}
|
|
46
|
+
}
|
package/titanpl-sdk/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Titan SDK
|
|
2
|
-
// This package is primarily for type definitions and development tools.
|
|
3
|
-
// The 't' object is injected globally by the Titan runtime.
|
|
4
|
-
|
|
5
|
-
export const VERSION = "0.0.1";
|
|
1
|
+
// Titan SDK
|
|
2
|
+
// This package is primarily for type definitions and development tools.
|
|
3
|
+
// The 't' object is injected globally by the Titan runtime.
|
|
4
|
+
|
|
5
|
+
export const VERSION = "0.0.1";
|