Skip to content

Commit

Permalink
fix: update yargs
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Drop support for node versions < 12
  • Loading branch information
jwbay committed Apr 10, 2022
1 parent 7a5570e commit c93e4c2
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 219 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@types/glob": "^5.0.30",
"@types/jest": "^27.4.1",
"@types/node": "^7.0.13",
"@types/yargs": "^6.6.0",
"@types/yargs": "^17.0.10",
"jest": "^27.0.0",
"rimraf": "^2.5.4",
"semantic-release": "18.0.0",
Expand All @@ -56,6 +56,6 @@
"dependencies": {
"glob": "^7.0.5",
"json-stable-stringify": "^1.0.1",
"yargs": "^5.0.0"
"yargs": "^17.0.0"
}
}
107 changes: 55 additions & 52 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,61 @@
import * as yargs from 'yargs';
import sync from './';

const {
check,
files,
primary,
languages,
space,
lineendings,
finalnewline,
newkeysempty
} = yargs
.describe('c', 'Audit files in memory instead of changing them on the filesystem and throw an error if any changes would be made')
.alias('c', 'check')
.boolean('c')

.describe('f', 'Glob pattern for the resource JSON files')
.example('--files', `'**/locales/*.json'`)
.alias('f', 'files')

.describe('p', 'Primary localization language. Other language files will be changed to match')
.alias('p', 'primary')

.describe('l', `Language files to create if they don't exist`)
.example('--languages', 'es fr pt-BR ja')
.alias('l', 'languages')
.array('l')

.describe('s', 'Space value used for JSON.stringify when writing JSON files to disk')
.alias('s', 'space')

.describe('le', 'Line endings used when writing JSON files to disk -- either LF or CRLF')
.alias('le', 'lineendings')

.describe('fn', 'Insert a final newline when writing JSON files to disk')
.alias('fn', 'finalnewline')
.boolean('fn')

.describe('e', 'Use empty string for new keys instead of the primary language value')
.alias('e', 'newkeysempty')
.boolean('e')

.help('h')
.alias('h', 'help')

.argv;
const params = yargs
.options({
check: {
type: 'boolean',
alias: 'c',
description: 'Audit files in memory instead of changing them on the filesystem and throw an error if any changes would be made'
},
files: {
type: 'string',
alias: 'f',
description: 'Glob pattern for the resource JSON files'
},
primary: {
type: 'string',
alias: 'p',
description: 'Primary localization language. Other language files will be changed to match'
},
languages: {
type: 'array',
alias: 'l',
description: `Language files to create if they don't exist`
},
space: {
type: 'string',
alias: 's',
description: 'Space value used for JSON.stringify when writing JSON files to disk'
},
lineendings: {
choices: ['LF', 'CRLF'] as const,
alias: 'le',
description: 'Line endings used when writing JSON files to disk -- either LF or CRLF'
},
finalnewline: {
type: 'boolean',
alias: 'fn',
description: 'Insert a final newline when writing JSON files to disk'
},
newkeysempty: {
type: 'boolean',
alias: 'e',
description: 'Use empty string for new keys instead of the primary language value'
}
})
.example([
[`$0 --check --files '**/locales/*.json' --primary en --languages es fr pt-BR ja --space \t --lineendings LF --finalnewline --newkeysempty`]
])
.parseSync();

sync({
check,
files,
primary,
createResources: languages,
space,
lineEndings: lineendings,
finalNewline: finalnewline,
newKeysEmpty: newkeysempty
check: Boolean(params.check),
files: params.files,
primary: params.primary,
createResources: params.languages as string[],
space: params.space,
lineEndings: params.lineendings,
finalNewline: Boolean(params.finalnewline),
newKeysEmpty: Boolean(params.newkeysempty)
});
Loading

0 comments on commit c93e4c2

Please sign in to comment.