-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
54 lines (47 loc) · 1.52 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const program = require('commander')
const chalk = require('chalk')
const AddTranslation = require('./src/commands/AddTranslation')
const BulkAdd = require('./src/commands/BulkAdd')
if (!process.env.LISTENING_TO_UNHANDLED_REJECTION) {
process.on('unhandledRejection', reason => {
console.log(reason)
})
// Avoid memory leak by adding too many listeners
process.env.LISTENING_TO_UNHANDLED_REJECTION = true
}
const wrapWithErrorHandler = (command, ...args) => {
return async (...args) => {
try {
await command(...args)
} catch (e) {
console.log(chalk.red(e.stack))
process.exitCode = 1
}
}
}
program
.version('0.0.5')
.description('locale-man 👮: Interactive translation manager for node')
/**
* Add a translation
*/
program
.command('add <key>')
.alias('a')
.description('Add a translation')
.action(wrapWithErrorHandler(AddTranslation.handle))
.option('-l, --locales <locales>', 'Comma-spearated list of supported locales')
.option('-o, --output-dir <output-dir>', 'Path to folder with json translation files')
.option('-s, --silent', 'Silent mode (no output)')
/**
* Bulk add
*/
program
.command('bulk-add')
.alias('ba')
.description('Add several translations at once')
.action(wrapWithErrorHandler(BulkAdd.handle))
.option('-l, --locales <locales>', 'Comma-spearated list of supported locales')
.option('-o, --output-dir <output-dir>', 'Path to folder with json translation files')
.option('-s, --silent', 'Silent mode (no output)')
program.parse(process.argv)