( input: CmdRunContext, )
| 31 | * written, or billed; lockfile and target files stay untouched. |
| 32 | */ |
| 33 | export default async function estimate( |
| 34 | input: CmdRunContext, |
| 35 | ): Promise<CmdRunContext> { |
| 36 | console.log(chalk.hex(colors.orange)("[Estimate]")); |
| 37 | |
| 38 | if (!input.localizer?.estimate) { |
| 39 | throw new Error( |
| 40 | `Cost estimate is not available for the "${input.localizer?.id}" provider. ` + |
| 41 | `Estimates use Lingo.dev server-side pricing — remove --estimate or switch to the Lingo.dev provider.`, |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | const charsByLocale = new Map<string, number>(); |
| 46 | |
| 47 | return new Listr<CmdRunContext>( |
| 48 | [ |
| 49 | { |
| 50 | title: "Computing translation delta", |
| 51 | task: async (ctx, task) => { |
| 52 | if (!ctx.tasks.length) { |
| 53 | task.title = "Nothing to estimate — everything is up to date."; |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | for (const runTask of ctx.tasks) { |
| 58 | const bucketLoader = createLoaderForTask(runTask); |
| 59 | const deltaProcessor = createDeltaProcessor( |
| 60 | runTask.bucketPathPattern, |
| 61 | ); |
| 62 | const checksums = await deltaProcessor.loadChecksums(); |
| 63 | const sourceData = await bucketLoader.pull(runTask.sourceLocale); |
| 64 | const targetData = await bucketLoader.pull(runTask.targetLocale); |
| 65 | const delta = await deltaProcessor.calculateDelta({ |
| 66 | sourceData, |
| 67 | targetData, |
| 68 | checksums, |
| 69 | }); |
| 70 | const processableData = computeProcessableData( |
| 71 | sourceData, |
| 72 | delta, |
| 73 | ctx.flags.force, |
| 74 | runTask.onlyKeys, |
| 75 | ); |
| 76 | |
| 77 | const chars = countTranslatableChars(processableData); |
| 78 | charsByLocale.set( |
| 79 | runTask.targetLocale, |
| 80 | (charsByLocale.get(runTask.targetLocale) ?? 0) + chars, |
| 81 | ); |
| 82 | } |
| 83 | |
| 84 | task.title = `Delta computed for ${chalk.hex(colors.yellow)( |
| 85 | ctx.tasks.length.toString(), |
| 86 | )} task(s)`; |
| 87 | }, |
| 88 | }, |
| 89 | { |
| 90 | title: "Fetching cost estimate", |
no test coverage detected