| 16 | const KNOWN_COMMANDS = ['extract'] |
| 17 | |
| 18 | async function main(argv: string[]): Promise<void> { |
| 19 | loudRejection() |
| 20 | |
| 21 | program |
| 22 | // TODO: fix this |
| 23 | .version('5.0.6', '-v, --version') |
| 24 | .usage('<command> [flags]') |
| 25 | .action(command => { |
| 26 | if (!KNOWN_COMMANDS.includes(command)) { |
| 27 | program.help() |
| 28 | } |
| 29 | }) |
| 30 | |
| 31 | program |
| 32 | .command('help', {isDefault: true}) |
| 33 | .description('Show this help message.') |
| 34 | .action(() => program.help()) |
| 35 | |
| 36 | // Long text wrapping to available terminal columns: https://github.com/tj/commander.js/pull/956 |
| 37 | // NOTE: please keep the help text in sync with babel-plugin-formatjs documentation. |
| 38 | program |
| 39 | .command('extract [files...]') |
| 40 | .description( |
| 41 | `Extract string messages from React components that use react-intl. |
| 42 | The input language is expected to be TypeScript or ES2017 with JSX.` |
| 43 | ) |
| 44 | .option( |
| 45 | '--format <path>', |
| 46 | `Path to a formatter file that controls the shape of JSON file from \`--out-file\`. |
| 47 | The formatter file must export a function called \`format\` with the signature |
| 48 | \`\`\` |
| 49 | type FormatFn = <T = Record<string, MessageDescriptor>>( |
| 50 | msgs: Record<string, MessageDescriptor> |
| 51 | ) => T |
| 52 | \`\`\` |
| 53 | This is especially useful to convert from our extracted format to a TMS-specific format. |
| 54 | ` |
| 55 | ) |
| 56 | .option( |
| 57 | '--in-file <path>', |
| 58 | `The file containing list of files to extract from, separated by newlines. This is mainly |
| 59 | to deal with the case where you have a large number of files to extract from and bash chokes.` |
| 60 | ) |
| 61 | .option( |
| 62 | '--out-file <path>', |
| 63 | `The target file path where the plugin will output an aggregated |
| 64 | \`.json\` file of all the translations from the \`files\` supplied.` |
| 65 | ) |
| 66 | .option( |
| 67 | '--id-interpolation-pattern <pattern>', |
| 68 | `If certain message descriptors don't have id, this \`pattern\` will be used to automatically |
| 69 | generate IDs for them. Default to \`[sha512:contenthash:base64:6]\` where \`contenthash\` is the hash of |
| 70 | \`defaultMessage\` and \`description\`. |
| 71 | See https://github.com/webpack/loader-utils#interpolatename for sample patterns`, |
| 72 | '[sha512:contenthash:base64:6]' |
| 73 | ) |
| 74 | .option( |
| 75 | '--extract-source-location', |