@titanpl/cli 2.0.0 → 2.0.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/README.md +17 -17
- package/index.js +160 -160
- package/package.json +5 -5
- package/src/commands/build.js +5 -5
- package/src/commands/dev.js +12 -5
- package/src/commands/init.js +196 -182
- package/src/commands/migrate.js +124 -106
- package/src/commands/start.js +4 -4
- package/src/commands/update.js +90 -90
- package/src/engine.js +152 -143
package/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
# @titanpl/cli
|
|
2
|
-
|
|
3
|
-
The command-line interface (CLI) for Titan Planet. It provides the `titan` and `tit` commands for initializing, building, and running Titan Planet servers.
|
|
4
|
-
|
|
5
|
-
## What it works (What it does)
|
|
6
|
-
The CLI is responsible for bridging your JavaScript codebase with the underlying Rust/Axum engine. It handles scaffolding, compiling JS actions, generating metadata, and running the server.
|
|
7
|
-
|
|
8
|
-
## How it works
|
|
9
|
-
You can install this package globally or use it via your package runner (e.g., `npx`). Alternatively, you can install it as a dev dependency in your project.
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npx titan help
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
It parses your application source code, coordinates with `@titanpl/packet` to build the required JS endpoints, and then spins up the pre-compiled native core engine for your OS.
|
|
16
|
-
|
|
17
|
-
**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.
|
|
1
|
+
# @titanpl/cli
|
|
2
|
+
|
|
3
|
+
The command-line interface (CLI) for Titan Planet. It provides the `titan` and `tit` commands for initializing, building, and running Titan Planet servers.
|
|
4
|
+
|
|
5
|
+
## What it works (What it does)
|
|
6
|
+
The CLI is responsible for bridging your JavaScript codebase with the underlying Rust/Axum engine. It handles scaffolding, compiling JS actions, generating metadata, and running the server.
|
|
7
|
+
|
|
8
|
+
## How it works
|
|
9
|
+
You can install this package globally or use it via your package runner (e.g., `npx`). Alternatively, you can install it as a dev dependency in your project.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx titan help
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
It parses your application source code, coordinates with `@titanpl/packet` to build the required JS endpoints, and then spins up the pre-compiled native core engine for your OS.
|
|
16
|
+
|
|
17
|
+
**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.
|
package/index.js
CHANGED
|
@@ -1,161 +1,161 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
|
-
|
|
7
|
-
import { buildCommand } from "./src/commands/build.js";
|
|
8
|
-
import { devCommand } from "./src/commands/dev.js";
|
|
9
|
-
import { startCommand } from "./src/commands/start.js";
|
|
10
|
-
import { migrateCommand } from "./src/commands/migrate.js";
|
|
11
|
-
import { updateCommand } from "./src/commands/update.js";
|
|
12
|
-
import { initCommand } from "./src/commands/init.js";
|
|
13
|
-
|
|
14
|
-
/* -------------------------------------------------------
|
|
15
|
-
* Resolve __dirname (ESM safe)
|
|
16
|
-
* ----------------------------------------------------- */
|
|
17
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
18
|
-
const __dirname = path.dirname(__filename);
|
|
19
|
-
|
|
20
|
-
/* -------------------------------------------------------
|
|
21
|
-
* Colors (Old Titan Theme Style)
|
|
22
|
-
* ----------------------------------------------------- */
|
|
23
|
-
const cyan = (t) => `\x1b[36m${t}\x1b[0m`;
|
|
24
|
-
const green = (t) => `\x1b[32m${t}\x1b[0m`;
|
|
25
|
-
const yellow = (t) => `\x1b[33m${t}\x1b[0m`;
|
|
26
|
-
const red = (t) => `\x1b[31m${t}\x1b[0m`;
|
|
27
|
-
const bold = (t) => `\x1b[1m${t}\x1b[0m`;
|
|
28
|
-
const gray = (t) => `\x1b[90m${t}\x1b[0m`;
|
|
29
|
-
|
|
30
|
-
/* -------------------------------------------------------
|
|
31
|
-
* Version
|
|
32
|
-
* ----------------------------------------------------- */
|
|
33
|
-
let VERSION = "1.0.0";
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
const pkg = JSON.parse(
|
|
37
|
-
fs.readFileSync(path.join(__dirname, "package.json"), "utf8")
|
|
38
|
-
);
|
|
39
|
-
VERSION = pkg.version;
|
|
40
|
-
} catch { }
|
|
41
|
-
|
|
42
|
-
/* -------------------------------------------------------
|
|
43
|
-
* Help Output
|
|
44
|
-
* ----------------------------------------------------- */
|
|
45
|
-
function help() {
|
|
46
|
-
console.log(`
|
|
47
|
-
${bold(cyan("╭───────────────────────────────────────────────╮"))}
|
|
48
|
-
${bold(cyan("│"))} 🪐 ${bold(cyan("Titan Planet"))} CLI ${gray(`v${VERSION}`.padEnd(6, ' '))} ${bold(cyan("│"))}
|
|
49
|
-
${bold(cyan("╰───────────────────────────────────────────────╯"))}
|
|
50
|
-
|
|
51
|
-
${yellow("Usage:")} ${bold("titan <command> [options]")}
|
|
52
|
-
|
|
53
|
-
${bold("Commands:")}
|
|
54
|
-
${cyan("init")} ${gray("Scaffold a new Titan project")}
|
|
55
|
-
${cyan("create")} ${gray("Create a new project or extension (e.g. 'titan create ext my-ext')")}
|
|
56
|
-
${cyan("build")} ${gray("Compile actions and build production dist")}
|
|
57
|
-
${cyan("dev")} ${gray("Start the Gravity Engine in dev/watch mode")}
|
|
58
|
-
${cyan("start")} ${gray("Start the production Gravity Engine")}
|
|
59
|
-
${cyan("update")} ${gray("Update an existing project to latest Titan version")}
|
|
60
|
-
${cyan("migrate")} ${gray("Migrate a legacy project to the new architecture")}
|
|
61
|
-
|
|
62
|
-
${bold("Options:")}
|
|
63
|
-
${cyan("-v, --version")} ${gray("Output the current version")}
|
|
64
|
-
${cyan("-h, --help")} ${gray("Display this help message")}
|
|
65
|
-
|
|
66
|
-
${gray(" The Titan Planet Engine runs your JS/TS server natively without Node.js. ")}
|
|
67
|
-
${cyan("https://titan-docs-ez.vercel.app")}
|
|
68
|
-
`);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/* -------------------------------------------------------
|
|
72
|
-
* CLI Router
|
|
73
|
-
* ----------------------------------------------------- */
|
|
74
|
-
process.title = "TitanPL";
|
|
75
|
-
const cmd = process.argv[2];
|
|
76
|
-
|
|
77
|
-
(async () => {
|
|
78
|
-
try {
|
|
79
|
-
// -------------------------------------------------------
|
|
80
|
-
// Legacy Check
|
|
81
|
-
// -------------------------------------------------------
|
|
82
|
-
if (cmd !== 'migrate' && cmd !== 'init') {
|
|
83
|
-
const legacyCargo = path.join(process.cwd(), "server", "Cargo.toml");
|
|
84
|
-
if (fs.existsSync(legacyCargo)) {
|
|
85
|
-
console.log(yellow(`\n⚠️ This project uses legacy server architecture. Migration recommended.`));
|
|
86
|
-
console.log(`Please run: ${bold(cyan('titan migrate'))}\n`);
|
|
87
|
-
process.exit(1);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// -------------------------------------------------------
|
|
92
|
-
// Old tit / titan detection note
|
|
93
|
-
// -------------------------------------------------------
|
|
94
|
-
const scriptBase = path.basename(process.argv[1]);
|
|
95
|
-
if (scriptBase === 'tit') {
|
|
96
|
-
console.log(yellow(`\n⚠️ [Notice]: \`tit\` is deprecated. Please use \`titan\` instead.\n`));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
switch (cmd) {
|
|
101
|
-
case "init": {
|
|
102
|
-
const projectName = process.argv[3];
|
|
103
|
-
let template = null;
|
|
104
|
-
const tIndex = process.argv.indexOf("-t") !== -1 ? process.argv.indexOf("-t") : process.argv.indexOf("--template");
|
|
105
|
-
if (tIndex !== -1 && process.argv[tIndex + 1]) {
|
|
106
|
-
template = process.argv[tIndex + 1];
|
|
107
|
-
}
|
|
108
|
-
await initCommand(projectName, template);
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
case "create": {
|
|
113
|
-
const type = process.argv[3];
|
|
114
|
-
const name = process.argv[4];
|
|
115
|
-
if (type === "ext" || type === "extension") {
|
|
116
|
-
await initCommand(name, "extension");
|
|
117
|
-
} else {
|
|
118
|
-
// Fallback to init behavior
|
|
119
|
-
await initCommand(type, null);
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
case "build":
|
|
125
|
-
console.log(cyan("→ Building Titan project..."));
|
|
126
|
-
await buildCommand();
|
|
127
|
-
console.log(green("✔ Build complete"));
|
|
128
|
-
break;
|
|
129
|
-
|
|
130
|
-
case "dev":
|
|
131
|
-
await devCommand();
|
|
132
|
-
break;
|
|
133
|
-
|
|
134
|
-
case "start":
|
|
135
|
-
console.log(cyan("→ Starting Titan Server..."));
|
|
136
|
-
startCommand();
|
|
137
|
-
break;
|
|
138
|
-
|
|
139
|
-
case "update":
|
|
140
|
-
await updateCommand();
|
|
141
|
-
break;
|
|
142
|
-
|
|
143
|
-
case "migrate":
|
|
144
|
-
await migrateCommand();
|
|
145
|
-
break;
|
|
146
|
-
|
|
147
|
-
case "--version":
|
|
148
|
-
case "-v":
|
|
149
|
-
case "version":
|
|
150
|
-
console.log(cyan(`Titan CLI v${VERSION}`));
|
|
151
|
-
break;
|
|
152
|
-
|
|
153
|
-
default:
|
|
154
|
-
help();
|
|
155
|
-
}
|
|
156
|
-
} catch (err) {
|
|
157
|
-
console.error(red("✖ Titan CLI Error"));
|
|
158
|
-
console.error(gray(err?.message || err));
|
|
159
|
-
process.exit(1);
|
|
160
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
|
|
7
|
+
import { buildCommand } from "./src/commands/build.js";
|
|
8
|
+
import { devCommand } from "./src/commands/dev.js";
|
|
9
|
+
import { startCommand } from "./src/commands/start.js";
|
|
10
|
+
import { migrateCommand } from "./src/commands/migrate.js";
|
|
11
|
+
import { updateCommand } from "./src/commands/update.js";
|
|
12
|
+
import { initCommand } from "./src/commands/init.js";
|
|
13
|
+
|
|
14
|
+
/* -------------------------------------------------------
|
|
15
|
+
* Resolve __dirname (ESM safe)
|
|
16
|
+
* ----------------------------------------------------- */
|
|
17
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
18
|
+
const __dirname = path.dirname(__filename);
|
|
19
|
+
|
|
20
|
+
/* -------------------------------------------------------
|
|
21
|
+
* Colors (Old Titan Theme Style)
|
|
22
|
+
* ----------------------------------------------------- */
|
|
23
|
+
const cyan = (t) => `\x1b[36m${t}\x1b[0m`;
|
|
24
|
+
const green = (t) => `\x1b[32m${t}\x1b[0m`;
|
|
25
|
+
const yellow = (t) => `\x1b[33m${t}\x1b[0m`;
|
|
26
|
+
const red = (t) => `\x1b[31m${t}\x1b[0m`;
|
|
27
|
+
const bold = (t) => `\x1b[1m${t}\x1b[0m`;
|
|
28
|
+
const gray = (t) => `\x1b[90m${t}\x1b[0m`;
|
|
29
|
+
|
|
30
|
+
/* -------------------------------------------------------
|
|
31
|
+
* Version
|
|
32
|
+
* ----------------------------------------------------- */
|
|
33
|
+
let VERSION = "1.0.0";
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const pkg = JSON.parse(
|
|
37
|
+
fs.readFileSync(path.join(__dirname, "package.json"), "utf8")
|
|
38
|
+
);
|
|
39
|
+
VERSION = pkg.version;
|
|
40
|
+
} catch { }
|
|
41
|
+
|
|
42
|
+
/* -------------------------------------------------------
|
|
43
|
+
* Help Output
|
|
44
|
+
* ----------------------------------------------------- */
|
|
45
|
+
function help() {
|
|
46
|
+
console.log(`
|
|
47
|
+
${bold(cyan("╭───────────────────────────────────────────────╮"))}
|
|
48
|
+
${bold(cyan("│"))} 🪐 ${bold(cyan("Titan Planet"))} CLI ${gray(`v${VERSION}`.padEnd(6, ' '))} ${bold(cyan("│"))}
|
|
49
|
+
${bold(cyan("╰───────────────────────────────────────────────╯"))}
|
|
50
|
+
|
|
51
|
+
${yellow("Usage:")} ${bold("titan <command> [options]")}
|
|
52
|
+
|
|
53
|
+
${bold("Commands:")}
|
|
54
|
+
${cyan("init")} ${gray("Scaffold a new Titan project")}
|
|
55
|
+
${cyan("create")} ${gray("Create a new project or extension (e.g. 'titan create ext my-ext')")}
|
|
56
|
+
${cyan("build")} ${gray("Compile actions and build production dist")}
|
|
57
|
+
${cyan("dev")} ${gray("Start the Gravity Engine in dev/watch mode")}
|
|
58
|
+
${cyan("start")} ${gray("Start the production Gravity Engine")}
|
|
59
|
+
${cyan("update")} ${gray("Update an existing project to latest Titan version")}
|
|
60
|
+
${cyan("migrate")} ${gray("Migrate a legacy project to the new architecture")}
|
|
61
|
+
|
|
62
|
+
${bold("Options:")}
|
|
63
|
+
${cyan("-v, --version")} ${gray("Output the current version")}
|
|
64
|
+
${cyan("-h, --help")} ${gray("Display this help message")}
|
|
65
|
+
|
|
66
|
+
${gray(" The Titan Planet Engine runs your JS/TS server natively without Node.js. ")}
|
|
67
|
+
${cyan("https://titan-docs-ez.vercel.app")}
|
|
68
|
+
`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/* -------------------------------------------------------
|
|
72
|
+
* CLI Router
|
|
73
|
+
* ----------------------------------------------------- */
|
|
74
|
+
process.title = "TitanPL";
|
|
75
|
+
const cmd = process.argv[2];
|
|
76
|
+
|
|
77
|
+
(async () => {
|
|
78
|
+
try {
|
|
79
|
+
// -------------------------------------------------------
|
|
80
|
+
// Legacy Check
|
|
81
|
+
// -------------------------------------------------------
|
|
82
|
+
if (cmd !== 'migrate' && cmd !== 'init') {
|
|
83
|
+
const legacyCargo = path.join(process.cwd(), "server", "Cargo.toml");
|
|
84
|
+
if (fs.existsSync(legacyCargo)) {
|
|
85
|
+
console.log(yellow(`\n⚠️ This project uses legacy server architecture. Migration recommended.`));
|
|
86
|
+
console.log(`Please run: ${bold(cyan('titan migrate'))}\n`);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// -------------------------------------------------------
|
|
92
|
+
// Old tit / titan detection note
|
|
93
|
+
// -------------------------------------------------------
|
|
94
|
+
const scriptBase = path.basename(process.argv[1]);
|
|
95
|
+
if (scriptBase === 'tit') {
|
|
96
|
+
console.log(yellow(`\n⚠️ [Notice]: \`tit\` is deprecated. Please use \`titan\` instead.\n`));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
switch (cmd) {
|
|
101
|
+
case "init": {
|
|
102
|
+
const projectName = process.argv[3];
|
|
103
|
+
let template = null;
|
|
104
|
+
const tIndex = process.argv.indexOf("-t") !== -1 ? process.argv.indexOf("-t") : process.argv.indexOf("--template");
|
|
105
|
+
if (tIndex !== -1 && process.argv[tIndex + 1]) {
|
|
106
|
+
template = process.argv[tIndex + 1];
|
|
107
|
+
}
|
|
108
|
+
await initCommand(projectName, template);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
case "create": {
|
|
113
|
+
const type = process.argv[3];
|
|
114
|
+
const name = process.argv[4];
|
|
115
|
+
if (type === "ext" || type === "extension") {
|
|
116
|
+
await initCommand(name, "extension");
|
|
117
|
+
} else {
|
|
118
|
+
// Fallback to init behavior
|
|
119
|
+
await initCommand(type, null);
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
case "build":
|
|
125
|
+
console.log(cyan("→ Building Titan project..."));
|
|
126
|
+
await buildCommand();
|
|
127
|
+
console.log(green("✔ Build complete"));
|
|
128
|
+
break;
|
|
129
|
+
|
|
130
|
+
case "dev":
|
|
131
|
+
await devCommand();
|
|
132
|
+
break;
|
|
133
|
+
|
|
134
|
+
case "start":
|
|
135
|
+
console.log(cyan("→ Starting Titan Server..."));
|
|
136
|
+
startCommand();
|
|
137
|
+
break;
|
|
138
|
+
|
|
139
|
+
case "update":
|
|
140
|
+
await updateCommand();
|
|
141
|
+
break;
|
|
142
|
+
|
|
143
|
+
case "migrate":
|
|
144
|
+
await migrateCommand();
|
|
145
|
+
break;
|
|
146
|
+
|
|
147
|
+
case "--version":
|
|
148
|
+
case "-v":
|
|
149
|
+
case "version":
|
|
150
|
+
console.log(cyan(`Titan CLI v${VERSION}`));
|
|
151
|
+
break;
|
|
152
|
+
|
|
153
|
+
default:
|
|
154
|
+
help();
|
|
155
|
+
}
|
|
156
|
+
} catch (err) {
|
|
157
|
+
console.error(red("✖ Titan CLI Error"));
|
|
158
|
+
console.error(gray(err?.message || err));
|
|
159
|
+
process.exit(1);
|
|
160
|
+
}
|
|
161
161
|
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@titanpl/cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "The unified CLI for Titan Planet. Use it to create, manage, build, and deploy high-performance backend projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"titanpl",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"tit": "./index.js"
|
|
22
22
|
},
|
|
23
23
|
"optionalDependencies": {
|
|
24
|
-
"@titanpl/engine-win32-x64": "2.0.
|
|
25
|
-
"@titanpl/engine-linux-x64": "2.0.
|
|
26
|
-
"@titanpl/engine-darwin-arm64": "2.0.
|
|
24
|
+
"@titanpl/engine-win32-x64": "2.0.2",
|
|
25
|
+
"@titanpl/engine-linux-x64": "2.0.2",
|
|
26
|
+
"@titanpl/engine-darwin-arm64": "2.0.2"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@titanpl/packet": "2.0.
|
|
29
|
+
"@titanpl/packet": "2.0.2",
|
|
30
30
|
"prompts": "^2.4.2",
|
|
31
31
|
"commander": "^11.0.0",
|
|
32
32
|
"chalk": "^4.1.2"
|
package/src/commands/build.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { build } from "@titanpl/packet";
|
|
2
|
-
|
|
3
|
-
export async function buildCommand() {
|
|
4
|
-
const dist = await build(process.cwd());
|
|
5
|
-
console.log("✔ Build complete →", dist);
|
|
1
|
+
import { build } from "@titanpl/packet";
|
|
2
|
+
|
|
3
|
+
export async function buildCommand() {
|
|
4
|
+
const dist = await build(process.cwd());
|
|
5
|
+
console.log("✔ Build complete →", dist);
|
|
6
6
|
}
|
package/src/commands/dev.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import { dev } from "@titanpl/packet";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { dev } from "@titanpl/packet";
|
|
2
|
+
import { resolveEngineBinaryPath } from "../engine.js";
|
|
3
|
+
|
|
4
|
+
export async function devCommand() {
|
|
5
|
+
// Resolve the engine binary from CLI's context (where optionalDependencies live)
|
|
6
|
+
// and inject it into the environment so packet can find it without re-resolving.
|
|
7
|
+
const enginePath = resolveEngineBinaryPath();
|
|
8
|
+
if (enginePath) {
|
|
9
|
+
process.env.TITAN_ENGINE_BINARY = enginePath;
|
|
10
|
+
}
|
|
11
|
+
await dev(process.cwd());
|
|
12
|
+
}
|