Skip to content

Commit

Permalink
feat(core): add function to overwrite a file
Browse files Browse the repository at this point in the history
  • Loading branch information
MHCYR committed Oct 9, 2023
1 parent 65bbe76 commit 4fffffd
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async function initWithConfigFile() {
config = existingConfig;
} else {
config = await getInitialValues();
overwriteFile(`${process.cwd()}/${RC_FILE_NAME}`, JSON.stringify(config));
}
return config;
}
Expand Down Expand Up @@ -194,3 +195,21 @@ function verifyRemoteOrigin(origin) {
const isOriginRemote = isOriginRemoteRegex.test(origin);
return isOriginRemote;
}

/**
* Overwrites the document on a file
* @async
* @function overwriteFile
* @param {string} filePath - The path of the file to overwrite
* @param {string} content - The content to overwrite
* @returns {Promise<void>}
*/
async function overwriteFile(filePath, content) {
fs.writeFile(filePath, content, (err) => {
if (err) {
console.error(err);
} else {
console.log("Config saved");
}
});
}

0 comments on commit 4fffffd

Please # to comment.