From 046bc3af62c9b3db78c0f9f1d52388da8b066ee0 Mon Sep 17 00:00:00 2001 From: Clete AI Date: Mon, 12 May 2025 20:21:15 +0000 Subject: [PATCH] Clete AI[bot] PR: Fix typos and improve error handling This is a PR opened by AI tool [Clete AI](https://www.clete.ai) to implement changes: Fix typos and improve error handling --- index.js | 81 ++++++++++++++++++++++++++-------------------- model/questions.js | 2 +- package.json | 2 +- 3 files changed, 48 insertions(+), 37 deletions(-) diff --git a/index.js b/index.js index 532cddc..d1da302 100644 --- a/index.js +++ b/index.js @@ -10,24 +10,30 @@ const fs = require("fs"), let newPaystack = (old = String, recent = String, type, min)=>{ if(type == "paystack-js"){ fs.writeFile(`${recent}.js`, old, 'utf8', err => { - if (err) return console.log(err); - }); - - console.info("Done!!!") - console.info('Please check directory for "paystack.js"') - - if(min == "min"){ - minify(`${recent}.js`) - .then((data)=>{ - fs.writeFile(`${recent}.min.js`, data, 'utf8', err => { - if (err) return console.log(err); - else console.info(`"${recent}.min.js" also added as minified version`) + if (err) { + console.error("Error writing file:", err); + return; + } + console.info(`Please check directory for "${recent}.js"`); + + if(min == "min"){ + minify(`${recent}.js`) + .then((data)=>{ + fs.writeFile(`${recent}.min.js`, data, 'utf8', err => { + if (err) { + console.error("Error writing minified file:", err); + return; + } + console.info(`"${recent}.min.js" also added as minified version`); + }); + }) + .catch((err) => { + console.error("Error minifying file:", err); }); - }) - .catch(console.error); - } - else if(min == undefined) return - else console.log(`${min} is not a correct argument`) + } + else if(min == undefined) return; + else console.error(`Error: "${min}" is not a correct argument`); + }); }else if(type == "inline" || type == "embed"){ prompt(setupQuestion).then(answers => { console.info(answers) @@ -36,26 +42,31 @@ let newPaystack = (old = String, recent = String, type, min)=>{ let result = old.replace(/the-public-key/g, answers.public_key); - fs.writeFile(`${recent}.js`, result, 'utf8', err => { - if (err) return console.log(err); - }); - - console.info("Done!!!") - console.info(`Done. Please check directory for "${recent}.js"`) + if (err) { + console.error("Error writing file:", err); + return; + } + console.info(`Please check directory for "${recent}.js"`); - if(min == "min"){ - minify(`${recent}.js`) - .then((data)=>{ - fs.writeFile(`${recent}.min.js`, data, 'utf8', err => { - if (err) return console.log(err); - else console.info(`"${recent}.min.js" also added as minified version`) + if(min == "min"){ + minify(`${recent}.js`) + .then((data)=>{ + fs.writeFile(`${recent}.min.js`, data, 'utf8', err => { + if (err) { + console.error("Error writing minified file:", err); + return; + } + console.info(`"${recent}.min.js" also added as minified version`); + }); + }) + .catch((err) => { + console.error("Error minifying file:", err); }); - }) - .catch(console.error); - } - else if(min == undefined) return - else console.log(`${min} is not a correct argument`) + } + else if(min == undefined) return; + else console.error(`Error: "${min}" is not a correct argument`); + }); }else{ console.error("You can try again") @@ -67,7 +78,7 @@ let newPaystack = (old = String, recent = String, type, min)=>{ } program - .version('1.2.0') + .version('1.2.3') .description('A simple CLI tool that makes paystack easier for developers to intergrate'); program diff --git a/model/questions.js b/model/questions.js index 1d86405..decec17 100644 --- a/model/questions.js +++ b/model/questions.js @@ -3,7 +3,7 @@ module.exports = { { type : 'input', name : 'public_key', - message : 'Enter your Paystack Pubic Key:' + message : 'Enter your Paystack Public Key:' } ], confirm : [ diff --git a/package.json b/package.json index a9fe866..035ca33 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "preferGlobal": true, "bin": "./index.js", "version": "1.2.3", - "description": "A simple CLI tool that makes paystack easier for developers to intergrate", + "description": "A simple CLI tool that makes paystack easier for developers to integrate", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1"