Skip to content

Commit

Permalink
Add --config option to the export command
Browse files Browse the repository at this point in the history
  • Loading branch information
gilsonmandalogo committed Oct 11, 2024
1 parent 1179db7 commit 49bcadf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
19 changes: 10 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -83,6 +77,7 @@ function main() {
.option('-m, --month <number>', 'Month to be exported', String(new Date().getMonth()))
.requiredOption('-o, --output <path>', 'Path to save exported file')
.addOption(new Option('-t, --type <type>', 'Type of output').default('csv').choices(['csv', 'pdf']))
.option('-c, --config <path>', 'Custom path for configuration file', configPath)
.action(exportFile)

const configCommand = program.command('config <name> [value]')
Expand All @@ -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)
Expand Down Expand Up @@ -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']

Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wise-statements",
"version": "4.0.3",
"version": "4.1.0",
"main": "app.js",
"repository": "[email protected]:gilsonmandalogo/wise-statements.git",
"author": "Gilson Júnior <[email protected]>",
Expand All @@ -11,7 +11,7 @@
},
"dependencies": {
"chalk": "^5.0.1",
"commander": "^9.4.1",
"commander": "^12.1.0",
"node-fetch": "^3.2.3"
},
"devDependencies": {
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
Expand Down

0 comments on commit 49bcadf

Please sign in to comment.