@formatjs/cli-lib 7.3.4 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib_esnext/src/cli.js +19 -4
- package/lib_esnext/src/extract.d.ts +4 -0
- package/package.json +1 -1
package/lib_esnext/src/cli.js
CHANGED
|
@@ -6,6 +6,8 @@ import compileFolder from './compile_folder';
|
|
|
6
6
|
import { debug } from './console_utils';
|
|
7
7
|
import extract from './extract';
|
|
8
8
|
import { verify } from './verify';
|
|
9
|
+
import { readFileSync } from 'fs-extra';
|
|
10
|
+
import { resolve } from 'path';
|
|
9
11
|
const KNOWN_COMMANDS = ['extract'];
|
|
10
12
|
async function main(argv) {
|
|
11
13
|
loudRejection();
|
|
@@ -37,6 +39,8 @@ type FormatFn = <T = Record<string, MessageDescriptor>>(
|
|
|
37
39
|
\`\`\`
|
|
38
40
|
This is especially useful to convert from our extracted format to a TMS-specific format.
|
|
39
41
|
`)
|
|
42
|
+
.option('--in-file <path>', `The file containing list of files to extract from, separated by newlines. This is mainly
|
|
43
|
+
to deal with the case where you have a large number of files to extract from and bash chokes.`)
|
|
40
44
|
.option('--out-file <path>', `The target file path where the plugin will output an aggregated
|
|
41
45
|
\`.json\` file of all the translations from the \`files\` supplied.`)
|
|
42
46
|
.option('--id-interpolation-pattern <pattern>', `If certain message descriptors don't have id, this \`pattern\` will be used to automatically
|
|
@@ -72,9 +76,20 @@ sentences are not translator-friendly.`)
|
|
|
72
76
|
.action(async (filePatterns, cmdObj) => {
|
|
73
77
|
debug('File pattern:', filePatterns);
|
|
74
78
|
debug('Options:', cmdObj);
|
|
75
|
-
const files =
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
const files = [];
|
|
80
|
+
if (filePatterns.length) {
|
|
81
|
+
files.push(...globSync(filePatterns, {
|
|
82
|
+
ignore: cmdObj.ignore,
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
if (cmdObj.inFile) {
|
|
86
|
+
debug('Reading inFile:', cmdObj.inFile);
|
|
87
|
+
const inFile = readFileSync(cmdObj.inFile, 'utf8');
|
|
88
|
+
files.push(...inFile
|
|
89
|
+
.split('\n')
|
|
90
|
+
.filter(Boolean)
|
|
91
|
+
.map(f => resolve(f)));
|
|
92
|
+
}
|
|
78
93
|
debug('Files to extract:', files);
|
|
79
94
|
await extract(files, {
|
|
80
95
|
outFile: cmdObj.outFile,
|
|
@@ -88,7 +103,7 @@ sentences are not translator-friendly.`)
|
|
|
88
103
|
format: cmdObj.format,
|
|
89
104
|
// It is possible that the glob pattern does NOT match anything.
|
|
90
105
|
// But so long as the glob pattern is provided, don't read from stdin.
|
|
91
|
-
readFromStdin:
|
|
106
|
+
readFromStdin: files.length === 0,
|
|
92
107
|
preserveWhitespace: cmdObj.preserveWhitespace,
|
|
93
108
|
flatten: cmdObj.flatten,
|
|
94
109
|
});
|