titanpl 1.0.0 → 1.4.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 +15 -18
- package/package.json +7 -5
- package/packages/cli/README.md +17 -0
- package/packages/cli/index.js +20 -0
- package/packages/cli/package.json +34 -0
- package/packages/cli/src/commands/build.js +6 -0
- package/packages/cli/src/commands/dev.js +5 -0
- package/packages/cli/src/commands/init.js +182 -0
- package/packages/cli/src/commands/migrate.js +106 -0
- package/packages/cli/src/commands/start.js +5 -0
- package/packages/cli/src/commands/update.js +90 -0
- package/packages/cli/src/engine.js +143 -0
- package/packages/engine-darwin-arm64/README.md +13 -0
- package/packages/engine-darwin-arm64/package.json +10 -0
- package/packages/engine-linux-x64/README.md +11 -0
- package/packages/engine-linux-x64/package.json +10 -0
- package/packages/engine-win32-x64/README.md +11 -0
- package/packages/engine-win32-x64/bin/titan-engine.exe +0 -0
- package/packages/engine-win32-x64/bin/titan-server.exe +0 -0
- package/packages/engine-win32-x64/package.json +10 -0
- package/packages/native/README.md +11 -0
- package/packages/native/index.d.ts +41 -0
- package/packages/native/index.js +39 -0
- package/packages/native/package.json +26 -0
- package/packages/native/t.native.d.ts +2043 -0
- package/packages/packet/README.md +11 -0
- package/packages/packet/index.js +84 -0
- package/packages/packet/js/titan/builder.js +50 -0
- package/packages/packet/js/titan/bundle.js +164 -0
- package/packages/packet/js/titan/dev.js +172 -0
- package/packages/packet/js/titan/error-box.js +277 -0
- package/packages/packet/node_modules/typescript/LICENSE.txt +55 -0
- package/packages/packet/node_modules/typescript/README.md +50 -0
- package/packages/packet/node_modules/typescript/SECURITY.md +41 -0
- package/packages/packet/node_modules/typescript/ThirdPartyNoticeText.txt +193 -0
- package/packages/packet/node_modules/typescript/bin/tsc +2 -0
- package/packages/packet/node_modules/typescript/bin/tsserver +2 -0
- package/packages/packet/node_modules/typescript/lib/_tsc.js +133818 -0
- package/packages/packet/node_modules/typescript/lib/_tsserver.js +659 -0
- package/packages/packet/node_modules/typescript/lib/_typingsInstaller.js +222 -0
- package/packages/packet/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +2122 -0
- package/packages/packet/node_modules/typescript/lib/de/diagnosticMessages.generated.json +2122 -0
- package/packages/packet/node_modules/typescript/lib/es/diagnosticMessages.generated.json +2122 -0
- package/packages/packet/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +2122 -0
- package/packages/packet/node_modules/typescript/lib/it/diagnosticMessages.generated.json +2122 -0
- package/packages/packet/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +2122 -0
- package/packages/packet/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +2122 -0
- package/packages/packet/node_modules/typescript/lib/lib.d.ts +22 -0
- package/packages/packet/node_modules/typescript/lib/lib.decorators.d.ts +384 -0
- package/packages/packet/node_modules/typescript/lib/lib.decorators.legacy.d.ts +22 -0
- package/packages/packet/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +41 -0
- package/packages/packet/node_modules/typescript/lib/lib.dom.d.ts +39429 -0
- package/packages/packet/node_modules/typescript/lib/lib.dom.iterable.d.ts +571 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2015.collection.d.ts +147 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2015.core.d.ts +597 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2015.d.ts +28 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2015.generator.d.ts +77 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2015.iterable.d.ts +605 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2015.promise.d.ts +81 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2015.proxy.d.ts +128 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2015.reflect.d.ts +144 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2015.symbol.d.ts +46 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +326 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2016.array.include.d.ts +116 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2016.d.ts +21 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2016.full.d.ts +23 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2016.intl.d.ts +31 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +21 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2017.d.ts +26 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2017.date.d.ts +31 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2017.full.d.ts +23 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2017.intl.d.ts +44 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2017.object.d.ts +49 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +135 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2017.string.d.ts +45 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +53 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +77 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +53 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2018.d.ts +24 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2018.full.d.ts +24 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2018.intl.d.ts +83 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2018.promise.d.ts +30 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2018.regexp.d.ts +37 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2019.array.d.ts +79 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2019.d.ts +24 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2019.full.d.ts +24 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2019.intl.d.ts +23 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2019.object.d.ts +33 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2019.string.d.ts +37 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2019.symbol.d.ts +24 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2020.bigint.d.ts +765 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2020.d.ts +27 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2020.date.d.ts +42 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2020.full.d.ts +24 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2020.intl.d.ts +474 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2020.number.d.ts +28 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2020.promise.d.ts +47 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +99 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2020.string.d.ts +44 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +41 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2021.d.ts +23 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2021.full.d.ts +24 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2021.intl.d.ts +166 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2021.promise.d.ts +48 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2021.string.d.ts +33 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2021.weakref.d.ts +78 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2022.array.d.ts +121 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2022.d.ts +25 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2022.error.d.ts +75 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2022.full.d.ts +24 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2022.intl.d.ts +145 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2022.object.d.ts +26 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2022.regexp.d.ts +39 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2022.string.d.ts +25 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2023.array.d.ts +924 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2023.collection.d.ts +21 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2023.d.ts +22 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2023.full.d.ts +24 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2023.intl.d.ts +56 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +65 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2024.collection.d.ts +29 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2024.d.ts +26 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2024.full.d.ts +24 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2024.object.d.ts +29 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2024.promise.d.ts +35 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2024.regexp.d.ts +25 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +68 -0
- package/packages/packet/node_modules/typescript/lib/lib.es2024.string.d.ts +29 -0
- package/packages/packet/node_modules/typescript/lib/lib.es5.d.ts +4601 -0
- package/packages/packet/node_modules/typescript/lib/lib.es6.d.ts +23 -0
- package/packages/packet/node_modules/typescript/lib/lib.esnext.array.d.ts +35 -0
- package/packages/packet/node_modules/typescript/lib/lib.esnext.collection.d.ts +96 -0
- package/packages/packet/node_modules/typescript/lib/lib.esnext.d.ts +29 -0
- package/packages/packet/node_modules/typescript/lib/lib.esnext.decorators.d.ts +28 -0
- package/packages/packet/node_modules/typescript/lib/lib.esnext.disposable.d.ts +193 -0
- package/packages/packet/node_modules/typescript/lib/lib.esnext.error.d.ts +24 -0
- package/packages/packet/node_modules/typescript/lib/lib.esnext.float16.d.ts +445 -0
- package/packages/packet/node_modules/typescript/lib/lib.esnext.full.d.ts +24 -0
- package/packages/packet/node_modules/typescript/lib/lib.esnext.intl.d.ts +21 -0
- package/packages/packet/node_modules/typescript/lib/lib.esnext.iterator.d.ts +148 -0
- package/packages/packet/node_modules/typescript/lib/lib.esnext.promise.d.ts +34 -0
- package/packages/packet/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +25 -0
- package/packages/packet/node_modules/typescript/lib/lib.scripthost.d.ts +322 -0
- package/packages/packet/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +41 -0
- package/packages/packet/node_modules/typescript/lib/lib.webworker.d.ts +13150 -0
- package/packages/packet/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +23 -0
- package/packages/packet/node_modules/typescript/lib/lib.webworker.iterable.d.ts +340 -0
- package/packages/packet/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +2122 -0
- package/packages/packet/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +2122 -0
- package/packages/packet/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +2122 -0
- package/packages/packet/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +2122 -0
- package/packages/packet/node_modules/typescript/lib/tsc.js +8 -0
- package/packages/packet/node_modules/typescript/lib/tsserver.js +8 -0
- package/packages/packet/node_modules/typescript/lib/tsserverlibrary.d.ts +17 -0
- package/packages/packet/node_modules/typescript/lib/tsserverlibrary.js +21 -0
- package/packages/packet/node_modules/typescript/lib/typesMap.json +497 -0
- package/packages/packet/node_modules/typescript/lib/typescript.d.ts +11437 -0
- package/packages/packet/node_modules/typescript/lib/typescript.js +200276 -0
- package/packages/packet/node_modules/typescript/lib/typingsInstaller.js +8 -0
- package/packages/packet/node_modules/typescript/lib/watchGuard.js +53 -0
- package/packages/packet/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +2122 -0
- package/packages/packet/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +2122 -0
- package/packages/packet/node_modules/typescript/package.json +120 -0
- package/packages/packet/package.json +23 -0
- package/packages/packet/ts/titan/builder.js +74 -0
- package/packages/packet/ts/titan/bundle.js +227 -0
- package/packages/packet/ts/titan/dev.js +175 -0
- package/packages/packet/ts/titan/error-box.js +277 -0
- package/packages/route/README.md +24 -0
- package/packages/route/index.d.ts +16 -0
- package/packages/route/index.js +52 -0
- package/packages/route/package.json +22 -0
- package/templates/extension/README.md +4 -0
- package/templates/extension/index.js +1 -12
- package/templates/extension/package.json +4 -4
- package/templates/js/app/app.js +1 -1
- package/templates/js/package.json +9 -8
- package/templates/rust-js/package.json +7 -7
- package/templates/rust-js/titan/dev.js +2 -2
- package/templates/rust-ts/package.json +7 -7
- package/templates/rust-ts/titan/dev.js +2 -2
- package/templates/ts/app/app.ts +1 -1
- package/templates/ts/package.json +9 -8
- package/titanpl-sdk/README.md +2 -0
- package/titanpl-sdk/package.json +4 -4
- package/titanpl-sdk/templates/titan/bundle.js +1 -1
- package/titanpl-sdk/templates/titan/dev.js +2 -2
- package/titanpl-sdk/templates/titan/error-box.js +2 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @titanpl/packet
|
|
2
|
+
|
|
3
|
+
The internal bundler and module packer for Titan Planet.
|
|
4
|
+
|
|
5
|
+
## What it works (What it does)
|
|
6
|
+
This library parses all your app routes, components, middleware, and logic paths, then packages them into a static `build` output layer consisting of metadata files and JavaScript assets.
|
|
7
|
+
|
|
8
|
+
## How it works
|
|
9
|
+
This package is triggered whenever you run `titan init` or `titan build` from the `@titanpl/cli`. It hooks into tools like `esbuild` to optimize your scripts efficiently. It strips unnecessary pieces out so that only explicit route actions make their way aggressively over to the Titan runtime engine.
|
|
10
|
+
|
|
11
|
+
**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,84 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get project type (js or ts)
|
|
6
|
+
*/
|
|
7
|
+
function getProjectType(root) {
|
|
8
|
+
try {
|
|
9
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
10
|
+
if (pkg.titan && pkg.titan.template && pkg.titan.template.includes("ts")) return "ts";
|
|
11
|
+
} catch (e) { }
|
|
12
|
+
|
|
13
|
+
if (fs.existsSync(path.join(root, "tsconfig.json"))) return "ts";
|
|
14
|
+
return "js";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Ensure dist directory exists
|
|
19
|
+
*/
|
|
20
|
+
function ensureDist(root) {
|
|
21
|
+
const dist = path.join(root, "dist");
|
|
22
|
+
const actions = path.join(dist, "actions");
|
|
23
|
+
|
|
24
|
+
if (!fs.existsSync(dist)) {
|
|
25
|
+
fs.mkdirSync(dist, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!fs.existsSync(actions)) {
|
|
29
|
+
fs.mkdirSync(actions, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return dist;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Production build
|
|
37
|
+
*/
|
|
38
|
+
export async function build(root = process.cwd()) {
|
|
39
|
+
const type = getProjectType(root);
|
|
40
|
+
const { bundle: bundleActions } = await import(`./${type}/titan/bundle.js`);
|
|
41
|
+
const { buildMetadata } = await import(`./${type}/titan/builder.js`);
|
|
42
|
+
|
|
43
|
+
const dist = ensureDist(root);
|
|
44
|
+
|
|
45
|
+
await buildMetadata(root, dist);
|
|
46
|
+
await bundleActions({
|
|
47
|
+
root,
|
|
48
|
+
outDir: dist,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return dist;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Dev mode build
|
|
56
|
+
*/
|
|
57
|
+
export async function dev(options = {}) {
|
|
58
|
+
const root = typeof options === 'string' ? options : (options.root || process.cwd());
|
|
59
|
+
const type = getProjectType(root);
|
|
60
|
+
const { dev: devServer } = await import(`./${type}/titan/dev.js`);
|
|
61
|
+
|
|
62
|
+
const dist = ensureDist(root);
|
|
63
|
+
|
|
64
|
+
await devServer({
|
|
65
|
+
root,
|
|
66
|
+
outDir: dist,
|
|
67
|
+
onRebuild: options.onRebuild
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return dist;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Direct export of current project tools
|
|
75
|
+
*/
|
|
76
|
+
export async function getTools(root = process.cwd()) {
|
|
77
|
+
const type = getProjectType(root);
|
|
78
|
+
const bundleModule = await import(`./${type}/titan/bundle.js`);
|
|
79
|
+
const builderModule = await import(`./${type}/titan/builder.js`);
|
|
80
|
+
return {
|
|
81
|
+
bundleActions: bundleModule.bundle,
|
|
82
|
+
buildMetadata: builderModule.buildMetadata
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { pathToFileURL } from "url";
|
|
4
|
+
|
|
5
|
+
export async function buildMetadata(root, dist) {
|
|
6
|
+
const appDir = path.join(root, "app");
|
|
7
|
+
const appFile = "app.js";
|
|
8
|
+
const appPath = path.join(appDir, appFile);
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(appPath)) {
|
|
11
|
+
console.error(`\x1b[31m❌ app/${appFile} not found.\x1b[0m`);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const appUrl = pathToFileURL(appPath).href;
|
|
17
|
+
const cacheBuster = `?t=${Date.now()}`;
|
|
18
|
+
await import(appUrl + cacheBuster);
|
|
19
|
+
|
|
20
|
+
const config = globalThis.__TITAN_CONFIG__ || { port: 3000, threads: 4, stack_mb: 8 };
|
|
21
|
+
const routes = globalThis.__TITAN_ROUTES_MAP__ || {};
|
|
22
|
+
const dynamicRoutes = globalThis.__TITAN_DYNAMIC_ROUTES__ || {};
|
|
23
|
+
const actionMap = globalThis.__TITAN_ACTION_MAP__ || {};
|
|
24
|
+
|
|
25
|
+
const routesPath = path.join(dist, "routes.json");
|
|
26
|
+
const actionMapPath = path.join(dist, "action_map.json");
|
|
27
|
+
|
|
28
|
+
fs.writeFileSync(
|
|
29
|
+
routesPath,
|
|
30
|
+
JSON.stringify(
|
|
31
|
+
{
|
|
32
|
+
__config: config,
|
|
33
|
+
routes,
|
|
34
|
+
__dynamic_routes: Object.values(dynamicRoutes).flat()
|
|
35
|
+
},
|
|
36
|
+
null,
|
|
37
|
+
2
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
fs.writeFileSync(
|
|
42
|
+
actionMapPath,
|
|
43
|
+
JSON.stringify(actionMap, null, 2)
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error("\x1b[31m❌ Failed to parse routes from app.js\x1b[0m", err);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundle.js (JavaScript Version)
|
|
3
|
+
* Handles esbuild bundling with error reporting
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import esbuild from 'esbuild';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
import { createRequire } from 'module';
|
|
11
|
+
import { renderErrorBox, parseEsbuildError } from './error-box.js';
|
|
12
|
+
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = path.dirname(__filename);
|
|
15
|
+
|
|
16
|
+
// Required for resolving node_modules inside ESM
|
|
17
|
+
const require = createRequire(import.meta.url);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Titan Node Builtin Rewrite Map
|
|
21
|
+
*/
|
|
22
|
+
const NODE_BUILTIN_MAP = {
|
|
23
|
+
"fs": "@titanpl/node/fs",
|
|
24
|
+
"node:fs": "@titanpl/node/fs",
|
|
25
|
+
"path": "@titanpl/node/path",
|
|
26
|
+
"node:path": "@titanpl/node/path",
|
|
27
|
+
"os": "@titanpl/node/os",
|
|
28
|
+
"node:os": "@titanpl/node/os",
|
|
29
|
+
"crypto": "@titanpl/node/crypto",
|
|
30
|
+
"node:crypto": "@titanpl/node/crypto",
|
|
31
|
+
"process": "@titanpl/node/process",
|
|
32
|
+
"util": "@titanpl/node/util",
|
|
33
|
+
"node:util": "@titanpl/node/util",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const titanNodeCompatPlugin = {
|
|
37
|
+
name: "titan-node-compat",
|
|
38
|
+
setup(build) {
|
|
39
|
+
build.onResolve({ filter: /.*/ }, args => {
|
|
40
|
+
if (NODE_BUILTIN_MAP[args.path]) {
|
|
41
|
+
try {
|
|
42
|
+
const resolved = require.resolve(NODE_BUILTIN_MAP[args.path]);
|
|
43
|
+
return { path: resolved };
|
|
44
|
+
} catch (e) {
|
|
45
|
+
throw new Error(`[TitanPL] Failed to resolve Node shim: ${NODE_BUILTIN_MAP[args.path]}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function getTitanVersion() {
|
|
53
|
+
try {
|
|
54
|
+
const pkgPath = require.resolve("@titanpl/cli/package.json");
|
|
55
|
+
return JSON.parse(fs.readFileSync(pkgPath, "utf-8")).version;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
return "1.0.0";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class BundleError extends Error {
|
|
62
|
+
constructor(message, errors = [], warnings = []) {
|
|
63
|
+
super(message);
|
|
64
|
+
this.name = 'BundleError';
|
|
65
|
+
this.errors = errors;
|
|
66
|
+
this.warnings = warnings;
|
|
67
|
+
this.isBundleError = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function validateEntryPoint(entryPoint) {
|
|
72
|
+
const absPath = path.resolve(entryPoint);
|
|
73
|
+
if (!fs.existsSync(absPath)) {
|
|
74
|
+
throw new BundleError(`Entry point does not exist: ${entryPoint}`, [{ text: `Cannot find file: ${absPath}`, location: { file: entryPoint } }]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Bundles a single file
|
|
80
|
+
*/
|
|
81
|
+
export async function bundleFile(options) {
|
|
82
|
+
const { entryPoint, outfile, format = 'iife', globalName = '__titan_exports', target = 'es2020' } = options;
|
|
83
|
+
|
|
84
|
+
await validateEntryPoint(entryPoint);
|
|
85
|
+
|
|
86
|
+
const outDir = path.dirname(outfile);
|
|
87
|
+
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const result = await esbuild.build({
|
|
91
|
+
entryPoints: [entryPoint],
|
|
92
|
+
bundle: true,
|
|
93
|
+
outfile,
|
|
94
|
+
format,
|
|
95
|
+
globalName,
|
|
96
|
+
platform: 'node',
|
|
97
|
+
target,
|
|
98
|
+
logLevel: 'silent',
|
|
99
|
+
plugins: [titanNodeCompatPlugin],
|
|
100
|
+
banner: { js: "var Titan = t;" },
|
|
101
|
+
footer: options.footer || {}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
if (result.errors?.length) {
|
|
105
|
+
throw new BundleError(`Build failed`, result.errors);
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
if (err.errors) throw new BundleError(`Build failed`, err.errors);
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Main JS Bundler
|
|
115
|
+
*/
|
|
116
|
+
export async function bundle(options = {}) {
|
|
117
|
+
const root = options.root || process.cwd();
|
|
118
|
+
const outDir = options.outDir || path.join(root, 'dist');
|
|
119
|
+
const titanVersion = getTitanVersion();
|
|
120
|
+
|
|
121
|
+
const actionsDir = path.join(root, 'app', 'actions');
|
|
122
|
+
const bundleDir = path.join(outDir, 'actions');
|
|
123
|
+
|
|
124
|
+
if (fs.existsSync(bundleDir)) fs.rmSync(bundleDir, { recursive: true, force: true });
|
|
125
|
+
fs.mkdirSync(bundleDir, { recursive: true });
|
|
126
|
+
|
|
127
|
+
if (!fs.existsSync(actionsDir)) return;
|
|
128
|
+
|
|
129
|
+
const files = fs.readdirSync(actionsDir).filter(f => f.endsWith('.js'));
|
|
130
|
+
|
|
131
|
+
for (const file of files) {
|
|
132
|
+
const actionName = path.basename(file, path.extname(file));
|
|
133
|
+
const entryPoint = path.join(actionsDir, file);
|
|
134
|
+
const outfile = path.join(bundleDir, actionName + ".jsbundle");
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
await bundleFile({
|
|
138
|
+
entryPoint,
|
|
139
|
+
outfile,
|
|
140
|
+
footer: {
|
|
141
|
+
js: `
|
|
142
|
+
(function () {
|
|
143
|
+
const fn = __titan_exports["${actionName}"] || __titan_exports.default;
|
|
144
|
+
if (typeof fn !== "function") throw new Error("[TitanPL] Action '${actionName}' not found or not a function");
|
|
145
|
+
globalThis["${actionName}"] = globalThis.defineAction(fn);
|
|
146
|
+
})();`
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error();
|
|
151
|
+
if (error.isBundleError && error.errors?.length) {
|
|
152
|
+
for (const err of error.errors) {
|
|
153
|
+
const errorInfo = parseEsbuildError(err);
|
|
154
|
+
errorInfo.titanVersion = titanVersion;
|
|
155
|
+
console.error(renderErrorBox(errorInfo));
|
|
156
|
+
console.error();
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
console.error(renderErrorBox({ title: 'Build Error', message: error.message, titanVersion }));
|
|
160
|
+
}
|
|
161
|
+
throw new Error('__TITAN_BUNDLE_FAILED__');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import chokidar from "chokidar";
|
|
2
|
+
import { spawn, execSync } from "child_process";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import { bundle } from "./bundle.js";
|
|
6
|
+
import { buildMetadata } from "./builder.js";
|
|
7
|
+
import { createRequire } from "module";
|
|
8
|
+
import os from "os";
|
|
9
|
+
|
|
10
|
+
const cyan = (t) => `\x1b[36m${t}\x1b[0m`;
|
|
11
|
+
const green = (t) => `\x1b[32m${t}\x1b[0m`;
|
|
12
|
+
const yellow = (t) => `\x1b[33m${t}\x1b[0m`;
|
|
13
|
+
const red = (t) => `\x1b[31m${t}\x1b[0m`;
|
|
14
|
+
const gray = (t) => `\x1b[90m${t}\x1b[0m`;
|
|
15
|
+
const bold = (t) => `\x1b[1m${t}\x1b[0m`;
|
|
16
|
+
|
|
17
|
+
function getTitanVersion() {
|
|
18
|
+
try {
|
|
19
|
+
const require = createRequire(import.meta.url);
|
|
20
|
+
const pkgPath = require.resolve("@titanpl/cli/package.json");
|
|
21
|
+
return JSON.parse(fs.readFileSync(pkgPath, "utf-8")).version;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return "1.0.0";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getEngineBinaryPath(root) {
|
|
28
|
+
const platform = os.platform();
|
|
29
|
+
const arch = os.arch();
|
|
30
|
+
const binName = platform === 'win32' ? 'titan-server.exe' : 'titan-server';
|
|
31
|
+
const pkgName = `@titanpl/engine-${platform}-${arch}`;
|
|
32
|
+
|
|
33
|
+
// Monorepo search
|
|
34
|
+
let current = root;
|
|
35
|
+
for (let i = 0; i < 5; i++) {
|
|
36
|
+
const potential = path.join(current, 'engine', 'target', 'release', binName);
|
|
37
|
+
if (fs.existsSync(potential)) return potential;
|
|
38
|
+
current = path.dirname(current);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Node modules search
|
|
42
|
+
try {
|
|
43
|
+
const require = createRequire(import.meta.url);
|
|
44
|
+
const pkgPath = require.resolve(`${pkgName}/package.json`);
|
|
45
|
+
const binPath = path.join(path.dirname(pkgPath), 'bin', binName);
|
|
46
|
+
if (fs.existsSync(binPath)) return binPath;
|
|
47
|
+
} catch (e) { }
|
|
48
|
+
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let serverProcess = null;
|
|
53
|
+
|
|
54
|
+
async function killServer() {
|
|
55
|
+
if (!serverProcess) return;
|
|
56
|
+
|
|
57
|
+
return new Promise((resolve) => {
|
|
58
|
+
const onExit = () => {
|
|
59
|
+
serverProcess = null;
|
|
60
|
+
resolve();
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
serverProcess.on('exit', onExit);
|
|
64
|
+
|
|
65
|
+
if (os.platform() === 'win32') {
|
|
66
|
+
try {
|
|
67
|
+
execSync(`taskkill /pid ${serverProcess.pid} /f /t`, { stdio: 'ignore' });
|
|
68
|
+
} catch (e) { }
|
|
69
|
+
} else {
|
|
70
|
+
serverProcess.kill('SIGKILL');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
setTimeout(onExit, 500);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function startServer(root, outDir) {
|
|
78
|
+
const binaryPath = getEngineBinaryPath(root);
|
|
79
|
+
if (!binaryPath) {
|
|
80
|
+
console.error(red("[TitanPL] Error: Could not find engine binary. Ensure you have installed the correct engine package."));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const distPath = path.resolve(root, "dist");
|
|
85
|
+
|
|
86
|
+
serverProcess = spawn(binaryPath, ['run', distPath, '--watch'], {
|
|
87
|
+
stdio: 'inherit',
|
|
88
|
+
env: {
|
|
89
|
+
...process.env,
|
|
90
|
+
TITAN_ENV: 'development',
|
|
91
|
+
Titan_Dev: '1'
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
serverProcess.on('error', (err) => {
|
|
96
|
+
if (err.code === 'ENOENT') {
|
|
97
|
+
console.error(red("[TitanPL] Failed to start engine: Binary not found."));
|
|
98
|
+
} else {
|
|
99
|
+
console.error(red(`[TitanPL] Engine error: ${err.message}`));
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function dev(options) {
|
|
105
|
+
const root = options.root || process.cwd();
|
|
106
|
+
const outDir = options.outDir || path.join(root, "dist");
|
|
107
|
+
|
|
108
|
+
const version = getTitanVersion();
|
|
109
|
+
|
|
110
|
+
console.clear();
|
|
111
|
+
console.log("");
|
|
112
|
+
console.log(` ${bold(cyan("⏣ Titan Planet"))} ${gray("v" + version)} ${yellow("[ Dev Mode ]")}`);
|
|
113
|
+
console.log("");
|
|
114
|
+
console.log(` ${gray("Type: ")} JS Actions`);
|
|
115
|
+
console.log(` ${gray("Hot Reload: ")} ${green("Enabled")}`);
|
|
116
|
+
|
|
117
|
+
if (fs.existsSync(path.join(root, ".env"))) {
|
|
118
|
+
console.log(` ${gray("Env: ")} ${yellow("Loaded")}`);
|
|
119
|
+
}
|
|
120
|
+
console.log("");
|
|
121
|
+
|
|
122
|
+
const runBuildCycle = async () => {
|
|
123
|
+
try {
|
|
124
|
+
await killServer();
|
|
125
|
+
|
|
126
|
+
await buildMetadata(root, outDir);
|
|
127
|
+
await bundle({ root, outDir });
|
|
128
|
+
|
|
129
|
+
console.log(cyan(`\n[TitanPL] Starting Engine...`));
|
|
130
|
+
startServer(root, outDir);
|
|
131
|
+
} catch (err) {
|
|
132
|
+
if (err.message !== '__TITAN_BUNDLE_FAILED__') {
|
|
133
|
+
console.error(red(`[TitanPL] Build failed: ${err.message}`));
|
|
134
|
+
}
|
|
135
|
+
console.log(yellow("\n[TitanPL] Waiting for fixes before restarting orbit..."));
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// Initial build
|
|
140
|
+
await runBuildCycle();
|
|
141
|
+
|
|
142
|
+
// Watch for changes inside app/
|
|
143
|
+
const appDir = path.join(root, "app");
|
|
144
|
+
const envFile = path.join(root, ".env");
|
|
145
|
+
|
|
146
|
+
const watcher = chokidar.watch([appDir, envFile], {
|
|
147
|
+
ignoreInitial: true,
|
|
148
|
+
awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 }
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
let buildTimer = null;
|
|
152
|
+
watcher.on("all", async (event, file) => {
|
|
153
|
+
if (!file) return;
|
|
154
|
+
const relPath = path.relative(root, file);
|
|
155
|
+
if (relPath.startsWith("dist") || relPath.startsWith(".titan") || relPath.startsWith("server") || relPath.startsWith("node_modules")) return;
|
|
156
|
+
|
|
157
|
+
if (buildTimer) clearTimeout(buildTimer);
|
|
158
|
+
buildTimer = setTimeout(() => {
|
|
159
|
+
console.clear();
|
|
160
|
+
console.log(cyan(`[TitanPL] File changed: ${relPath}. Rebuilding...`));
|
|
161
|
+
runBuildCycle();
|
|
162
|
+
}, 300); // Debounce
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Cleanup on exit
|
|
166
|
+
process.on('SIGINT', async () => {
|
|
167
|
+
await killServer();
|
|
168
|
+
process.exit(0);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return watcher;
|
|
172
|
+
}
|