@titanpl/cli 26.16.5 → 26.16.8
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/index.js +19 -0
- package/package.json +5 -5
- package/src/commands/init.js +19 -5
- package/src/commands/migrate.js +30 -0
- package/src/commands/update.js +90 -0
package/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { buildCommand } from "./src/commands/build.js";
|
|
|
8
8
|
import { devCommand } from "./src/commands/dev.js";
|
|
9
9
|
import { startCommand } from "./src/commands/start.js";
|
|
10
10
|
import { migrateCommand } from "./src/commands/migrate.js";
|
|
11
|
+
import { updateCommand } from "./src/commands/update.js";
|
|
11
12
|
import { initCommand } from "./src/commands/init.js";
|
|
12
13
|
|
|
13
14
|
/* -------------------------------------------------------
|
|
@@ -51,9 +52,11 @@ ${bold(cyan("╰─────────────────────
|
|
|
51
52
|
|
|
52
53
|
${bold("Commands:")}
|
|
53
54
|
${cyan("init")} ${gray("Scaffold a new Titan project")}
|
|
55
|
+
${cyan("create")} ${gray("Create a new project or extension (e.g. 'titan create ext my-ext')")}
|
|
54
56
|
${cyan("build")} ${gray("Compile actions and build production dist")}
|
|
55
57
|
${cyan("dev")} ${gray("Start the Gravity Engine in dev/watch mode")}
|
|
56
58
|
${cyan("start")} ${gray("Start the production Gravity Engine")}
|
|
59
|
+
${cyan("update")} ${gray("Update an existing project to latest Titan version")}
|
|
57
60
|
${cyan("migrate")} ${gray("Migrate a legacy project to the new architecture")}
|
|
58
61
|
|
|
59
62
|
${bold("Options:")}
|
|
@@ -105,6 +108,18 @@ const cmd = process.argv[2];
|
|
|
105
108
|
break;
|
|
106
109
|
}
|
|
107
110
|
|
|
111
|
+
case "create": {
|
|
112
|
+
const type = process.argv[3];
|
|
113
|
+
const name = process.argv[4];
|
|
114
|
+
if (type === "ext" || type === "extension") {
|
|
115
|
+
await initCommand(name, "extension");
|
|
116
|
+
} else {
|
|
117
|
+
// Fallback to init behavior
|
|
118
|
+
await initCommand(type, null);
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
|
|
108
123
|
case "build":
|
|
109
124
|
console.log(cyan("→ Building Titan project..."));
|
|
110
125
|
await buildCommand();
|
|
@@ -120,6 +135,10 @@ const cmd = process.argv[2];
|
|
|
120
135
|
startCommand();
|
|
121
136
|
break;
|
|
122
137
|
|
|
138
|
+
case "update":
|
|
139
|
+
await updateCommand();
|
|
140
|
+
break;
|
|
141
|
+
|
|
123
142
|
case "migrate":
|
|
124
143
|
await migrateCommand();
|
|
125
144
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@titanpl/cli",
|
|
3
|
-
"version": "26.16.
|
|
3
|
+
"version": "26.16.8",
|
|
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",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"titan": "./index.js"
|
|
20
20
|
},
|
|
21
21
|
"optionalDependencies": {
|
|
22
|
-
"@titanpl/engine-win32-x64": "26.16.
|
|
23
|
-
"@titanpl/engine-linux-x64": "26.16.
|
|
24
|
-
"@titanpl/engine-darwin-arm64": "26.16.
|
|
22
|
+
"@titanpl/engine-win32-x64": "26.16.8",
|
|
23
|
+
"@titanpl/engine-linux-x64": "26.16.8",
|
|
24
|
+
"@titanpl/engine-darwin-arm64": "26.16.8"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@titanpl/packet": "26.16.
|
|
27
|
+
"@titanpl/packet": "26.16.8",
|
|
28
28
|
"prompts": "^2.4.2",
|
|
29
29
|
"commander": "^11.0.0",
|
|
30
30
|
"chalk": "^4.1.2"
|
package/src/commands/init.js
CHANGED
|
@@ -117,17 +117,31 @@ export async function initCommand(projectName, templateName) {
|
|
|
117
117
|
// 2. Copy specific template
|
|
118
118
|
copyDir(templateDir, target, ["_gitignore", "_dockerignore"]);
|
|
119
119
|
|
|
120
|
-
// 3. Dotfiles
|
|
121
|
-
const
|
|
120
|
+
// 3. Dotfiles and Template Remapping
|
|
121
|
+
const remapping = {
|
|
122
122
|
"_gitignore": ".gitignore",
|
|
123
123
|
"_dockerignore": ".dockerignore",
|
|
124
|
+
"_titan.json": "titan.json",
|
|
124
125
|
".env": ".env"
|
|
125
126
|
};
|
|
126
|
-
for (const [srcName, destName] of Object.entries(
|
|
127
|
-
const src = path.join(
|
|
127
|
+
for (const [srcName, destName] of Object.entries(remapping)) {
|
|
128
|
+
const src = path.join(target, srcName);
|
|
128
129
|
const dest = path.join(target, destName);
|
|
129
130
|
if (fs.existsSync(src)) {
|
|
130
|
-
fs.
|
|
131
|
+
fs.renameSync(src, dest);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Replace {{name}} in package.json and titan.json
|
|
136
|
+
const filesToSub = ['package.json', 'titan.json', 'README.md', 'index.js', 'app/app.js', 'app/app.ts'];
|
|
137
|
+
for (const f of filesToSub) {
|
|
138
|
+
const p = path.join(target, f);
|
|
139
|
+
if (fs.existsSync(p)) {
|
|
140
|
+
let content = fs.readFileSync(p, 'utf8');
|
|
141
|
+
content = content.replace(/{{name}}/g, projName);
|
|
142
|
+
// Also replace native_name (underscore version)
|
|
143
|
+
content = content.replace(/{{native_name}}/g, projName.replace(/-/g, '_'));
|
|
144
|
+
fs.writeFileSync(p, content);
|
|
131
145
|
}
|
|
132
146
|
}
|
|
133
147
|
|
package/src/commands/migrate.js
CHANGED
|
@@ -70,6 +70,36 @@ export async function migrateCommand() {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
// 4. Synchronize Dockerfile and other common files
|
|
74
|
+
try {
|
|
75
|
+
const commonDir = path.resolve(__dirname, '..', '..', '..', '..', 'templates', 'common');
|
|
76
|
+
if (fs.existsSync(commonDir)) {
|
|
77
|
+
const filesToSync = [
|
|
78
|
+
['Dockerfile', 'Dockerfile'],
|
|
79
|
+
['_dockerignore', '.dockerignore'],
|
|
80
|
+
['_gitignore', '.gitignore'],
|
|
81
|
+
['app/t.native.d.ts', 'app/t.native.d.ts'],
|
|
82
|
+
['app/t.native.js', 'app/t.native.js']
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
for (const [srcRel, destRel] of filesToSync) {
|
|
86
|
+
const src = path.join(commonDir, srcRel);
|
|
87
|
+
const dest = path.join(root, destRel);
|
|
88
|
+
if (fs.existsSync(src)) {
|
|
89
|
+
// Create parent dir if needed
|
|
90
|
+
const parent = path.dirname(dest);
|
|
91
|
+
if (!fs.existsSync(parent)) {
|
|
92
|
+
fs.mkdirSync(parent, { recursive: true });
|
|
93
|
+
}
|
|
94
|
+
fs.copyFileSync(src, dest);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
console.log(` Synchronized Dockerfiles and native definitions.`);
|
|
98
|
+
}
|
|
99
|
+
} catch (e) {
|
|
100
|
+
console.log(` ⚠️ Failed to synchronize common template files.`);
|
|
101
|
+
}
|
|
102
|
+
|
|
73
103
|
console.log(`\n🎉 Migration complete!`);
|
|
74
104
|
console.log(` Please run 'npm install' to fetch the new dependencies.`);
|
|
75
105
|
console.log(` Then run 'titan dev' to start your application.\n`);
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
9
|
+
export async function updateCommand() {
|
|
10
|
+
const root = process.cwd();
|
|
11
|
+
console.log(chalk.cyan(`\n→ Updating Titan project to latest...`));
|
|
12
|
+
|
|
13
|
+
const pkgPath = path.join(root, 'package.json');
|
|
14
|
+
if (!fs.existsSync(pkgPath)) {
|
|
15
|
+
console.log(chalk.red(`✖ No package.json found. Are you in a project root ? `));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 1. Update package.json versions
|
|
20
|
+
try {
|
|
21
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
22
|
+
let modified = false;
|
|
23
|
+
|
|
24
|
+
const titanDeps = [
|
|
25
|
+
'titanpl',
|
|
26
|
+
'titanpl-sdk',
|
|
27
|
+
'@titanpl/cli',
|
|
28
|
+
'@titanpl/route',
|
|
29
|
+
'@titanpl/native',
|
|
30
|
+
'@titanpl/packet',
|
|
31
|
+
'@titanpl/core',
|
|
32
|
+
'@titanpl/node'
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
if (pkg.dependencies) {
|
|
36
|
+
for (const dep of titanDeps) {
|
|
37
|
+
if (pkg.dependencies[dep]) {
|
|
38
|
+
pkg.dependencies[dep] = "latest";
|
|
39
|
+
modified = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (pkg.devDependencies) {
|
|
45
|
+
for (const dep of titanDeps) {
|
|
46
|
+
if (pkg.devDependencies[dep]) {
|
|
47
|
+
pkg.devDependencies[dep] = "latest";
|
|
48
|
+
modified = true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (modified) {
|
|
54
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
55
|
+
console.log(chalk.green(` ✔ Updated Titan dependencies in package.json`));
|
|
56
|
+
}
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.log(chalk.yellow(` ⚠️ Failed to update package.json: ${e.message}`));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 2. Refresh Dockerfile and dotfiles from templates
|
|
62
|
+
const commonDir = path.resolve(__dirname, '..', '..', '..', '..', 'templates', 'common');
|
|
63
|
+
if (fs.existsSync(commonDir)) {
|
|
64
|
+
const filesToSync = [
|
|
65
|
+
['Dockerfile', 'Dockerfile'],
|
|
66
|
+
['_dockerignore', '.dockerignore'],
|
|
67
|
+
['_gitignore', '.gitignore'],
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
for (const [srcName, destName] of filesToSync) {
|
|
71
|
+
const src = path.join(commonDir, srcName);
|
|
72
|
+
const dest = path.join(root, destName);
|
|
73
|
+
if (fs.existsSync(src)) {
|
|
74
|
+
fs.copyFileSync(src, dest);
|
|
75
|
+
console.log(chalk.green(` ✔ Synchronized ${destName}`));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Also update app/t.native.d.ts if it exists
|
|
80
|
+
const nativeTypesSrc = path.join(commonDir, 'app', 't.native.d.ts');
|
|
81
|
+
const nativeTypesDest = path.join(root, 'app', 't.native.d.ts');
|
|
82
|
+
if (fs.existsSync(nativeTypesSrc) && fs.existsSync(path.join(root, 'app'))) {
|
|
83
|
+
fs.copyFileSync(nativeTypesSrc, nativeTypesDest);
|
|
84
|
+
console.log(chalk.green(` ✔ Updated app/t.native.d.ts`));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
console.log(chalk.green(`\n✔ Update complete!\n`));
|
|
89
|
+
console.log(chalk.yellow(` Please run 'npm install' to apply changes.\n`));
|
|
90
|
+
}
|