From 49bcadfd4c155f0ae93cf9c813b88f0eee48ab09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gilson=20J=C3=BAnior?= Date: Fri, 11 Oct 2024 00:10:21 +0000 Subject: [PATCH] Add --config option to the export command --- app.js | 19 ++++++++++--------- package.json | 4 ++-- yarn.lock | 14 +++++++------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app.js b/app.js index 700b9ed..9fbd2b4 100755 --- a/app.js +++ b/app.js @@ -66,12 +66,6 @@ async function get(path, returnStream, headers) { } function main() { - fs.mkdirSync(appPath, { recursive: true }) - - if (!fs.existsSync(configPath)) { - fs.writeFileSync(configPath, '{}', 'utf-8') - } - program .name(app.name) .version(app.version) @@ -83,6 +77,7 @@ function main() { .option('-m, --month ', 'Month to be exported', String(new Date().getMonth())) .requiredOption('-o, --output ', 'Path to save exported file') .addOption(new Option('-t, --type ', 'Type of output').default('csv').choices(['csv', 'pdf'])) + .option('-c, --config ', 'Custom path for configuration file', configPath) .action(exportFile) const configCommand = program.command('config [value]') @@ -98,7 +93,7 @@ const exportFile = async (options) => { log(chalk.underline(`${app.name} v${app.version}`)) log('') - validateConfig() + validateConfig(options.config) const numberFormatter = new Intl.NumberFormat(config.locale) const dateFormatter = new Intl.DateTimeFormat(config.locale) @@ -191,8 +186,8 @@ const exportFile = async (options) => { } } -function validateConfig() { - const file = fs.readFileSync(configPath, 'utf-8') +function validateConfig(path) { + const file = fs.readFileSync(path, 'utf-8') const parsed = JSON.parse(file) const keys = ['api-token', 'profile', 'locale', 'pdf-locale', 'currency'] @@ -206,6 +201,12 @@ function validateConfig() { } function configAction(name, value) { + fs.mkdirSync(appPath, { recursive: true }) + + if (!fs.existsSync(configPath)) { + fs.writeFileSync(configPath, '{}', 'utf-8') + } + const file = fs.readFileSync(configPath, 'utf-8') const parsed = JSON.parse(file) diff --git a/package.json b/package.json index 7e57967..594d151 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wise-statements", - "version": "4.0.3", + "version": "4.1.0", "main": "app.js", "repository": "git@github.com:gilsonmandalogo/wise-statements.git", "author": "Gilson JĂșnior ", @@ -11,7 +11,7 @@ }, "dependencies": { "chalk": "^5.0.1", - "commander": "^9.4.1", + "commander": "^12.1.0", "node-fetch": "^3.2.3" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index dc0067c..3a5ed43 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3,9 +3,9 @@ "@types/node@^18.11.11": - version "18.19.50" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.50.tgz#8652b34ee7c0e7e2004b3f08192281808d41bf5a" - integrity sha512-xonK+NRrMBRtkL1hVCc3G+uXtjh1Al4opBLjqVmipe5ZAaBYWW6cNAiBVZ1BvmkBhep698rP3UM3aRAdSALuhg== + version "18.19.55" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.55.tgz#29c3f8e1485a92ec96636957ddec55aabc6e856e" + integrity sha512-zzw5Vw52205Zr/nmErSEkN5FLqXPuKX/k5d1D7RKHATGqU7y6YfX9QxZraUzUrFGqH6XzOzG196BC35ltJC4Cw== dependencies: undici-types "~5.26.4" @@ -14,10 +14,10 @@ chalk@^5.0.1: resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.3.0.tgz#67c20a7ebef70e7f3970a01f90fa210cb6860385" integrity sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w== -commander@^9.4.1: - version "9.5.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30" - integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ== +commander@^12.1.0: + version "12.1.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-12.1.0.tgz#01423b36f501259fdaac4d0e4d60c96c991585d3" + integrity sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA== data-uri-to-buffer@^4.0.0: version "4.0.0"