@titanpl/cli 2.0.0 → 2.0.1
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/package.json +5 -5
- package/src/commands/dev.js +8 -1
- package/src/commands/init.js +2 -10
- package/src/commands/migrate.js +25 -7
- package/src/engine.js +37 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@titanpl/cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
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.
|
|
25
|
-
"@titanpl/engine-linux-x64": "2.0.
|
|
26
|
-
"@titanpl/engine-darwin-arm64": "2.0.
|
|
24
|
+
"@titanpl/engine-win32-x64": "2.0.1",
|
|
25
|
+
"@titanpl/engine-linux-x64": "2.0.1",
|
|
26
|
+
"@titanpl/engine-darwin-arm64": "2.0.1"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@titanpl/packet": "2.0.
|
|
29
|
+
"@titanpl/packet": "2.0.1",
|
|
30
30
|
"prompts": "^2.4.2",
|
|
31
31
|
"commander": "^11.0.0",
|
|
32
32
|
"chalk": "^4.1.2"
|
package/src/commands/dev.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { dev } from "@titanpl/packet";
|
|
2
|
+
import { resolveEngineBinaryPath } from "../engine.js";
|
|
2
3
|
|
|
3
4
|
export async function devCommand() {
|
|
5
|
+
// Resolve the engine binary from CLI's context (where optionalDependencies live)
|
|
6
|
+
// and inject it into the environment so packet can find it without re-resolving.
|
|
7
|
+
const enginePath = resolveEngineBinaryPath();
|
|
8
|
+
if (enginePath) {
|
|
9
|
+
process.env.TITAN_ENGINE_BINARY = enginePath;
|
|
10
|
+
}
|
|
4
11
|
await dev(process.cwd());
|
|
5
|
-
}
|
|
12
|
+
}
|
package/src/commands/init.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
|
-
import {
|
|
4
|
+
import { execSync } from 'child_process';
|
|
5
5
|
import prompts from 'prompts';
|
|
6
6
|
import chalk from 'chalk';
|
|
7
7
|
|
|
@@ -166,15 +166,7 @@ export async function initCommand(projectName, templateName) {
|
|
|
166
166
|
|
|
167
167
|
console.log(chalk.gray(` Installing dependencies...`));
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
const npm = spawn('npm', ['install'], {
|
|
171
|
-
cwd: target,
|
|
172
|
-
stdio: 'inherit',
|
|
173
|
-
shell: true
|
|
174
|
-
});
|
|
175
|
-
npm.on('error', reject);
|
|
176
|
-
npm.on('close', resolve);
|
|
177
|
-
});
|
|
169
|
+
execSync('npm install', { cwd: target, stdio: 'inherit' });
|
|
178
170
|
|
|
179
171
|
console.log(chalk.green(`\n✔ Project '${projName}' created successfully!\n`));
|
|
180
172
|
console.log(chalk.yellow(` cd ${projName}`));
|
package/src/commands/migrate.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
3
7
|
|
|
4
8
|
export async function migrateCommand() {
|
|
5
9
|
const root = process.cwd();
|
|
@@ -51,15 +55,29 @@ export async function migrateCommand() {
|
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
|
|
54
|
-
// Add dependencies
|
|
58
|
+
// Add / fix dependencies — ensure correct @titanpl/ scope
|
|
55
59
|
pkg.dependencies = pkg.dependencies || {};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
|
|
61
|
+
// Remove any stale old-scope packages (@titan/ typo) that may exist
|
|
62
|
+
const stalePackages = ['@titanp/native', '@titan/route', '@titan/cli', '@titan/packet'];
|
|
63
|
+
for (const stale of stalePackages) {
|
|
64
|
+
if (pkg.dependencies[stale]) {
|
|
65
|
+
delete pkg.dependencies[stale];
|
|
66
|
+
modified = true;
|
|
67
|
+
}
|
|
59
68
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
|
|
70
|
+
const requiredDeps = {
|
|
71
|
+
'@titanpl/cli': 'latest',
|
|
72
|
+
'@titanpl/route': 'latest',
|
|
73
|
+
'@titanpl/native': 'latest',
|
|
74
|
+
'@titanpl/packet': 'latest',
|
|
75
|
+
};
|
|
76
|
+
for (const [dep, version] of Object.entries(requiredDeps)) {
|
|
77
|
+
if (!pkg.dependencies[dep]) {
|
|
78
|
+
pkg.dependencies[dep] = version;
|
|
79
|
+
modified = true;
|
|
80
|
+
}
|
|
63
81
|
}
|
|
64
82
|
|
|
65
83
|
if (modified) {
|
package/src/engine.js
CHANGED
|
@@ -10,13 +10,17 @@ const __dirname = path.dirname(__filename);
|
|
|
10
10
|
|
|
11
11
|
const require = createRequire(import.meta.url);
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Resolves the engine binary path. Returns null if not found (non-fatal).
|
|
15
|
+
* Used by the dev command to pre-resolve and inject the path via env.
|
|
16
|
+
*/
|
|
17
|
+
export function resolveEngineBinaryPath() {
|
|
18
|
+
const platform = os.platform();
|
|
19
|
+
const arch = os.arch();
|
|
16
20
|
const pkgName = `@titanpl/engine-${platform}-${arch}`;
|
|
17
21
|
const binName = platform === 'win32' ? 'titan-server.exe' : 'titan-server';
|
|
18
22
|
|
|
19
|
-
// 1.
|
|
23
|
+
// 1. Monorepo search (local dev)
|
|
20
24
|
const searchPaths = [
|
|
21
25
|
__dirname,
|
|
22
26
|
process.cwd(),
|
|
@@ -29,38 +33,43 @@ export function getEngineBinaryPath() {
|
|
|
29
33
|
for (let i = 0; i < 8; i++) {
|
|
30
34
|
const potential = path.join(current, 'engine', 'target', 'release', binName);
|
|
31
35
|
if (fs.existsSync(potential)) return potential;
|
|
32
|
-
|
|
33
36
|
const parent = path.dirname(current);
|
|
34
37
|
if (parent === current) break;
|
|
35
38
|
current = parent;
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
// 2. Resolve
|
|
42
|
+
// 2. Resolve from CLI's own context (correct require context for optionalDependencies)
|
|
40
43
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} catch (e) {
|
|
46
|
-
// Fallback: check if the binary exists in a standard location even if require.resolve fails
|
|
47
|
-
const fallbackBin = path.join(process.cwd(), 'node_modules', pkgName, 'bin', binName);
|
|
48
|
-
if (fs.existsSync(fallbackBin)) return fallbackBin;
|
|
49
|
-
throw e;
|
|
50
|
-
}
|
|
51
|
-
const pkgDir = path.dirname(pkgPath);
|
|
52
|
-
const binaryPath = path.join(pkgDir, 'bin', binName);
|
|
44
|
+
const pkgPath = require.resolve(`${pkgName}/package.json`);
|
|
45
|
+
const binaryPath = path.join(path.dirname(pkgPath), 'bin', binName);
|
|
46
|
+
if (fs.existsSync(binaryPath)) return binaryPath;
|
|
47
|
+
} catch (e) { }
|
|
53
48
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
// 3. Fallback: sibling in node_modules (global install layout)
|
|
50
|
+
const cliParent = path.dirname(path.dirname(__dirname)); // up from cli/src → cli → parent
|
|
51
|
+
const siblingBin = path.join(cliParent, pkgName, 'bin', binName);
|
|
52
|
+
if (fs.existsSync(siblingBin)) return siblingBin;
|
|
53
|
+
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Resolves the engine binary path. Exits with a fatal error if not found.
|
|
59
|
+
* Used by the start command.
|
|
60
|
+
*/
|
|
61
|
+
export function getEngineBinaryPath() {
|
|
62
|
+
const platform = os.platform();
|
|
63
|
+
const arch = os.arch();
|
|
64
|
+
const pkgName = `@titanpl/engine-${platform}-${arch}`;
|
|
65
|
+
|
|
66
|
+
const resolved = resolveEngineBinaryPath();
|
|
67
|
+
if (resolved) return resolved;
|
|
68
|
+
|
|
69
|
+
console.error(`\n[TITAN FATAL] Unsupported platform: ${platform} (${arch})`);
|
|
70
|
+
console.error(`Or the optional dependency '${pkgName}' failed to install.`);
|
|
71
|
+
console.error(`Try: npm install -g @titanpl/cli\n`);
|
|
72
|
+
process.exit(1);
|
|
64
73
|
}
|
|
65
74
|
|
|
66
75
|
export function startEngine(watchMode = false) {
|