This commit is contained in:
thatben 2025-02-21 10:07:52 +01:00
parent ef5982e86b
commit 2e3783e4d0
No known key found for this signature in database
GPG Key ID: 62C543548433D43E
4 changed files with 18 additions and 19 deletions

View File

@ -9,7 +9,7 @@ import { runCommand } from '../utils/command.js';
import { showErrorMessage, showInfoMessage, showSuccessMessage } from '../utils/messages.js';
import { checkDependencies } from '../services/nodeService.js';
import { saveConfig } from '../services/config.js';
import { getCodexRootPath, getCodexBinPath, getCodexDataDirDefaultPath, getCodexLogsPath } from '../utils/appdata.js';
import { getCodexRootPath, getCodexBinPath } from '../utils/appdata.js';
const platform = os.platform();
@ -68,7 +68,7 @@ export async function getCodexVersion(config) {
}
}
export async function checkCodexInstallation(config, showNavigationMenu) {
export async function installCodex(config, showNavigationMenu) {
const version = await getCodexVersion(config);
if (version.length > 0) {
@ -77,15 +77,12 @@ export async function checkCodexInstallation(config, showNavigationMenu) {
await showNavigationMenu();
} else {
console.log(chalk.cyanBright('Codex is not installed, proceeding with installation...'));
await installCodex(config, showNavigationMenu);
await performInstall(config, showNavigationMenu);
}
}
async function saveDefaultCodexConfig(config, codexExePath) {
async function saveCodexExePath(config, codexExePath) {
config.codexExe = codexExePath;
config.dataDir = getCodexDataDirDefaultPath();
config.logsDir = getCodexLogsPath();
config.storageQuota = 8 * 1024 * 1024 * 1024;
if (!fs.existsSync(config.codexExe)) {
console.log(showErrorMessage(`Codex executable not found in expected path: ${config.codexExe}`));
throw new Error("Exe not found");
@ -99,12 +96,10 @@ async function saveDefaultCodexConfig(config, codexExePath) {
async function clearCodexExePathFromConfig(config) {
config.codexExe = "";
config.dataDir = "";
config.logsDir = "";
saveConfig(config);
}
export async function installCodex(config, showNavigationMenu) {
async function performInstall(config, showNavigationMenu) {
const agreed = await showPrivacyDisclaimer();
if (!agreed) {
console.log(showInfoMessage('You can find manual setup instructions at docs.codex.storage'));
@ -129,7 +124,7 @@ export async function installCodex(config, showNavigationMenu) {
await runCommand('curl -LO --ssl-no-revoke https://get.codex.storage/install.cmd');
await runCommand(`set "INSTALL_DIR=${installPath}" && "${process.cwd()}\\install.cmd"`);
await saveDefaultCodexConfig(config, path.join(installPath, "codex.exe"));
await saveCodexExePath(config, path.join(installPath, "codex.exe"));
try {
await runCommand('del /f install.cmd');
@ -171,7 +166,7 @@ export async function installCodex(config, showNavigationMenu) {
await runCommand(`INSTALL_DIR="${installPath}" timeout 120 bash install.sh`);
}
await saveDefaultCodexConfig(config, path.join(installPath, "codex"));
await saveCodexExePath(config, path.join(installPath, "codex"));
} catch (error) {
if (error.message.includes('ECONNREFUSED') || error.message.includes('ETIMEDOUT')) {
@ -190,10 +185,13 @@ export async function installCodex(config, showNavigationMenu) {
try {
const version = await getCodexVersion(config);
console.log(chalk.green(version));
console.log(showSuccessMessage(
'Codex is successfully installed!\n' +
`Install path: "${config.codexExe}"\n\n` +
`Version: ${version}`
'The default configuration should work for most platforms.\n' +
'Please review the configuration before starting Codex.\n'
));
} catch (error) {
throw new Error('Installation completed but Codex command is not available. Please restart your terminal and try again.');

View File

@ -6,7 +6,7 @@ import boxen from 'boxen';
import { ASCII_ART } from './constants/ascii.js';
import { handleCommandLineOperation, parseCommandLineArgs } from './cli/commandParser.js';
import { uploadFile, downloadFile, showLocalFiles } from './handlers/fileHandlers.js';
import { checkCodexInstallation, installCodex, uninstallCodex } from './handlers/installationHandlers.js';
import { installCodex, uninstallCodex } from './handlers/installationHandlers.js';
import { runCodex, checkNodeStatus } from './handlers/nodeHandlers.js';
import { showInfoMessage } from './utils/messages.js';
import { loadConfig } from './services/config.js';
@ -99,7 +99,7 @@ export async function main() {
switch (choice.split('.')[0]) {
case '1':
await checkCodexInstallation(config, showNavigationMenu);
await installCodex(config, showNavigationMenu);
break;
case '2':
await showConfigMenu(config);

View File

@ -1,15 +1,16 @@
import fs from 'fs';
import path from 'path';
import { getAppDataDir } from '../utils/appdata.js';
import { getCodexDataDirDefaultPath, getCodexLogsDefaultPath } from '../utils/appdata.js';
const defaultConfig = {
codexExe: "",
// TODO:
// Save user-selected config options. Use these when starting Codex.
dataDir: "",
logsDir: "",
storageQuota: 0,
dataDir: getCodexDataDirDefaultPath(),
logsDir: getCodexLogsDefaultPath(),
storageQuota: 8 * 1024 * 1024 * 1024
// ports: {
// discPort: 8090,
// listenPort: 8070,

View File

@ -19,7 +19,7 @@ export function getCodexDataDirDefaultPath() {
return path.join(appData("codex"), "datadir");
}
export function getCodexLogsPath() {
export function getCodexLogsDefaultPath() {
return ensureExists(path.join(appData("codex"), "logs"));
}