( input: CmdRunContext, )
| 9 | import { CmdRunContext } from "./_types"; |
| 10 | |
| 11 | export default async function plan( |
| 12 | input: CmdRunContext, |
| 13 | ): Promise<CmdRunContext> { |
| 14 | console.log(chalk.hex(colors.orange)("[Planning]")); |
| 15 | |
| 16 | let buckets = getBuckets(input.config!); |
| 17 | if (input.flags.bucket) { |
| 18 | buckets = buckets.filter((b) => input.flags.bucket!.includes(b.type)); |
| 19 | } |
| 20 | |
| 21 | const _sourceLocale = input.flags.sourceLocale || input.config!.locale.source; |
| 22 | if (!_sourceLocale) { |
| 23 | throw new Error( |
| 24 | `No source locale provided. Use --source-locale to specify the source locale or add it to i18n.json (locale.source)`, |
| 25 | ); |
| 26 | } |
| 27 | const _targetLocales = |
| 28 | input.flags.targetLocale || input.config!.locale.targets; |
| 29 | if (!_targetLocales.length) { |
| 30 | throw new Error( |
| 31 | `No target locales provided. Use --target-locale to specify the target locales or add them to i18n.json (locale.targets)`, |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | return new Listr<CmdRunContext>( |
| 36 | [ |
| 37 | { |
| 38 | title: "Locating content buckets", |
| 39 | task: async (ctx, task) => { |
| 40 | const bucketCount = buckets.length; |
| 41 | const bucketFilter = input.flags.bucket |
| 42 | ? ` ${chalk.dim(`(filtered by: ${chalk.hex(colors.yellow)(input.flags.bucket!.join(", "))})`)}` |
| 43 | : ""; |
| 44 | task.title = `Found ${chalk.hex(colors.yellow)(bucketCount.toString())} bucket(s)${bucketFilter}`; |
| 45 | }, |
| 46 | }, |
| 47 | { |
| 48 | title: "Detecting locales", |
| 49 | task: async (ctx, task) => { |
| 50 | task.title = `Found ${chalk.hex(colors.yellow)(_targetLocales.length.toString())} target locale(s)`; |
| 51 | }, |
| 52 | }, |
| 53 | { |
| 54 | title: "Locating localizable files", |
| 55 | task: async (ctx, task) => { |
| 56 | const patterns: string[] = []; |
| 57 | |
| 58 | for (const bucket of buckets) { |
| 59 | for (const bucketPath of bucket.paths) { |
| 60 | if (input.flags.file) { |
| 61 | if ( |
| 62 | !input.flags.file.some( |
| 63 | (f) => |
| 64 | bucketPath.pathPattern.includes(f) || |
| 65 | minimatch(bucketPath.pathPattern, f), |
| 66 | ) |
| 67 | ) { |
| 68 | continue; |
no test coverage detected