-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli.js
66 lines (52 loc) · 1.58 KB
/
cli.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
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
let argv = require('minimist')(process.argv);
const chokidar = require('chokidar');
if (argv._) {
let myself = argv._.indexOf(__filename);
if (myself == -1) {
myself = argv._.findIndex(a => a.indexOf('.bin/vuei18n-po') != -1);
}
if (myself != -1 && myself + 1 < argv._.length) {
argv.po = argv._.slice(myself + 1);
}
else if (myself == -1 && argv._.length > 0) {
argv.po = argv._.slice();
}
}
if (argv.h || argv.help || !argv.po) {
const package = require('./package.json');
console.log(`
${package.description}
Usage:
vuei18n-po [OPTIONS] GLOB_OR_FILE.po ...
Options:
--pluralRules=FILE.js
language plural rules to be imported for VueI18n pluralizationRules
--messagesFile=FILE.json
a single file containing all the translation strings, language as a key
--messagesDir=DIRECTORY
directory where translations go split by a language
--whiteList=GLOB
files that are tested for presence of the message keys;
the unnused keys are filtered out
--es6
use es6 format for file generation (eg: plural file)
--watch
watch for file change to regenerate files
`);
process.exit(0);
}
if (argv.version) {
const package = require('./package.json');
console.log('vuei18n-po', package.version);
process.exit(0);
}
const vuei18nPo = require('./index.js');
delete argv._;
if (argv.watch) {
console.log("Watch for file change...");
chokidar.watch(argv.po).on('add', () => vuei18nPo(argv));
chokidar.watch(argv.po).on('change', () => vuei18nPo(argv));
} else {
vuei18nPo(argv);
}