#2 implement debugger

This commit is contained in:
Logan Cusano
2024-06-02 20:10:55 -04:00
parent e54c80a95b
commit f706ac89b4
15 changed files with 190 additions and 94 deletions

View File

@@ -1,4 +1,6 @@
// Modules
import { DebugBuilder } from "./debugger.mjs";
const log = new DebugBuilder("client", "updateConfig");
import replace from 'replace-in-file';
class Options {
@@ -19,7 +21,7 @@ class Options {
export const updateId = async (updatedId) => {
await updateConfig('CLIENT_NUID', updatedId);
process.env.CLIENT_NUID = updatedId;
console.log("Updated NUID to: ", updatedId);
log.INFO("Updated NUID to: ", updatedId);
}
/**
@@ -49,7 +51,7 @@ export function updateClientConfig (runningConfig, newConfigObject) {
this.updateConfig('CLIENT_NAME', newConfigObject.name);
updatedKeys.push({ 'CLIENT_NAME': newConfigObject.name });
process.env.CLIENT_NAME = newConfigObject.name;
console.log("Updated name to: ", newConfigObject.name);
log.INFO("Updated name to: ", newConfigObject.name);
}
}
if (configKeys.includes("ip")) {
@@ -57,7 +59,7 @@ export function updateClientConfig (runningConfig, newConfigObject) {
this.updateConfig('CLIENT_IP', newConfigObject.ip);
updatedKeys.push({ 'CLIENT_IP': newConfigObject.ip });
process.env.CLIENT_IP = newConfigObject.ip;
console.log("Updated ip to: ", newConfigObject.ip);
log.INFO("Updated ip to: ", newConfigObject.ip);
}
}
if (configKeys.includes("port")) {
@@ -65,7 +67,7 @@ export function updateClientConfig (runningConfig, newConfigObject) {
this.updateConfig('CLIENT_PORT', newConfigObject.port);
updatedKeys.push({ 'CLIENT_PORT': newConfigObject.port });
process.env.CLIENT_PORT = newConfigObject.port;
console.log("Updated port to: ", newConfigObject.port);
log.INFO("Updated port to: ", newConfigObject.port);
}
}
if (configKeys.includes("location")) {
@@ -73,7 +75,7 @@ export function updateClientConfig (runningConfig, newConfigObject) {
this.updateConfig('CLIENT_LOCATION', newConfigObject.location);
updatedKeys.push({ 'CLIENT_LOCATION': newConfigObject.location });
process.env.CLIENT_LOCATION = newConfigObject.location;
console.log("Updated location to: ", newConfigObject.location);
log.INFO("Updated location to: ", newConfigObject.location);
}
}
@@ -88,7 +90,7 @@ export function updateClientConfig (runningConfig, newConfigObject) {
export function updateConfig (key, value) {
const options = new Options(key, value);
console.log("Options:", options);
log.INFO("Options:", options);
updateConfigFile(options, (updatedFiles) => {
// Do Something
@@ -102,8 +104,8 @@ export function updateConfig (key, value) {
*/
function updateConfigFile(options, callback) {
replace(options, (error, changedFiles) => {
if (error) return console.error('Error occurred:', error);
console.log('Updated config file: ', changedFiles);
if (error) return log.ERROR('Error occurred:', error);
log.INFO('Updated config file: ', changedFiles);
callback(changedFiles);
});
}