mirror of
https://github.com/logos-storage/logos-storage-installer.git
synced 2026-01-10 09:23:10 +00:00
Adds config module
This commit is contained in:
parent
9a1ce2bf52
commit
2a8888669a
@ -9,7 +9,6 @@ import { uploadFile, downloadFile, showLocalFiles } from './handlers/fileHandler
|
||||
import { checkCodexInstallation, installCodex, uninstallCodex } from './handlers/installationHandlers.js';
|
||||
import { runCodex, checkNodeStatus } from './handlers/nodeHandlers.js';
|
||||
import { showInfoMessage } from './utils/messages.js';
|
||||
import { getAppDataDir } from "./utils/appdata.js";
|
||||
|
||||
async function showNavigationMenu() {
|
||||
console.log('\n')
|
||||
@ -74,8 +73,6 @@ export async function main() {
|
||||
try {
|
||||
while (true) {
|
||||
console.log('\n' + chalk.cyanBright(ASCII_ART));
|
||||
console.log(showInfoMessage(`Working directory: ${getAppDataDir()}`));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,12 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
export function getAppDataDir() {
|
||||
return appData("codex-cli");
|
||||
const dir = appData("codex-cli");
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
function appData(...app) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user