From 2bf284150be4d7e5b2d6c87133cfdbea578b7201 Mon Sep 17 00:00:00 2001 From: Adan Toscano Date: Tue, 10 Oct 2023 21:15:25 +0100 Subject: [PATCH] feat: add to utils --- src/services/utils.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/services/utils.js b/src/services/utils.js index 083c233..986b138 100644 --- a/src/services/utils.js +++ b/src/services/utils.js @@ -1,4 +1,5 @@ import * as fs from "node:fs"; +import checkStringInFile from "./check-string-in-file.js"; /** * The name of the config file @@ -22,14 +23,15 @@ export const TEMP_FOLDER_NAME = ".api-mock-runner"; * @returns {Promise} */ export async function addToGitignore(textToAppend) { - // TODO: create function that validates if is already in gitignore - fs.appendFile(`${process.cwd()}/.gitignore`, `\n${textToAppend}`, (err) => { - if (err) { - console.error(err); - } else { - console.log(`${textToAppend} added to .gitignore`); - } - }); + if (!checkStringInFile(textToAppend, `${process.cwd()}/.gitignore`)) { + fs.appendFile(`${process.cwd()}/.gitignore`, `\n${textToAppend}`, (err) => { + if (err) { + console.error(err); + } else { + console.log(`${textToAppend} added to .gitignore`); + } + }); + } } /** * Verify if the origin is remote