titanpl 26.17.0 → 26.17.2
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/package.json +4 -3
- package/packages/cli/package.json +32 -0
- package/packages/cli/src/commands/build.js +6 -0
- package/packages/cli/src/commands/dev.js +7 -0
- package/packages/cli/src/commands/init.js +163 -0
- package/packages/cli/src/commands/migrate.js +106 -0
- package/packages/cli/src/commands/start.js +5 -0
- package/packages/cli/src/commands/update.js +90 -0
- package/packages/cli/src/engine.js +143 -0
- package/packages/engine-darwin-arm64/README.md +13 -0
- package/packages/engine-darwin-arm64/package.json +10 -0
- package/packages/engine-linux-x64/README.md +11 -0
- package/packages/engine-linux-x64/package.json +10 -0
- package/packages/engine-win32-x64/README.md +11 -0
- package/packages/engine-win32-x64/bin/titan-server.exe +0 -0
- package/packages/engine-win32-x64/package.json +10 -0
- package/packages/native/README.md +11 -0
- package/packages/native/index.js +39 -0
- package/packages/native/package.json +26 -0
- package/packages/native/t.native.d.ts +2043 -0
- package/packages/packet/README.md +11 -0
- package/packages/packet/index.js +63 -0
- package/packages/packet/js/titan/builder.js +73 -0
- package/packages/packet/js/titan/bundle.js +261 -0
- package/packages/packet/js/titan/dev.js +85 -0
- package/packages/packet/js/titan/error-box.js +277 -0
- package/packages/packet/js/titan/titan.js +129 -0
- package/packages/packet/package.json +18 -0
- package/packages/packet/ts/titan/builder.js +121 -0
- package/packages/packet/ts/titan/bundle.js +123 -0
- package/packages/packet/ts/titan/dev.js +454 -0
- package/packages/packet/ts/titan/titan.d.ts +17 -0
- package/packages/packet/ts/titan/titan.js +124 -0
- package/packages/route/README.md +24 -0
- package/packages/route/index.d.ts +16 -0
- package/packages/route/index.js +52 -0
- package/packages/route/package.json +22 -0
- package/templates/extension/package.json +3 -3
- package/templates/js/package.json +6 -6
- package/templates/rust-js/package.json +6 -6
- package/templates/rust-ts/package.json +6 -6
- package/templates/ts/package.json +6 -6
- package/titanpl-sdk/package.json +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "titanpl",
|
|
3
|
-
"version": "26.17.
|
|
3
|
+
"version": "26.17.2",
|
|
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",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"files": [
|
|
18
18
|
"index.js",
|
|
19
|
+
"packages/",
|
|
19
20
|
"templates/",
|
|
20
21
|
"titanpl-sdk",
|
|
21
22
|
"README.md"
|
|
@@ -69,8 +70,8 @@
|
|
|
69
70
|
"test:all": "vitest run && vitest run --config vitest.config.e2e.ts"
|
|
70
71
|
},
|
|
71
72
|
"dependencies": {
|
|
72
|
-
"@titanpl/core": "
|
|
73
|
-
"@titanpl/node": "
|
|
73
|
+
"@titanpl/core": "26.17.1",
|
|
74
|
+
"@titanpl/node": "26.17.1",
|
|
74
75
|
"chokidar": "^5.0.0",
|
|
75
76
|
"esbuild": "^0.27.2",
|
|
76
77
|
"prompts": "^2.4.2"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@titanpl/cli",
|
|
3
|
+
"version": "26.17.2",
|
|
4
|
+
"description": "The unified CLI for Titan Planet. Use it to create, manage, build, and deploy high-performance backend projects.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"titanpl",
|
|
7
|
+
"titan",
|
|
8
|
+
"ezetgalaxy",
|
|
9
|
+
"cli"
|
|
10
|
+
],
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"author": "ezetgalaxy",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "index.js",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"titan": "./index.js"
|
|
20
|
+
},
|
|
21
|
+
"optionalDependencies": {
|
|
22
|
+
"@titanpl/engine-win32-x64": "26.17.2",
|
|
23
|
+
"@titanpl/engine-linux-x64": "26.17.2",
|
|
24
|
+
"@titanpl/engine-darwin-arm64": "26.17.2"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@titanpl/packet": "26.17.2",
|
|
28
|
+
"prompts": "^2.4.2",
|
|
29
|
+
"commander": "^11.0.0",
|
|
30
|
+
"chalk": "^4.1.2"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { spawn } from 'child_process';
|
|
5
|
+
import prompts from 'prompts';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
|
|
11
|
+
export function copyDir(src, dest, excludes = []) {
|
|
12
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
13
|
+
|
|
14
|
+
for (const file of fs.readdirSync(src)) {
|
|
15
|
+
if (excludes.includes(file)) continue;
|
|
16
|
+
|
|
17
|
+
const srcPath = path.join(src, file);
|
|
18
|
+
const destPath = path.join(dest, file);
|
|
19
|
+
|
|
20
|
+
if (fs.lstatSync(srcPath).isDirectory()) {
|
|
21
|
+
copyDir(srcPath, destPath, excludes);
|
|
22
|
+
} else {
|
|
23
|
+
fs.copyFileSync(srcPath, destPath);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function initCommand(projectName, templateName) {
|
|
29
|
+
let projName = projectName;
|
|
30
|
+
|
|
31
|
+
if (!projName) {
|
|
32
|
+
const res = await prompts({
|
|
33
|
+
type: 'text',
|
|
34
|
+
name: 'name',
|
|
35
|
+
message: 'Project name:',
|
|
36
|
+
initial: 'my-titan-app'
|
|
37
|
+
});
|
|
38
|
+
projName = res.name;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!projName) {
|
|
42
|
+
console.log(chalk.red("✖ Initialization cancelled."));
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let selectedTemplate = templateName;
|
|
47
|
+
|
|
48
|
+
if (!selectedTemplate) {
|
|
49
|
+
const langRes = await prompts({
|
|
50
|
+
type: 'select',
|
|
51
|
+
name: 'value',
|
|
52
|
+
message: 'Select language:',
|
|
53
|
+
choices: [
|
|
54
|
+
{ title: 'JavaScript', value: 'js' },
|
|
55
|
+
{ title: 'TypeScript', value: 'ts' },
|
|
56
|
+
],
|
|
57
|
+
initial: 0
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
if (!langRes.value) {
|
|
61
|
+
console.log(chalk.red("✖ Operation cancelled."));
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
const lang = langRes.value;
|
|
65
|
+
|
|
66
|
+
const archRes = await prompts({
|
|
67
|
+
type: 'select',
|
|
68
|
+
name: 'value',
|
|
69
|
+
message: 'Select template:',
|
|
70
|
+
choices: [
|
|
71
|
+
{
|
|
72
|
+
title: `Standard (${lang.toUpperCase()})`,
|
|
73
|
+
description: `Standard Titan app with ${lang.toUpperCase()} actions`,
|
|
74
|
+
value: 'standard'
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
title: `Rust + ${lang.toUpperCase()} (Hybrid)`,
|
|
78
|
+
description: `High-performance Rust actions + ${lang.toUpperCase()} flexibility`,
|
|
79
|
+
value: 'hybrid'
|
|
80
|
+
}
|
|
81
|
+
],
|
|
82
|
+
initial: 0
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (!archRes.value) {
|
|
86
|
+
console.log(chalk.red("✖ Operation cancelled."));
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
const arch = archRes.value;
|
|
90
|
+
|
|
91
|
+
if (lang === 'js') {
|
|
92
|
+
selectedTemplate = arch === 'standard' ? 'js' : 'rust-js';
|
|
93
|
+
} else {
|
|
94
|
+
selectedTemplate = arch === 'standard' ? 'ts' : 'rust-ts';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const target = path.resolve(process.cwd(), projName);
|
|
99
|
+
const templateDir = path.resolve(__dirname, '..', '..', '..', '..', 'templates', selectedTemplate);
|
|
100
|
+
const commonDir = path.resolve(__dirname, '..', '..', '..', '..', 'templates', 'common');
|
|
101
|
+
|
|
102
|
+
if (!fs.existsSync(templateDir) || !fs.existsSync(commonDir)) {
|
|
103
|
+
console.log(chalk.red(`✖ Error finding template paths.Are you in a valid Titan monorepo ? `));
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (fs.existsSync(target)) {
|
|
108
|
+
console.log(chalk.red(`✖ Directory '${projName}' already exists.`));
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
console.log(chalk.cyan(`\n→ Creating new Titan project in '${projName}'...\n`));
|
|
113
|
+
|
|
114
|
+
// 1. Copy common
|
|
115
|
+
copyDir(commonDir, target, ["_gitignore", "_dockerignore"]);
|
|
116
|
+
|
|
117
|
+
// 2. Copy specific template
|
|
118
|
+
copyDir(templateDir, target, ["_gitignore", "_dockerignore"]);
|
|
119
|
+
|
|
120
|
+
// 3. Dotfiles and Template Remapping
|
|
121
|
+
const remapping = {
|
|
122
|
+
"_gitignore": ".gitignore",
|
|
123
|
+
"_dockerignore": ".dockerignore",
|
|
124
|
+
"_titan.json": "titan.json",
|
|
125
|
+
".env": ".env"
|
|
126
|
+
};
|
|
127
|
+
for (const [srcName, destName] of Object.entries(remapping)) {
|
|
128
|
+
const src = path.join(target, srcName);
|
|
129
|
+
const dest = path.join(target, destName);
|
|
130
|
+
if (fs.existsSync(src)) {
|
|
131
|
+
fs.renameSync(src, dest);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Replace {{name}} in package.json and titan.json
|
|
136
|
+
const filesToSub = ['package.json', 'titan.json', 'README.md', 'index.js', 'app/app.js', 'app/app.ts'];
|
|
137
|
+
for (const f of filesToSub) {
|
|
138
|
+
const p = path.join(target, f);
|
|
139
|
+
if (fs.existsSync(p)) {
|
|
140
|
+
let content = fs.readFileSync(p, 'utf8');
|
|
141
|
+
content = content.replace(/{{name}}/g, projName);
|
|
142
|
+
// Also replace native_name (underscore version)
|
|
143
|
+
content = content.replace(/{{native_name}}/g, projName.replace(/-/g, '_'));
|
|
144
|
+
fs.writeFileSync(p, content);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
console.log(chalk.gray(` Installing dependencies...`));
|
|
149
|
+
|
|
150
|
+
await new Promise((resolve, reject) => {
|
|
151
|
+
const npm = spawn('npm', ['install'], {
|
|
152
|
+
cwd: target,
|
|
153
|
+
stdio: 'inherit',
|
|
154
|
+
shell: true
|
|
155
|
+
});
|
|
156
|
+
npm.on('error', reject);
|
|
157
|
+
npm.on('close', resolve);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
console.log(chalk.green(`\n✔ Project '${projName}' created successfully!\n`));
|
|
161
|
+
console.log(chalk.yellow(` cd ${projName}`));
|
|
162
|
+
console.log(chalk.yellow(` npm run dev\n`));
|
|
163
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
export async function migrateCommand() {
|
|
5
|
+
const root = process.cwd();
|
|
6
|
+
console.log(`\n🔍 Checking project for legacy Titan architecture...`);
|
|
7
|
+
|
|
8
|
+
const serverDir = path.join(root, 'server');
|
|
9
|
+
const titanDir = path.join(root, 'titan');
|
|
10
|
+
const pkgPath = path.join(root, 'package.json');
|
|
11
|
+
|
|
12
|
+
if (!fs.existsSync(serverDir) && !fs.existsSync(titanDir)) {
|
|
13
|
+
console.log(`✅ This project is already using the modern Titan runtime architecture.`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
console.log(`\n⚠️ Legacy server architecture detected. Migrating to runtime-first model...`);
|
|
18
|
+
|
|
19
|
+
// 1. Delete server/
|
|
20
|
+
if (fs.existsSync(serverDir)) {
|
|
21
|
+
console.log(` Deleting legacy server/ folder...`);
|
|
22
|
+
fs.rmSync(serverDir, { recursive: true, force: true });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 2. Delete titan/ folder
|
|
26
|
+
if (fs.existsSync(titanDir)) {
|
|
27
|
+
console.log(` Deleting legacy titan/ runtime folder...`);
|
|
28
|
+
fs.rmSync(titanDir, { recursive: true, force: true });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 3. Update package.json
|
|
32
|
+
if (fs.existsSync(pkgPath)) {
|
|
33
|
+
console.log(` Updating package.json...`);
|
|
34
|
+
try {
|
|
35
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
36
|
+
let modified = false;
|
|
37
|
+
|
|
38
|
+
// Update scripts
|
|
39
|
+
if (pkg.scripts) {
|
|
40
|
+
if (pkg.scripts.build && pkg.scripts.build.includes('cd server')) {
|
|
41
|
+
pkg.scripts.build = "titan build";
|
|
42
|
+
modified = true;
|
|
43
|
+
}
|
|
44
|
+
if (pkg.scripts.start && pkg.scripts.start.includes('cd server')) {
|
|
45
|
+
pkg.scripts.start = "titan start";
|
|
46
|
+
modified = true;
|
|
47
|
+
}
|
|
48
|
+
if (pkg.scripts.dev && pkg.scripts.dev.includes('titan/dev.js')) {
|
|
49
|
+
pkg.scripts.dev = "titan dev";
|
|
50
|
+
modified = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Add dependencies
|
|
55
|
+
pkg.dependencies = pkg.dependencies || {};
|
|
56
|
+
if (!pkg.dependencies['@titan/native']) {
|
|
57
|
+
pkg.dependencies['@titan/native'] = "latest";
|
|
58
|
+
modified = true;
|
|
59
|
+
}
|
|
60
|
+
if (!pkg.dependencies['@titan/route']) {
|
|
61
|
+
pkg.dependencies['@titan/route'] = "latest";
|
|
62
|
+
modified = true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (modified) {
|
|
66
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
67
|
+
}
|
|
68
|
+
} catch (e) {
|
|
69
|
+
console.log(` ⚠️ Failed to update package.json automatically. Please do it manually.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 4. Synchronize Dockerfile and other common files
|
|
74
|
+
try {
|
|
75
|
+
const commonDir = path.resolve(__dirname, '..', '..', '..', '..', 'templates', 'common');
|
|
76
|
+
if (fs.existsSync(commonDir)) {
|
|
77
|
+
const filesToSync = [
|
|
78
|
+
['Dockerfile', 'Dockerfile'],
|
|
79
|
+
['_dockerignore', '.dockerignore'],
|
|
80
|
+
['_gitignore', '.gitignore'],
|
|
81
|
+
['app/t.native.d.ts', 'app/t.native.d.ts'],
|
|
82
|
+
['app/t.native.js', 'app/t.native.js']
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
for (const [srcRel, destRel] of filesToSync) {
|
|
86
|
+
const src = path.join(commonDir, srcRel);
|
|
87
|
+
const dest = path.join(root, destRel);
|
|
88
|
+
if (fs.existsSync(src)) {
|
|
89
|
+
// Create parent dir if needed
|
|
90
|
+
const parent = path.dirname(dest);
|
|
91
|
+
if (!fs.existsSync(parent)) {
|
|
92
|
+
fs.mkdirSync(parent, { recursive: true });
|
|
93
|
+
}
|
|
94
|
+
fs.copyFileSync(src, dest);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
console.log(` Synchronized Dockerfiles and native definitions.`);
|
|
98
|
+
}
|
|
99
|
+
} catch (e) {
|
|
100
|
+
console.log(` ⚠️ Failed to synchronize common template files.`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
console.log(`\n🎉 Migration complete!`);
|
|
104
|
+
console.log(` Please run 'npm install' to fetch the new dependencies.`);
|
|
105
|
+
console.log(` Then run 'titan dev' to start your application.\n`);
|
|
106
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
9
|
+
export async function updateCommand() {
|
|
10
|
+
const root = process.cwd();
|
|
11
|
+
console.log(chalk.cyan(`\n→ Updating Titan project to latest...`));
|
|
12
|
+
|
|
13
|
+
const pkgPath = path.join(root, 'package.json');
|
|
14
|
+
if (!fs.existsSync(pkgPath)) {
|
|
15
|
+
console.log(chalk.red(`✖ No package.json found. Are you in a project root ? `));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 1. Update package.json versions
|
|
20
|
+
try {
|
|
21
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
22
|
+
let modified = false;
|
|
23
|
+
|
|
24
|
+
const titanDeps = [
|
|
25
|
+
'titanpl',
|
|
26
|
+
'titanpl-sdk',
|
|
27
|
+
'@titanpl/cli',
|
|
28
|
+
'@titanpl/route',
|
|
29
|
+
'@titanpl/native',
|
|
30
|
+
'@titanpl/packet',
|
|
31
|
+
'@titanpl/core',
|
|
32
|
+
'@titanpl/node'
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
if (pkg.dependencies) {
|
|
36
|
+
for (const dep of titanDeps) {
|
|
37
|
+
if (pkg.dependencies[dep]) {
|
|
38
|
+
pkg.dependencies[dep] = "latest";
|
|
39
|
+
modified = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (pkg.devDependencies) {
|
|
45
|
+
for (const dep of titanDeps) {
|
|
46
|
+
if (pkg.devDependencies[dep]) {
|
|
47
|
+
pkg.devDependencies[dep] = "latest";
|
|
48
|
+
modified = true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (modified) {
|
|
54
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
55
|
+
console.log(chalk.green(` ✔ Updated Titan dependencies in package.json`));
|
|
56
|
+
}
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.log(chalk.yellow(` ⚠️ Failed to update package.json: ${e.message}`));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 2. Refresh Dockerfile and dotfiles from templates
|
|
62
|
+
const commonDir = path.resolve(__dirname, '..', '..', '..', '..', 'templates', 'common');
|
|
63
|
+
if (fs.existsSync(commonDir)) {
|
|
64
|
+
const filesToSync = [
|
|
65
|
+
['Dockerfile', 'Dockerfile'],
|
|
66
|
+
['_dockerignore', '.dockerignore'],
|
|
67
|
+
['_gitignore', '.gitignore'],
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
for (const [srcName, destName] of filesToSync) {
|
|
71
|
+
const src = path.join(commonDir, srcName);
|
|
72
|
+
const dest = path.join(root, destName);
|
|
73
|
+
if (fs.existsSync(src)) {
|
|
74
|
+
fs.copyFileSync(src, dest);
|
|
75
|
+
console.log(chalk.green(` ✔ Synchronized ${destName}`));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Also update app/t.native.d.ts if it exists
|
|
80
|
+
const nativeTypesSrc = path.join(commonDir, 'app', 't.native.d.ts');
|
|
81
|
+
const nativeTypesDest = path.join(root, 'app', 't.native.d.ts');
|
|
82
|
+
if (fs.existsSync(nativeTypesSrc) && fs.existsSync(path.join(root, 'app'))) {
|
|
83
|
+
fs.copyFileSync(nativeTypesSrc, nativeTypesDest);
|
|
84
|
+
console.log(chalk.green(` ✔ Updated app/t.native.d.ts`));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
console.log(chalk.green(`\n✔ Update complete!\n`));
|
|
89
|
+
console.log(chalk.yellow(` Please run 'npm install' to apply changes.\n`));
|
|
90
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { createRequire } from 'module';
|
|
5
|
+
import { spawn } from 'child_process';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
|
|
13
|
+
export function getEngineBinaryPath() {
|
|
14
|
+
const platform = os.platform(); // 'win32', 'linux', 'darwin'
|
|
15
|
+
const arch = os.arch(); // 'x64', 'arm64'
|
|
16
|
+
const pkgName = `@titanpl/engine-${platform}-${arch}`;
|
|
17
|
+
const binName = platform === 'win32' ? 'titan-server.exe' : 'titan-server';
|
|
18
|
+
|
|
19
|
+
// 1. Robust Binary Discovery (Monorepo, Local, or Global)
|
|
20
|
+
const searchPaths = [
|
|
21
|
+
__dirname,
|
|
22
|
+
process.cwd(),
|
|
23
|
+
path.join(process.cwd(), '..'),
|
|
24
|
+
path.join(process.cwd(), '..', '..')
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
for (let startPath of searchPaths) {
|
|
28
|
+
let current = startPath;
|
|
29
|
+
for (let i = 0; i < 8; i++) {
|
|
30
|
+
const potential = path.join(current, 'engine', 'target', 'release', binName);
|
|
31
|
+
if (fs.existsSync(potential)) return potential;
|
|
32
|
+
|
|
33
|
+
const parent = path.dirname(current);
|
|
34
|
+
if (parent === current) break;
|
|
35
|
+
current = parent;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 2. Resolve installed optional dependency
|
|
40
|
+
try {
|
|
41
|
+
// We use a try/catch specifically for the resolve to provide a better diagnostic
|
|
42
|
+
let pkgPath;
|
|
43
|
+
try {
|
|
44
|
+
pkgPath = require.resolve(`${pkgName}/package.json`);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
// Fallback: check if the binary exists in a standard location even if require.resolve fails
|
|
47
|
+
const fallbackBin = path.join(process.cwd(), 'node_modules', pkgName, 'bin', binName);
|
|
48
|
+
if (fs.existsSync(fallbackBin)) return fallbackBin;
|
|
49
|
+
throw e;
|
|
50
|
+
}
|
|
51
|
+
const pkgDir = path.dirname(pkgPath);
|
|
52
|
+
const binaryPath = path.join(pkgDir, 'bin', binName);
|
|
53
|
+
|
|
54
|
+
if (fs.existsSync(binaryPath)) {
|
|
55
|
+
return binaryPath;
|
|
56
|
+
}
|
|
57
|
+
throw new Error(`Corrupted installation: Binary missing at ${binaryPath}.`);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.error(`\n[TITAN FATAL] Unsupported platform: ${platform} (${arch})`);
|
|
60
|
+
console.error(`Or the optional dependency '${pkgName}' failed to install.`);
|
|
61
|
+
console.error(`Error: ${err.message}\n`);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function startEngine(watchMode = false) {
|
|
67
|
+
const distPath = path.resolve(process.cwd(), 'dist');
|
|
68
|
+
|
|
69
|
+
if (!fs.existsSync(distPath)) {
|
|
70
|
+
console.error("❌ 'dist/' directory not found. Please run 'titan build' first.");
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const binaryPath = getEngineBinaryPath();
|
|
75
|
+
|
|
76
|
+
// Arguments passed to Rust backend
|
|
77
|
+
const args = ['run', distPath];
|
|
78
|
+
if (watchMode) args.push('--watch');
|
|
79
|
+
|
|
80
|
+
console.log(`🚀 Starting Titan Engine...`);
|
|
81
|
+
|
|
82
|
+
const engineProcess = spawn(binaryPath, args, {
|
|
83
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
84
|
+
env: {
|
|
85
|
+
...process.env,
|
|
86
|
+
TITAN_ENV: watchMode ? 'development' : 'production',
|
|
87
|
+
Titan_Dev: watchMode ? '1' : '0'
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
let stderrBuffer = "";
|
|
92
|
+
|
|
93
|
+
engineProcess.stdout.pipe(process.stdout);
|
|
94
|
+
engineProcess.stderr.on('data', (data) => {
|
|
95
|
+
const chunk = data.toString();
|
|
96
|
+
stderrBuffer += chunk;
|
|
97
|
+
process.stderr.write(data);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
engineProcess.on('close', (code) => {
|
|
101
|
+
if (code !== 0 && code !== null) {
|
|
102
|
+
// Check for port binding errors
|
|
103
|
+
const isPortError = stderrBuffer.includes("Address already in use") ||
|
|
104
|
+
stderrBuffer.includes("address in use") ||
|
|
105
|
+
stderrBuffer.includes("os error 10048") || // Windows
|
|
106
|
+
stderrBuffer.includes("EADDRINUSE") ||
|
|
107
|
+
stderrBuffer.includes("AddrInUse");
|
|
108
|
+
|
|
109
|
+
if (isPortError) {
|
|
110
|
+
// Try to read intended port
|
|
111
|
+
let port = 5100;
|
|
112
|
+
try {
|
|
113
|
+
const routesPath = path.join(process.cwd(), "dist", "routes.json");
|
|
114
|
+
if (fs.existsSync(routesPath)) {
|
|
115
|
+
const routesConfig = JSON.parse(fs.readFileSync(routesPath, "utf8"));
|
|
116
|
+
if (routesConfig && routesConfig.__config && routesConfig.__config.port) {
|
|
117
|
+
port = routesConfig.__config.port;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} catch (e) { }
|
|
121
|
+
|
|
122
|
+
const cyan = (t) => `\x1b[36m${t}\x1b[0m`;
|
|
123
|
+
const yellow = (t) => `\x1b[33m${t}\x1b[0m`;
|
|
124
|
+
const red = (t) => `\x1b[31m${t}\x1b[0m`;
|
|
125
|
+
|
|
126
|
+
console.log("");
|
|
127
|
+
console.log(red("⏣ Your application cannot enter this orbit"));
|
|
128
|
+
console.log(red(`↳ Another application is already bound to port ${port}.`));
|
|
129
|
+
console.log("");
|
|
130
|
+
|
|
131
|
+
console.log(yellow("Recommended Actions:"));
|
|
132
|
+
console.log(yellow(" 1.") + " Release the occupied orbit (stop the other service).");
|
|
133
|
+
console.log(yellow(" 2.") + " Assign your application to a new orbit in " + cyan("app/app.js"));
|
|
134
|
+
console.log(yellow(" Example: ") + cyan(`t.start(${port + 1}, "Titan Running!")`));
|
|
135
|
+
console.log("");
|
|
136
|
+
} else {
|
|
137
|
+
console.error(`\n❌ [Titan Engine died with exit code ${code}]`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return engineProcess;
|
|
143
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @titanpl/engine-darwin-arm64
|
|
2
|
+
|
|
3
|
+
The macOS ARM64 pre-compiled native engine binary for Titan Planet.
|
|
4
|
+
|
|
5
|
+
## What it works (What it does)
|
|
6
|
+
This package is the compiled core Rust + Axum server embedded with the Boa JavaScript runtime. It is specifically built for Apple Silicon (ARM64) macOS devices.
|
|
7
|
+
|
|
8
|
+
## How it works
|
|
9
|
+
This package is listed as an "optional dependency" in `@titanpl/cli`. During package installation, your package manager identifies the OS and automatically downloads this binary if it matches `darwin` + `arm64`. You do not need to install it directly.
|
|
10
|
+
|
|
11
|
+
When you run `titan start`, the CLI locates this binary and executes it as your web server.
|
|
12
|
+
|
|
13
|
+
**Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux and macOS versions are in development (dev only) for the new architecture and will be launched later.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @titanpl/engine-linux-x64
|
|
2
|
+
|
|
3
|
+
The Linux x64 pre-compiled native engine binary for Titan Planet.
|
|
4
|
+
|
|
5
|
+
## What it works (What it does)
|
|
6
|
+
This package holds the core Rust + Axum high-performance web server tightly coupled with the Boa JavaScript execution runtime. It is built natively for Linux x64 environments, requiring no Node.js execution layer.
|
|
7
|
+
|
|
8
|
+
## How it works
|
|
9
|
+
You don't need to manually interact with this module. It acts as an optional dependency resolved by `#titanpl/cli`. If you run TitanPlanet on a Linux x64 machine, npm/yarn automatically downloads this native binary to run your application.
|
|
10
|
+
|
|
11
|
+
**Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux version is in development (dev only) for the new architecture and will be launched later.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @titanpl/engine-win32-x64
|
|
2
|
+
|
|
3
|
+
The Windows x64 pre-compiled native engine binary for Titan Planet.
|
|
4
|
+
|
|
5
|
+
## What it works (What it does)
|
|
6
|
+
This module provides the highly concurrent Rust-based server binary (`titan.exe`) powered by Axum and Boa. It removes the necessity of a Node.js event loop by only executing static routes in Rust and specific dynamic logic in embedded JavaScript.
|
|
7
|
+
|
|
8
|
+
## How it works
|
|
9
|
+
Like the other engine packages, this works entirely behind the scenes. When `@titanpl/cli` is installed on a Windows instance, it fetches this `.exe` runtime. The CLI then maps your built assets and JS routes into the binary for deployment.
|
|
10
|
+
|
|
11
|
+
**Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux version is in development (dev only) for the new architecture and will be launched later.
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @titanpl/native
|
|
2
|
+
|
|
3
|
+
The native utility extension module for Titan Planet.
|
|
4
|
+
|
|
5
|
+
## What it works (What it does)
|
|
6
|
+
It acts as the low-level communication bridge offering type definitions and utility wrappers out-of-the-box. Rather than being dependent on heavy JavaScript libraries, this package bridges Node-style features gracefully to the Titan runtime environment.
|
|
7
|
+
|
|
8
|
+
## How it works
|
|
9
|
+
You can import tools and primitives from this package into your server-side actions alongside `@titanpl/core` when you want direct low-level interaction or need access to platform operations that interact directly with the C/Rust engine.
|
|
10
|
+
|
|
11
|
+
**Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux version is in development (dev only) for the new architecture and will be launched later.
|