@titanpl/cli 3.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.
Files changed (52) hide show
  1. package/README.md +19 -2
  2. package/index.js +5 -4
  3. package/package.json +12 -5
  4. package/src/commands/build.js +5 -4
  5. package/src/commands/init.js +15 -1
  6. package/src/engine.js +13 -2
  7. package/templates/common/.env +1 -0
  8. package/templates/common/Dockerfile +60 -0
  9. package/templates/common/README.md +85 -0
  10. package/templates/common/_dockerignore +35 -0
  11. package/templates/common/_gitignore +34 -0
  12. package/templates/common/_tanfig.json +14 -0
  13. package/templates/common/app/t.native.d.ts +2043 -0
  14. package/templates/common/app/t.native.js +39 -0
  15. package/templates/extension/README.md +69 -0
  16. package/templates/extension/index.d.ts +27 -0
  17. package/templates/extension/index.js +17 -0
  18. package/templates/extension/jsconfig.json +14 -0
  19. package/templates/extension/native/Cargo.toml +9 -0
  20. package/templates/extension/native/src/lib.rs +5 -0
  21. package/templates/extension/package-lock.json +522 -0
  22. package/templates/extension/package.json +26 -0
  23. package/templates/extension/titan.json +18 -0
  24. package/templates/js/app/actions/getuser.js +9 -0
  25. package/templates/js/app/app.js +7 -0
  26. package/templates/js/eslint.config.js +5 -0
  27. package/templates/js/jsconfig.json +27 -0
  28. package/templates/js/package.json +32 -0
  29. package/templates/rust-js/app/actions/getuser.js +9 -0
  30. package/templates/rust-js/app/actions/rust_hello.rs +14 -0
  31. package/templates/rust-js/app/app.js +9 -0
  32. package/templates/rust-js/eslint.config.js +5 -0
  33. package/templates/rust-js/jsconfig.json +27 -0
  34. package/templates/rust-js/package.json +27 -0
  35. package/templates/rust-js/titan/bundle.js +157 -0
  36. package/templates/rust-js/titan/dev.js +323 -0
  37. package/templates/rust-js/titan/titan.js +126 -0
  38. package/templates/rust-ts/app/actions/getuser.ts +9 -0
  39. package/templates/rust-ts/app/actions/rust_hello.rs +14 -0
  40. package/templates/rust-ts/app/app.ts +9 -0
  41. package/templates/rust-ts/eslint.config.js +12 -0
  42. package/templates/rust-ts/package.json +29 -0
  43. package/templates/rust-ts/titan/bundle.js +163 -0
  44. package/templates/rust-ts/titan/dev.js +435 -0
  45. package/templates/rust-ts/titan/titan.d.ts +19 -0
  46. package/templates/rust-ts/titan/titan.js +124 -0
  47. package/templates/rust-ts/tsconfig.json +28 -0
  48. package/templates/ts/app/actions/getuser.ts +9 -0
  49. package/templates/ts/app/app.ts +7 -0
  50. package/templates/ts/eslint.config.js +12 -0
  51. package/templates/ts/package.json +35 -0
  52. package/templates/ts/tsconfig.json +28 -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
- npx titan help
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
- **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.
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
- console.log(cyan(" Building Titan project..."));
126
- await buildCommand();
127
- console.log(green("✔ Build complete"));
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/cli",
3
- "version": "3.0.0",
3
+ "version": "5.0.0",
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",
@@ -12,8 +12,16 @@
12
12
  "author": "ezetgalaxy",
13
13
  "type": "module",
14
14
  "main": "index.js",
15
+ "files": [
16
+ "index.js",
17
+ "src/",
18
+ "templates/",
19
+ "README.md"
20
+ ],
15
21
  "scripts": {
16
- "test": "echo \"Error: no test specified\" && exit 1"
22
+ "test": "echo \"Error: no test specified\" && exit 1",
23
+ "prepack": "node -e \"const fs=require('fs');const p=require('path');const src=p.resolve(__dirname,'..','..','templates');const dest=p.resolve(__dirname,'templates');if(fs.existsSync(src)&&!fs.existsSync(dest)){const cp=(s,d)=>{fs.mkdirSync(d,{recursive:true});for(const f of fs.readdirSync(s)){const sp=p.join(s,f),dp=p.join(d,f);fs.lstatSync(sp).isDirectory()?cp(sp,dp):fs.copyFileSync(sp,dp)}};cp(src,dest);console.log('Copied templates for packaging')}\"",
24
+ "postpack": "node -e \"const fs=require('fs');const p=require('path');const d=p.resolve(__dirname,'templates');if(fs.existsSync(d)){fs.rmSync(d,{recursive:true,force:true});console.log('Cleaned up templates after packaging')}\""
17
25
  },
18
26
  "bin": {
19
27
  "titan": "./index.js",
@@ -22,8 +30,7 @@
22
30
  },
23
31
  "optionalDependencies": {
24
32
  "@titanpl/engine-win32-x64": "2.0.4",
25
- "@titanpl/engine-linux-x64": "2.0.4",
26
- "@titanpl/engine-darwin-arm64": "2.0.4"
33
+ "@titanpl/engine-linux-x64": "2.0.4"
27
34
  },
28
35
  "dependencies": {
29
36
  "@titanpl/packet": "2.0.4",
@@ -31,4 +38,4 @@
31
38
  "commander": "^11.0.0",
32
39
  "chalk": "^4.1.2"
33
40
  }
34
- }
41
+ }
@@ -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 dist = await build(process.cwd());
5
- console.log("✔ Build complete →", dist);
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
  }
@@ -164,7 +164,8 @@ export async function initCommand(projectName, templateName) {
164
164
  const remapping = {
165
165
  "_gitignore": ".gitignore",
166
166
  "_dockerignore": ".dockerignore",
167
- "_titan.json": "titan.json",
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/@titanpl/engine-...
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
- Titan_Dev: watchMode ? '1' : '0'
123
+ TITAN_DEV: watchMode ? '1' : '0',
124
+ NODE_ENV: watchMode ? 'development' : 'production'
114
125
  }
115
126
  });
116
127
 
@@ -0,0 +1 @@
1
+ TITAN_DEV=1
@@ -0,0 +1,60 @@
1
+ # ================================================================
2
+ # STAGE 1 — Builder
3
+ # ================================================================
4
+ FROM node:20-slim AS builder
5
+
6
+ WORKDIR /app
7
+
8
+ # build-essential is required for native Titan extensions (C++ or Rust based)
9
+ RUN apt-get update && apt-get install -y --no-install-recommends \
10
+ build-essential pkg-config git ca-certificates \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
+ ENV NODE_ENV=production
14
+
15
+ COPY package.json package-lock.json* ./
16
+
17
+ # Install dependencies (including optional engines)
18
+ RUN npm install --include=optional
19
+
20
+ COPY . .
21
+
22
+ # Run the Titan release build step
23
+ # This extracts extensions to .ext and prepares the 'build/' folder
24
+ RUN npx titan build --release
25
+
26
+
27
+ # ================================================================
28
+ # STAGE 2 — Runtime (Optimized Pure Engine)
29
+ # ================================================================
30
+ FROM ubuntu:24.04
31
+
32
+ # Use an unprivileged user for security
33
+ RUN groupadd -r titan && useradd -r -g titan titan
34
+
35
+ WORKDIR /app
36
+
37
+ RUN apt-get update && apt-get install -y --no-install-recommends \
38
+ ca-certificates curl \
39
+ && rm -rf /var/lib/apt/lists/*
40
+
41
+ # Copy the entire release build folder prepared by Stage 1
42
+ COPY --from=builder /app/build ./
43
+
44
+ # Ensure permissions
45
+ RUN chown -R titan:titan /app
46
+
47
+ # Standard environment variables
48
+ ENV HOST=0.0.0.0
49
+ ENV PORT=5100
50
+ ENV TITAN_DEV=0
51
+
52
+ USER titan
53
+ EXPOSE 5100
54
+
55
+ # Health check
56
+ HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
57
+ CMD curl -f http://localhost:5100/ || exit 1
58
+
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.
@@ -0,0 +1,35 @@
1
+ node_modules
2
+ npm-debug.log
3
+ .git
4
+ .gitignore
5
+
6
+ package-lock.json
7
+ yarn.lock
8
+
9
+ # Titan Gravity Engine
10
+ dist/
11
+ .titan/
12
+ .ext/
13
+
14
+ deploy/
15
+
16
+ # Rust Build Artifacts
17
+ server/target/
18
+ Cargo.lock
19
+
20
+ # OS Files
21
+ .DS_Store
22
+ Thumbs.db
23
+ *.tmp
24
+ *.bak
25
+
26
+ # Environment & Secrets
27
+ .env
28
+ .env.local
29
+ .env.*.local
30
+
31
+ # IDEs
32
+ .vscode/
33
+ .idea/
34
+ *.swp
35
+ *.swo
@@ -0,0 +1,34 @@
1
+ # Node & Packages
2
+ node_modules/
3
+ npm-debug.log*
4
+ yarn-debug.log*
5
+ yarn-error.log*
6
+ package-lock.json
7
+ yarn.lock
8
+
9
+ # Titan Engine (Auto-generated - DO NOT COMMIT)
10
+ dist/
11
+ .titan/
12
+ .ext/
13
+ .env
14
+ build/
15
+
16
+ # Rust Build Artifacts (If using Hybrid)
17
+ server/target/
18
+ Cargo.lock
19
+
20
+ # OS Files
21
+ .DS_Store
22
+ Thumbs.db
23
+ *.tmp
24
+ *.bak
25
+
26
+ # Environment & Secrets
27
+ .env.local
28
+ .env.*.local
29
+
30
+ # IDEs
31
+ .vscode/
32
+ .idea/
33
+ *.swp
34
+ *.swo
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "{{name}}",
3
+ "description": "A powerful Titan Planet project",
4
+ "version": "1.0.0",
5
+ "build": {
6
+ "purpose": "test",
7
+ "files": [
8
+ "public",
9
+ "static",
10
+ "db",
11
+ "config"
12
+ ]
13
+ }
14
+ }