Skip to content

Commit

Permalink
[ts] add xlsx formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
grasword committed Oct 13, 2023
1 parent 322de0b commit a5ca67b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 76 deletions.
100 changes: 27 additions & 73 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@
"dependencies": {
"@2bad/mimir-translator": "0.0.0",
"@2bad/mimir-validator": "0.0.0",
"@oclif/core": "3.0.0-beta.25",
"@oclif/plugin-help": "5.2.20",
"@oclif/plugin-plugins": "3.8.4",
"@e965/xlsx": "0.20.0",
"@oclif/core": "3.2.1",
"@oclif/plugin-help": "6.0.2",
"@oclif/plugin-plugins": "3.9.1",
"chalk": "5.3.0",
"easy-table": "1.2.0"
},
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/source/commands/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export default class Validate extends Command {
rules: Flags.string({ char: 'r', summary: 'This option specifies the rules to be used.' }),
keys: Flags.string({ char: 'k', summary: 'This option specifies the keys to be scanned.' }),
ignoreKeys: Flags.string({ char: 'i', summary: 'This option specifies the keys to be ignored.' }),
outputFile: Flags.string({
char: 'o',
summary: 'This option specifies the name of the file where report should be saved'
}),
format: Flags.string({
char: 'f',
summary: 'This option specifies the output format for the console.',
Expand Down Expand Up @@ -58,6 +62,10 @@ export default class Validate extends Command {
case 'json':
this.log(format.json(report))
break
case 'xlsx':
format.xlsx(report, flags.outputFile)
this.log()
break
case 'compact':
this.log(format.compact(report, flags.path))
break
Expand Down
1 change: 1 addition & 0 deletions packages/cli/source/formatters/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
export { compact } from '~/formatters/compact.js'
export { json } from '~/formatters/json.js'
export { stylish } from '~/formatters/stylish.js'
export { xlsx } from '~/formatters/xlsx.js'
18 changes: 18 additions & 0 deletions packages/cli/source/formatters/xlsx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { type Problem } from '@2bad/mimir-validator'
import { utils, writeFile } from '@e965/xlsx'
import { resolve } from 'node:path'

/**
*
* @param data
* @param report
* @param filePath
*/
export const xlsx = (report: Problem[], filePath = './report.xlsx'): void => {
const worksheet = utils.json_to_sheet(report)

const workbook = utils.book_new()
utils.book_append_sheet(workbook, worksheet, 'Translations')

writeFile(workbook, resolve(filePath))
}

0 comments on commit a5ca67b

Please sign in to comment.