@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
@@ -0,0 +1,39 @@
1
+ // titan.js - Named exports for users who prefer imports over the global `t`
2
+
3
+ export const fetch = t.fetch;
4
+ export const log = t.log;
5
+ export const read = t.read;
6
+
7
+ // Authentication & Security
8
+ export const jwt = t.jwt;
9
+ export const password = t.password;
10
+
11
+ // Database
12
+ export const db = t.db;
13
+
14
+ // File System & Path
15
+ export const fs = t.fs;
16
+ export const path = t.path;
17
+
18
+ // Crypto & Buffer
19
+ export const crypto = t.crypto;
20
+ export const buffer = t.buffer;
21
+
22
+ // Storage & Sessions
23
+ export const ls = t.ls;
24
+ export const localStorage = t.localStorage;
25
+ export const session = t.session;
26
+ export const cookies = t.cookies;
27
+
28
+ // System
29
+ export const os = t.os;
30
+ export const net = t.net;
31
+ export const proc = t.proc;
32
+
33
+ // Utilities
34
+ export const time = t.time;
35
+ export const url = t.url;
36
+ export const response = t.response;
37
+ export const valid = t.valid;
38
+
39
+ export const defineAction = (handler) => handler;
@@ -0,0 +1,69 @@
1
+ # Titan Extension Template
2
+
3
+ This template provides a starting point for building native extensions for Titan.
4
+
5
+ ## Directory Structure
6
+
7
+ - `index.js`: The JavaScript entry point for your extension. It runs within the Titan runtime.
8
+ - `index.d.ts`: TypeScript definitions for your extension. This ensures users get autocompletion when using your extension.
9
+ - `native/`: (Optional) Rust source code for native high-performance logic.
10
+ - `titan.json`: Configuration file defining your extension's native ABI (if using Rust).
11
+
12
+ ## Type Definitions (`index.d.ts`)
13
+
14
+ The `index.d.ts` file is crucial for Developer Experience (DX). It allows Titan projects to "see" your extension's API on the global `t` object.
15
+
16
+ ### How it works
17
+
18
+ Titan uses **Declaration Merging** to extend the global `Titan.Runtime` interface. When a user installs your extension, this file acts as a plugin to their TypeScript environment.
19
+
20
+ ### Customizing Types
21
+
22
+ Edit `index.d.ts` to match the API you expose in `index.js`.
23
+
24
+ **Example:**
25
+
26
+ If your `index.js` looks like this:
27
+
28
+ ```javascript
29
+ // index.js
30
+ t.ext.my_cool_ext = {
31
+ greet: (name) => `Hello, ${name}!`,
32
+ compute: (x) => x * 2
33
+ };
34
+ ```
35
+
36
+ Your `index.d.ts` should look like this:
37
+
38
+ ```typescript
39
+ // index.d.ts
40
+ declare global {
41
+ namespace Titan {
42
+ interface Runtime {
43
+ "my-cool-ext": {
44
+ /**
45
+ * Sends a greeting.
46
+ */
47
+ greet(name: string): string;
48
+
49
+ /**
50
+ * Computes a value.
51
+ */
52
+ compute(x: number): number;
53
+ }
54
+ }
55
+ }
56
+ }
57
+ export { };
58
+ ```
59
+
60
+ ## Native Bindings (Rust)
61
+
62
+ If your extension requires native performance or system access, use the `native/` directory.
63
+ 1. Define functions in `native/src/lib.rs`.
64
+ 2. Map them in `titan.json`.
65
+ 3. Call them from `index.js` using `Titan.native.invoke(...)` (or the helper provided in the template).
66
+
67
+ ---
68
+
69
+ **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,27 @@
1
+ // Type definitions for {{name}}
2
+ // This file facilitates type inference when this extension is installed in a Titan project.
3
+
4
+ declare global {
5
+ namespace Titan {
6
+ interface Runtime {
7
+ /**
8
+ * {{name}} Extension
9
+ */
10
+ "{{name}}": {
11
+ /**
12
+ * Example hello function
13
+ */
14
+ hello(name: string): string;
15
+
16
+ /**
17
+ * Example calc function (native wrapper)
18
+ */
19
+ calc(a: number, b: number): number;
20
+
21
+ // Add your extension methods here
22
+ }
23
+ }
24
+ }
25
+ }
26
+
27
+ export { };
@@ -0,0 +1,17 @@
1
+ // Define your extension Key
2
+ if (typeof Titan === "undefined") globalThis.Titan = t;
3
+ const EXT_KEY = "{{name}}";
4
+
5
+ // Preserve any native functions already attached to this key
6
+ t[EXT_KEY] = Object.assign(t[EXT_KEY] || {}, {
7
+ // Example pure JavaScript function
8
+ hello: function (name) {
9
+ return `Hello ${name} from ${EXT_KEY}!`;
10
+ },
11
+
12
+ // Example Wrapper for Native function
13
+ calc: function (a, b) {
14
+ // Assumes the native function 'add' is mapped in titan.json
15
+ return t[EXT_KEY].add(a, b);
16
+ }
17
+ });
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "target": "es2021",
5
+ "checkJs": false,
6
+ "allowJs": true,
7
+ "moduleResolution": "node"
8
+ },
9
+ "include": [
10
+ "index.js",
11
+ "node_modules/titan-sdk/index.d.ts",
12
+ "node_modules/**/titan-ext.d.ts"
13
+ ]
14
+ }
@@ -0,0 +1,9 @@
1
+ [package]
2
+ name = "{{native_name}}_native"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+
6
+ [lib]
7
+ crate-type = ["cdylib"]
8
+
9
+ [dependencies]
@@ -0,0 +1,5 @@
1
+
2
+ #[unsafe(no_mangle)]
3
+ pub extern "C" fn add(a: f64, b: f64) -> f64 {
4
+ a + b
5
+ }