Merge branch 'feature/codex-logfile' into feature/tool-config

This commit is contained in:
Ben 2025-02-17 11:16:02 +01:00
commit 01f469c9e2
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
3 changed files with 80 additions and 1 deletions

View File

@ -49,6 +49,10 @@ function handleExit() {
process.exit(0);
}
function getWorkingDir(commandArgs) {
}
export async function main() {
const commandArgs = parseCommandLineArgs();
if (commandArgs) {
@ -69,7 +73,6 @@ export async function main() {
try {
while (true) {
console.log('\n' + chalk.cyanBright(ASCII_ART));
const { choice } = await inquirer.prompt([
{
type: 'list',

43
src/services/config.js Normal file
View File

@ -0,0 +1,43 @@
import fs from 'fs';
import path from 'path';
import { getAppDataDir } from '../utils/appdata.js';
const defaultConfig = {
dataDir: "",
storageQuota: 0,
ports: {
discPort: 8090,
listenPort: 8070,
apiPort: 8080
}
};
function getConfigFilename() {
return path.join(getAppDataDir(), "config.json");
}
export function saveConfig(config) {
const filePath = getConfigFilename();
console.log("writing to: " + filePath );
try {
fs.writeFileSync(filePath, JSON.stringify(config));
} catch (error) {
console.error(`Failed to save config file to '${filePath}' error: '${error}'.`);
throw error;
}
}
export function loadConfig() {
const filePath = getConfigFilename();
console.log("loading from: " + filePath );
try {
if (!fs.existsSync(filePath)) {
saveConfig(defaultConfig);
return defaultConfig;
}
return JSON.parse(fs.readFileSync(filePath));
} catch (error) {
console.error(`Failed to load config file from '${filePath}' error: '${error}'.`);
throw error;
}
}

33
src/utils/appdata.js Normal file
View File

@ -0,0 +1,33 @@
import path from 'path';
import fs from 'fs';
export function getAppDataDir() {
const dir = appData("codex-cli");
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
return dir;
}
function appData(...app) {
let appData;
if (process.platform === 'win32') {
appData = path.join(process.env.APPDATA, ...app);
} else if (process.platform === 'darwin') {
appData = path.join(process.env.HOME, 'Library', 'Application Support', ...app);
} else {
appData = path.join(process.env.HOME, ...prependDot(...app));
}
return appData;
}
function prependDot(...app) {
return app.map((item, i) => {
if (i === 0) {
return `.${item}`;
} else {
return item;
}
});
}