@titanpl/cli 4.0.0 → 5.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 +19 -2
- package/index.js +5 -4
- package/package.json +1 -1
- package/src/commands/build.js +5 -4
- package/src/commands/init.js +15 -1
- package/src/engine.js +13 -2
- package/templates/common/Dockerfile +11 -49
- package/templates/common/README.md +85 -0
- package/templates/common/_gitignore +1 -0
- package/templates/common/_tanfig.json +14 -0
package/README.md
CHANGED
|
@@ -5,13 +5,30 @@ The command-line interface (CLI) for Titan Planet. It provides the `titan` and `
|
|
|
5
5
|
## What it works (What it does)
|
|
6
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
7
|
|
|
8
|
+
## Commands
|
|
9
|
+
|
|
10
|
+
| Command | Arguments | Description |
|
|
11
|
+
| :--- | :--- | :--- |
|
|
12
|
+
| `init` | `<dir>` | Initialize a new Titan project in the specified directory. |
|
|
13
|
+
| `dev` | | Start the development server with hot-reload and strict type checking. |
|
|
14
|
+
| `build` | | Bundle JavaScript/TypeScript actions into `.jsbundle` files. |
|
|
15
|
+
| `build` | `--release` | Create a self-contained production bundle in `build/` (incl. engine). |
|
|
16
|
+
| `start` | | Start the Titan server (checks for `build/` or local engine). |
|
|
17
|
+
| `update` | | Update the local engine to the latest version. |
|
|
18
|
+
| `ext create` | `<name>` | Scaffold a new native Extension. |
|
|
19
|
+
| `ext run` | | Run the current extension in a test harness. |
|
|
20
|
+
| `help` | | Show available commands and options. |
|
|
21
|
+
|
|
8
22
|
## How it works
|
|
9
23
|
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
24
|
|
|
11
25
|
```bash
|
|
12
|
-
|
|
26
|
+
npm install -g @titanpl/cli
|
|
27
|
+
titan help
|
|
13
28
|
```
|
|
14
29
|
|
|
15
30
|
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
31
|
|
|
17
|
-
**
|
|
32
|
+
**Note:** All commands now prioritize `tanfig.json` for project configuration.
|
|
33
|
+
|
|
34
|
+
**Note on Platform Architecture:** Titan Planet's new v2 architecture supports Windows and Linux (incl. Docker). MacOS support is in active development.
|
package/index.js
CHANGED
|
@@ -53,7 +53,7 @@ ${bold(cyan("╰─────────────────────
|
|
|
53
53
|
${bold("Commands:")}
|
|
54
54
|
${cyan("init")} ${gray("Scaffold a new Titan project")}
|
|
55
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")}
|
|
56
|
+
${cyan("build")} ${gray("Compile actions and build production dist. Use --release or -r for a production-ready folder.")}
|
|
57
57
|
${cyan("dev")} ${gray("Start the Gravity Engine in dev/watch mode")}
|
|
58
58
|
${cyan("start")} ${gray("Start the production Gravity Engine")}
|
|
59
59
|
${cyan("update")} ${gray("Update an existing project to latest Titan version")}
|
|
@@ -122,9 +122,10 @@ const cmd = process.argv[2];
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
case "build":
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
const isRelease = process.argv.includes("--release") || process.argv.includes("-r");
|
|
126
|
+
console.log(cyan(`→ Building Titan project${isRelease ? " (Release mode)" : ""}...`));
|
|
127
|
+
await buildCommand(isRelease);
|
|
128
|
+
console.log(green(`✔ ${isRelease ? "Release" : "Build"} complete`));
|
|
128
129
|
break;
|
|
129
130
|
|
|
130
131
|
case "dev":
|
package/package.json
CHANGED
package/src/commands/build.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { build } from "@titanpl/packet";
|
|
1
|
+
import { build, release } from "@titanpl/packet";
|
|
2
2
|
|
|
3
|
-
export async function buildCommand() {
|
|
4
|
-
const
|
|
5
|
-
|
|
3
|
+
export async function buildCommand(isRelease = false) {
|
|
4
|
+
const buildFn = isRelease ? release : build;
|
|
5
|
+
const dist = await buildFn(process.cwd());
|
|
6
|
+
console.log(`✔ ${isRelease ? 'Release' : 'Build'} complete →`, dist);
|
|
6
7
|
}
|
package/src/commands/init.js
CHANGED
|
@@ -164,7 +164,8 @@ export async function initCommand(projectName, templateName) {
|
|
|
164
164
|
const remapping = {
|
|
165
165
|
"_gitignore": ".gitignore",
|
|
166
166
|
"_dockerignore": ".dockerignore",
|
|
167
|
-
"
|
|
167
|
+
"_tanfig.json": "tanfig.json",
|
|
168
|
+
"_titan.json": "tanfig.json",
|
|
168
169
|
".env": ".env"
|
|
169
170
|
};
|
|
170
171
|
for (const [srcName, destName] of Object.entries(remapping)) {
|
|
@@ -175,6 +176,19 @@ export async function initCommand(projectName, templateName) {
|
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
|
|
179
|
+
// 4. Ensure tanfig.json exists with default build config
|
|
180
|
+
const tanfigPath = path.join(target, "tanfig.json");
|
|
181
|
+
if (!fs.existsSync(tanfigPath)) {
|
|
182
|
+
const defaultConfig = {
|
|
183
|
+
name: projName,
|
|
184
|
+
build: {
|
|
185
|
+
files: ["public", "static", "db", "config"]
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
fs.writeFileSync(tanfigPath, JSON.stringify(defaultConfig, null, 2));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
|
|
178
192
|
// Recursive template substitution
|
|
179
193
|
const substitute = (dir) => {
|
|
180
194
|
for (const file of fs.readdirSync(dir)) {
|
package/src/engine.js
CHANGED
|
@@ -51,11 +51,21 @@ export function resolveEngineBinaryPath() {
|
|
|
51
51
|
const siblingBin = path.join(cliParent, pkgName, 'bin', binName);
|
|
52
52
|
if (fs.existsSync(siblingBin)) return siblingBin;
|
|
53
53
|
|
|
54
|
-
// 4. Walk upwards from current dir searching for node_modules
|
|
54
|
+
// 4. Walk upwards from current dir searching for binary in root or .ext/node_modules
|
|
55
55
|
let searchDir = process.cwd();
|
|
56
56
|
for (let i = 0; i < 5; i++) {
|
|
57
|
+
// Check root (Directly in build/ folder)
|
|
58
|
+
const rootBin = path.join(searchDir, binName);
|
|
59
|
+
if (fs.existsSync(rootBin)) return rootBin;
|
|
60
|
+
|
|
61
|
+
// Check node_modules
|
|
57
62
|
const nmBin = path.join(searchDir, 'node_modules', pkgName, 'bin', binName);
|
|
58
63
|
if (fs.existsSync(nmBin)) return nmBin;
|
|
64
|
+
|
|
65
|
+
// Check .ext (Release mode layout)
|
|
66
|
+
const extBin = path.join(searchDir, '.ext', pkgName, 'bin', binName);
|
|
67
|
+
if (fs.existsSync(extBin)) return extBin;
|
|
68
|
+
|
|
59
69
|
const parent = path.dirname(searchDir);
|
|
60
70
|
if (parent === searchDir) break;
|
|
61
71
|
searchDir = parent;
|
|
@@ -110,7 +120,8 @@ export function startEngine(watchMode = false) {
|
|
|
110
120
|
env: {
|
|
111
121
|
...process.env,
|
|
112
122
|
TITAN_ENV: watchMode ? 'development' : 'production',
|
|
113
|
-
|
|
123
|
+
TITAN_DEV: watchMode ? '1' : '0',
|
|
124
|
+
NODE_ENV: watchMode ? 'development' : 'production'
|
|
114
125
|
}
|
|
115
126
|
});
|
|
116
127
|
|
|
@@ -14,31 +14,14 @@ ENV NODE_ENV=production
|
|
|
14
14
|
|
|
15
15
|
COPY package.json package-lock.json* ./
|
|
16
16
|
|
|
17
|
-
# Install
|
|
17
|
+
# Install dependencies (including optional engines)
|
|
18
18
|
RUN npm install --include=optional
|
|
19
19
|
|
|
20
|
-
# ------------------------------------------------
|
|
21
|
-
# Extract Titan Extensions (packages with titan.json)
|
|
22
|
-
# ------------------------------------------------
|
|
23
|
-
RUN mkdir -p /app/.ext && \
|
|
24
|
-
find node_modules -mindepth 2 -maxdepth 3 -type f -name "titan.json" | while read file; do \
|
|
25
|
-
pkg_dir=$(dirname "$file"); \
|
|
26
|
-
pkg_name=$(basename "$pkg_dir"); \
|
|
27
|
-
echo "Extracting Titan extension: $pkg_name"; \
|
|
28
|
-
cp -a "$pkg_dir" "/app/.ext/$pkg_name"; \
|
|
29
|
-
rm -rf "/app/.ext/$pkg_name/node_modules"; \
|
|
30
|
-
done
|
|
31
|
-
|
|
32
|
-
# ------------------------------------------------
|
|
33
|
-
# Copy ANY installed Titan Engine (Architecture agnostic)
|
|
34
|
-
# ------------------------------------------------
|
|
35
|
-
RUN mkdir -p /app/.ext/@titanpl && \
|
|
36
|
-
cp -r node_modules/@titanpl/engine-linux-* /app/.ext/@titanpl/
|
|
37
|
-
|
|
38
20
|
COPY . .
|
|
39
21
|
|
|
40
|
-
# Run the Titan build step
|
|
41
|
-
|
|
22
|
+
# Run the Titan release build step
|
|
23
|
+
# This extracts extensions to .ext and prepares the 'build/' folder
|
|
24
|
+
RUN npx titan build --release
|
|
42
25
|
|
|
43
26
|
|
|
44
27
|
# ================================================================
|
|
@@ -55,31 +38,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
55
38
|
ca-certificates curl \
|
|
56
39
|
&& rm -rf /var/lib/apt/lists/*
|
|
57
40
|
|
|
58
|
-
#
|
|
59
|
-
COPY --from=builder /app/
|
|
60
|
-
|
|
61
|
-
# titan extensions + engine
|
|
62
|
-
COPY --from=builder /app/.ext ./.ext
|
|
63
|
-
|
|
64
|
-
# runtime assets
|
|
65
|
-
COPY --from=builder /app/package.json ./package.json
|
|
66
|
-
|
|
67
|
-
# ---------------- OPTIONAL APP FOLDERS ----------------
|
|
68
|
-
# Static assets
|
|
69
|
-
# COPY --from=builder /app/app/static ./static
|
|
70
|
-
|
|
71
|
-
# Public assets
|
|
72
|
-
# COPY --from=builder /app/app/public ./public
|
|
73
|
-
|
|
74
|
-
# DB
|
|
75
|
-
# COPY --from=builder /app/app/db ./db
|
|
41
|
+
# Copy the entire release build folder prepared by Stage 1
|
|
42
|
+
COPY --from=builder /app/build ./
|
|
76
43
|
|
|
77
|
-
#
|
|
78
|
-
|
|
79
|
-
# 2. Node modules symlink for extension JS dependency resolution
|
|
80
|
-
RUN echo "TITAN_DEV=0" > .env && \
|
|
81
|
-
ln -s /app/.ext /app/node_modules && \
|
|
82
|
-
chown -R titan:titan /app
|
|
44
|
+
# Ensure permissions
|
|
45
|
+
RUN chown -R titan:titan /app
|
|
83
46
|
|
|
84
47
|
# Standard environment variables
|
|
85
48
|
ENV HOST=0.0.0.0
|
|
@@ -89,10 +52,9 @@ ENV TITAN_DEV=0
|
|
|
89
52
|
USER titan
|
|
90
53
|
EXPOSE 5100
|
|
91
54
|
|
|
92
|
-
# Health check
|
|
55
|
+
# Health check
|
|
93
56
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
|
94
57
|
CMD curl -f http://localhost:5100/ || exit 1
|
|
95
58
|
|
|
96
|
-
#
|
|
97
|
-
|
|
98
|
-
CMD ["/bin/sh", "-c", "exec $(find .ext/@titanpl/engine-linux-* -name titan-server -type f | head -n 1) run dist"]
|
|
59
|
+
# Start the server using the 'titan-server' binary created by the release process
|
|
60
|
+
CMD ["./titan-server", "run", "dist"]
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# ⏣ Titan Project
|
|
2
|
+
|
|
3
|
+
Welcome to your new **Titan Planet** project! Titan is a high-performance web framework designed for scale, speed, and developer happiness.
|
|
4
|
+
|
|
5
|
+
## 🚀 Getting Started
|
|
6
|
+
|
|
7
|
+
### 1. Install Dependencies
|
|
8
|
+
```bash
|
|
9
|
+
npm install
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### 2. Start Development Server
|
|
13
|
+
Run the project in development mode with hot-reloading:
|
|
14
|
+
```bash
|
|
15
|
+
titan dev
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### 3. Build for Production
|
|
19
|
+
Create a self-contained production bundle in the `build/` directory:
|
|
20
|
+
```bash
|
|
21
|
+
titan build --release
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 4. Run Production Server
|
|
25
|
+
```bash
|
|
26
|
+
cd build
|
|
27
|
+
titan start
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 📂 Project Structure
|
|
33
|
+
|
|
34
|
+
- `app/actions/` - Your JavaScript/TypeScript backend logic.
|
|
35
|
+
- `public/` - Static assets served directly (images, robots.txt, etc.).
|
|
36
|
+
- `tanfig.json` - Core project configuration and build settings.
|
|
37
|
+
- `.env` - Environment variables.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 🛠 Configuration (`tanfig.json`)
|
|
42
|
+
|
|
43
|
+
Your project uses `tanfig.json` to control the build and runtime behavior.
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"name": "my-titan-app",
|
|
48
|
+
"build": {
|
|
49
|
+
"purpose": "test",
|
|
50
|
+
"files": ["public", "static", "db", "config"]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Build Options:
|
|
56
|
+
- **`purpose`**:
|
|
57
|
+
- `test`: (Default) Creates a `node_modules` junction for local testing.
|
|
58
|
+
- `deploy`: Slim build without `node_modules`, ready for production.
|
|
59
|
+
- **`files`**: List of folders/files from the root to include in the production `build/` folder.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 🐳 Docker Deployment
|
|
64
|
+
|
|
65
|
+
This project comes with a pre-configured, multi-stage `Dockerfile` optimized for Titan's native engine.
|
|
66
|
+
|
|
67
|
+
### Build Image
|
|
68
|
+
```bash
|
|
69
|
+
docker build -t my-titan-app .
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Run Container
|
|
73
|
+
```bash
|
|
74
|
+
docker run -p 5100:5100 my-titan-app
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 🌐 Community & Support
|
|
80
|
+
|
|
81
|
+
- **Documentation**: [docs.titanpl.com](https://docs.titanpl.com)
|
|
82
|
+
- **GitHub**: [github.com/t8nlab/titanpl](https://github.com/t8nlab/titanpl)
|
|
83
|
+
- **Discord**: [Join our community](https://discord.gg/titanpl)
|
|
84
|
+
|
|
85
|
+
Built with ❤️ by the **Titan Planet** team.
|