@intlayer/cli 9.3.0 → 9.3.2

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.
Files changed (136) hide show
  1. package/README.md +24 -24
  2. package/dist/cjs/IntlayerEventListener.cjs +2 -6
  3. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  4. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -2
  5. package/dist/cjs/_virtual/_utils_asset.cjs +2 -1
  6. package/dist/cjs/auth/login.cjs.map +1 -1
  7. package/dist/cjs/auth/sessionToken.cjs.map +1 -1
  8. package/dist/cjs/build.cjs.map +1 -1
  9. package/dist/cjs/bundle.cjs +0 -1
  10. package/dist/cjs/bundle.cjs.map +1 -1
  11. package/dist/cjs/ci.cjs.map +1 -1
  12. package/dist/cjs/cli.cjs.map +1 -1
  13. package/dist/cjs/config.cjs.map +1 -1
  14. package/dist/cjs/editor.cjs +3 -1
  15. package/dist/cjs/editor.cjs.map +1 -1
  16. package/dist/cjs/extract.cjs.map +1 -1
  17. package/dist/cjs/fill/deepMergeContent.cjs +0 -1
  18. package/dist/cjs/fill/deepMergeContent.cjs.map +1 -1
  19. package/dist/cjs/fill/extractTranslatableContent.cjs +0 -1
  20. package/dist/cjs/fill/extractTranslatableContent.cjs.map +1 -1
  21. package/dist/cjs/fill/fill.cjs +4 -2
  22. package/dist/cjs/fill/fill.cjs.map +1 -1
  23. package/dist/cjs/fill/formatAutoFilledFilePath.cjs +4 -1
  24. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
  25. package/dist/cjs/fill/formatFillData.cjs.map +1 -1
  26. package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs +0 -1
  27. package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs.map +1 -1
  28. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs +0 -1
  29. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs.map +1 -1
  30. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -1
  31. package/dist/cjs/fill/translateDictionary.cjs +7 -6
  32. package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
  33. package/dist/cjs/fill/writeFill.cjs.map +1 -1
  34. package/dist/cjs/getTargetDictionary.cjs.map +1 -1
  35. package/dist/cjs/init.cjs +14 -133
  36. package/dist/cjs/init.cjs.map +1 -1
  37. package/dist/cjs/initBuildOptimization.cjs.map +1 -1
  38. package/dist/cjs/initCompiler.cjs.map +1 -1
  39. package/dist/cjs/initMCP.cjs.map +1 -1
  40. package/dist/cjs/initSkills.cjs +2 -1
  41. package/dist/cjs/initSkills.cjs.map +1 -1
  42. package/dist/cjs/listContentDeclaration.cjs +2 -1
  43. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  44. package/dist/cjs/listProjects.cjs.map +1 -1
  45. package/dist/cjs/liveSync.cjs.map +1 -1
  46. package/dist/cjs/pull.cjs.map +1 -1
  47. package/dist/cjs/push/pullLog.cjs.map +1 -1
  48. package/dist/cjs/push/push.cjs +2 -1
  49. package/dist/cjs/push/push.cjs.map +1 -1
  50. package/dist/cjs/pushConfig.cjs.map +1 -1
  51. package/dist/cjs/pushLog.cjs.map +1 -1
  52. package/dist/cjs/reviewDoc/reviewDoc.cjs +4 -2
  53. package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
  54. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +4 -2
  55. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
  56. package/dist/cjs/reviewDoc/reviewDocLog.cjs +6 -3
  57. package/dist/cjs/reviewDoc/reviewDocLog.cjs.map +1 -1
  58. package/dist/cjs/reviewDoc/reviewDocProgress.cjs.map +1 -1
  59. package/dist/cjs/reviewDoc/reviewDocSynthesis.cjs.map +1 -1
  60. package/dist/cjs/scan.cjs +2 -1
  61. package/dist/cjs/scan.cjs.map +1 -1
  62. package/dist/cjs/searchDoc.cjs.map +1 -1
  63. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  64. package/dist/cjs/test/test.cjs.map +1 -1
  65. package/dist/cjs/translateDoc/translateDoc.cjs +3 -2
  66. package/dist/cjs/translateDoc/translateDoc.cjs.map +1 -1
  67. package/dist/cjs/translateDoc/translateFile.cjs +6 -3
  68. package/dist/cjs/translateDoc/translateFile.cjs.map +1 -1
  69. package/dist/cjs/translateDoc/validation.cjs +0 -1
  70. package/dist/cjs/translateDoc/validation.cjs.map +1 -1
  71. package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
  72. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  73. package/dist/cjs/utils/checkConfigConsistency.cjs +0 -1
  74. package/dist/cjs/utils/checkConfigConsistency.cjs.map +1 -1
  75. package/dist/cjs/utils/checkFileModifiedRange.cjs +3 -2
  76. package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
  77. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
  78. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  79. package/dist/cjs/utils/fixChunkStartEndChars.cjs +0 -1
  80. package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
  81. package/dist/cjs/utils/formatLineRanges.cjs +0 -1
  82. package/dist/cjs/utils/formatLineRanges.cjs.map +1 -1
  83. package/dist/cjs/utils/formatTimeDiff.cjs +0 -1
  84. package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
  85. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
  86. package/dist/cjs/utils/getOutputFilePath.cjs +2 -1
  87. package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
  88. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
  89. package/dist/cjs/utils/listSpecialChars.cjs +0 -1
  90. package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
  91. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
  92. package/dist/cjs/utils/openBrowser.cjs.map +1 -1
  93. package/dist/cjs/utils/selectCmsEnvironment.cjs +2 -1
  94. package/dist/cjs/utils/selectCmsEnvironment.cjs.map +1 -1
  95. package/dist/cjs/utils/setupAI.cjs.map +1 -1
  96. package/dist/cjs/watch.cjs.map +1 -1
  97. package/dist/esm/IntlayerEventListener.mjs +2 -6
  98. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  99. package/dist/esm/_virtual/_utils_asset.mjs +2 -1
  100. package/dist/esm/cli.mjs.map +1 -1
  101. package/dist/esm/editor.mjs +3 -1
  102. package/dist/esm/editor.mjs.map +1 -1
  103. package/dist/esm/fill/fill.mjs +4 -2
  104. package/dist/esm/fill/fill.mjs.map +1 -1
  105. package/dist/esm/fill/formatAutoFilledFilePath.mjs +4 -1
  106. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
  107. package/dist/esm/fill/translateDictionary.mjs +7 -6
  108. package/dist/esm/fill/translateDictionary.mjs.map +1 -1
  109. package/dist/esm/init.mjs +15 -134
  110. package/dist/esm/init.mjs.map +1 -1
  111. package/dist/esm/initSkills.mjs +2 -1
  112. package/dist/esm/initSkills.mjs.map +1 -1
  113. package/dist/esm/listContentDeclaration.mjs +2 -1
  114. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  115. package/dist/esm/push/push.mjs +2 -1
  116. package/dist/esm/push/push.mjs.map +1 -1
  117. package/dist/esm/reviewDoc/reviewDoc.mjs +4 -2
  118. package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
  119. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +4 -2
  120. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
  121. package/dist/esm/reviewDoc/reviewDocLog.mjs +6 -3
  122. package/dist/esm/reviewDoc/reviewDocLog.mjs.map +1 -1
  123. package/dist/esm/scan.mjs +2 -1
  124. package/dist/esm/scan.mjs.map +1 -1
  125. package/dist/esm/translateDoc/translateDoc.mjs +3 -2
  126. package/dist/esm/translateDoc/translateDoc.mjs.map +1 -1
  127. package/dist/esm/translateDoc/translateFile.mjs +6 -3
  128. package/dist/esm/translateDoc/translateFile.mjs.map +1 -1
  129. package/dist/esm/utils/checkFileModifiedRange.mjs +3 -2
  130. package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
  131. package/dist/esm/utils/getOutputFilePath.mjs +2 -1
  132. package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
  133. package/dist/esm/utils/selectCmsEnvironment.mjs +2 -1
  134. package/dist/esm/utils/selectCmsEnvironment.mjs.map +1 -1
  135. package/dist/types/init.d.ts.map +1 -1
  136. package/package.json +12 -12
@@ -1 +1 @@
1
- {"version":3,"file":"reviewDocBlockAware.mjs","names":[],"sources":["../../../src/reviewDoc/reviewDocBlockAware.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname } from 'node:path';\nimport { readAsset } from 'utils:asset';\nimport type { AIConfig } from '@intlayer/ai';\nimport type { AIOptions } from '@intlayer/api';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { retryManager } from '@intlayer/config/utils';\nimport { getLocaleName } from '@intlayer/core/localization';\nimport {\n buildAlignmentPlan,\n mergeReviewedSegments,\n type PlannedAction,\n type ReviewReportSummary,\n} from '@intlayer/engine/docReview';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { ENGLISH } from '@intlayer/types/locales';\nimport { sanitizeChunk, validateTranslation } from '../translateDoc/validation';\nimport { chunkInference } from '../utils/chunkInference';\nimport { fixChunkStartEndChars } from '../utils/fixChunkStartEndChars';\nimport type { AIClient } from '../utils/setupAI';\n\n/**\n * Review a file using block-aware alignment.\n *\n * 1. Segments both base and target documents into semantic blocks.\n * 2. Aligns blocks using structure (special chars, numbers) and context.\n * 3. Detects which blocks changed, were added, or deleted.\n * 4. Applies deletions immediately without AI.\n * 5. Sends changed/new blocks to AI in bottom-up order (last block first), so\n * line numbers of earlier blocks are not shifted by edits below them.\n * 6. Rewrites the file after each block so progress is persisted incrementally.\n *\n * @returns The per-action block counts of the alignment plan, so the caller can\n * synthesize what was reused and what had to be edited.\n */\nexport const reviewFileBlockAware = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n aiOptions?: AIOptions,\n configOptions?: GetConfigurationOptions,\n customInstructions?: string,\n changedLines?: number[],\n aiClient?: AIClient,\n aiConfig?: AIConfig\n): Promise<ReviewReportSummary> => {\n const configuration = getConfiguration(configOptions);\n const applicationLogger = getAppLogger({\n log: { ...configuration.log, prefix: '' },\n });\n\n const baseText = await readFile(baseFilePath, 'utf-8');\n const targetText = await readFile(outputFilePath, 'utf-8').catch(() => '');\n\n const basePrompt = readAsset('./prompts/REVIEW_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // Build block-aware alignment and plan\n const { baseBlocks, targetBlocks, plan, segmentsToReview } =\n buildAlignmentPlan({\n baseText,\n targetText,\n changedLines,\n });\n\n const countActions = (kind: PlannedAction['kind']): number =>\n plan.actions.filter((action: PlannedAction) => action.kind === kind).length;\n\n const reviewSummary: ReviewReportSummary = {\n reuse: countActions('reuse'),\n review: countActions('review'),\n insertNew: countActions('insert_new'),\n delete: countActions('delete'),\n };\n\n const deleteCount = reviewSummary.delete;\n\n applicationLogger(\n `${filePrefix}Block-aware alignment complete. Total blocks: base=${colorizeNumber(baseBlocks.length)}, target=${colorizeNumber(targetBlocks.length)}`\n );\n applicationLogger(\n `${filePrefix}Actions: reuse=${colorizeNumber(reviewSummary.reuse)}, review=${colorizeNumber(reviewSummary.review)}, new=${colorizeNumber(reviewSummary.insertNew)}, delete=${colorizeNumber(deleteCount)}`\n );\n\n // Map shared across the entire run: each entry overrides the default behavior\n // of mergeReviewedSegments for that action index.\n const reviewedSegmentsMap = new Map<number, string>();\n\n // --- Step 1: apply deletions immediately (no AI needed) ---\n for (const [actionIndex, action] of plan.actions.entries()) {\n if (action.kind === 'delete') {\n reviewedSegmentsMap.set(actionIndex, '');\n }\n }\n\n const writeCurrentState = (): void => {\n const output = mergeReviewedSegments(\n plan,\n targetBlocks,\n reviewedSegmentsMap\n );\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, output);\n };\n\n if (deleteCount > 0) {\n writeCurrentState();\n applicationLogger(\n `${filePrefix}${colorizeNumber(deleteCount)} block(s) deleted without AI.`\n );\n }\n\n if (segmentsToReview.length === 0) {\n if (deleteCount === 0) {\n applicationLogger(\n `${filePrefix}No segments need review, reusing existing translation`\n );\n writeCurrentState();\n }\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} updated successfully (no AI changes needed).`\n );\n return reviewSummary;\n }\n\n applicationLogger(\n `${filePrefix}Segments to review: ${colorizeNumber(segmentsToReview.length)} (processing bottom-up)`\n );\n\n // --- Step 2: process AI segments in bottom-up order ---\n // Reversing ensures edits near the end of the file don't shift line numbers\n // that matter for blocks higher up, and each intermediate file write is valid.\n const segmentsBottomUp = segmentsToReview\n .map((segment, originalIndex) => ({\n segment,\n displayNumber: originalIndex + 1,\n }))\n .reverse();\n\n for (const { segment, displayNumber } of segmentsBottomUp) {\n const baseBlock = segment.baseBlock;\n\n const getBaseChunkContextPrompt = () =>\n `**BLOCK ${displayNumber} of ${segmentsToReview.length}** is the base block in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///\\n` +\n baseBlock.content +\n `///chunksEnd///`;\n\n const getTargetChunkPrompt = () =>\n `**BLOCK ${displayNumber} of ${segmentsToReview.length}** is the current block to review in ${formatLocale(locale, false)}.\\n` +\n `///chunksStart///\\n` +\n (segment.targetBlockText ?? '') +\n `///chunksEnd///`;\n\n const reviewedChunkResult = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n { role: 'system', content: getBaseChunkContextPrompt() },\n { role: 'system', content: getTargetChunkPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **BLOCK ${colorizeNumber(displayNumber)} of ${colorizeNumber(segmentsToReview.length)}** that should be translated in ${getLocaleName(locale, ENGLISH)} (${locale}).`,\n },\n ],\n [{ role: 'user', content: baseBlock.content }],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n applicationLogger(\n `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Block ${colorizeNumber(displayNumber)} of ${colorizeNumber(segmentsToReview.length)}`\n );\n\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n baseBlock.content\n );\n processedChunk = fixChunkStartEndChars(processedChunk, baseBlock.content);\n\n const isValid = validateTranslation(\n baseBlock.content,\n processedChunk,\n applicationLogger\n );\n\n if (!isValid) {\n throw new Error(\n 'Validation failed for chunk (structure or length mismatch). Retrying...'\n );\n }\n\n return processedChunk;\n })();\n\n reviewedSegmentsMap.set(segment.actionIndex, reviewedChunkResult);\n\n // Rewrite the file after every block so progress is never lost.\n writeCurrentState();\n }\n\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} created/updated successfully.`\n );\n\n return reviewSummary;\n};\n"],"mappings":";;;;;;;;;;;;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c,MAAM,iBAAiB,OAAO,uCAAuC,aAAa,QAAQ,KAAK,EAAE,2BAEzH,QAAQ,mBAAmB,MAC5B;EAEF,MAAM,sBAAsB,MAAM,aAAa,YAAY;GACzD,MAAM,SAAS,MAAM,eACnB;IACE;KAAE,MAAM;KAAU,SAAS;IAAW;IACtC;KAAE,MAAM;KAAU,SAAS,0BAA0B;IAAE;IACvD;KAAE,MAAM;KAAU,SAAS,qBAAqB;IAAE;IAClD;KACE,MAAM;KACN,SAAS,6CAA6C,eAAe,aAAa,EAAE,MAAM,eAAe,iBAAiB,MAAM,EAAE,kCAAkC,cAAc,QAAQ,OAAO,EAAE,IAAI,OAAO;IAChN;GACF,GACA,CAAC;IAAE,MAAM;IAAQ,SAAS,UAAU;GAAQ,CAAC,GAC7C,WACA,eACA,UACA,QACF;GAEA,kBACE,GAAG,SAAS,eAAe,OAAO,SAAS,EAAE,uBAAuB,eAAe,aAAa,EAAE,MAAM,eAAe,iBAAiB,MAAM,GAChJ;GAEA,IAAI,iBAAiB,cACnB,QAAQ,aACR,UAAU,OACZ;GACA,iBAAiB,sBAAsB,gBAAgB,UAAU,OAAO;GAQxE,IAAI,CANY,oBACd,UAAU,SACV,gBACA,iBAGS,GACT,MAAM,IAAI,MACR,yEACF;GAGF,OAAO;EACT,CAAC,CAAC,CAAC;EAEH,oBAAoB,IAAI,QAAQ,aAAa,mBAAmB;EAGhE,kBAAkB;CACpB;CAEA,kBACE,GAAG,SAAS,KAAK,WAAW,KAAK,EAAE,QAAQ,WAAW,cAAc,EAAE,+BACxE;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"reviewDocBlockAware.mjs","names":[],"sources":["../../../src/reviewDoc/reviewDocBlockAware.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname } from 'node:path';\nimport { readAsset } from 'utils:asset';\nimport type { AIConfig } from '@intlayer/ai';\nimport type { AIOptions } from '@intlayer/api';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { retryManager } from '@intlayer/config/utils';\nimport { getLocaleName } from '@intlayer/core/localization';\nimport {\n buildAlignmentPlan,\n mergeReviewedSegments,\n type PlannedAction,\n type ReviewReportSummary,\n} from '@intlayer/engine/docReview';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { ENGLISH } from '@intlayer/types/locales';\nimport { sanitizeChunk, validateTranslation } from '../translateDoc/validation';\nimport { chunkInference } from '../utils/chunkInference';\nimport { fixChunkStartEndChars } from '../utils/fixChunkStartEndChars';\nimport type { AIClient } from '../utils/setupAI';\n\n/**\n * Review a file using block-aware alignment.\n *\n * 1. Segments both base and target documents into semantic blocks.\n * 2. Aligns blocks using structure (special chars, numbers) and context.\n * 3. Detects which blocks changed, were added, or deleted.\n * 4. Applies deletions immediately without AI.\n * 5. Sends changed/new blocks to AI in bottom-up order (last block first), so\n * line numbers of earlier blocks are not shifted by edits below them.\n * 6. Rewrites the file after each block so progress is persisted incrementally.\n *\n * @returns The per-action block counts of the alignment plan, so the caller can\n * synthesize what was reused and what had to be edited.\n */\nexport const reviewFileBlockAware = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n aiOptions?: AIOptions,\n configOptions?: GetConfigurationOptions,\n customInstructions?: string,\n changedLines?: number[],\n aiClient?: AIClient,\n aiConfig?: AIConfig\n): Promise<ReviewReportSummary> => {\n const configuration = getConfiguration(configOptions);\n const applicationLogger = getAppLogger({\n log: { ...configuration.log, prefix: '' },\n });\n\n const baseText = await readFile(baseFilePath, 'utf-8');\n const targetText = await readFile(outputFilePath, 'utf-8').catch(() => '');\n\n const basePrompt = readAsset('./prompts/REVIEW_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // Build block-aware alignment and plan\n const { baseBlocks, targetBlocks, plan, segmentsToReview } =\n buildAlignmentPlan({\n baseText,\n targetText,\n changedLines,\n });\n\n const countActions = (kind: PlannedAction['kind']): number =>\n plan.actions.filter((action: PlannedAction) => action.kind === kind).length;\n\n const reviewSummary: ReviewReportSummary = {\n reuse: countActions('reuse'),\n review: countActions('review'),\n insertNew: countActions('insert_new'),\n delete: countActions('delete'),\n };\n\n const deleteCount = reviewSummary.delete;\n\n applicationLogger(\n `${filePrefix}Block-aware alignment complete. Total blocks: base=${colorizeNumber(baseBlocks.length)}, target=${colorizeNumber(targetBlocks.length)}`\n );\n applicationLogger(\n `${filePrefix}Actions: reuse=${colorizeNumber(reviewSummary.reuse)}, review=${colorizeNumber(reviewSummary.review)}, new=${colorizeNumber(reviewSummary.insertNew)}, delete=${colorizeNumber(deleteCount)}`\n );\n\n // Map shared across the entire run: each entry overrides the default behavior\n // of mergeReviewedSegments for that action index.\n const reviewedSegmentsMap = new Map<number, string>();\n\n // --- Step 1: apply deletions immediately (no AI needed) ---\n for (const [actionIndex, action] of plan.actions.entries()) {\n if (action.kind === 'delete') {\n reviewedSegmentsMap.set(actionIndex, '');\n }\n }\n\n const writeCurrentState = (): void => {\n const output = mergeReviewedSegments(\n plan,\n targetBlocks,\n reviewedSegmentsMap\n );\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, output);\n };\n\n if (deleteCount > 0) {\n writeCurrentState();\n applicationLogger(\n `${filePrefix}${colorizeNumber(deleteCount)} block(s) deleted without AI.`\n );\n }\n\n if (segmentsToReview.length === 0) {\n if (deleteCount === 0) {\n applicationLogger(\n `${filePrefix}No segments need review, reusing existing translation`\n );\n writeCurrentState();\n }\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} updated successfully (no AI changes needed).`\n );\n return reviewSummary;\n }\n\n applicationLogger(\n `${filePrefix}Segments to review: ${colorizeNumber(segmentsToReview.length)} (processing bottom-up)`\n );\n\n // --- Step 2: process AI segments in bottom-up order ---\n // Reversing ensures edits near the end of the file don't shift line numbers\n // that matter for blocks higher up, and each intermediate file write is valid.\n const segmentsBottomUp = segmentsToReview\n .map((segment, originalIndex) => ({\n segment,\n displayNumber: originalIndex + 1,\n }))\n .reverse();\n\n for (const { segment, displayNumber } of segmentsBottomUp) {\n const baseBlock = segment.baseBlock;\n\n const getBaseChunkContextPrompt = () =>\n `**BLOCK ${displayNumber} of ${segmentsToReview.length}** is the base block in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///\\n` +\n baseBlock.content +\n `///chunksEnd///`;\n\n const getTargetChunkPrompt = () =>\n `**BLOCK ${displayNumber} of ${segmentsToReview.length}** is the current block to review in ${formatLocale(locale, false)}.\\n` +\n `///chunksStart///\\n` +\n (segment.targetBlockText ?? '') +\n `///chunksEnd///`;\n\n const reviewedChunkResult = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n { role: 'system', content: getBaseChunkContextPrompt() },\n { role: 'system', content: getTargetChunkPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **BLOCK ${colorizeNumber(displayNumber)} of ${colorizeNumber(segmentsToReview.length)}** that should be translated in ${getLocaleName(locale, ENGLISH)} (${locale}).`,\n },\n ],\n [{ role: 'user', content: baseBlock.content }],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n applicationLogger(\n `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Block ${colorizeNumber(displayNumber)} of ${colorizeNumber(segmentsToReview.length)}`\n );\n\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n baseBlock.content\n );\n processedChunk = fixChunkStartEndChars(processedChunk, baseBlock.content);\n\n const isValid = validateTranslation(\n baseBlock.content,\n processedChunk,\n applicationLogger\n );\n\n if (!isValid) {\n throw new Error(\n 'Validation failed for chunk (structure or length mismatch). Retrying...'\n );\n }\n\n return processedChunk;\n })();\n\n reviewedSegmentsMap.set(segment.actionIndex, reviewedChunkResult);\n\n // Rewrite the file after every block so progress is never lost.\n writeCurrentState();\n }\n\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} created/updated successfully.`\n );\n\n return reviewSummary;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAa,uBAAuB,OAClC,cACA,gBACA,QACA,YACA,WACA,eACA,oBACA,cACA,UACA,aACiC;CACjC,MAAM,gBAAgB,iBAAiB,aAAa;CACpD,MAAM,oBAAoB,aAAa,EACrC,KAAK;EAAE,GAAG,cAAc;EAAK,QAAQ;CAAG,EAC1C,CAAC;CAED,MAAM,WAAW,MAAM,SAAS,cAAc,OAAO;CACrD,MAAM,aAAa,MAAM,SAAS,gBAAgB,OAAO,CAAC,CAAC,YAAY,EAAE;CAEzE,MAAM,aAAa,UAAU,8BAA8B,OAAO,CAAC,CAChE,WAAW,kBAAkB,GAAG,aAAa,QAAQ,KAAK,GAAG,CAAC,CAC9D,WAAW,sBAAsB,GAAG,aAAa,YAAY,KAAK,GAAG,CAAC,CACtE,QAAQ,0BAA0B,WAAW,sBAAsB,GAAG,CAAC,CACvE,QAAQ,0BAA0B,sBAAsB,GAAG;CAE9D,MAAM,iBAAiB,GAA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aAAa,EAAE,MAAM,eAAe,iBAAiB,MAAM,GAChJ;GAEA,IAAI,iBAAiB,cACnB,QAAQ,aACR,UAAU,OACZ;GACA,iBAAiB,sBAAsB,gBAAgB,UAAU,OAAO;GAQxE,IAAI,CANY,oBACd,UAAU,SACV,gBACA,iBAGS,GACT,MAAM,IAAI,MACR,yEACF;GAGF,OAAO;EACT,CAAC,CAAC,CAAC;EAEH,oBAAoB,IAAI,QAAQ,aAAa,mBAAmB;EAGhE,kBAAkB;CACpB;CAEA,kBACE,GAAG,SAAS,KAAK,WAAW,KAAK,EAAE,QAAQ,WAAW,cAAc,EAAE,+BACxE;CAEA,OAAO;AACT"}
@@ -15,9 +15,11 @@ import { buildReviewReport, formatReviewReport } from "@intlayer/engine/docRevie
15
15
  * @returns The structured review report.
16
16
  */
17
17
  const buildFileReviewReport = async (baseFilePath, outputFilePath, changedLines) => {
18
+ const baseText = await readFile(baseFilePath, "utf-8");
19
+ const targetText = existsSync(outputFilePath) ? await readFile(outputFilePath, "utf-8").catch(() => "") : "";
18
20
  return buildReviewReport({
19
- baseText: await readFile(baseFilePath, "utf-8"),
20
- targetText: existsSync(outputFilePath) ? await readFile(outputFilePath, "utf-8").catch(() => "") : "",
21
+ baseText,
22
+ targetText,
21
23
  changedLines
22
24
  });
23
25
  };
@@ -33,8 +35,9 @@ const buildFileReviewReport = async (baseFilePath, outputFilePath, changedLines)
33
35
  * @param configOptions - Optional Intlayer configuration overrides.
34
36
  */
35
37
  const logReviewFileBlocks = (report, baseFilePath, locale, baseLocale, configOptions) => {
38
+ const configuration = getConfiguration(configOptions);
36
39
  const appLogger = getAppLogger({ log: {
37
- ...getConfiguration(configOptions).log,
40
+ ...configuration.log,
38
41
  prefix: ""
39
42
  } });
40
43
  const formatted = formatReviewReport(report, {
@@ -1 +1 @@
1
- {"version":3,"file":"reviewDocLog.mjs","names":[],"sources":["../../../src/reviewDoc/reviewDocLog.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n buildReviewReport,\n formatReviewReport,\n type ReviewReport,\n} from '@intlayer/engine/docReview';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\n\n/**\n * Compare a base document with its translation without calling any AI.\n *\n * @param baseFilePath - Absolute path of the base (source) document.\n * @param outputFilePath - Absolute path of the target (translated) document.\n * @param changedLines - 1-based base line numbers that changed (from git), if any.\n * @returns The structured review report.\n */\nexport const buildFileReviewReport = async (\n baseFilePath: string,\n outputFilePath: string,\n changedLines?: number[]\n): Promise<ReviewReport> => {\n const baseText = await readFile(baseFilePath, 'utf-8');\n const targetText = existsSync(outputFilePath)\n ? await readFile(outputFilePath, 'utf-8').catch(() => '')\n : '';\n\n return buildReviewReport({ baseText, targetText, changedLines });\n};\n\n/**\n * Log the blocks that need attention (with their line ranges and content) for a\n * single file/locale pair, so another agent or a human can generate the missing\n * translations.\n *\n * @param report - The report built by {@link buildFileReviewReport}.\n * @param baseFilePath - Absolute path of the base (source) document.\n * @param locale - The target locale being reviewed.\n * @param baseLocale - The base locale used as reference.\n * @param configOptions - Optional Intlayer configuration overrides.\n */\nexport const logReviewFileBlocks = (\n report: ReviewReport,\n baseFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n configOptions?: GetConfigurationOptions\n): void => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger({ log: { ...configuration.log, prefix: '' } });\n\n const formatted = formatReviewReport(report, {\n baseLabel: formatLocale(baseLocale),\n targetLabel: formatLocale(locale),\n });\n\n appLogger(`${formatPath(baseFilePath)} → ${formatLocale(locale)}`);\n for (const line of formatted.split('\\n')) {\n appLogger(line);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAuBA,MAAa,wBAAwB,OACnC,cACA,gBACA,iBAC0B;CAM1B,OAAO,kBAAkB;EAAE,gBALJ,SAAS,cAAc,OAAO;EAKhB,YAJlB,WAAW,cAAc,IACxC,MAAM,SAAS,gBAAgB,OAAO,CAAC,CAAC,YAAY,EAAE,IACtD;EAE6C;CAAa,CAAC;AACjE;;;;;;;;;;;;AAaA,MAAa,uBACX,QACA,cACA,QACA,YACA,kBACS;CAET,MAAM,YAAY,aAAa,EAAE,KAAK;EAAE,GADlB,iBAAiB,aACgB,CAAC,CAAC;EAAK,QAAQ;CAAG,EAAE,CAAC;CAE5E,MAAM,YAAY,mBAAmB,QAAQ;EAC3C,WAAW,aAAa,UAAU;EAClC,aAAa,aAAa,MAAM;CAClC,CAAC;CAED,UAAU,GAAG,WAAW,YAAY,EAAE,KAAK,aAAa,MAAM,GAAG;CACjE,KAAK,MAAM,QAAQ,UAAU,MAAM,IAAI,GACrC,UAAU,IAAI;AAElB"}
1
+ {"version":3,"file":"reviewDocLog.mjs","names":[],"sources":["../../../src/reviewDoc/reviewDocLog.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n buildReviewReport,\n formatReviewReport,\n type ReviewReport,\n} from '@intlayer/engine/docReview';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\n\n/**\n * Compare a base document with its translation without calling any AI.\n *\n * @param baseFilePath - Absolute path of the base (source) document.\n * @param outputFilePath - Absolute path of the target (translated) document.\n * @param changedLines - 1-based base line numbers that changed (from git), if any.\n * @returns The structured review report.\n */\nexport const buildFileReviewReport = async (\n baseFilePath: string,\n outputFilePath: string,\n changedLines?: number[]\n): Promise<ReviewReport> => {\n const baseText = await readFile(baseFilePath, 'utf-8');\n const targetText = existsSync(outputFilePath)\n ? await readFile(outputFilePath, 'utf-8').catch(() => '')\n : '';\n\n return buildReviewReport({ baseText, targetText, changedLines });\n};\n\n/**\n * Log the blocks that need attention (with their line ranges and content) for a\n * single file/locale pair, so another agent or a human can generate the missing\n * translations.\n *\n * @param report - The report built by {@link buildFileReviewReport}.\n * @param baseFilePath - Absolute path of the base (source) document.\n * @param locale - The target locale being reviewed.\n * @param baseLocale - The base locale used as reference.\n * @param configOptions - Optional Intlayer configuration overrides.\n */\nexport const logReviewFileBlocks = (\n report: ReviewReport,\n baseFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n configOptions?: GetConfigurationOptions\n): void => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger({ log: { ...configuration.log, prefix: '' } });\n\n const formatted = formatReviewReport(report, {\n baseLabel: formatLocale(baseLocale),\n targetLabel: formatLocale(locale),\n });\n\n appLogger(`${formatPath(baseFilePath)} → ${formatLocale(locale)}`);\n for (const line of formatted.split('\\n')) {\n appLogger(line);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAuBA,MAAa,wBAAwB,OACnC,cACA,gBACA,iBAC0B;CAC1B,MAAM,WAAW,MAAM,SAAS,cAAc,OAAO;CACrD,MAAM,aAAa,WAAW,cAAc,IACxC,MAAM,SAAS,gBAAgB,OAAO,CAAC,CAAC,YAAY,EAAE,IACtD;CAEJ,OAAO,kBAAkB;EAAE;EAAU;EAAY;CAAa,CAAC;AACjE;;;;;;;;;;;;AAaA,MAAa,uBACX,QACA,cACA,QACA,YACA,kBACS;CACT,MAAM,gBAAgB,iBAAiB,aAAa;CACpD,MAAM,YAAY,aAAa,EAAE,KAAK;EAAE,GAAG,cAAc;EAAK,QAAQ;CAAG,EAAE,CAAC;CAE5E,MAAM,YAAY,mBAAmB,QAAQ;EAC3C,WAAW,aAAa,UAAU;EAClC,aAAa,aAAa,MAAM;CAClC,CAAC;CAED,UAAU,GAAG,WAAW,YAAY,EAAE,KAAK,aAAa,MAAM,GAAG;CACjE,KAAK,MAAM,QAAQ,UAAU,MAAM,IAAI,GACrC,UAAU,IAAI;AAElB"}
package/dist/esm/scan.mjs CHANGED
@@ -42,7 +42,8 @@ const scoreColor = (score) => {
42
42
  * ```
43
43
  */
44
44
  const scan = async (url, options = {}) => {
45
- const appLogger = getAppLogger(getConfiguration(options.configOptions));
45
+ const configuration = getConfiguration(options.configOptions);
46
+ const appLogger = getAppLogger(configuration);
46
47
  const result = await scanWebsite(url, { deep: options.deep });
47
48
  if (options.json) {
48
49
  appLogger(JSON.stringify(result, null, 2));
@@ -1 +1 @@
1
- {"version":3,"file":"scan.mjs","names":[],"sources":["../../src/scan.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { formatSize, type ScanEvent, scanWebsite } from '@intlayer/engine/scan';\nimport type { ConfigurationOptions } from './cli';\n\n/** Options accepted by the {@link scan} command. */\nexport type ScanCommandOptions = {\n /** Disable the deeper puppeteer-based render scan. */\n deep?: boolean;\n /** Output the raw {@link ScanResult} as JSON instead of formatted text. */\n json?: boolean;\n configOptions?: ConfigurationOptions;\n};\n\n/** Human-readable labels for each scorable check type. */\nconst checkLabels: Record<string, string> = {\n robots_robotsPresent: 'robots.txt present',\n robots_noLocalizedUrlsForgotten: 'robots.txt keeps locale paths crawlable',\n sitemap_sitemapPresent: 'sitemap.xml present',\n sitemap_noLocalizedUrlsForgotten: 'sitemap lists every locale',\n sitemap_hasAlternates: 'sitemap has alternate links',\n sitemap_hasXDefault: 'sitemap has x-default',\n url_htmlLang: 'html lang attribute',\n url_htmlDir: 'html dir attribute',\n url_hasCanonical: 'canonical link',\n url_hreflang: 'hreflang tags',\n url_hasLocalizedLinks: 'localized internal links',\n url_hasXDefault: 'x-default hreflang',\n url_allAnchorsLocalized: 'all internal links localized',\n url_currentLocale: 'current locale detected',\n url_unusedBundleContent: 'unused bundle locale content',\n};\n\nconst statusIcon = (status: ScanEvent['status']): string => {\n if (status === 'success') return colorize('✓', ANSIColors.GREEN);\n if (status === 'warning') return colorize('⚠', ANSIColors.YELLOW);\n return colorize('✗', ANSIColors.RED);\n};\n\nconst scoreColor = (score: number) => {\n if (score >= 80) return ANSIColors.GREEN;\n if (score >= 50) return ANSIColors.YELLOW;\n return ANSIColors.RED;\n};\n\n/**\n * Scan a website for i18n/SEO health and bundle weight, printing a formatted\n * report (or JSON with `--json`).\n *\n * @example\n * ```sh\n * npx intlayer scan https://intlayer.org\n * ```\n */\nexport const scan = async (\n url: string,\n options: ScanCommandOptions = {}\n): Promise<void> => {\n const configuration = getConfiguration(options.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const result = await scanWebsite(url, { deep: options.deep });\n\n if (options.json) {\n appLogger(JSON.stringify(result, null, 2));\n return;\n }\n\n appLogger(\n `\\n🔍 Scanned ${colorize(result.url, ANSIColors.GREY_LIGHT)} ${colorize(\n `(${result.mode} mode)`,\n ANSIColors.GREY\n )}\\n`\n );\n\n appLogger(\n `Score: ${colorize(`${result.score}/100`, scoreColor(result.score))}`\n );\n appLogger(\n `Page size: ${colorize(formatSize(result.totalPageSize), ANSIColors.BLUE)} ${colorize(\n `(HTML ${formatSize(result.htmlSize)})`,\n ANSIColors.GREY\n )}`\n );\n if (result.locales.length > 0) {\n appLogger(\n `Locales: ${colorize(result.locales.join(', '), ANSIColors.GREEN)}`\n );\n }\n\n appLogger('\\nChecks:');\n for (const event of result.events) {\n const type = event.type.split('\\\\')[0];\n\n if (!type) continue;\n\n const label = checkLabels[type] ?? type;\n appLogger(` ${statusIcon(event.status)} ${label}`);\n }\n\n if (result.bundle && result.bundle.totalLocaleSize > 0) {\n const { bundle } = result;\n appLogger('\\nBundle locale weight:');\n appLogger(\n ` Translations shipped: ${colorize(formatSize(bundle.totalLocaleSize), ANSIColors.BLUE)}`\n );\n appLogger(\n ` Unused (other locales): ${colorize(\n `${formatSize(bundle.totalUnusedLocaleSize)} (${bundle.unusedPercentOfLocale}%)`,\n bundle.unusedPercentOfLocale > 30\n ? ANSIColors.RED\n : bundle.unusedPercentOfLocale > 0\n ? ANSIColors.YELLO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O,QAAQ,KAAK,IAAI,GAAG,WAAW,KAAK,GAClE;CAGF,UAAU,WAAW;CACrB,KAAK,MAAM,SAAS,OAAO,QAAQ;EACjC,MAAM,OAAO,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC;EAEpC,IAAI,CAAC,MAAM;EAEX,MAAM,QAAQ,YAAY,SAAS;EACnC,UAAU,KAAK,WAAW,MAAM,MAAM,EAAE,GAAG,OAAO;CACpD;CAEA,IAAI,OAAO,UAAU,OAAO,OAAO,kBAAkB,GAAG;EACtD,MAAM,EAAE,WAAW;EACnB,UAAU,yBAAyB;EACnC,UACE,2BAA2B,SAAS,WAAW,OAAO,eAAe,GAAG,WAAW,IAAI,GACzF;EACA,UACE,6BAA6B,SAC3B,GAAG,WAAW,OAAO,qBAAqB,EAAE,IAAI,OAAO,sBAAsB,KAC7E,OAAO,wBAAwB,KAC3B,WAAW,MACX,OAAO,wBAAwB,IAC7B,WAAW,SACX,WAAW,KACnB,GACF;CACF;AACF"}
1
+ {"version":3,"file":"scan.mjs","names":[],"sources":["../../src/scan.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { formatSize, type ScanEvent, scanWebsite } from '@intlayer/engine/scan';\nimport type { ConfigurationOptions } from './cli';\n\n/** Options accepted by the {@link scan} command. */\nexport type ScanCommandOptions = {\n /** Disable the deeper puppeteer-based render scan. */\n deep?: boolean;\n /** Output the raw {@link ScanResult} as JSON instead of formatted text. */\n json?: boolean;\n configOptions?: ConfigurationOptions;\n};\n\n/** Human-readable labels for each scorable check type. */\nconst checkLabels: Record<string, string> = {\n robots_robotsPresent: 'robots.txt present',\n robots_noLocalizedUrlsForgotten: 'robots.txt keeps locale paths crawlable',\n sitemap_sitemapPresent: 'sitemap.xml present',\n sitemap_noLocalizedUrlsForgotten: 'sitemap lists every locale',\n sitemap_hasAlternates: 'sitemap has alternate links',\n sitemap_hasXDefault: 'sitemap has x-default',\n url_htmlLang: 'html lang attribute',\n url_htmlDir: 'html dir attribute',\n url_hasCanonical: 'canonical link',\n url_hreflang: 'hreflang tags',\n url_hasLocalizedLinks: 'localized internal links',\n url_hasXDefault: 'x-default hreflang',\n url_allAnchorsLocalized: 'all internal links localized',\n url_currentLocale: 'current locale detected',\n url_unusedBundleContent: 'unused bundle locale content',\n};\n\nconst statusIcon = (status: ScanEvent['status']): string => {\n if (status === 'success') return colorize('✓', ANSIColors.GREEN);\n if (status === 'warning') return colorize('⚠', ANSIColors.YELLOW);\n return colorize('✗', ANSIColors.RED);\n};\n\nconst scoreColor = (score: number) => {\n if (score >= 80) return ANSIColors.GREEN;\n if (score >= 50) return ANSIColors.YELLOW;\n return ANSIColors.RED;\n};\n\n/**\n * Scan a website for i18n/SEO health and bundle weight, printing a formatted\n * report (or JSON with `--json`).\n *\n * @example\n * ```sh\n * npx intlayer scan https://intlayer.org\n * ```\n */\nexport const scan = async (\n url: string,\n options: ScanCommandOptions = {}\n): Promise<void> => {\n const configuration = getConfiguration(options.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const result = await scanWebsite(url, { deep: options.deep });\n\n if (options.json) {\n appLogger(JSON.stringify(result, null, 2));\n return;\n }\n\n appLogger(\n `\\n🔍 Scanned ${colorize(result.url, ANSIColors.GREY_LIGHT)} ${colorize(\n `(${result.mode} mode)`,\n ANSIColors.GREY\n )}\\n`\n );\n\n appLogger(\n `Score: ${colorize(`${result.score}/100`, scoreColor(result.score))}`\n );\n appLogger(\n `Page size: ${colorize(formatSize(result.totalPageSize), ANSIColors.BLUE)} ${colorize(\n `(HTML ${formatSize(result.htmlSize)})`,\n ANSIColors.GREY\n )}`\n );\n if (result.locales.length > 0) {\n appLogger(\n `Locales: ${colorize(result.locales.join(', '), ANSIColors.GREEN)}`\n );\n }\n\n appLogger('\\nChecks:');\n for (const event of result.events) {\n const type = event.type.split('\\\\')[0];\n\n if (!type) continue;\n\n const label = checkLabels[type] ?? type;\n appLogger(` ${statusIcon(event.status)} ${label}`);\n }\n\n if (result.bundle && result.bundle.totalLocaleSize > 0) {\n const { bundle } = result;\n appLogger('\\nBundle locale weight:');\n appLogger(\n ` Translations shipped: ${colorize(formatSize(bundle.totalLocaleSize), ANSIColors.BLUE)}`\n );\n appLogger(\n ` Unused (other locales): ${colorize(\n `${formatSize(bundle.totalUnusedLocaleSize)} (${bundle.unusedPercentOfLocale}%)`,\n bundle.unusedPercentOfLocale > 30\n ? ANSIColors.RED\n : bundle.unusedPercentOfLocale > 0\n ? ANSIColors.YELLOW\n : ANSIColors.GREEN\n )}`\n );\n }\n};\n"],"mappings":";;;;;;;AAgBA,MAAM,cAAsC;CAC1C,sBAAsB;CACtB,iCAAiC;CACjC,wBAAwB;CACxB,kCAAkC;CAClC,uBAAuB;CACvB,qBAAqB;CACrB,cAAc;CACd,aAAa;CACb,kBAAkB;CAClB,cAAc;CACd,uBAAuB;CACvB,iBAAiB;CACjB,yBAAyB;CACzB,mBAAmB;CACnB,yBAAyB;AAC3B;AAEA,MAAM,cAAc,WAAwC;CAC1D,IAAI,WAAW,WAAW,OAAO,SAAS,KAAK,WAAW,KAAK;CAC/D,IAAI,WAAW,WAAW,OAAO,SAAS,KAAK,WAAW,MAAM;CAChE,OAAO,SAAS,KAAK,WAAW,GAAG;AACrC;AAEA,MAAM,cAAc,UAAkB;CACpC,IAAI,SAAS,IAAI,OAAO,WAAW;CACnC,IAAI,SAAS,IAAI,OAAO,WAAW;CACnC,OAAO,WAAW;AACpB;;;;;;;;;;AAWA,MAAa,OAAO,OAClB,KACA,UAA8B,CAAC,MACb;CAClB,MAAM,gBAAgB,iBAAiB,QAAQ,aAAa;CAC5D,MAAM,YAAY,aAAa,aAAa;CAE5C,MAAM,SAAS,MAAM,YAAY,KAAK,EAAE,MAAM,QAAQ,KAAK,CAAC;CAE5D,IAAI,QAAQ,MAAM;EAChB,UAAU,KAAK,UAAU,QAAQ,MAAM,CAAC,CAAC;EACzC;CACF;CAEA,UACE,gBAAgB,SAAS,OAAO,KAAK,WAAW,UAAU,EAAE,GAAG,SAC7D,IAAI,OAAO,KAAK,SAChB,WAAW,IACb,EAAE,GACJ;CAEA,UACE,UAAU,SAAS,GAAG,OAAO,MAAM,OAAO,WAAW,OAAO,KAAK,CAAC,GACpE;CACA,UACE,cAAc,SAAS,WAAW,OAAO,aAAa,GAAG,WAAW,IAAI,EAAE,GAAG,SAC3E,SAAS,WAAW,OAAO,QAAQ,EAAE,IACrC,WAAW,IACb,GACF;CACA,IAAI,OAAO,QAAQ,SAAS,GAC1B,UACE,YAAY,SAAS,OAAO,QAAQ,KAAK,IAAI,GAAG,WAAW,KAAK,GAClE;CAGF,UAAU,WAAW;CACrB,KAAK,MAAM,SAAS,OAAO,QAAQ;EACjC,MAAM,OAAO,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC;EAEpC,IAAI,CAAC,MAAM;EAEX,MAAM,QAAQ,YAAY,SAAS;EACnC,UAAU,KAAK,WAAW,MAAM,MAAM,EAAE,GAAG,OAAO;CACpD;CAEA,IAAI,OAAO,UAAU,OAAO,OAAO,kBAAkB,GAAG;EACtD,MAAM,EAAE,WAAW;EACnB,UAAU,yBAAyB;EACnC,UACE,2BAA2B,SAAS,WAAW,OAAO,eAAe,GAAG,WAAW,IAAI,GACzF;EACA,UACE,6BAA6B,SAC3B,GAAG,WAAW,OAAO,qBAAqB,EAAE,IAAI,OAAO,sBAAsB,KAC7E,OAAO,wBAAwB,KAC3B,WAAW,MACX,OAAO,wBAAwB,IAC7B,WAAW,SACX,WAAW,KACnB,GACF;CACF;AACF"}
@@ -41,7 +41,7 @@ const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLoca
41
41
  maxErrors: 5,
42
42
  shouldStop: false
43
43
  };
44
- await parallelize(docList.flatMap((docPath) => locales.map((locale) => async () => {
44
+ const allTasks = docList.flatMap((docPath) => locales.map((locale) => async () => {
45
45
  if (errorState.shouldStop) return;
46
46
  const absoluteBaseFilePath = join(configuration.system.baseDir, docPath);
47
47
  const outputFilePath = getOutputFilePath(absoluteBaseFilePath, locale, baseLocale);
@@ -72,7 +72,8 @@ const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLoca
72
72
  flushStrategy,
73
73
  limit: globalChunkLimiter
74
74
  });
75
- })), (task) => task(), 50);
75
+ }));
76
+ await parallelize(allTasks, (task) => task(), 50);
76
77
  const batchDuration = ((performance.now() - batchStartTime) / 1e3).toFixed(2);
77
78
  if (errorState.count > 0) appLogger(`Finished with ${errorState.count} errors in ${batchDuration}s.`);
78
79
  else appLogger(`${colorize("✔", ANSIColors.GREEN)} Batch completed successfully in ${colorizeNumber(batchDuration)}s.`);
@@ -1 +1 @@
1
- {"version":3,"file":"translateDoc.mjs","names":[],"sources":["../../../src/translateDoc/translateDoc.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colorize,\n colorizeNumber,\n getAppLogger,\n x,\n} from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { listGitFiles, logConfigDetails } from '@intlayer/engine/cli';\nimport { parallelize, pLimit } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport fg from 'fast-glob';\nimport { checkFileModifiedRange } from '../utils/checkFileModifiedRange';\nimport { getOutputFilePath } from '../utils/getOutputFilePath';\nimport { setupAI } from '../utils/setupAI';\nimport { translateFile } from './translateFile';\nimport type { ErrorState, TranslateDocOptions } from './types';\n\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed = 20, // Default to a higher concurrency for chunks\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n flushStrategy = 'incremental',\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n logConfigDetails(configOptions);\n\n const appLogger = getAppLogger(configuration);\n\n // 1. GLOBAL QUEUE SETUP\n // We use pLimit to create a single bottleneck for AI requests.\n // This queue is shared across all files and locales.\n const maxConcurrentChunks = nbSimultaneousFileProcessed;\n const globalChunkLimiter = pLimit(maxConcurrentChunks);\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const aiResult = await setupAI(configuration, aiOptions);\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig, isCustomAI } = aiResult;\n if (isCustomAI && aiClient && aiConfig) {\n const { hasAIAccess, error } = await aiClient.checkAISDKAccess(aiConfig);\n if (!hasAIAccess) {\n appLogger(`${x} ${error}`);\n return;\n }\n }\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n if (gitChangedFiles) {\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n const batchStartTime = performance.now();\n\n appLogger(\n `Translating ${colorizeNumber(docList.length)} files to ${colorizeNumber(locales.length)} locales. \\n` +\n `Global Concurrency: ${colorizeNumber(maxConcurrentChunks)} chunks in parallel.`\n );\n\n const errorState: ErrorState = {\n count: 0,\n maxErrors: 5,\n shouldStop: false,\n };\n\n // FLATTENED TASK LIST\n // We create a task for every File x Locale combination.\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n if (errorState.shouldStop) return;\n\n const absoluteBaseFilePath = join(configuration.system.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip logic\n if (skipIfExists && existsSync(outputFilePath)) return;\n\n if (flushStrategy === 'incremental' && !existsSync(outputFilePath)) {\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n // Execute translation using the SHARED limiter\n await translateFile({\n baseFilePath: absoluteBaseFilePath,\n outputFilePath,\n locale: locale as Locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy,\n limit: globalChunkLimiter, // Pass the global queue\n });\n })\n );\n\n // HIGH-THROUGHPUT FILE OPENER\n // We open many files simultaneously (e.g., 50) to ensure the global chunk queue\n // is always saturated with work.\n // If we open too few files, the chunk queue might drain faster than we can read new files.\n const FILE_OPEN_LIMIT = 50;\n\n await parallelize(allTasks, (task) => task(), FILE_OPEN_LIMIT);\n\n const batchEndTime = performance.now();\n const batchDuration = ((batchEndTime - batchStartTime) / 1000).toFixed(2);\n\n if (errorState.count > 0) {\n appLogger(`Finished with ${errorState.count} errors in ${batchDuration}s.`);\n } else {\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} Batch completed successfully in ${colorizeNumber(batchDuration)}s.`\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,MAAa,eAAe,OAAO,EACjC,YACA,SACA,qBACA,YACA,WACA,8BAA8B,IAC9B,eACA,oBACA,sBACA,qBACA,cACA,YACA,gBAAgB,oBACS;CACzB,MAAM,gBAAgB,iBAAiB,aAAa;CACpD,iBAAiB,aAAa;CAE9B,MAAM,YAAY,aAAa,aAAa;CAK5C,MAAM,sBAAsB;CAC5B,MAAM,qBAAqB,OAAO,mBAAmB;CAErD,IAAI,UAAoB,MAAM,GAAG,YAAY,EAC3C,QAAQ,oBACV,CAAC;CAED,MAAM,WAAW,MAAM,QAAQ,eAAe,SAAS;CACvD,IAAI,CAAC,UAAU,aAAa;CAE5B,MAAM,EAAE,UAAU,UAAU,eAAe;CAC3C,IAAI,cAAc,YAAY,UAAU;EACtC,MAAM,EAAE,aAAa,UAAU,MAAM,SAAS,iBAAiB,QAAQ;EACvE,IAAI,CAAC,aAAa;GAChB,UAAU,GAAG,EAAE,GAAG,OAAO;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Ae,aAAa,EAAE,GACtG;AAEJ"}
1
+ {"version":3,"file":"translateDoc.mjs","names":[],"sources":["../../../src/translateDoc/translateDoc.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colorize,\n colorizeNumber,\n getAppLogger,\n x,\n} from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { listGitFiles, logConfigDetails } from '@intlayer/engine/cli';\nimport { parallelize, pLimit } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport fg from 'fast-glob';\nimport { checkFileModifiedRange } from '../utils/checkFileModifiedRange';\nimport { getOutputFilePath } from '../utils/getOutputFilePath';\nimport { setupAI } from '../utils/setupAI';\nimport { translateFile } from './translateFile';\nimport type { ErrorState, TranslateDocOptions } from './types';\n\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed = 20, // Default to a higher concurrency for chunks\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n flushStrategy = 'incremental',\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n logConfigDetails(configOptions);\n\n const appLogger = getAppLogger(configuration);\n\n // 1. GLOBAL QUEUE SETUP\n // We use pLimit to create a single bottleneck for AI requests.\n // This queue is shared across all files and locales.\n const maxConcurrentChunks = nbSimultaneousFileProcessed;\n const globalChunkLimiter = pLimit(maxConcurrentChunks);\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const aiResult = await setupAI(configuration, aiOptions);\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig, isCustomAI } = aiResult;\n if (isCustomAI && aiClient && aiConfig) {\n const { hasAIAccess, error } = await aiClient.checkAISDKAccess(aiConfig);\n if (!hasAIAccess) {\n appLogger(`${x} ${error}`);\n return;\n }\n }\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n if (gitChangedFiles) {\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n const batchStartTime = performance.now();\n\n appLogger(\n `Translating ${colorizeNumber(docList.length)} files to ${colorizeNumber(locales.length)} locales. \\n` +\n `Global Concurrency: ${colorizeNumber(maxConcurrentChunks)} chunks in parallel.`\n );\n\n const errorState: ErrorState = {\n count: 0,\n maxErrors: 5,\n shouldStop: false,\n };\n\n // FLATTENED TASK LIST\n // We create a task for every File x Locale combination.\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n if (errorState.shouldStop) return;\n\n const absoluteBaseFilePath = join(configuration.system.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip logic\n if (skipIfExists && existsSync(outputFilePath)) return;\n\n if (flushStrategy === 'incremental' && !existsSync(outputFilePath)) {\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n // Execute translation using the SHARED limiter\n await translateFile({\n baseFilePath: absoluteBaseFilePath,\n outputFilePath,\n locale: locale as Locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy,\n limit: globalChunkLimiter, // Pass the global queue\n });\n })\n );\n\n // HIGH-THROUGHPUT FILE OPENER\n // We open many files simultaneously (e.g., 50) to ensure the global chunk queue\n // is always saturated with work.\n // If we open too few files, the chunk queue might drain faster than we can read new files.\n const FILE_OPEN_LIMIT = 50;\n\n await parallelize(allTasks, (task) => task(), FILE_OPEN_LIMIT);\n\n const batchEndTime = performance.now();\n const batchDuration = ((batchEndTime - batchStartTime) / 1000).toFixed(2);\n\n if (errorState.count > 0) {\n appLogger(`Finished with ${errorState.count} errors in ${batchDuration}s.`);\n } else {\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} Batch completed successfully in ${colorizeNumber(batchDuration)}s.`\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,MAAa,eAAe,OAAO,EACjC,YACA,SACA,qBACA,YACA,WACA,8BAA8B,IAC9B,eACA,oBACA,sBACA,qBACA,cACA,YACA,gBAAgB,oBACS;CACzB,MAAM,gBAAgB,iBAAiB,aAAa;CACpD,iBAAiB,aAAa;CAE9B,MAAM,YAAY,aAAa,aAAa;CAK5C,MAAM,sBAAsB;CAC5B,MAAM,qBAAqB,OAAO,mBAAmB;CAErD,IAAI,UAAoB,MAAM,GAAG,YAAY,EAC3C,QAAQ,oBACV,CAAC;CAED,MAAM,WAAW,MAAM,QAAQ,eAAe,SAAS;CACvD,IAAI,CAAC,UAAU,aAAa;CAE5B,MAAM,EAAE,UAAU,UAAU,eAAe;CAC3C,IAAI,cAAc,YAAY,UAAU;EACtC,MAAM,EAAE,aAAa,UAAU,MAAM,SAAS,iBAAiB,QAAQ;EACvE,IAAI,CAAC,aAAa;GAChB,UAAU,GAAG,EAAE,GAAG,OAAO;GACzB;EACF;CACF;CAEA,IAAI,YAAY;EACd,MAAM,kBAAkB,MAAM,aAAa,UAAU;EACrD,IAAI,iBACF,UAAU,QAAQ,QAAQ,SACxB,gBAAgB,MAAM,YAAY,KAAK,QAAQ,IAAI,GAAG,IAAI,MAAM,OAAO,CACzE;CAEJ;CAEA,MAAM,iBAAiB,YAAY,IAAI;CAEvC,UACE,eAAe,eAAe,QAAQ,MAAM,EAAE,YAAY,eAAe,QAAQ,MAAM,EAAE,kCAChE,eAAe,mBAAmB,EAAE,qBAC/D;CAEA,MAAM,aAAyB;EAC7B,OAAO;EACP,WAAW;EACX,YAAY;CACd;CAIA,MAAM,WAAW,QAAQ,SAAS,YAChC,QAAQ,KAAK,WAAW,YAAY;EAClC,IAAI,WAAW,YAAY;EAE3B,MAAM,uBAAuB,KAAK,cAAc,OAAO,SAAS,OAAO;EACvE,MAAM,iBAAiB,kBACrB,sBACA,QACA,UACF;EAGA,IAAI,gBAAgB,WAAW,cAAc,GAAG;EAEhD,IAAI,kBAAkB,iBAAiB,CAAC,WAAW,cAAc,GAAG;GAClE,UAAU,QAAQ,cAAc,GAAG,EAAE,WAAW,KAAK,CAAC;GACtD,cAAc,gBAAgB,EAAE;EAClC;EAEA,MAAM,uBAAuB,uBAAuB,gBAAgB;GAClE;GACA;EACF,CAAC;EAED,IAAI,qBAAqB,WAAW;GAClC,UAAU,qBAAqB,OAAO;GACtC;EACF;EAGA,MAAM,cAAc;GAClB,cAAc;GACd;GACQ;GACR;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,OAAO;EACT,CAAC;CACH,CAAC,CACH;CAQA,MAAM,YAAY,WAAW,SAAS,KAAK,GAAG,EAAe;CAG7D,MAAM,kBADe,YAAY,IACE,IAAI,kBAAkB,IAAI,CAAE,QAAQ,CAAC;CAExE,IAAI,WAAW,QAAQ,GACrB,UAAU,iBAAiB,WAAW,MAAM,aAAa,cAAc,GAAG;MAE1E,UACE,GAAG,SAAS,KAAK,WAAW,KAAK,EAAE,mCAAmC,eAAe,aAAa,EAAE,GACtG;AAEJ"}
@@ -17,10 +17,13 @@ const translateFile = async ({ baseFilePath, outputFilePath, locale, baseLocale,
17
17
  const appLogger = getAppLogger(configuration, { config: { prefix: "" } });
18
18
  const fileStartTime = performance.now();
19
19
  try {
20
- const chunks = chunkText(await readFile(baseFilePath, "utf-8"));
20
+ const fileContent = await readFile(baseFilePath, "utf-8");
21
+ const chunks = chunkText(fileContent);
21
22
  const totalChunks = chunks.length;
22
- const filePrefix = `${colon(`${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `, { colSize: 40 })}${ANSIColors.RESET}`;
23
- const prefix = `${colon(`${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `, { colSize: 40 })}${ANSIColors.RESET}`;
23
+ const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;
24
+ const filePrefix = `${colon(filePrefixText, { colSize: 40 })}${ANSIColors.RESET}`;
25
+ const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;
26
+ const prefix = `${colon(prefixText, { colSize: 40 })}${ANSIColors.RESET}`;
24
27
  appLogger(`${filePrefix}Split into ${colorizeNumber(totalChunks)} chunks. Queuing...`);
25
28
  const basePrompt = readAsset("./prompts/TRANSLATE_PROMPT.md", "utf-8").replaceAll("{{localeName}}", `${formatLocale(locale, false)}`).replaceAll("{{baseLocaleName}}", `${formatLocale(baseLocale, false)}`).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
26
29
  const translatedParts = new Array(totalChunks).fill("");
@@ -1 +1 @@
1
- {"version":3,"file":"translateFile.mjs","names":[],"sources":["../../../src/translateDoc/translateFile.ts"],"sourcesContent":["import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname, relative } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport { readAsset } from 'utils:asset';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { retryManager } from '@intlayer/config/utils';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport { chunkText } from '../utils/calculateChunks';\nimport { chunkInference } from '../utils/chunkInference';\nimport { fixChunkStartEndChars } from '../utils/fixChunkStartEndChars';\nimport type { TranslateFileOptions } from './types';\nimport { sanitizeChunk, validateTranslation } from './validation';\n\nexport const translateFile = async ({\n baseFilePath,\n outputFilePath,\n locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy = 'incremental',\n onChunkReceive,\n limit, // The Global Limiter\n}: TranslateFileOptions): Promise<string | null> => {\n if (errorState.shouldStop) return null;\n\n const appLogger = getAppLogger(configuration, { config: { prefix: '' } });\n const fileStartTime = performance.now();\n\n try {\n const fileContent = await readFile(baseFilePath, 'utf-8');\n const chunks = chunkText(fileContent);\n const totalChunks = chunks.length;\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = `${colon(filePrefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = `${colon(prefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n\n appLogger(\n `${filePrefix}Split into ${colorizeNumber(totalChunks)} chunks. Queuing...`\n );\n\n const basePrompt = readAsset('./prompts/TRANSLATE_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const translatedParts: string[] = new Array(totalChunks).fill('');\n\n // Fallback if no limiter is provided (runs immediately)\n const runTask = limit ?? ((fn) => fn());\n\n // MAP CHUNKS TO GLOBAL TASKS\n // This pushes ALL chunks for this file into the Global Queue immediately.\n // They will execute whenever the global concurrency slots open up.\n const tasks = chunks.map((chunk, i) =>\n runTask(async () => {\n if (errorState.shouldStop) return null;\n\n const chunkLogger = getAppLogger(configuration, {\n config: {\n prefix: `${prefix} ${ANSIColors.GREY_DARK}[${i + 1}/${totalChunks}] ${ANSIColors.RESET}`,\n },\n });\n\n const chunkStartTime = performance.now();\n const isFirstChunk = i === 0;\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Context Preparation\n const getPrevChunkPrompt = () =>\n `>>> CONTEXT: PREVIOUS SOURCE CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i - 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END PREVIOUS CONTEXT <<<`;\n\n const getBaseChunkContextPrompt = () =>\n `>>> CONTEXT: NEXT CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i + 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END NEXT CONTEXT <<<`;\n\n chunkLogger('Process started');\n\n const chunkTranslation = retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n ...(chunks[i + 1]\n ? [\n {\n role: 'system',\n content: getBaseChunkContextPrompt(),\n } as const,\n ]\n : []),\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: [\n `You are translating TARGET CHUNK (${i + 1}/${totalChunks}).`,\n `Translate ONLY the target chunk. Preserve frontmatter/code exactly.`,\n ].join('\\n'),\n },\n ],\n [\n {\n role: 'user',\n content: `>>> TARGET CHUNK START <<<\\n${fileToTranslateCurrentChunk}\\n>>> TARGET CHUNK END <<<`,\n },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n processedChunk = fixChunkStartEndChars(\n processedChunk,\n fileToTranslateCurrentChunk\n );\n\n const isValid = validateTranslation(\n fileToTranslateCurrentChunk,\n processedChunk,\n chunkLogger\n );\n\n if (!isValid) {\n // Throwing an error here signals retryManager to try again\n throw new Error(\n `Validation failed for chunk ${i + 1}/${totalChunks}`\n );\n }\n\n return { content: processedChunk, tokens: result.tokenUsed };\n });\n\n const { content: translatedChunk, tokens } = await chunkTranslation();\n const chunkEndTime = performance.now();\n const chunkDuration = (chunkEndTime - chunkStartTime).toFixed(0);\n\n // Store Result\n translatedParts[i] = translatedChunk;\n\n if (onChunkReceive) {\n onChunkReceive(translatedChunk, i, totalChunks);\n }\n\n // Incremental Flush Strategy\n if (flushStrategy === 'incremental') {\n const isContiguous = translatedParts\n .slice(0, i + 1)\n .every((p) => p && p !== '');\n\n if (isContiguous) {\n let endIdx = 0;\n while (\n endIdx < totalChunks &&\n translatedParts[endIdx] &&\n translatedParts[endIdx] !== ''\n ) {\n endIdx++;\n }\n const currentContent = translatedParts.slice(0, endIdx).join('');\n // Write asynchronously/sync is fine here as node handles file locks reasonably well for single process\n await mkdir(dirname(outputFilePath), { recursive: true });\n await writeFile(outputFilePath, currentContent);\n }\n }\n\n chunkLogger(\n [\n `${colorizeNumber(tokens)} tokens used `,\n `${ANSIColors.GREY_DARK}in ${colorizeNumber(chunkDuration)}ms${ANSIColors.RESET}`,\n ].join('')\n );\n })\n );\n\n // Wait for all chunks for this specific file/locale to finish\n await Promise.all(tasks);\n\n // Final Flush\n const fullContent = translatedParts.join('');\n if (flushStrategy === 'end' || flushStrategy === 'incremental') {\n await mkdir(dirname(outputFilePath), { recursive: true });\n await writeFile(outputFilePath, fullContent);\n }\n\n const fileEndTime = performance.now();\n const totalDuration = ((fileEndTime - fileStartTime) / 1000).toFixed(2);\n const relativePath = relative(configuration.system.baseDir, outputFilePath);\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} completed in ${colorizeNumber(totalDuration)}s.`\n );\n\n return fullContent;\n } catch (error: any) {\n errorState.count++;\n const errorMessage = error?.message ?? JSON.stringify(error);\n appLogger(`${colorize('✖', ANSIColors.RED)} Error: ${errorMessage}`);\n if (errorState.count >= errorState.maxErrors) errorState.shouldStop = true;\n return null;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AAmBA,MAAa,gBAAgB,OAAO,EAClC,cACA,gBACA,QACA,YACA,eACA,YACA,WACA,oBACA,UACA,UACA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F,MAAM,iBAAiB,gBAAgB,MAAM,GAAG,MAAM,CAAC,CAAC,KAAK,EAAE;KAE/D,MAAM,MAAM,QAAQ,cAAc,GAAG,EAAE,WAAW,KAAK,CAAC;KACxD,MAAM,UAAU,gBAAgB,cAAc;IAChD;;GAGF,YACE,CACE,GAAG,eAAe,MAAM,EAAE,gBAC1B,GAAG,WAAW,UAAU,KAAK,eAAe,aAAa,EAAE,IAAI,WAAW,OAC5E,CAAC,CAAC,KAAK,EAAE,CACX;EACF,CAAC,CACH;EAGA,MAAM,QAAQ,IAAI,KAAK;EAGvB,MAAM,cAAc,gBAAgB,KAAK,EAAE;EAC3C,IAAI,kBAAkB,SAAS,kBAAkB,eAAe;GAC9D,MAAM,MAAM,QAAQ,cAAc,GAAG,EAAE,WAAW,KAAK,CAAC;GACxD,MAAM,UAAU,gBAAgB,WAAW;EAC7C;EAGA,MAAM,kBADc,YAAY,IACE,IAAI,iBAAiB,IAAI,CAAE,QAAQ,CAAC;EACtE,MAAM,eAAe,SAAS,cAAc,OAAO,SAAS,cAAc;EAE1E,UACE,GAAG,SAAS,KAAK,WAAW,KAAK,EAAE,QAAQ,WAAW,YAAY,EAAE,gBAAgB,eAAe,aAAa,EAAE,GACpH;EAEA,OAAO;CACT,SAAS,OAAY;EACnB,WAAW;EACX,MAAM,eAAe,OAAO,WAAW,KAAK,UAAU,KAAK;EAC3D,UAAU,GAAG,SAAS,KAAK,WAAW,GAAG,EAAE,UAAU,cAAc;EACnE,IAAI,WAAW,SAAS,WAAW,WAAW,WAAW,aAAa;EACtE,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"translateFile.mjs","names":[],"sources":["../../../src/translateDoc/translateFile.ts"],"sourcesContent":["import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname, relative } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport { readAsset } from 'utils:asset';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { retryManager } from '@intlayer/config/utils';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\nimport { chunkText } from '../utils/calculateChunks';\nimport { chunkInference } from '../utils/chunkInference';\nimport { fixChunkStartEndChars } from '../utils/fixChunkStartEndChars';\nimport type { TranslateFileOptions } from './types';\nimport { sanitizeChunk, validateTranslation } from './validation';\n\nexport const translateFile = async ({\n baseFilePath,\n outputFilePath,\n locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy = 'incremental',\n onChunkReceive,\n limit, // The Global Limiter\n}: TranslateFileOptions): Promise<string | null> => {\n if (errorState.shouldStop) return null;\n\n const appLogger = getAppLogger(configuration, { config: { prefix: '' } });\n const fileStartTime = performance.now();\n\n try {\n const fileContent = await readFile(baseFilePath, 'utf-8');\n const chunks = chunkText(fileContent);\n const totalChunks = chunks.length;\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = `${colon(filePrefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = `${colon(prefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n\n appLogger(\n `${filePrefix}Split into ${colorizeNumber(totalChunks)} chunks. Queuing...`\n );\n\n const basePrompt = readAsset('./prompts/TRANSLATE_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const translatedParts: string[] = new Array(totalChunks).fill('');\n\n // Fallback if no limiter is provided (runs immediately)\n const runTask = limit ?? ((fn) => fn());\n\n // MAP CHUNKS TO GLOBAL TASKS\n // This pushes ALL chunks for this file into the Global Queue immediately.\n // They will execute whenever the global concurrency slots open up.\n const tasks = chunks.map((chunk, i) =>\n runTask(async () => {\n if (errorState.shouldStop) return null;\n\n const chunkLogger = getAppLogger(configuration, {\n config: {\n prefix: `${prefix} ${ANSIColors.GREY_DARK}[${i + 1}/${totalChunks}] ${ANSIColors.RESET}`,\n },\n });\n\n const chunkStartTime = performance.now();\n const isFirstChunk = i === 0;\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Context Preparation\n const getPrevChunkPrompt = () =>\n `>>> CONTEXT: PREVIOUS SOURCE CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i - 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END PREVIOUS CONTEXT <<<`;\n\n const getBaseChunkContextPrompt = () =>\n `>>> CONTEXT: NEXT CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i + 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END NEXT CONTEXT <<<`;\n\n chunkLogger('Process started');\n\n const chunkTranslation = retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n ...(chunks[i + 1]\n ? [\n {\n role: 'system',\n content: getBaseChunkContextPrompt(),\n } as const,\n ]\n : []),\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: [\n `You are translating TARGET CHUNK (${i + 1}/${totalChunks}).`,\n `Translate ONLY the target chunk. Preserve frontmatter/code exactly.`,\n ].join('\\n'),\n },\n ],\n [\n {\n role: 'user',\n content: `>>> TARGET CHUNK START <<<\\n${fileToTranslateCurrentChunk}\\n>>> TARGET CHUNK END <<<`,\n },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n processedChunk = fixChunkStartEndChars(\n processedChunk,\n fileToTranslateCurrentChunk\n );\n\n const isValid = validateTranslation(\n fileToTranslateCurrentChunk,\n processedChunk,\n chunkLogger\n );\n\n if (!isValid) {\n // Throwing an error here signals retryManager to try again\n throw new Error(\n `Validation failed for chunk ${i + 1}/${totalChunks}`\n );\n }\n\n return { content: processedChunk, tokens: result.tokenUsed };\n });\n\n const { content: translatedChunk, tokens } = await chunkTranslation();\n const chunkEndTime = performance.now();\n const chunkDuration = (chunkEndTime - chunkStartTime).toFixed(0);\n\n // Store Result\n translatedParts[i] = translatedChunk;\n\n if (onChunkReceive) {\n onChunkReceive(translatedChunk, i, totalChunks);\n }\n\n // Incremental Flush Strategy\n if (flushStrategy === 'incremental') {\n const isContiguous = translatedParts\n .slice(0, i + 1)\n .every((p) => p && p !== '');\n\n if (isContiguous) {\n let endIdx = 0;\n while (\n endIdx < totalChunks &&\n translatedParts[endIdx] &&\n translatedParts[endIdx] !== ''\n ) {\n endIdx++;\n }\n const currentContent = translatedParts.slice(0, endIdx).join('');\n // Write asynchronously/sync is fine here as node handles file locks reasonably well for single process\n await mkdir(dirname(outputFilePath), { recursive: true });\n await writeFile(outputFilePath, currentContent);\n }\n }\n\n chunkLogger(\n [\n `${colorizeNumber(tokens)} tokens used `,\n `${ANSIColors.GREY_DARK}in ${colorizeNumber(chunkDuration)}ms${ANSIColors.RESET}`,\n ].join('')\n );\n })\n );\n\n // Wait for all chunks for this specific file/locale to finish\n await Promise.all(tasks);\n\n // Final Flush\n const fullContent = translatedParts.join('');\n if (flushStrategy === 'end' || flushStrategy === 'incremental') {\n await mkdir(dirname(outputFilePath), { recursive: true });\n await writeFile(outputFilePath, fullContent);\n }\n\n const fileEndTime = performance.now();\n const totalDuration = ((fileEndTime - fileStartTime) / 1000).toFixed(2);\n const relativePath = relative(configuration.system.baseDir, outputFilePath);\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} completed in ${colorizeNumber(totalDuration)}s.`\n );\n\n return fullContent;\n } catch (error: any) {\n errorState.count++;\n const errorMessage = error?.message ?? JSON.stringify(error);\n appLogger(`${colorize('✖', ANSIColors.RED)} Error: ${errorMessage}`);\n if (errorState.count >= errorState.maxErrors) errorState.shouldStop = true;\n return null;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AAmBA,MAAa,gBAAgB,OAAO,EAClC,cACA,gBACA,QACA,YACA,eACA,YACA,WACA,oBACA,UACA,UACA,gBAAgB,eAChB,gBACA,YACkD;CAClD,IAAI,WAAW,YAAY,OAAO;CAElC,MAAM,YAAY,aAAa,eAAe,EAAE,QAAQ,EAAE,QAAQ,GAAG,EAAE,CAAC;CACxE,MAAM,gBAAgB,YAAY,IAAI;CAEtC,IAAI;EACF,MAAM,cAAc,MAAM,SAAS,cAAc,OAAO;EACxD,MAAM,SAAS,UAAU,WAAW;EACpC,MAAM,cAAc,OAAO;EAE3B,MAAM,iBAAiB,GAAG,WAAW,UAAU,GAAG,WAAW,YAAY,IAAI,WAAW,UAAU;EAClG,MAAM,aAAa,GAAG,MAAM,gBAAgB,EAAE,SAAS,GAAG,CAAC,IAAI,WAAW;EAC1E,MAAM,aAAa,GAAG,WAAW,UAAU,GAAG,WAAW,YAAY,IAAI,WAAW,UAAU,IAAI,aAAa,MAAM,IAAI,WAAW,UAAU;EAC9I,MAAM,SAAS,GAAG,MAAM,YAAY,EAAE,SAAS,GAAG,CAAC,IAAI,WAAW;EAElE,UACE,GAAG,WAAW,aAAa,eAAe,WAAW,EAAE,oBACzD;EAEA,MAAM,aAAa,UAAU,iCAAiC,OAAO,CAAC,CACnE,WAAW,kBAAkB,GAAG,aAAa,QAAQ,KAAK,GAAG,CAAC,CAC9D,WAAW,sBAAsB,GAAG,aAAa,YAAY,KAAK,GAAG,CAAC,CACtE,QAAQ,0BAA0B,WAAW,sBAAsB,GAAG,CAAC,CACvE,QAAQ,0BAA0B,sBAAsB,GAAG;EAE9D,MAAM,kBAA4B,IAAI,MAAM,WAAW,CAAC,CAAC,KAAK,EAAE;EAGhE,MAAM,UAAU,WAAW,OAAO,GA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WAAW,WAAW,aAAa;EACtE,OAAO;CACT;AACF"}
@@ -8,7 +8,7 @@ import { formatTimeDiff } from "./formatTimeDiff.mjs";
8
8
  * 50 years expressed in milliseconds is far greater than any reasonable
9
9
  * "relative" duration we expect the helper to receive (e.g. a couple of years).
10
10
  */
11
- const TIMESTAMP_THRESHOLD_MS = 50 * 365 * 24 * 60 * 60 * 1e3;
11
+ const TIMESTAMP_THRESHOLD_MS = 15768e8;
12
12
  /**
13
13
  * Normalises the input date representation into a pair:
14
14
  * 1. `relativeTime` – a Date instance whose epoch-time equals the duration
@@ -65,9 +65,10 @@ const checkFileModifiedRange = (filePath, options) => {
65
65
  else if (maxDate) shouldSkip = fileLastUpdateTime >= maxDate;
66
66
  if (shouldSkip) {
67
67
  const referenceDate = minDate && maxDate ? new Date(Math.abs(maxDate.getTime() - minDate.getTime())) : minDate ?? maxDate;
68
+ const relativeTime = new Date(now.getTime() - referenceDate.getTime());
68
69
  return {
69
70
  isSkipped: true,
70
- message: `Skipping file because it has been modified within the last ${formatTimeDiff(new Date(now.getTime() - referenceDate.getTime()))} - ${filePath}`
71
+ message: `Skipping file because it has been modified within the last ${formatTimeDiff(relativeTime)} - ${filePath}`
71
72
  };
72
73
  }
73
74
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"checkFileModifiedRange.mjs","names":[],"sources":["../../../src/utils/checkFileModifiedRange.ts"],"sourcesContent":["import { checkLastUpdateTime } from './checkLastUpdateTime';\nimport { formatTimeDiff } from './formatTimeDiff';\n\ntype GetTimeRangeResult = {\n relativeTime: Date;\n absoluteTime: Date;\n};\n\n/**\n * Threshold that helps us differentiate between a numeric *timestamp* (ms from epoch)\n * and a numeric *duration* (ms ago).\n * 50 years expressed in milliseconds is far greater than any reasonable\n * \"relative\" duration we expect the helper to receive (e.g. a couple of years).\n */\nconst TIMESTAMP_THRESHOLD_MS = 50 * 365 * 24 * 60 * 60 * 1000; // 50 years\n\n/**\n * Normalises the input date representation into a pair:\n * 1. `relativeTime` – a Date instance whose epoch-time equals the duration\n * between `now` and the absolute date.\n * 2. `absoluteTime` – the concrete point in time represented as a Date.\n *\n * Rules for interpreting the input:\n * • Date => treated as an absolute time.\n * • string => parsed via the Date constructor => absolute time.\n * • number:\n * – if the value is larger than the TIMESTAMP_THRESHOLD_MS we assume it\n * is a unix timestamp (absolute time).\n * – otherwise we treat it as a *relative* duration expressed in\n * milliseconds.\n */\nconst normaliseInputDate = (\n date: Date | number | string,\n now: Date = new Date()\n): GetTimeRangeResult => {\n // Case 1: Already a Date instance\n if (date instanceof Date) {\n return {\n absoluteTime: date,\n relativeTime: new Date(now.getTime() - date.getTime()),\n };\n }\n\n // Case 2: Numeric value – decide between timestamp vs relative ms.\n if (typeof date === 'number') {\n if (date > TIMESTAMP_THRESHOLD_MS) {\n // Treat as *unix timestamp* (absolute)\n const absoluteTime = new Date(date);\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n // Treat as a *relative* duration (milliseconds in the past)\n const relativeMs = date;\n return {\n // Relative duration expressed as a Date object starting at the epoch\n relativeTime: new Date(relativeMs),\n // The concrete date obtained by subtracting the duration from *now*\n absoluteTime: new Date(now.getTime() - relativeMs),\n };\n }\n\n // Case 3: String representation – let Date parse it.\n if (typeof date === 'string') {\n const absoluteTime = new Date(date);\n if (Number.isNaN(absoluteTime.getTime())) {\n throw new Error(`Invalid date string provided: ${date}`);\n }\n\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n throw new Error(`Unsupported date format: ${date}`);\n};\n\ntype CheckFileModifiedRangeResult = {\n isSkipped: boolean;\n message: string;\n};\n\ntype CheckFileModifiedRangeOptions = {\n skipIfModifiedBefore?: Date | number | string;\n skipIfModifiedAfter?: Date | number | string;\n};\n\nexport const checkFileModifiedRange = (\n filePath: string,\n options: CheckFileModifiedRangeOptions\n): CheckFileModifiedRangeResult => {\n const fileLastUpdateTime = checkLastUpdateTime(filePath);\n const { skipIfModifiedBefore, skipIfModifiedAfter } = options;\n\n // Normalise the provided thresholds to concrete dates.\n const now = new Date();\n const minDate = skipIfModifiedBefore\n ? normaliseInputDate(skipIfModifiedBefore, now).absoluteTime\n : undefined;\n const maxDate = skipIfModifiedAfter\n ? normaliseInputDate(skipIfModifiedAfter, now).absoluteTime\n : undefined;\n\n // Determine if the file should be skipped.\n let shouldSkip = false;\n\n if (minDate instanceof Date && maxDate instanceof Date) {\n // Skip when the modification time falls *within* the range [minDate, maxDate]\n shouldSkip = fileLastUpdateTime >= minDate && fileLastUpdateTime <= maxDate;\n } else if (minDate instanceof Date) {\n // Only lower bound – skip when the file was modified *after* minDate\n shouldSkip = fileLastUpdateTime >= minDate;\n } else if (maxDate) {\n // Only upper bound – skip when the file was modified *after* maxDate\n shouldSkip = fileLastUpdateTime >= maxDate;\n }\n\n if (shouldSkip) {\n // For the sake of the message we compute the relative time to *now* using\n // whichever bound was responsible for the skip logic.\n const referenceDate = (\n minDate && maxDate\n ? // When both bounds are present, the *range* caused the skip so we use\n // the distance between the two bounds as the relative duration.\n new Date(Math.abs(maxDate.getTime() - minDate.getTime()))\n : (minDate ?? maxDate)\n )!;\n\n const relativeTime = new Date(now.getTime() - referenceDate.getTime());\n\n return {\n isSkipped: true,\n message: `Skipping file because it has been modified within the last ${formatTimeDiff(relativeTime)} - ${filePath}`,\n };\n }\n\n return {\n isSkipped: false,\n message: `File ${filePath} can be processed - ${filePath}`,\n };\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAM,yBAAyB,KAAK,MAAM,KAAK,KAAK,KAAK;;;;;;;;;;;;;;;;AAiBzD,MAAM,sBACJ,MACA,sBAAY,IAAI,KAAK,MACE;CAEvB,IAAI,gBAAgB,MAClB,OAAO;EACL,cAAc;EACd,cAAc,IAAI,KAAK,IAAI,QAAQ,IAAI,KAAK,QAAQ,CAAC;CACvD;CAIF,IAAI,OAAO,SAAS,UAAU;EAC5B,IAAI,OAAO,wBAAwB;GAEjC,MAAM,eAAe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ACL,WAAW;EACX,SAAS,QAAQ,SAAS,sBAAsB;CAClD;AACF"}
1
+ {"version":3,"file":"checkFileModifiedRange.mjs","names":[],"sources":["../../../src/utils/checkFileModifiedRange.ts"],"sourcesContent":["import { checkLastUpdateTime } from './checkLastUpdateTime';\nimport { formatTimeDiff } from './formatTimeDiff';\n\ntype GetTimeRangeResult = {\n relativeTime: Date;\n absoluteTime: Date;\n};\n\n/**\n * Threshold that helps us differentiate between a numeric *timestamp* (ms from epoch)\n * and a numeric *duration* (ms ago).\n * 50 years expressed in milliseconds is far greater than any reasonable\n * \"relative\" duration we expect the helper to receive (e.g. a couple of years).\n */\nconst TIMESTAMP_THRESHOLD_MS = 50 * 365 * 24 * 60 * 60 * 1000; // 50 years\n\n/**\n * Normalises the input date representation into a pair:\n * 1. `relativeTime` – a Date instance whose epoch-time equals the duration\n * between `now` and the absolute date.\n * 2. `absoluteTime` – the concrete point in time represented as a Date.\n *\n * Rules for interpreting the input:\n * • Date => treated as an absolute time.\n * • string => parsed via the Date constructor => absolute time.\n * • number:\n * – if the value is larger than the TIMESTAMP_THRESHOLD_MS we assume it\n * is a unix timestamp (absolute time).\n * – otherwise we treat it as a *relative* duration expressed in\n * milliseconds.\n */\nconst normaliseInputDate = (\n date: Date | number | string,\n now: Date = new Date()\n): GetTimeRangeResult => {\n // Case 1: Already a Date instance\n if (date instanceof Date) {\n return {\n absoluteTime: date,\n relativeTime: new Date(now.getTime() - date.getTime()),\n };\n }\n\n // Case 2: Numeric value – decide between timestamp vs relative ms.\n if (typeof date === 'number') {\n if (date > TIMESTAMP_THRESHOLD_MS) {\n // Treat as *unix timestamp* (absolute)\n const absoluteTime = new Date(date);\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n // Treat as a *relative* duration (milliseconds in the past)\n const relativeMs = date;\n return {\n // Relative duration expressed as a Date object starting at the epoch\n relativeTime: new Date(relativeMs),\n // The concrete date obtained by subtracting the duration from *now*\n absoluteTime: new Date(now.getTime() - relativeMs),\n };\n }\n\n // Case 3: String representation – let Date parse it.\n if (typeof date === 'string') {\n const absoluteTime = new Date(date);\n if (Number.isNaN(absoluteTime.getTime())) {\n throw new Error(`Invalid date string provided: ${date}`);\n }\n\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n throw new Error(`Unsupported date format: ${date}`);\n};\n\ntype CheckFileModifiedRangeResult = {\n isSkipped: boolean;\n message: string;\n};\n\ntype CheckFileModifiedRangeOptions = {\n skipIfModifiedBefore?: Date | number | string;\n skipIfModifiedAfter?: Date | number | string;\n};\n\nexport const checkFileModifiedRange = (\n filePath: string,\n options: CheckFileModifiedRangeOptions\n): CheckFileModifiedRangeResult => {\n const fileLastUpdateTime = checkLastUpdateTime(filePath);\n const { skipIfModifiedBefore, skipIfModifiedAfter } = options;\n\n // Normalise the provided thresholds to concrete dates.\n const now = new Date();\n const minDate = skipIfModifiedBefore\n ? normaliseInputDate(skipIfModifiedBefore, now).absoluteTime\n : undefined;\n const maxDate = skipIfModifiedAfter\n ? normaliseInputDate(skipIfModifiedAfter, now).absoluteTime\n : undefined;\n\n // Determine if the file should be skipped.\n let shouldSkip = false;\n\n if (minDate instanceof Date && maxDate instanceof Date) {\n // Skip when the modification time falls *within* the range [minDate, maxDate]\n shouldSkip = fileLastUpdateTime >= minDate && fileLastUpdateTime <= maxDate;\n } else if (minDate instanceof Date) {\n // Only lower bound – skip when the file was modified *after* minDate\n shouldSkip = fileLastUpdateTime >= minDate;\n } else if (maxDate) {\n // Only upper bound – skip when the file was modified *after* maxDate\n shouldSkip = fileLastUpdateTime >= maxDate;\n }\n\n if (shouldSkip) {\n // For the sake of the message we compute the relative time to *now* using\n // whichever bound was responsible for the skip logic.\n const referenceDate = (\n minDate && maxDate\n ? // When both bounds are present, the *range* caused the skip so we use\n // the distance between the two bounds as the relative duration.\n new Date(Math.abs(maxDate.getTime() - minDate.getTime()))\n : (minDate ?? maxDate)\n )!;\n\n const relativeTime = new Date(now.getTime() - referenceDate.getTime());\n\n return {\n isSkipped: true,\n message: `Skipping file because it has been modified within the last ${formatTimeDiff(relativeTime)} - ${filePath}`,\n };\n }\n\n return {\n isSkipped: false,\n message: `File ${filePath} can be processed - ${filePath}`,\n };\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAM,yBAAyB;;;;;;;;;;;;;;;;AAiB/B,MAAM,sBACJ,MACA,sBAAY,IAAI,KAAK,MACE;CAEvB,IAAI,gBAAgB,MAClB,OAAO;EACL,cAAc;EACd,cAAc,IAAI,KAAK,IAAI,QAAQ,IAAI,KAAK,QAAQ,CAAC;CACvD;CAIF,IAAI,OAAO,SAAS,UAAU;EAC5B,IAAI,OAAO,wBAAwB;GAEjC,MAAM,eAAe,IAAI,KAAK,IAAI;GAClC,OAAO;IACL;IACA,cAAc,IAAI,KAAK,IAAI,QAAQ,IAAI,aAAa,QAAQ,CAAC;GAC/D;EACF;EAGA,MAAM,aAAa;EACnB,OAAO;GAEL,cAAc,IAAI,KAAK,UAAU;GAEjC,cAAc,IAAI,KAAK,IAAI,QAAQ,IAAI,UAAU;EACnD;CACF;CAGA,IAAI,OAAO,SAAS,UAAU;EAC5B,MAAM,eAAe,IAAI,KAAK,IAAI;EAClC,IAAI,OAAO,MAAM,aAAa,QAAQ,CAAC,GACrC,MAAM,IAAI,MAAM,iCAAiC,MAAM;EAGzD,OAAO;GACL;GACA,cAAc,IAAI,KAAK,IAAI,QAAQ,IAAI,aAAa,QAAQ,CAAC;EAC/D;CACF;CAEA,MAAM,IAAI,MAAM,4BAA4B,MAAM;AACpD;AAYA,MAAa,0BACX,UACA,YACiC;CACjC,MAAM,qBAAqB,oBAAoB,QAAQ;CACvD,MAAM,EAAE,sBAAsB,wBAAwB;CAGtD,MAAM,sBAAM,IAAI,KAAK;CACrB,MAAM,UAAU,uBACZ,mBAAmB,sBAAsB,GAAG,CAAC,CAAC,eAC9C;CACJ,MAAM,UAAU,sBACZ,mBAAmB,qBAAqB,GAAG,CAAC,CAAC,eAC7C;CAGJ,IAAI,aAAa;CAEjB,IAAI,mBAAmB,QAAQ,mBAAmB,MAEhD,aAAa,sBAAsB,WAAW,sBAAsB;MAC/D,IAAI,mBAAmB,MAE5B,aAAa,sBAAsB;MAC9B,IAAI,SAET,aAAa,sBAAsB;CAGrC,IAAI,YAAY;EAGd,MAAM,gBACJ,WAAW,UAGP,IAAI,KAAK,KAAK,IAAI,QAAQ,QAAQ,IAAI,QAAQ,QAAQ,CAAC,CAAC,IACvD,WAAW;EAGlB,MAAM,eAAe,IAAI,KAAK,IAAI,QAAQ,IAAI,cAAc,QAAQ,CAAC;EAErE,OAAO;GACL,WAAW;GACX,SAAS,8DAA8D,eAAe,YAAY,EAAE,KAAK;EAC3G;CACF;CAEA,OAAO;EACL,WAAW;EACX,SAAS,QAAQ,SAAS,sBAAsB;CAClD;AACF"}
@@ -97,7 +97,8 @@ const getPatternForLocale = (output, locale) => {
97
97
  const resolveOutputPattern = async (output, locale, context, sourceFilePath, baseDir) => {
98
98
  const pattern = getPatternForLocale(output, locale);
99
99
  if (pattern === false || pattern === void 0) return false;
100
- return resolveRelativePath(typeof pattern === "function" ? await pattern(context) : parseStringPattern(pattern, context), sourceFilePath, baseDir);
100
+ const rawPath = typeof pattern === "function" ? await pattern(context) : parseStringPattern(pattern, context);
101
+ return resolveRelativePath(rawPath, sourceFilePath, baseDir);
101
102
  };
102
103
 
103
104
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"getOutputFilePath.mjs","names":[],"sources":["../../../src/utils/getOutputFilePath.ts"],"sourcesContent":["import { parseStringPattern } from '@intlayer/config/utils';\nimport { resolveRelativePath } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { Fill } from '@intlayer/types/dictionary';\nimport type {\n FilePathPattern,\n FilePathPatternContext,\n} from '@intlayer/types/filePathPattern';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Get the output file path by replacing the base locale with the target locale\n *\n * This function handles two types of replacements:\n * 1. Actual locale values (e.g., `/en/` → `/fr/`)\n * 2. Template placeholders (e.g., `{{baseLocale}}` → `{{locale}}`, `{{baseLocaleName}}` → `{{localeName}}`)\n *\n * Replacement patterns:\n * - `/baseLocale/` → `/locale/`\n * - `\\baseLocale\\` → `\\locale\\`\n * - `_baseLocale.` → `_locale.`\n * - `baseLocale_` → `locale_`\n * - `.baseLocaleName.` → `.localeName.`\n * - `{{baseLocale}}` → `{{locale}}`\n * - `{{baseLocaleName}}` → `{{localeName}}`\n *\n * If no patterns match, appends `.locale` to the file extension.\n *\n * @param filePath - The input file path\n * @param locale - The target locale\n * @param baseLocale - The base locale to replace\n * @returns The output file path with locale replacements\n */\nexport const getOutputFilePath = (\n filePath: string,\n locale: LocalesValues,\n baseLocale: LocalesValues\n): string => {\n if (!filePath || !locale || !baseLocale) {\n throw new Error('filePath, locale, and baseLocale are required');\n }\n\n let outputFilePath = filePath;\n\n // Define replacement patterns with global flag to replace all occurrences\n const replacements = [\n // Template placeholders (processed first)\n {\n pattern: /\\{\\{baseLocale\\}\\}/g,\n replacement: '{{locale}}',\n },\n {\n pattern: /\\{\\{baseLocaleName\\}\\}/g,\n replacement: '{{localeName}}',\n },\n\n // Path separators (most specific first)\n {\n // Unix path separators\n pattern: new RegExp(`/${baseLocale}/`, 'g'),\n replacement: `/${locale}/`,\n },\n {\n // Windows path separators\n pattern: new RegExp(`\\\\\\\\${baseLocale}\\\\\\\\`, 'g'),\n replacement: `\\\\${locale}\\\\`,\n },\n\n // File naming patterns\n {\n // file_en.md → file_fr.md\n pattern: new RegExp(`_${baseLocale}\\\\.`, 'g'),\n replacement: `_${locale}.`,\n },\n {\n // /file_en.md → /file_fr.md\n pattern: new RegExp(`/${baseLocale}_`, 'g'),\n replacement: `/${locale}_`,\n },\n {\n // Start of filename pattern en_guide.md → fr_guide.md (or after path separator)\n pattern: new RegExp(`(^|[\\\\/])${baseLocale}_`, 'g'),\n replacement: `$1${locale}_`,\n },\n {\n // Dot delimited pattern guide.en.md → guide.fr.md\n pattern: new RegExp(`\\\\.${baseLocale}\\\\.`, 'g'),\n replacement: `.${locale}.`,\n },\n ];\n\n // Apply all replacements\n for (const { pattern, replacement } of replacements) {\n outputFilePath = outputFilePath.replace(pattern, replacement);\n }\n\n // If no changes were made, append locale as extension\n if (outputFilePath === filePath) {\n const lastDotIndex = filePath.lastIndexOf('.');\n if (lastDotIndex > 0) {\n // Insert locale before the file extension\n return `${filePath.slice(0, lastDotIndex)}.${locale}${filePath.slice(lastDotIndex)}`;\n } else {\n // No extension found, just append\n return `${filePath}.${locale}`;\n }\n }\n\n return outputFilePath;\n};\n\n/**\n * Get the effective FilePathPattern for a given locale from a Fill/CompilerOutput value.\n *\n * - If Fill is an object, returns the pattern for that locale (or `false` if disabled/missing).\n * - If Fill is a string/function, returns it as-is (applies to all locales).\n * - If Fill is `false`, returns `false` (disabled for all locales).\n * - If Fill is `true` or a locale entry is `true`, returns `undefined` (use default).\n */\nexport const getPatternForLocale = (\n output: Fill,\n locale: Locale\n): FilePathPattern | false | undefined => {\n if (output === false) return false;\n if (output === true) return undefined;\n if (typeof output === 'string' || typeof output === 'function')\n return output as FilePathPattern;\n if (typeof output === 'object' && output !== null) {\n const entry = (output as Record<string, boolean | FilePathPattern>)[locale];\n if (entry === undefined || entry === false) return false;\n if (entry === true) return undefined;\n return entry as FilePathPattern;\n }\n return false;\n};\n\n/**\n * Resolve a Fill/CompilerOutput pattern to an absolute file path for a given locale.\n * Returns `false` if the locale is disabled or no pattern is configured.\n */\nexport const resolveOutputPattern = async (\n output: Fill,\n locale: Locale,\n context: FilePathPatternContext,\n sourceFilePath: string,\n baseDir: string\n): Promise<string | false> => {\n const pattern = getPatternForLocale(output, locale);\n if (pattern === false || pattern === undefined) return false;\n\n const rawPath =\n typeof pattern === 'function'\n ? await pattern(context)\n : parseStringPattern(pattern, context);\n\n return resolveRelativePath(rawPath, sourceFilePath, baseDir);\n};\n"],"mappings":";;;;;;;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AAY,WAAW,MAAM;EACjD,MAAM,QAAS,OAAqD;EACpE,IAAI,UAAU,UAAa,UAAU,OAAO,OAAO;EACnD,IAAI,UAAU,MAAM,OAAO;EAC3B,OAAO;CACT;CACA,OAAO;AACT;;;;;AAMA,MAAa,uBAAuB,OAClC,QACA,QACA,SACA,gBACA,YAC4B;CAC5B,MAAM,UAAU,oBAAoB,QAAQ,MAAM;CAClD,IAAI,YAAY,SAAS,YAAY,QAAW,OAAO;CAOvD,OAAO,oBAJL,OAAO,YAAY,aACf,MAAM,QAAQ,OAAO,IACrB,mBAAmB,SAAS,OAAO,GAEL,gBAAgB,OAAO;AAC7D"}
1
+ {"version":3,"file":"getOutputFilePath.mjs","names":[],"sources":["../../../src/utils/getOutputFilePath.ts"],"sourcesContent":["import { parseStringPattern } from '@intlayer/config/utils';\nimport { resolveRelativePath } from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { Fill } from '@intlayer/types/dictionary';\nimport type {\n FilePathPattern,\n FilePathPatternContext,\n} from '@intlayer/types/filePathPattern';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Get the output file path by replacing the base locale with the target locale\n *\n * This function handles two types of replacements:\n * 1. Actual locale values (e.g., `/en/` → `/fr/`)\n * 2. Template placeholders (e.g., `{{baseLocale}}` → `{{locale}}`, `{{baseLocaleName}}` → `{{localeName}}`)\n *\n * Replacement patterns:\n * - `/baseLocale/` → `/locale/`\n * - `\\baseLocale\\` → `\\locale\\`\n * - `_baseLocale.` → `_locale.`\n * - `baseLocale_` → `locale_`\n * - `.baseLocaleName.` → `.localeName.`\n * - `{{baseLocale}}` → `{{locale}}`\n * - `{{baseLocaleName}}` → `{{localeName}}`\n *\n * If no patterns match, appends `.locale` to the file extension.\n *\n * @param filePath - The input file path\n * @param locale - The target locale\n * @param baseLocale - The base locale to replace\n * @returns The output file path with locale replacements\n */\nexport const getOutputFilePath = (\n filePath: string,\n locale: LocalesValues,\n baseLocale: LocalesValues\n): string => {\n if (!filePath || !locale || !baseLocale) {\n throw new Error('filePath, locale, and baseLocale are required');\n }\n\n let outputFilePath = filePath;\n\n // Define replacement patterns with global flag to replace all occurrences\n const replacements = [\n // Template placeholders (processed first)\n {\n pattern: /\\{\\{baseLocale\\}\\}/g,\n replacement: '{{locale}}',\n },\n {\n pattern: /\\{\\{baseLocaleName\\}\\}/g,\n replacement: '{{localeName}}',\n },\n\n // Path separators (most specific first)\n {\n // Unix path separators\n pattern: new RegExp(`/${baseLocale}/`, 'g'),\n replacement: `/${locale}/`,\n },\n {\n // Windows path separators\n pattern: new RegExp(`\\\\\\\\${baseLocale}\\\\\\\\`, 'g'),\n replacement: `\\\\${locale}\\\\`,\n },\n\n // File naming patterns\n {\n // file_en.md → file_fr.md\n pattern: new RegExp(`_${baseLocale}\\\\.`, 'g'),\n replacement: `_${locale}.`,\n },\n {\n // /file_en.md → /file_fr.md\n pattern: new RegExp(`/${baseLocale}_`, 'g'),\n replacement: `/${locale}_`,\n },\n {\n // Start of filename pattern en_guide.md → fr_guide.md (or after path separator)\n pattern: new RegExp(`(^|[\\\\/])${baseLocale}_`, 'g'),\n replacement: `$1${locale}_`,\n },\n {\n // Dot delimited pattern guide.en.md → guide.fr.md\n pattern: new RegExp(`\\\\.${baseLocale}\\\\.`, 'g'),\n replacement: `.${locale}.`,\n },\n ];\n\n // Apply all replacements\n for (const { pattern, replacement } of replacements) {\n outputFilePath = outputFilePath.replace(pattern, replacement);\n }\n\n // If no changes were made, append locale as extension\n if (outputFilePath === filePath) {\n const lastDotIndex = filePath.lastIndexOf('.');\n if (lastDotIndex > 0) {\n // Insert locale before the file extension\n return `${filePath.slice(0, lastDotIndex)}.${locale}${filePath.slice(lastDotIndex)}`;\n } else {\n // No extension found, just append\n return `${filePath}.${locale}`;\n }\n }\n\n return outputFilePath;\n};\n\n/**\n * Get the effective FilePathPattern for a given locale from a Fill/CompilerOutput value.\n *\n * - If Fill is an object, returns the pattern for that locale (or `false` if disabled/missing).\n * - If Fill is a string/function, returns it as-is (applies to all locales).\n * - If Fill is `false`, returns `false` (disabled for all locales).\n * - If Fill is `true` or a locale entry is `true`, returns `undefined` (use default).\n */\nexport const getPatternForLocale = (\n output: Fill,\n locale: Locale\n): FilePathPattern | false | undefined => {\n if (output === false) return false;\n if (output === true) return undefined;\n if (typeof output === 'string' || typeof output === 'function')\n return output as FilePathPattern;\n if (typeof output === 'object' && output !== null) {\n const entry = (output as Record<string, boolean | FilePathPattern>)[locale];\n if (entry === undefined || entry === false) return false;\n if (entry === true) return undefined;\n return entry as FilePathPattern;\n }\n return false;\n};\n\n/**\n * Resolve a Fill/CompilerOutput pattern to an absolute file path for a given locale.\n * Returns `false` if the locale is disabled or no pattern is configured.\n */\nexport const resolveOutputPattern = async (\n output: Fill,\n locale: Locale,\n context: FilePathPatternContext,\n sourceFilePath: string,\n baseDir: string\n): Promise<string | false> => {\n const pattern = getPatternForLocale(output, locale);\n if (pattern === false || pattern === undefined) return false;\n\n const rawPath =\n typeof pattern === 'function'\n ? await pattern(context)\n : parseStringPattern(pattern, context);\n\n return resolveRelativePath(rawPath, sourceFilePath, baseDir);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,qBACX,UACA,QACA,eACW;CACX,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,YAC3B,MAAM,IAAI,MAAM,+CAA+C;CAGjE,IAAI,iBAAiB;CAGrB,MAAM,eAAe;EAEnB;GACE,SAAS;GACT,aAAa;EACf;EACA;GACE,SAAS;GACT,aAAa;EACf;EAGA;GAEE,SAAS,IAAI,OAAO,IAAI,WAAW,IAAI,GAAG;GAC1C,aAAa,IAAI,OAAO;EAC1B;EACA;GAEE,SAAS,IAAI,OAAO,OAAO,WAAW,OAAO,GAAG;GAChD,aAAa,KAAK,OAAO;EAC3B;EAGA;GAEE,SAAS,IAAI,OAAO,IAAI,WAAW,MAAM,GAAG;GAC5C,aAAa,IAAI,OAAO;EAC1B;EACA;GA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0) return;
25
25
  const targetEnvironment = projectEnvironments.find((environment) => environment.name.toLowerCase() === environmentName.toLowerCase() || String(environment.id) === environmentName);
26
26
  if (!targetEnvironment) {
27
- appLogger(`Environment "${environmentName}" not found in project. Available: ${colorize(projectEnvironments.map((environment) => environment.name).join(", "), ANSIColors.BLUE)}.`, { level: "error" });
27
+ const availableNames = projectEnvironments.map((environment) => environment.name).join(", ");
28
+ appLogger(`Environment "${environmentName}" not found in project. Available: ${colorize(availableNames, ANSIColors.BLUE)}.`, { level: "error" });
28
29
  return;
29
30
  }
30
31
  if (targetEnvironment.isDefault) {
@@ -1 +1 @@
1
- {"version":3,"file":"selectCmsEnvironment.mjs","names":[],"sources":["../../../src/utils/selectCmsEnvironment.ts"],"sourcesContent":["import type { IntlayerAPIProxy } from '@intlayer/api';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\n\n/**\n * Selects the CMS project environment that matches `environmentName`.\n *\n * Convention: session.activeEnvironmentId = null means \"production\" (default).\n * When the target environment is the project's default, we reset the session to\n * null instead of storing the env's ObjectId — so no API call is needed.\n *\n * No-op when `environmentName` is undefined.\n */\nexport const selectCmsEnvironment = async (\n environmentName: string | undefined,\n intlayerAPI: IntlayerAPIProxy,\n config: IntlayerConfig\n): Promise<void> => {\n if (!environmentName) return;\n\n const appLogger = getAppLogger(config);\n\n try {\n const sessionResult = await intlayerAPI.oAuth.getCliSessionMe();\n const project = sessionResult.data?.project;\n\n if (!project) {\n appLogger(\n `Cannot resolve environment \"${environmentName}\": no project selected in session.`,\n { level: 'warn' }\n );\n return;\n }\n\n const projectEnvironments: any[] = (project as any).environments ?? [];\n\n if (projectEnvironments.length === 0) {\n // No environments stored — everything is implicitly production; nothing to select\n return;\n }\n\n const targetEnvironment = projectEnvironments.find(\n (environment: any) =>\n environment.name.toLowerCase() === environmentName.toLowerCase() ||\n String(environment.id) === environmentName\n );\n\n if (!targetEnvironment) {\n const availableNames = projectEnvironments\n .map((environment: any) => environment.name)\n .join(', ');\n appLogger(\n `Environment \"${environmentName}\" not found in project. Available: ${colorize(availableNames, ANSIColors.BLUE)}.`,\n { level: 'error' }\n );\n return;\n }\n\n // Production / default env → null convention; no API call needed\n if (targetEnvironment.isDefault) {\n appLogger(\n `Using environment: ${colorize(targetEnvironment.name, ANSIColors.CYAN)} (default)`\n );\n return;\n }\n\n await intlayerAPI.project.selectEnvironment(String(targetEnvironment.id));\n\n appLogger(\n `Using environment: ${colorize(targetEnvironment.name, ANSIColors.CYAN)}`\n );\n } catch (error) {\n appLogger(`Failed to select environment \"${environmentName}\": ${error}`, {\n level: 'warn',\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAa,uBAAuB,OAClC,iBACA,aACA,WACkB;CAClB,IAAI,CAAC,iBAAiB;CAEtB,MAAM,YAAY,aAAa,MAAM;CAErC,IAAI;EAEF,MAAM,WAAU,MADY,YAAY,MAAM,gBAAgB,EACjC,CAAC,MAAM;EAEpC,IAAI,CAAC,SAAS;GACZ,UACE,+BAA+B,gBAAgB,qCAC/C,EAAE,OAAO,OAAO,CAClB;GACA;EACF;EAEA,MAAM,sBAA8B,QAAgB,gBAAgB,CAAC;EAErE,IAAI,oBAAoB,WAAW,GAEjC;EAGF,MAAM,oBAAoB,oBAAoB,MAC3C,gBACC,YAAY,KAAK,YAAY,MAAM,gBAAgB,YAAY,KAC/D,OAAO,YAAY,EAAE,MAAM,eAC/B;EAEA,IAAI,CAAC,mBAAmB;GAItB,UACE,gBAAgB,gBAAgB,qCAAqC,SAJhD,oBACpB,KAAK,gBAAqB,YAAY,IAAI,CAAC,CAC3C,KAAK,IAEqF,GAAG,WAAW,IAAI,EAAE,IAC/G,EAAE,OAAO,QAAQ,CACnB;GACA;EACF;EAGA,IAAI,kBAAkB,WAAW;GAC/B,UACE,sBAAsB,SAAS,kBAAkB,MAAM,WAAW,IAAI,EAAE,WAC1E;GACA;EACF;EAEA,MAAM,YAAY,QAAQ,kBAAkB,OAAO,kBAAkB,EAAE,CAAC;EAExE,UACE,sBAAsB,SAAS,kBAAkB,MAAM,WAAW,IAAI,GACxE;CACF,SAAS,OAAO;EACd,UAAU,iCAAiC,gBAAgB,KAAK,SAAS,EACvE,OAAO,OACT,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"selectCmsEnvironment.mjs","names":[],"sources":["../../../src/utils/selectCmsEnvironment.ts"],"sourcesContent":["import type { IntlayerAPIProxy } from '@intlayer/api';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\n\n/**\n * Selects the CMS project environment that matches `environmentName`.\n *\n * Convention: session.activeEnvironmentId = null means \"production\" (default).\n * When the target environment is the project's default, we reset the session to\n * null instead of storing the env's ObjectId — so no API call is needed.\n *\n * No-op when `environmentName` is undefined.\n */\nexport const selectCmsEnvironment = async (\n environmentName: string | undefined,\n intlayerAPI: IntlayerAPIProxy,\n config: IntlayerConfig\n): Promise<void> => {\n if (!environmentName) return;\n\n const appLogger = getAppLogger(config);\n\n try {\n const sessionResult = await intlayerAPI.oAuth.getCliSessionMe();\n const project = sessionResult.data?.project;\n\n if (!project) {\n appLogger(\n `Cannot resolve environment \"${environmentName}\": no project selected in session.`,\n { level: 'warn' }\n );\n return;\n }\n\n const projectEnvironments: any[] = (project as any).environments ?? [];\n\n if (projectEnvironments.length === 0) {\n // No environments stored — everything is implicitly production; nothing to select\n return;\n }\n\n const targetEnvironment = projectEnvironments.find(\n (environment: any) =>\n environment.name.toLowerCase() === environmentName.toLowerCase() ||\n String(environment.id) === environmentName\n );\n\n if (!targetEnvironment) {\n const availableNames = projectEnvironments\n .map((environment: any) => environment.name)\n .join(', ');\n appLogger(\n `Environment \"${environmentName}\" not found in project. Available: ${colorize(availableNames, ANSIColors.BLUE)}.`,\n { level: 'error' }\n );\n return;\n }\n\n // Production / default env → null convention; no API call needed\n if (targetEnvironment.isDefault) {\n appLogger(\n `Using environment: ${colorize(targetEnvironment.name, ANSIColors.CYAN)} (default)`\n );\n return;\n }\n\n await intlayerAPI.project.selectEnvironment(String(targetEnvironment.id));\n\n appLogger(\n `Using environment: ${colorize(targetEnvironment.name, ANSIColors.CYAN)}`\n );\n } catch (error) {\n appLogger(`Failed to select environment \"${environmentName}\": ${error}`, {\n level: 'warn',\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAa,uBAAuB,OAClC,iBACA,aACA,WACkB;CAClB,IAAI,CAAC,iBAAiB;CAEtB,MAAM,YAAY,aAAa,MAAM;CAErC,IAAI;EAEF,MAAM,WAAU,MADY,YAAY,MAAM,gBAAgB,EACjC,CAAC,MAAM;EAEpC,IAAI,CAAC,SAAS;GACZ,UACE,+BAA+B,gBAAgB,qCAC/C,EAAE,OAAO,OAAO,CAClB;GACA;EACF;EAEA,MAAM,sBAA8B,QAAgB,gBAAgB,CAAC;EAErE,IAAI,oBAAoB,WAAW,GAEjC;EAGF,MAAM,oBAAoB,oBAAoB,MAC3C,gBACC,YAAY,KAAK,YAAY,MAAM,gBAAgB,YAAY,KAC/D,OAAO,YAAY,EAAE,MAAM,eAC/B;EAEA,IAAI,CAAC,mBAAmB;GACtB,MAAM,iBAAiB,oBACpB,KAAK,gBAAqB,YAAY,IAAI,CAAC,CAC3C,KAAK,IAAI;GACZ,UACE,gBAAgB,gBAAgB,qCAAqC,SAAS,gBAAgB,WAAW,IAAI,EAAE,IAC/G,EAAE,OAAO,QAAQ,CACnB;GACA;EACF;EAGA,IAAI,kBAAkB,WAAW;GAC/B,UACE,sBAAsB,SAAS,kBAAkB,MAAM,WAAW,IAAI,EAAE,WAC1E;GACA;EACF;EAEA,MAAM,YAAY,QAAQ,kBAAkB,OAAO,kBAAkB,EAAE,CAAC;EAExE,UACE,sBAAsB,SAAS,kBAAkB,MAAM,WAAW,IAAI,GACxE;CACF,SAAS,OAAO;EACd,UAAU,iCAAiC,gBAAgB,KAAK,SAAS,EACvE,OAAO,OACT,CAAC;CACH;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","names":[],"sources":["../../src/init.ts"],"mappings":";;cAuBa,kBAAe;cA2hBf,OAAI,sBACK,UACV,aAAW,0BACA"}
1
+ {"version":3,"file":"init.d.ts","names":[],"sources":["../../src/init.ts"],"mappings":";;cAwBa,kBAAe;cAuXf,OAAI,sBACK,UACV,aAAW,0BACA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/cli",
3
- "version": "9.3.0",
3
+ "version": "9.3.2",
4
4
  "private": false,
5
5
  "description": "Provides uniform command-line interface scripts for Intlayer, used in packages like intlayer-cli and intlayer.",
6
6
  "keywords": [
@@ -67,22 +67,22 @@
67
67
  },
68
68
  "dependencies": {
69
69
  "@clack/prompts": "1.7.0",
70
- "@intlayer/api": "9.3.0",
71
- "@intlayer/babel": "9.3.0",
72
- "@intlayer/config": "9.3.0",
73
- "@intlayer/core": "9.3.0",
74
- "@intlayer/dictionaries-entry": "9.3.0",
75
- "@intlayer/engine": "9.3.0",
76
- "@intlayer/remote-dictionaries-entry": "9.3.0",
77
- "@intlayer/types": "9.3.0",
78
- "@intlayer/unmerged-dictionaries-entry": "9.3.0",
70
+ "@intlayer/api": "9.3.2",
71
+ "@intlayer/babel": "9.3.2",
72
+ "@intlayer/config": "9.3.2",
73
+ "@intlayer/core": "9.3.2",
74
+ "@intlayer/dictionaries-entry": "9.3.2",
75
+ "@intlayer/engine": "9.3.2",
76
+ "@intlayer/remote-dictionaries-entry": "9.3.2",
77
+ "@intlayer/types": "9.3.2",
78
+ "@intlayer/unmerged-dictionaries-entry": "9.3.2",
79
79
  "commander": "15.0.0",
80
80
  "enquirer": "2.4.1",
81
81
  "eventsource": "4.1.1",
82
82
  "fast-glob": "3.3.3"
83
83
  },
84
84
  "devDependencies": {
85
- "@intlayer/ai": "9.3.0",
85
+ "@intlayer/ai": "9.3.2",
86
86
  "@types/node": "26.2.0",
87
87
  "@utils/ts-config": "1.0.4",
88
88
  "@utils/ts-config-types": "1.0.4",
@@ -93,7 +93,7 @@
93
93
  "vitest": "4.1.10"
94
94
  },
95
95
  "peerDependencies": {
96
- "@intlayer/ai": "9.3.0"
96
+ "@intlayer/ai": "9.3.2"
97
97
  },
98
98
  "peerDependenciesMeta": {
99
99
  "@intlayer/ai": {