From 7907aa00af3684992ff81479c45057a49e653b41 Mon Sep 17 00:00:00 2001 From: Celso Dias Date: Tue, 19 Apr 2022 22:15:42 -0300 Subject: [PATCH] feat: add wrapper function --- src/index.js | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/index.js b/src/index.js index 675305a..9493d9a 100644 --- a/src/index.js +++ b/src/index.js @@ -11,31 +11,35 @@ const envPath = path.join(process.cwd(), fileName) const bufferEncoding = 'utf8' -if (fs.existsSync(envPath)) { - fs.readFile(envPath, bufferEncoding, (errorRead, fileData) => { - if (errorRead) { - console.log(errorRead) +function run() { + if (fs.existsSync(envPath)) { + fs.readFile(envPath, bufferEncoding, (errorRead, fileData) => { + if (errorRead) { + console.log({ errorRead }) - return - } + return + } - const result = fileData.replace(regex, '') + const result = fileData.replace(regex, '') - fs.writeFile( - path.join(process.cwd(), '.env.example'), - result, - bufferEncoding, - errorWrite => { - if (errorWrite) { - console.log(errorWrite) + fs.writeFile( + path.join(process.cwd(), '.env.example'), + result, + bufferEncoding, + errorWrite => { + if (errorWrite) { + console.log({ errorWrite }) - return - } + return + } - console.log('\nSuccessfully created .env.example') - } - ) - }) -} else { - console.log(`\nNo ${fileName} file found`) + console.log('\nSuccessfully created .env.example') + } + ) + }) + } else { + console.log(`\nNo ${fileName} file found`) + } } + +run()