mirror of
https://github.com/codex-storage/cli.git
synced 2025-02-28 08:30:41 +00:00
Merge branch 'feature/codex-logfile' into feature/tool-config
This commit is contained in:
commit
01f469c9e2
@ -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
43
src/services/config.js
Normal 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
33
src/utils/appdata.js
Normal 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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user