- Changed the regex expression to not require a value after the key
This commit is contained in:
@@ -28,7 +28,7 @@ async function firstTimeBoot() {
|
||||
console.log(`Generated a new unique ID for this node: '${localNodeConfig.node.nuid}'`);
|
||||
|
||||
// Update the config with the new ID
|
||||
updateId(localNodeConfig.node.nuid);
|
||||
await updateId(localNodeConfig.node.nuid);
|
||||
console.log("Updated the config with the new node ID");
|
||||
// TODO - Create the config file with the ID given and replace the update above
|
||||
// TODO - Implement web server so users can update radio systems easily
|
||||
|
||||
@@ -3,9 +3,9 @@ import replace from 'replace-in-file';
|
||||
|
||||
class Options {
|
||||
constructor(key, updatedValue) {
|
||||
this.files = "./.env";
|
||||
this.files = ".env";
|
||||
// A regex of the line containing the key in the config file
|
||||
this.from = new RegExp(`${key}="?(.+)"?`, "g");
|
||||
this.from = new RegExp(`${key}="?(.+)?"?`, "g");
|
||||
// Check to see if the value is a string and needs to be wrapped in double quotes
|
||||
if (Array(["string", "number"]).includes(typeof updatedValue)) this.to = `${key}="${updatedValue}",`;
|
||||
else this.to = `${key}=${updatedValue}`;
|
||||
@@ -16,10 +16,10 @@ class Options {
|
||||
* Wrapper to update the client's saved ID
|
||||
* @param updatedId The updated ID assigned to the node
|
||||
*/
|
||||
export function updateId (updatedId) {
|
||||
updateConfig('CLIENT_NUID', updatedId);
|
||||
export const updateId = async (updatedId) => {
|
||||
await updateConfig('CLIENT_NUID', updatedId);
|
||||
process.env.CLIENT_NUID = updatedId;
|
||||
console.log("Updated ID to: ", updatedId);
|
||||
console.log("Updated NUID to: ", updatedId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,7 +27,7 @@ export function updateId (updatedId) {
|
||||
*
|
||||
* @param {Object} runningConfig Running config object
|
||||
* @param {Object} newConfigObject Object with what keys you wish to update (node object format, will be converted)
|
||||
* @param {number} newConfigObject.id The ID given to the node to update
|
||||
* @param {number} newConfigObject.nuid The ID given to the node to update
|
||||
* @param {string} newConfigObject.name The name of the node
|
||||
* @param {string} newConfigObject.ip The IP the server can contact the node on
|
||||
* @param {number} newConfigObject.port The port the server can contact the node on
|
||||
@@ -38,10 +38,10 @@ export function updateClientConfig (runningConfig, newConfigObject) {
|
||||
var updatedKeys = []
|
||||
const configKeys = Object.keys(newConfigObject);
|
||||
|
||||
if (configKeys.includes("id")) {
|
||||
if (runningConfig.id != newConfigObject.id) {
|
||||
this.updateId(newConfigObject.id);
|
||||
updatedKeys.push({ 'CLIENT_NUID': newConfigObject.id });
|
||||
if (configKeys.includes("nuid")) {
|
||||
if (runningConfig.nuid != newConfigObject.nuid) {
|
||||
this.updateId(newConfigObject.nuid);
|
||||
updatedKeys.push({ 'CLIENT_NUID': newConfigObject.nuid });
|
||||
}
|
||||
}
|
||||
if (configKeys.includes("name")) {
|
||||
@@ -88,6 +88,8 @@ export function updateClientConfig (runningConfig, newConfigObject) {
|
||||
export function updateConfig (key, value) {
|
||||
const options = new Options(key, value);
|
||||
|
||||
console.log("Options:", options);
|
||||
|
||||
updateConfigFile(options, (updatedFiles) => {
|
||||
// Do Something
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user