@titanpl/cli 2.0.2 → 2.0.4

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 (46) hide show
  1. package/package.json +5 -5
  2. package/src/commands/init.js +23 -2
  3. package/src/engine.js +18 -1
  4. package/templates/common/Dockerfile +66 -0
  5. package/templates/common/_dockerignore +35 -0
  6. package/templates/common/_gitignore +33 -0
  7. package/templates/common/app/t.native.d.ts +2043 -0
  8. package/templates/common/app/t.native.js +39 -0
  9. package/templates/extension/README.md +69 -0
  10. package/templates/extension/index.d.ts +27 -0
  11. package/templates/extension/index.js +17 -0
  12. package/templates/extension/jsconfig.json +14 -0
  13. package/templates/extension/native/Cargo.toml +9 -0
  14. package/templates/extension/native/src/lib.rs +5 -0
  15. package/templates/extension/package-lock.json +522 -0
  16. package/templates/extension/package.json +26 -0
  17. package/templates/extension/titan.json +18 -0
  18. package/templates/js/app/actions/getuser.js +9 -0
  19. package/templates/js/app/app.js +7 -0
  20. package/templates/js/eslint.config.js +5 -0
  21. package/templates/js/jsconfig.json +27 -0
  22. package/templates/js/package.json +28 -0
  23. package/templates/rust-js/app/actions/getuser.js +9 -0
  24. package/templates/rust-js/app/actions/rust_hello.rs +14 -0
  25. package/templates/rust-js/app/app.js +9 -0
  26. package/templates/rust-js/eslint.config.js +5 -0
  27. package/templates/rust-js/jsconfig.json +27 -0
  28. package/templates/rust-js/package.json +27 -0
  29. package/templates/rust-js/titan/bundle.js +157 -0
  30. package/templates/rust-js/titan/dev.js +323 -0
  31. package/templates/rust-js/titan/titan.js +126 -0
  32. package/templates/rust-ts/app/actions/getuser.ts +9 -0
  33. package/templates/rust-ts/app/actions/rust_hello.rs +14 -0
  34. package/templates/rust-ts/app/app.ts +9 -0
  35. package/templates/rust-ts/eslint.config.js +12 -0
  36. package/templates/rust-ts/package.json +29 -0
  37. package/templates/rust-ts/titan/bundle.js +163 -0
  38. package/templates/rust-ts/titan/dev.js +435 -0
  39. package/templates/rust-ts/titan/titan.d.ts +19 -0
  40. package/templates/rust-ts/titan/titan.js +124 -0
  41. package/templates/rust-ts/tsconfig.json +28 -0
  42. package/templates/ts/app/actions/getuser.ts +9 -0
  43. package/templates/ts/app/app.ts +7 -0
  44. package/templates/ts/eslint.config.js +12 -0
  45. package/templates/ts/package.json +30 -0
  46. package/templates/ts/tsconfig.json +28 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/cli",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
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.2",
25
- "@titanpl/engine-linux-x64": "2.0.2",
26
- "@titanpl/engine-darwin-arm64": "2.0.2"
24
+ "@titanpl/engine-win32-x64": "2.0.4",
25
+ "@titanpl/engine-linux-x64": "2.0.4",
26
+ "@titanpl/engine-darwin-arm64": "2.0.4"
27
27
  },
28
28
  "dependencies": {
29
- "@titanpl/packet": "2.0.2",
29
+ "@titanpl/packet": "2.0.4",
30
30
  "prompts": "^2.4.2",
31
31
  "commander": "^11.0.0",
32
32
  "chalk": "^4.1.2"
@@ -99,8 +99,27 @@ export async function initCommand(projectName, templateName) {
99
99
  let templateDir = path.resolve(__dirname, '..', '..', '..', '..', 'templates', selectedTemplate);
100
100
  let commonDir = path.resolve(__dirname, '..', '..', '..', '..', 'templates', 'common');
101
101
 
102
+ const tryPaths = [
103
+ // 1. Monorepo root / titanpl package root
104
+ { t: path.resolve(__dirname, '..', '..', '..', '..', 'templates', selectedTemplate), c: path.resolve(__dirname, '..', '..', '..', '..', 'templates', 'common') },
105
+ // 2. Published CLI package (global install / npm package)
106
+ { t: path.resolve(__dirname, '..', '..', 'templates', selectedTemplate), c: path.resolve(__dirname, '..', '..', 'templates', 'common') },
107
+ // 3. Fallback: one dir up? Just in case
108
+ { t: path.resolve(__dirname, '..', '..', '..', 'templates', selectedTemplate), c: path.resolve(__dirname, '..', '..', '..', 'templates', 'common') }
109
+ ];
110
+
111
+ let found = false;
112
+ for (const paths of tryPaths) {
113
+ if (fs.existsSync(paths.t) && fs.existsSync(paths.c)) {
114
+ templateDir = paths.t;
115
+ commonDir = paths.c;
116
+ found = true;
117
+ break;
118
+ }
119
+ }
120
+
102
121
  // Robust monorepo/fallback template search: look upwards from cwd
103
- if (!fs.existsSync(templateDir) || !fs.existsSync(commonDir)) {
122
+ if (!found) {
104
123
  let searchDir = process.cwd();
105
124
  while (searchDir !== path.parse(searchDir).root) {
106
125
  const potentialTemplateDir = path.join(searchDir, 'templates', selectedTemplate);
@@ -108,6 +127,7 @@ export async function initCommand(projectName, templateName) {
108
127
  if (fs.existsSync(potentialTemplateDir) && fs.existsSync(potentialCommonDir)) {
109
128
  templateDir = potentialTemplateDir;
110
129
  commonDir = potentialCommonDir;
130
+ found = true;
111
131
  break;
112
132
  }
113
133
  const sdkPotentialTemplateDir = path.join(searchDir, 'titanpl-sdk', 'templates', selectedTemplate);
@@ -115,13 +135,14 @@ export async function initCommand(projectName, templateName) {
115
135
  if (fs.existsSync(sdkPotentialTemplateDir) && fs.existsSync(sdkPotentialCommonDir)) {
116
136
  templateDir = sdkPotentialTemplateDir;
117
137
  commonDir = sdkPotentialCommonDir;
138
+ found = true;
118
139
  break;
119
140
  }
120
141
  searchDir = path.dirname(searchDir);
121
142
  }
122
143
  }
123
144
 
124
- if (!fs.existsSync(templateDir) || !fs.existsSync(commonDir)) {
145
+ if (!found) {
125
146
  console.log(chalk.red(`✖ Error finding template paths. Are you in a valid Titan monorepo?`));
126
147
  process.exit(1);
127
148
  }
package/src/engine.js CHANGED
@@ -2,7 +2,7 @@ import os from 'os';
2
2
  import path from 'path';
3
3
  import fs from 'fs';
4
4
  import { createRequire } from 'module';
5
- import { spawn } from 'child_process';
5
+ import { spawn, execSync } from 'child_process';
6
6
  import { fileURLToPath } from 'url';
7
7
 
8
8
  const __filename = fileURLToPath(import.meta.url);
@@ -51,6 +51,23 @@ 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-...
55
+ let searchDir = process.cwd();
56
+ for (let i = 0; i < 5; i++) {
57
+ const nmBin = path.join(searchDir, 'node_modules', pkgName, 'bin', binName);
58
+ if (fs.existsSync(nmBin)) return nmBin;
59
+ const parent = path.dirname(searchDir);
60
+ if (parent === searchDir) break;
61
+ searchDir = parent;
62
+ }
63
+
64
+ // 5. Check global npm
65
+ try {
66
+ const globalModules = execSync('npm root -g').toString().trim();
67
+ const globalBin = path.join(globalModules, pkgName, 'bin', binName);
68
+ if (fs.existsSync(globalBin)) return globalBin;
69
+ } catch (e) { }
70
+
54
71
  return null;
55
72
  }
56
73
 
@@ -0,0 +1,66 @@
1
+ # ================================================================
2
+ # STAGE 1 — Build TitanPl
3
+ # ================================================================
4
+ FROM node:20.20.0-slim AS builder
5
+
6
+ WORKDIR /app
7
+
8
+ # Install native dependencies in case of native modules or hybrids
9
+ RUN apt-get update && apt-get install -y --no-install-recommends \
10
+ curl ca-certificates build-essential pkg-config libssl-dev git bash \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
+ ENV NODE_ENV=production
14
+
15
+ # ---------- Node Dependencies ----------
16
+ COPY package.json package-lock.json* ./
17
+ RUN npm install
18
+
19
+ # ---------- Copy Project ----------
20
+ COPY . .
21
+
22
+ # Run the Titan build command (compiles dist/)
23
+ RUN npx titan build
24
+
25
+ # ================================================================
26
+ # STAGE 2 — Gravity Engine (Production Ready)
27
+ # ================================================================
28
+ FROM node:20.20.0-slim
29
+
30
+ WORKDIR /app
31
+
32
+ # Ensure we have required OS-level certs if doing network fetching
33
+ RUN apt-get update && \
34
+ apt-get install -y --no-install-recommends ca-certificates curl && \
35
+ rm -rf /var/lib/apt/lists/*
36
+
37
+ # ---- Copy Production package.json and install ONLY dependencies ----
38
+ COPY package.json package-lock.json* ./
39
+ RUN npm ci --omit=dev
40
+
41
+ # ---- Copy Dist Build from Builder ----
42
+ COPY --from=builder /app/dist ./dist
43
+
44
+ # ---------------- OPTIONAL APP FOLDERS ----------------
45
+ # Static assets
46
+ # COPY --from=builder /app/app/static ./static
47
+
48
+ # Public assets
49
+ # COPY --from=builder /app/app/public ./public
50
+
51
+ # DB
52
+ # COPY --from=builder /app/app/db ./db
53
+
54
+ # ---- Create User After Copy ----
55
+ RUN useradd -m titan && chown -R titan:titan /app
56
+ USER titan
57
+
58
+ # ---- Platform Defaults ----
59
+ ENV HOST=0.0.0.0
60
+ ENV PORT=5100
61
+ ENV TITAN_DEV=0
62
+
63
+ EXPOSE 5100
64
+
65
+ # ---- Force Foreground Process via Titan CLI ----
66
+ CMD ["npx", "titan", "start"]
@@ -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,33 @@
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
+
15
+ # Rust Build Artifacts (If using Hybrid)
16
+ server/target/
17
+ Cargo.lock
18
+
19
+ # OS Files
20
+ .DS_Store
21
+ Thumbs.db
22
+ *.tmp
23
+ *.bak
24
+
25
+ # Environment & Secrets
26
+ .env.local
27
+ .env.*.local
28
+
29
+ # IDEs
30
+ .vscode/
31
+ .idea/
32
+ *.swp
33
+ *.swo