mirror of
https://github.com/codex-storage/cli.git
synced 2025-02-28 16:40:43 +00:00
Merge pull request #9 from codex-storage/fix-pathhandling
fixing the abrupt stop by handling path variables
This commit is contained in:
commit
7aec3668f2
@ -100,6 +100,46 @@ async function clearCodexExePathFromConfig(config) {
|
|||||||
saveConfig(config);
|
saveConfig(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function configureShellPath(installPath) {
|
||||||
|
try {
|
||||||
|
const homedir = os.homedir();
|
||||||
|
let shellConfigFile;
|
||||||
|
let exportLine = `export PATH="${installPath}:$PATH"`;
|
||||||
|
|
||||||
|
if (platform === 'win32') {
|
||||||
|
// For Windows, update the User PATH environment variable
|
||||||
|
const currentPath = process.env.PATH || '';
|
||||||
|
if (!currentPath.includes(installPath)) {
|
||||||
|
await runCommand(`setx PATH "${installPath};%PATH%"`);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// For Unix-like systems (macOS and Linux)
|
||||||
|
if (platform === 'darwin') {
|
||||||
|
// Check for zsh first (default on modern macOS)
|
||||||
|
if (fs.existsSync(path.join(homedir, '.zshrc'))) {
|
||||||
|
shellConfigFile = path.join(homedir, '.zshrc');
|
||||||
|
} else {
|
||||||
|
shellConfigFile = path.join(homedir, '.bash_profile');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Linux
|
||||||
|
shellConfigFile = path.join(homedir, '.bashrc');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if PATH is already configured
|
||||||
|
const fileContent = fs.existsSync(shellConfigFile) ? fs.readFileSync(shellConfigFile, 'utf8') : '';
|
||||||
|
if (!fileContent.includes(installPath)) {
|
||||||
|
fs.appendFileSync(shellConfigFile, `\n${exportLine}\n`);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(showErrorMessage(`Failed to configure PATH: ${error.message}`));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function performInstall(config) {
|
async function performInstall(config) {
|
||||||
const agreed = await showPrivacyDisclaimer();
|
const agreed = await showPrivacyDisclaimer();
|
||||||
if (!agreed) {
|
if (!agreed) {
|
||||||
@ -187,12 +227,23 @@ async function performInstall(config) {
|
|||||||
const version = await getCodexVersion(config);
|
const version = await getCodexVersion(config);
|
||||||
console.log(chalk.green(version));
|
console.log(chalk.green(version));
|
||||||
|
|
||||||
console.log(showSuccessMessage(
|
// Configure shell PATH
|
||||||
'Codex is successfully installed!\n' +
|
const pathConfigured = await configureShellPath(installPath);
|
||||||
`Install path: "${config.codexExe}"\n\n` +
|
if (pathConfigured) {
|
||||||
'The default configuration should work for most platforms.\n' +
|
console.log(showSuccessMessage(
|
||||||
'Please review the configuration before starting Codex.\n'
|
'Codex is successfully installed!\n' +
|
||||||
));
|
`Install path: "${config.codexExe}"\n\n` +
|
||||||
|
'PATH has been configured automatically.\n' +
|
||||||
|
'Please restart your terminal for the changes to take effect.\n\n' +
|
||||||
|
'The default configuration should work for most platforms.\n' +
|
||||||
|
'Please review the configuration before starting Codex.\n'
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
console.log(showInfoMessage(
|
||||||
|
'Codex is installed but PATH configuration failed.\n' +
|
||||||
|
`Please manually add "${installPath}" to your PATH.\n`
|
||||||
|
));
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error('Installation completed but Codex command is not available. Please restart your terminal and try again.');
|
throw new Error('Installation completed but Codex command is not available. Please restart your terminal and try again.');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user