@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.
@@ -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 = globSync(filePatterns, {
76
- ignore: cmdObj.ignore,
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: filePatterns.length === 0,
106
+ readFromStdin: files.length === 0,
92
107
  preserveWhitespace: cmdObj.preserveWhitespace,
93
108
  flatten: cmdObj.flatten,
94
109
  });
@@ -29,6 +29,10 @@ export type ExtractCLIOptions = Omit<ExtractOpts, 'overrideIdFn' | 'onMsgExtract
29
29
  * Output File
30
30
  */
31
31
  outFile?: string;
32
+ /**
33
+ * Input File
34
+ */
35
+ inFile?: string;
32
36
  /**
33
37
  * Ignore file glob pattern
34
38
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formatjs/cli-lib",
3
3
  "description": "Lib for CLI for formatjs.",
4
- "version": "7.3.4",
4
+ "version": "7.4.0",
5
5
  "license": "MIT",
6
6
  "author": "Linjie Ding <linjie@airtable.com>",
7
7
  "engines": {