From 4fffffd3d028a5dc5d51e04e45a5f650c9dee076 Mon Sep 17 00:00:00 2001 From: Mohacyr Rojas Date: Mon, 9 Oct 2023 12:37:17 -0600 Subject: [PATCH] feat(core): add function to overwrite a file --- src/index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/index.js b/src/index.js index 5e167ec..e12b4b1 100644 --- a/src/index.js +++ b/src/index.js @@ -59,6 +59,7 @@ async function initWithConfigFile() { config = existingConfig; } else { config = await getInitialValues(); + overwriteFile(`${process.cwd()}/${RC_FILE_NAME}`, JSON.stringify(config)); } return config; } @@ -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} + */ +async function overwriteFile(filePath, content) { + fs.writeFile(filePath, content, (err) => { + if (err) { + console.error(err); + } else { + console.log("Config saved"); + } + }); +}