ante-erp-cli 1.8.5 ā 1.9.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/bin/ante-cli.js +6 -0
- package/package.json +1 -1
- package/src/commands/regenerate-compose.js +141 -0
package/bin/ante-cli.js
CHANGED
|
@@ -34,6 +34,7 @@ import { migrate, seed, shell, optimize, reset as dbReset, info } from '../src/c
|
|
|
34
34
|
import { cloneDb } from '../src/commands/clone-db.js';
|
|
35
35
|
import { setDomain } from '../src/commands/set-domain.js';
|
|
36
36
|
import { sslEnable, sslStatus } from '../src/commands/ssl-enable.js';
|
|
37
|
+
import { regenerateCompose } from '../src/commands/regenerate-compose.js';
|
|
37
38
|
|
|
38
39
|
// Installation & Setup
|
|
39
40
|
program
|
|
@@ -218,6 +219,11 @@ program
|
|
|
218
219
|
.option('--no-interactive', 'Non-interactive mode')
|
|
219
220
|
.action(setDomain);
|
|
220
221
|
|
|
222
|
+
program
|
|
223
|
+
.command('regenerate-compose')
|
|
224
|
+
.description('Regenerate docker-compose.yml with correct configuration')
|
|
225
|
+
.action(regenerateCompose);
|
|
226
|
+
|
|
221
227
|
// SSL/HTTPS Management
|
|
222
228
|
const sslCmd = program
|
|
223
229
|
.command('ssl')
|
package/package.json
CHANGED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { readFileSync, writeFileSync, renameSync, existsSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { getInstallDir } from '../utils/config.js';
|
|
5
|
+
import { generateDockerCompose } from '../templates/docker-compose.yml.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Parse .env file to extract configuration
|
|
9
|
+
* @param {string} envPath - Path to .env file
|
|
10
|
+
* @returns {Object} Configuration object
|
|
11
|
+
*/
|
|
12
|
+
function parseEnvFile(envPath) {
|
|
13
|
+
const envContent = readFileSync(envPath, 'utf8');
|
|
14
|
+
const config = {};
|
|
15
|
+
|
|
16
|
+
envContent.split('\n').forEach(line => {
|
|
17
|
+
const match = line.match(/^([A-Z_]+)=(.*)$/);
|
|
18
|
+
if (match) {
|
|
19
|
+
config[match[1]] = match[2];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return config;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Detect which apps are installed from existing docker-compose.yml
|
|
28
|
+
* @param {string} composeFile - Path to docker-compose.yml
|
|
29
|
+
* @returns {Object} Installed apps
|
|
30
|
+
*/
|
|
31
|
+
function detectInstalledApps(composeFile) {
|
|
32
|
+
try {
|
|
33
|
+
const composeContent = readFileSync(composeFile, 'utf8');
|
|
34
|
+
return {
|
|
35
|
+
hasMain: composeContent.includes('frontend:') || composeContent.includes('container_name: ante-frontend'),
|
|
36
|
+
hasGateApp: composeContent.includes('gate-app:') || composeContent.includes('container_name: ante-gate-app'),
|
|
37
|
+
hasGuardianApp: composeContent.includes('guardian-app:') || composeContent.includes('container_name: ante-guardian-app')
|
|
38
|
+
};
|
|
39
|
+
} catch {
|
|
40
|
+
return { hasMain: true, hasGateApp: false, hasGuardianApp: false };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Regenerate docker-compose.yml with correct configuration
|
|
46
|
+
*/
|
|
47
|
+
export async function regenerateCompose() {
|
|
48
|
+
try {
|
|
49
|
+
console.log(chalk.bold('\nš§ Regenerate docker-compose.yml\n'));
|
|
50
|
+
|
|
51
|
+
const installDir = getInstallDir();
|
|
52
|
+
const composeFile = join(installDir, 'docker-compose.yml');
|
|
53
|
+
const envFile = join(installDir, '.env');
|
|
54
|
+
|
|
55
|
+
console.log(chalk.gray(`Installation: ${installDir}\n`));
|
|
56
|
+
|
|
57
|
+
// Check if files exist
|
|
58
|
+
if (!existsSync(composeFile)) {
|
|
59
|
+
console.log(chalk.red('ā docker-compose.yml not found'));
|
|
60
|
+
console.log(chalk.gray(' Run "ante install" first\n'));
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!existsSync(envFile)) {
|
|
65
|
+
console.log(chalk.red('ā .env file not found'));
|
|
66
|
+
console.log(chalk.gray(' Run "ante install" first\n'));
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Detect installed apps
|
|
71
|
+
const installed = detectInstalledApps(composeFile);
|
|
72
|
+
console.log(chalk.cyan('Detected Configuration:'));
|
|
73
|
+
console.log(chalk.gray(` Frontend Main: ${installed.hasMain ? 'ā Installed' : 'ā Not installed'}`));
|
|
74
|
+
console.log(chalk.gray(` Gate App: ${installed.hasGateApp ? 'ā Installed' : 'ā Not installed'}`));
|
|
75
|
+
console.log(chalk.gray(` Guardian App: ${installed.hasGuardianApp ? 'ā Installed' : 'ā Not installed'}\n`));
|
|
76
|
+
|
|
77
|
+
// Parse .env file
|
|
78
|
+
const envConfig = parseEnvFile(envFile);
|
|
79
|
+
|
|
80
|
+
// Extract port configuration
|
|
81
|
+
const frontendPort = parseInt(envConfig.FRONTEND_PORT) || 8080;
|
|
82
|
+
const backendPort = parseInt(envConfig.BACKEND_PORT) || 3001;
|
|
83
|
+
const gateAppPort = parseInt(envConfig.GATE_APP_PORT) || 8081;
|
|
84
|
+
const guardianAppPort = parseInt(envConfig.GUARDIAN_APP_PORT) || 8082;
|
|
85
|
+
const companyId = parseInt(envConfig.COMPANY_ID) || 1;
|
|
86
|
+
|
|
87
|
+
console.log(chalk.cyan('Port Configuration:'));
|
|
88
|
+
console.log(chalk.gray(` Frontend: ${frontendPort}`));
|
|
89
|
+
console.log(chalk.gray(` Backend: ${backendPort}`));
|
|
90
|
+
if (installed.hasGateApp) {
|
|
91
|
+
console.log(chalk.gray(` Gate App: ${gateAppPort}`));
|
|
92
|
+
}
|
|
93
|
+
if (installed.hasGuardianApp) {
|
|
94
|
+
console.log(chalk.gray(` Guardian: ${guardianAppPort}`));
|
|
95
|
+
}
|
|
96
|
+
console.log(chalk.gray(` Company ID: ${companyId}\n`));
|
|
97
|
+
|
|
98
|
+
// Backup existing docker-compose.yml
|
|
99
|
+
const timestamp = new Date().toISOString().split('.')[0].replace(/:/g, '-').replace('T', '_');
|
|
100
|
+
const backupFile = `${composeFile}.${timestamp}.bak`;
|
|
101
|
+
|
|
102
|
+
console.log(chalk.gray('š¦ Creating backup...'));
|
|
103
|
+
renameSync(composeFile, backupFile);
|
|
104
|
+
console.log(chalk.green(`ā Backup created: ${backupFile}\n`));
|
|
105
|
+
|
|
106
|
+
// Generate new docker-compose.yml
|
|
107
|
+
console.log(chalk.gray('āļø Generating new docker-compose.yml...'));
|
|
108
|
+
const newCompose = generateDockerCompose({
|
|
109
|
+
frontendPort,
|
|
110
|
+
backendPort,
|
|
111
|
+
gateAppPort,
|
|
112
|
+
guardianAppPort,
|
|
113
|
+
installMain: installed.hasMain,
|
|
114
|
+
installGate: installed.hasGateApp,
|
|
115
|
+
installGuardian: installed.hasGuardianApp,
|
|
116
|
+
companyId
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Write new docker-compose.yml
|
|
120
|
+
writeFileSync(composeFile, newCompose);
|
|
121
|
+
console.log(chalk.green('ā New docker-compose.yml generated\n'));
|
|
122
|
+
|
|
123
|
+
// Show what changed
|
|
124
|
+
console.log(chalk.bold.green('ā Configuration regenerated successfully!\n'));
|
|
125
|
+
console.log(chalk.cyan('Next Steps:'));
|
|
126
|
+
console.log(chalk.gray(' 1. Review the changes: diff docker-compose.yml ' + backupFile.replace(installDir + '/', '')));
|
|
127
|
+
console.log(chalk.gray(' 2. Restart services: ante restart'));
|
|
128
|
+
console.log(chalk.gray(' 3. Check status: ante status\n'));
|
|
129
|
+
|
|
130
|
+
// Show important fixes
|
|
131
|
+
if (installed.hasGuardianApp) {
|
|
132
|
+
console.log(chalk.yellow('ā Important: Guardian App port mapping updated'));
|
|
133
|
+
console.log(chalk.gray(` Old: ${guardianAppPort}:3000 (incorrect)`));
|
|
134
|
+
console.log(chalk.gray(` New: ${guardianAppPort}:9003 (correct)\n`));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error(chalk.red('\nā Failed to regenerate docker-compose.yml:'), error.message);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
}
|