// Debug const debug = require('debug')('client:updateConfig'); // Modules const replace = require('replace-in-file'); class Options { constructor(key, updatedValue) { this.files = "./config/clientConfig.js"; // A regex of the line containing the key in the config file this.from = new RegExp(`"${key}": (.+),`, "g"); // Check to see if the value is a string and needs to be wrapped in double quotes if (typeof updatedValue === "string") this.to = `"${key}": "${updatedValue}",`; else this.to = `"${key}": ${updatedValue},`; } } /** * Wrapper to update the client's saved ID * @param updatedId The updated ID assigned to the bot */ exports.updateId = (updatedId) => { const options = new Options("id", updatedId); updateConfigFile(options, (updatedFiles) => { // Do Something }) } /** * Wrapper to write changes to the file * @param options An instance of the Objects class specified to the key being updated * @param callback Callback when the files have been modified */ function updateConfigFile(options, callback){ replace(options, (error, changedFiles) => { if (error) return console.error('Error occurred:', error); debug('Modified files:', changedFiles); callback(changedFiles); }); }