mirror of https://github.com/Lissy93/dashy.git
✨ Adds a parameter to specify which config file to edit
This commit is contained in:
parent
f5a8c30257
commit
5ab619f195
|
@ -16,11 +16,11 @@ module.exports = async (newConfig, render) => {
|
|||
};
|
||||
|
||||
// Make the full file name and path to save the backup config file
|
||||
const backupFilePath = `${settings.defaultLocation}${settings.filename}-`
|
||||
const backupFilePath = `${settings.defaultLocation}${newConfig.filename || settings.filename}-`
|
||||
+ `${Math.round(new Date() / 1000)}${settings.backupDenominator}`;
|
||||
|
||||
// The path where the main conf.yml should be read and saved to
|
||||
const defaultFilePath = settings.defaultLocation + settings.defaultFile;
|
||||
const defaultFilePath = settings.defaultLocation + (newConfig.filename || settings.defaultFile);
|
||||
|
||||
// Returns a string confirming successful job
|
||||
const getSuccessMessage = () => `Successfully backed up ${settings.defaultFile} to`
|
||||
|
@ -36,16 +36,14 @@ module.exports = async (newConfig, render) => {
|
|||
});
|
||||
|
||||
// Makes a backup of the existing config file
|
||||
await fsPromises.copyFile(defaultFilePath, backupFilePath)
|
||||
.catch((error) => {
|
||||
render(getRenderMessage(false, `Unable to backup conf.yml: ${error}`));
|
||||
});
|
||||
await fsPromises
|
||||
.copyFile(defaultFilePath, backupFilePath)
|
||||
.catch((error) => render(getRenderMessage(false, `Unable to backup conf.yml: ${error}`)));
|
||||
|
||||
// Writes the new content to the conf.yml file
|
||||
await fsPromises.writeFile(defaultFilePath, newConfig.config.toString(), writeFileOptions)
|
||||
.catch((error) => {
|
||||
render(getRenderMessage(false, `Unable to write changes to conf.yml: ${error}`));
|
||||
});
|
||||
await fsPromises
|
||||
.writeFile(defaultFilePath, newConfig.config.toString(), writeFileOptions)
|
||||
.catch((error) => render(getRenderMessage(false, `Unable to write to conf.yml: ${error}`)));
|
||||
|
||||
// If successful, then render hasn't yet been called- call it
|
||||
await render(getRenderMessage(true));
|
||||
|
|
Loading…
Reference in New Issue