@intlayer/cli 8.1.2 → 8.1.3
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.
- package/dist/cjs/IntlayerEventListener.cjs +1 -186
- package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
- package/dist/cjs/_virtual/_utils_asset.cjs +2 -98
- package/dist/cjs/auth/login.cjs +2 -85
- package/dist/cjs/auth/login.cjs.map +1 -1
- package/dist/cjs/build.cjs +1 -27
- package/dist/cjs/build.cjs.map +1 -1
- package/dist/cjs/ci.cjs +1 -73
- package/dist/cjs/ci.cjs.map +1 -1
- package/dist/cjs/cli.cjs +1 -476
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/config.cjs +1 -12
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/editor.cjs +1 -50
- package/dist/cjs/editor.cjs.map +1 -1
- package/dist/cjs/extract.cjs +1 -96
- package/dist/cjs/extract.cjs.map +1 -1
- package/dist/cjs/fill/deepMergeContent.cjs +1 -27
- package/dist/cjs/fill/deepMergeContent.cjs.map +1 -1
- package/dist/cjs/fill/fill.cjs +1 -78
- package/dist/cjs/fill/fill.cjs.map +1 -1
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs +1 -29
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
- package/dist/cjs/fill/formatFillData.cjs +1 -50
- package/dist/cjs/fill/formatFillData.cjs.map +1 -1
- package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs +1 -26
- package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs.map +1 -1
- package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs +1 -50
- package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs.map +1 -1
- package/dist/cjs/fill/index.cjs +1 -6
- package/dist/cjs/fill/listTranslationsTasks.cjs +1 -70
- package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -1
- package/dist/cjs/fill/mergeChunks.cjs +1 -28
- package/dist/cjs/fill/mergeChunks.cjs.map +1 -1
- package/dist/cjs/fill/translateDictionary.cjs +1 -205
- package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
- package/dist/cjs/fill/writeFill.cjs +1 -54
- package/dist/cjs/fill/writeFill.cjs.map +1 -1
- package/dist/cjs/getTargetDictionary.cjs +1 -36
- package/dist/cjs/getTargetDictionary.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -39
- package/dist/cjs/init.cjs +1 -322
- package/dist/cjs/init.cjs.map +1 -1
- package/dist/cjs/initSkills.cjs +2 -0
- package/dist/cjs/initSkills.cjs.map +1 -0
- package/dist/cjs/listContentDeclaration.cjs +1 -41
- package/dist/cjs/listContentDeclaration.cjs.map +1 -1
- package/dist/cjs/listProjects.cjs +1 -28
- package/dist/cjs/listProjects.cjs.map +1 -1
- package/dist/cjs/liveSync.cjs +8 -151
- package/dist/cjs/liveSync.cjs.map +1 -1
- package/dist/cjs/pull.cjs +1 -146
- package/dist/cjs/pull.cjs.map +1 -1
- package/dist/cjs/push/pullLog.cjs +3 -102
- package/dist/cjs/push/pullLog.cjs.map +1 -1
- package/dist/cjs/push/push.cjs +1 -206
- package/dist/cjs/push/push.cjs.map +1 -1
- package/dist/cjs/pushConfig.cjs +1 -19
- package/dist/cjs/pushConfig.cjs.map +1 -1
- package/dist/cjs/pushLog.cjs +3 -84
- package/dist/cjs/pushLog.cjs.map +1 -1
- package/dist/cjs/reviewDoc/reviewDoc.cjs +1 -68
- package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
- package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +1 -94
- package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
- package/dist/cjs/searchDoc.cjs +1 -38
- package/dist/cjs/searchDoc.cjs.map +1 -1
- package/dist/cjs/test/index.cjs +1 -7
- package/dist/cjs/test/listMissingTranslations.cjs +1 -49
- package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
- package/dist/cjs/test/test.cjs +1 -53
- package/dist/cjs/test/test.cjs.map +1 -1
- package/dist/cjs/translateDoc/index.cjs +1 -9
- package/dist/cjs/translateDoc/translateDoc.cjs +1 -74
- package/dist/cjs/translateDoc/translateDoc.cjs.map +1 -1
- package/dist/cjs/translateDoc/translateFile.cjs +2 -103
- package/dist/cjs/translateDoc/translateFile.cjs.map +1 -1
- package/dist/cjs/translateDoc/validation.cjs +5 -49
- package/dist/cjs/translateDoc/validation.cjs.map +1 -1
- package/dist/cjs/translation-alignment/alignBlocks.cjs +1 -67
- package/dist/cjs/translation-alignment/alignBlocks.cjs.map +1 -1
- package/dist/cjs/translation-alignment/computeSimilarity.cjs +1 -25
- package/dist/cjs/translation-alignment/computeSimilarity.cjs.map +1 -1
- package/dist/cjs/translation-alignment/fingerprintBlock.cjs +1 -23
- package/dist/cjs/translation-alignment/fingerprintBlock.cjs.map +1 -1
- package/dist/cjs/translation-alignment/index.cjs +1 -22
- package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs +1 -18
- package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs.map +1 -1
- package/dist/cjs/translation-alignment/normalizeBlock.cjs +1 -22
- package/dist/cjs/translation-alignment/normalizeBlock.cjs.map +1 -1
- package/dist/cjs/translation-alignment/pipeline.cjs +1 -37
- package/dist/cjs/translation-alignment/pipeline.cjs.map +1 -1
- package/dist/cjs/translation-alignment/planActions.cjs +1 -46
- package/dist/cjs/translation-alignment/planActions.cjs.map +1 -1
- package/dist/cjs/translation-alignment/rebuildDocument.cjs +2 -49
- package/dist/cjs/translation-alignment/rebuildDocument.cjs.map +1 -1
- package/dist/cjs/translation-alignment/segmentDocument.cjs +5 -66
- package/dist/cjs/translation-alignment/segmentDocument.cjs.map +1 -1
- package/dist/cjs/utils/calculateChunks.cjs +2 -89
- package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
- package/dist/cjs/utils/checkAccess.cjs +1 -81
- package/dist/cjs/utils/checkAccess.cjs.map +1 -1
- package/dist/cjs/utils/checkConfigConsistency.cjs +1 -16
- package/dist/cjs/utils/checkConfigConsistency.cjs.map +1 -1
- package/dist/cjs/utils/checkFileModifiedRange.cjs +1 -81
- package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
- package/dist/cjs/utils/checkLastUpdateTime.cjs +1 -19
- package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
- package/dist/cjs/utils/chunkInference.cjs +1 -45
- package/dist/cjs/utils/chunkInference.cjs.map +1 -1
- package/dist/cjs/utils/fixChunkStartEndChars.cjs +3 -27
- package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
- package/dist/cjs/utils/formatTimeDiff.cjs +1 -20
- package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
- package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +1 -16
- package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
- package/dist/cjs/utils/getOutputFilePath.cjs +1 -74
- package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
- package/dist/cjs/utils/getParentPackageJSON.cjs +1 -20
- package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
- package/dist/cjs/utils/listSpecialChars.cjs +2 -54
- package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs +1 -102
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
- package/dist/cjs/utils/openBrowser.cjs +1 -19
- package/dist/cjs/utils/openBrowser.cjs.map +1 -1
- package/dist/cjs/utils/reorderParagraphs.cjs +3 -91
- package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
- package/dist/cjs/utils/setupAI.cjs +1 -64
- package/dist/cjs/utils/setupAI.cjs.map +1 -1
- package/dist/cjs/watch.cjs +1 -43
- package/dist/cjs/watch.cjs.map +1 -1
- package/dist/esm/IntlayerEventListener.mjs +1 -183
- package/dist/esm/IntlayerEventListener.mjs.map +1 -1
- package/dist/esm/_virtual/_rolldown/runtime.mjs +1 -8
- package/dist/esm/_virtual/_utils_asset.mjs +2 -97
- package/dist/esm/auth/login.mjs +2 -82
- package/dist/esm/auth/login.mjs.map +1 -1
- package/dist/esm/build.mjs +1 -25
- package/dist/esm/build.mjs.map +1 -1
- package/dist/esm/ci.mjs +1 -71
- package/dist/esm/ci.mjs.map +1 -1
- package/dist/esm/cli.mjs +1 -473
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/config.mjs +1 -10
- package/dist/esm/config.mjs.map +1 -1
- package/dist/esm/editor.mjs +1 -49
- package/dist/esm/editor.mjs.map +1 -1
- package/dist/esm/extract.mjs +1 -93
- package/dist/esm/extract.mjs.map +1 -1
- package/dist/esm/fill/deepMergeContent.mjs +1 -25
- package/dist/esm/fill/deepMergeContent.mjs.map +1 -1
- package/dist/esm/fill/fill.mjs +1 -76
- package/dist/esm/fill/fill.mjs.map +1 -1
- package/dist/esm/fill/formatAutoFilledFilePath.mjs +1 -27
- package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
- package/dist/esm/fill/formatFillData.mjs +1 -49
- package/dist/esm/fill/formatFillData.mjs.map +1 -1
- package/dist/esm/fill/getAvailableLocalesInDictionary.mjs +1 -24
- package/dist/esm/fill/getAvailableLocalesInDictionary.mjs.map +1 -1
- package/dist/esm/fill/getFilterMissingContentPerLocale.mjs +1 -48
- package/dist/esm/fill/getFilterMissingContentPerLocale.mjs.map +1 -1
- package/dist/esm/fill/index.mjs +1 -4
- package/dist/esm/fill/listTranslationsTasks.mjs +1 -68
- package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -1
- package/dist/esm/fill/mergeChunks.mjs +1 -26
- package/dist/esm/fill/mergeChunks.mjs.map +1 -1
- package/dist/esm/fill/translateDictionary.mjs +1 -203
- package/dist/esm/fill/translateDictionary.mjs.map +1 -1
- package/dist/esm/fill/writeFill.mjs +1 -52
- package/dist/esm/fill/writeFill.mjs.map +1 -1
- package/dist/esm/getTargetDictionary.mjs +1 -33
- package/dist/esm/getTargetDictionary.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -18
- package/dist/esm/init.mjs +1 -317
- package/dist/esm/init.mjs.map +1 -1
- package/dist/esm/initSkills.mjs +2 -0
- package/dist/esm/initSkills.mjs.map +1 -0
- package/dist/esm/listContentDeclaration.mjs +1 -38
- package/dist/esm/listContentDeclaration.mjs.map +1 -1
- package/dist/esm/listProjects.mjs +1 -26
- package/dist/esm/listProjects.mjs.map +1 -1
- package/dist/esm/liveSync.mjs +8 -148
- package/dist/esm/liveSync.mjs.map +1 -1
- package/dist/esm/pull.mjs +1 -144
- package/dist/esm/pull.mjs.map +1 -1
- package/dist/esm/push/pullLog.mjs +3 -100
- package/dist/esm/push/pullLog.mjs.map +1 -1
- package/dist/esm/push/push.mjs +1 -203
- package/dist/esm/push/push.mjs.map +1 -1
- package/dist/esm/pushConfig.mjs +1 -17
- package/dist/esm/pushConfig.mjs.map +1 -1
- package/dist/esm/pushLog.mjs +3 -82
- package/dist/esm/pushLog.mjs.map +1 -1
- package/dist/esm/reviewDoc/reviewDoc.mjs +1 -65
- package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
- package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +1 -92
- package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
- package/dist/esm/searchDoc.mjs +1 -36
- package/dist/esm/searchDoc.mjs.map +1 -1
- package/dist/esm/test/index.mjs +1 -4
- package/dist/esm/test/listMissingTranslations.mjs +1 -46
- package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
- package/dist/esm/test/test.mjs +1 -51
- package/dist/esm/test/test.mjs.map +1 -1
- package/dist/esm/translateDoc/index.mjs +1 -5
- package/dist/esm/translateDoc/translateDoc.mjs +1 -71
- package/dist/esm/translateDoc/translateDoc.mjs.map +1 -1
- package/dist/esm/translateDoc/translateFile.mjs +2 -101
- package/dist/esm/translateDoc/translateFile.mjs.map +1 -1
- package/dist/esm/translateDoc/validation.mjs +5 -46
- package/dist/esm/translateDoc/validation.mjs.map +1 -1
- package/dist/esm/translation-alignment/alignBlocks.mjs +1 -66
- package/dist/esm/translation-alignment/alignBlocks.mjs.map +1 -1
- package/dist/esm/translation-alignment/computeSimilarity.mjs +1 -22
- package/dist/esm/translation-alignment/computeSimilarity.mjs.map +1 -1
- package/dist/esm/translation-alignment/fingerprintBlock.mjs +1 -20
- package/dist/esm/translation-alignment/fingerprintBlock.mjs.map +1 -1
- package/dist/esm/translation-alignment/index.mjs +1 -11
- package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs +1 -16
- package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs.map +1 -1
- package/dist/esm/translation-alignment/normalizeBlock.mjs +1 -20
- package/dist/esm/translation-alignment/normalizeBlock.mjs.map +1 -1
- package/dist/esm/translation-alignment/pipeline.mjs +1 -35
- package/dist/esm/translation-alignment/pipeline.mjs.map +1 -1
- package/dist/esm/translation-alignment/planActions.mjs +1 -44
- package/dist/esm/translation-alignment/planActions.mjs.map +1 -1
- package/dist/esm/translation-alignment/rebuildDocument.mjs +2 -46
- package/dist/esm/translation-alignment/rebuildDocument.mjs.map +1 -1
- package/dist/esm/translation-alignment/segmentDocument.mjs +5 -64
- package/dist/esm/translation-alignment/segmentDocument.mjs.map +1 -1
- package/dist/esm/utils/calculateChunks.mjs +2 -87
- package/dist/esm/utils/calculateChunks.mjs.map +1 -1
- package/dist/esm/utils/checkAccess.mjs +1 -78
- package/dist/esm/utils/checkAccess.mjs.map +1 -1
- package/dist/esm/utils/checkConfigConsistency.mjs +1 -14
- package/dist/esm/utils/checkConfigConsistency.mjs.map +1 -1
- package/dist/esm/utils/checkFileModifiedRange.mjs +1 -80
- package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
- package/dist/esm/utils/checkLastUpdateTime.mjs +1 -17
- package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
- package/dist/esm/utils/chunkInference.mjs +1 -43
- package/dist/esm/utils/chunkInference.mjs.map +1 -1
- package/dist/esm/utils/fixChunkStartEndChars.mjs +3 -25
- package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
- package/dist/esm/utils/formatTimeDiff.mjs +1 -18
- package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
- package/dist/esm/utils/getIsFileUpdatedRecently.mjs +1 -14
- package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
- package/dist/esm/utils/getOutputFilePath.mjs +1 -72
- package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
- package/dist/esm/utils/getParentPackageJSON.mjs +1 -18
- package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
- package/dist/esm/utils/listSpecialChars.mjs +2 -52
- package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
- package/dist/esm/utils/mapChunksBetweenFiles.mjs +1 -100
- package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
- package/dist/esm/utils/openBrowser.mjs +1 -17
- package/dist/esm/utils/openBrowser.mjs.map +1 -1
- package/dist/esm/utils/reorderParagraphs.mjs +3 -90
- package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
- package/dist/esm/utils/setupAI.mjs +1 -62
- package/dist/esm/utils/setupAI.mjs.map +1 -1
- package/dist/esm/watch.mjs +1 -41
- package/dist/esm/watch.mjs.map +1 -1
- package/dist/types/auth/login.d.ts +1 -1
- package/dist/types/auth/login.d.ts.map +1 -1
- package/dist/types/build.d.ts +1 -1
- package/dist/types/build.d.ts.map +1 -1
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/extract.d.ts +1 -1
- package/dist/types/extract.d.ts.map +1 -1
- package/dist/types/fill/fill.d.ts +1 -1
- package/dist/types/fill/fill.d.ts.map +1 -1
- package/dist/types/fill/translateDictionary.d.ts +2 -2
- package/dist/types/fill/translateDictionary.d.ts.map +1 -1
- package/dist/types/fill/writeFill.d.ts.map +1 -1
- package/dist/types/getTargetDictionary.d.ts +2 -2
- package/dist/types/index.d.ts +7 -3
- package/dist/types/init.d.ts +2 -5
- package/dist/types/init.d.ts.map +1 -1
- package/dist/types/initSkills.d.ts +8 -0
- package/dist/types/initSkills.d.ts.map +1 -0
- package/dist/types/listContentDeclaration.d.ts +1 -1
- package/dist/types/listContentDeclaration.d.ts.map +1 -1
- package/dist/types/liveSync.d.ts +1 -1
- package/dist/types/pull.d.ts +1 -1
- package/dist/types/pull.d.ts.map +1 -1
- package/dist/types/push/pullLog.d.ts +1 -1
- package/dist/types/push/pullLog.d.ts.map +1 -1
- package/dist/types/push/push.d.ts +2 -2
- package/dist/types/pushConfig.d.ts +1 -1
- package/dist/types/reviewDoc/reviewDoc.d.ts +2 -2
- package/dist/types/reviewDoc/reviewDoc.d.ts.map +1 -1
- package/dist/types/reviewDoc/reviewDocBlockAware.d.ts +1 -1
- package/dist/types/reviewDoc/reviewDocBlockAware.d.ts.map +1 -1
- package/dist/types/searchDoc.d.ts +1 -1
- package/dist/types/searchDoc.d.ts.map +1 -1
- package/dist/types/test/listMissingTranslations.d.ts +1 -1
- package/dist/types/test/test.d.ts +1 -1
- package/dist/types/test/test.d.ts.map +1 -1
- package/dist/types/translateDoc/translateDoc.d.ts.map +1 -1
- package/dist/types/translateDoc/types.d.ts +2 -2
- package/dist/types/translateDoc/validation.d.ts +1 -1
- package/dist/types/utils/checkAccess.d.ts.map +1 -1
- package/dist/types/watch.d.ts +1 -1
- package/dist/types/watch.d.ts.map +1 -1
- package/package.json +11 -11
|
@@ -1,95 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require__utils_asset = require('../_virtual/_utils_asset.cjs');
|
|
4
|
-
const require_translateDoc_validation = require('../translateDoc/validation.cjs');
|
|
5
|
-
const require_translation_alignment_rebuildDocument = require('../translation-alignment/rebuildDocument.cjs');
|
|
6
|
-
const require_translation_alignment_pipeline = require('../translation-alignment/pipeline.cjs');
|
|
7
|
-
const require_utils_chunkInference = require('../utils/chunkInference.cjs');
|
|
8
|
-
const require_utils_fixChunkStartEndChars = require('../utils/fixChunkStartEndChars.cjs');
|
|
9
|
-
let _intlayer_chokidar = require("@intlayer/chokidar");
|
|
10
|
-
let _intlayer_config = require("@intlayer/config");
|
|
11
|
-
let node_path = require("node:path");
|
|
12
|
-
let node_fs = require("node:fs");
|
|
13
|
-
let node_fs_promises = require("node:fs/promises");
|
|
14
|
-
let _intlayer_core = require("@intlayer/core");
|
|
15
|
-
let _intlayer_types = require("@intlayer/types");
|
|
16
|
-
|
|
17
|
-
//#region src/reviewDoc/reviewDocBlockAware.ts
|
|
18
|
-
/**
|
|
19
|
-
* Review a file using block-aware alignment.
|
|
20
|
-
* This approach:
|
|
21
|
-
* 1. Segments both English and French documents into semantic blocks
|
|
22
|
-
* 2. Aligns blocks using structure (special chars, numbers) and context
|
|
23
|
-
* 3. Detects which blocks changed, were added, or deleted
|
|
24
|
-
* 4. Only sends changed/new blocks to AI for translation
|
|
25
|
-
* 5. Handles reordering automatically
|
|
26
|
-
*/
|
|
27
|
-
const reviewFileBlockAware = async (baseFilePath, outputFilePath, locale, baseLocale, aiOptions, configOptions, customInstructions, changedLines, aiClient, aiConfig) => {
|
|
28
|
-
const configuration = (0, _intlayer_config.getConfiguration)(configOptions);
|
|
29
|
-
const applicationLogger = (0, _intlayer_config.getAppLogger)(configuration);
|
|
30
|
-
const englishText = await (0, node_fs_promises.readFile)(baseFilePath, "utf-8");
|
|
31
|
-
const frenchText = await (0, node_fs_promises.readFile)(outputFilePath, "utf-8").catch(() => "");
|
|
32
|
-
const basePrompt = require__utils_asset.readAsset("./prompts/REVIEW_PROMPT.md", "utf-8").replaceAll("{{localeName}}", `${(0, _intlayer_chokidar.formatLocale)(locale, false)}`).replaceAll("{{baseLocaleName}}", `${(0, _intlayer_chokidar.formatLocale)(baseLocale, false)}`).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
|
|
33
|
-
const filePrefix = [(0, _intlayer_config.colon)(`${_intlayer_config.ANSIColors.GREY_DARK}[${(0, _intlayer_chokidar.formatPath)(baseFilePath)}${_intlayer_config.ANSIColors.GREY_DARK}] `, { colSize: 40 }), `→ ${_intlayer_config.ANSIColors.RESET}`].join("");
|
|
34
|
-
const prefix = [(0, _intlayer_config.colon)(`${_intlayer_config.ANSIColors.GREY_DARK}[${(0, _intlayer_chokidar.formatPath)(baseFilePath)}${_intlayer_config.ANSIColors.GREY_DARK}][${(0, _intlayer_chokidar.formatLocale)(locale)}${_intlayer_config.ANSIColors.GREY_DARK}] `, { colSize: 40 }), `→ ${_intlayer_config.ANSIColors.RESET}`].join("");
|
|
35
|
-
const { englishBlocks, frenchBlocks, plan, segmentsToReview } = require_translation_alignment_pipeline.buildAlignmentPlan({
|
|
36
|
-
englishText,
|
|
37
|
-
frenchText,
|
|
38
|
-
changedLines
|
|
39
|
-
});
|
|
40
|
-
applicationLogger(`${filePrefix}Block-aware alignment complete. Total blocks: EN=${(0, _intlayer_config.colorizeNumber)(englishBlocks.length)}, FR=${(0, _intlayer_config.colorizeNumber)(frenchBlocks.length)}`);
|
|
41
|
-
applicationLogger(`${filePrefix}Actions: reuse=${(0, _intlayer_config.colorizeNumber)(plan.actions.filter((a) => a.kind === "reuse").length)}, review=${(0, _intlayer_config.colorizeNumber)(plan.actions.filter((a) => a.kind === "review").length)}, new=${(0, _intlayer_config.colorizeNumber)(plan.actions.filter((a) => a.kind === "insert_new").length)}, delete=${(0, _intlayer_config.colorizeNumber)(plan.actions.filter((a) => a.kind === "delete").length)}`);
|
|
42
|
-
if (segmentsToReview.length === 0) {
|
|
43
|
-
applicationLogger(`${filePrefix}No segments need review, reusing existing translation`);
|
|
44
|
-
(0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
|
|
45
|
-
(0, node_fs.writeFileSync)(outputFilePath, require_translation_alignment_rebuildDocument.mergeReviewedSegments(plan, frenchBlocks, /* @__PURE__ */ new Map()));
|
|
46
|
-
applicationLogger(`${(0, _intlayer_config.colorize)("✔", _intlayer_config.ANSIColors.GREEN)} File ${(0, _intlayer_chokidar.formatPath)(outputFilePath)} updated successfully (no changes needed).`);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
applicationLogger(`${filePrefix}Segments to review: ${(0, _intlayer_config.colorizeNumber)(segmentsToReview.length)}`);
|
|
50
|
-
const reviewedSegmentsMap = /* @__PURE__ */ new Map();
|
|
51
|
-
for (const segment of segmentsToReview) {
|
|
52
|
-
const segmentNumber = segmentsToReview.indexOf(segment) + 1;
|
|
53
|
-
const englishBlock = segment.englishBlock;
|
|
54
|
-
const getBaseChunkContextPrompt = () => `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the base block in ${(0, _intlayer_chokidar.formatLocale)(baseLocale, false)} as reference.\n///chunksStart///\n` + englishBlock.content + `///chunksEnd///`;
|
|
55
|
-
const getFrenchChunkPrompt = () => `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the current block to review in ${(0, _intlayer_chokidar.formatLocale)(locale, false)}.\n///chunksStart///\n` + (segment.frenchBlockText ?? "") + `///chunksEnd///`;
|
|
56
|
-
const reviewedChunkResult = await (0, _intlayer_config.retryManager)(async () => {
|
|
57
|
-
const result = await require_utils_chunkInference.chunkInference([
|
|
58
|
-
{
|
|
59
|
-
role: "system",
|
|
60
|
-
content: basePrompt
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
role: "system",
|
|
64
|
-
content: getBaseChunkContextPrompt()
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
role: "system",
|
|
68
|
-
content: getFrenchChunkPrompt()
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
role: "system",
|
|
72
|
-
content: `The next user message will be the **BLOCK ${(0, _intlayer_config.colorizeNumber)(segmentNumber)} of ${(0, _intlayer_config.colorizeNumber)(segmentsToReview.length)}** that should be translated in ${(0, _intlayer_core.getLocaleName)(locale, _intlayer_types.Locales.ENGLISH)} (${locale}).`
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
role: "user",
|
|
76
|
-
content: englishBlock.content
|
|
77
|
-
}
|
|
78
|
-
], aiOptions, configuration, aiClient, aiConfig);
|
|
79
|
-
applicationLogger(`${prefix}${(0, _intlayer_config.colorizeNumber)(result.tokenUsed)} tokens used - Block ${(0, _intlayer_config.colorizeNumber)(segmentNumber)} of ${(0, _intlayer_config.colorizeNumber)(segmentsToReview.length)}`);
|
|
80
|
-
let processedChunk = require_translateDoc_validation.sanitizeChunk(result?.fileContent, englishBlock.content);
|
|
81
|
-
processedChunk = require_utils_fixChunkStartEndChars.fixChunkStartEndChars(processedChunk, englishBlock.content);
|
|
82
|
-
if (!require_translateDoc_validation.validateTranslation(englishBlock.content, processedChunk, applicationLogger)) throw new Error("Validation failed for chunk (structure or length mismatch). Retrying...");
|
|
83
|
-
return processedChunk;
|
|
84
|
-
})();
|
|
85
|
-
reviewedSegmentsMap.set(segment.actionIndex, reviewedChunkResult);
|
|
86
|
-
}
|
|
87
|
-
const finalFrenchOutput = require_translation_alignment_rebuildDocument.mergeReviewedSegments(plan, frenchBlocks, reviewedSegmentsMap);
|
|
88
|
-
(0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
|
|
89
|
-
(0, node_fs.writeFileSync)(outputFilePath, finalFrenchOutput);
|
|
90
|
-
applicationLogger(`${(0, _intlayer_config.colorize)("✔", _intlayer_config.ANSIColors.GREEN)} File ${(0, _intlayer_chokidar.formatPath)(outputFilePath)} created/updated successfully.`);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
//#endregion
|
|
94
|
-
exports.reviewFileBlockAware = reviewFileBlockAware;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../_virtual/_utils_asset.cjs`),t=require(`../translateDoc/validation.cjs`),n=require(`../translation-alignment/rebuildDocument.cjs`),r=require(`../translation-alignment/pipeline.cjs`),i=require(`../utils/chunkInference.cjs`),a=require(`../utils/fixChunkStartEndChars.cjs`);let o=require(`@intlayer/chokidar/utils`),s=require(`@intlayer/config/node`),c=require(`node:path`),l=require(`@intlayer/config/logger`),u=require(`@intlayer/config/utils`),d=require(`node:fs`),f=require(`node:fs/promises`),p=require(`@intlayer/core/localization`),m=require(`@intlayer/types`);const h=async(h,g,_,v,y,b,x,S,C,w)=>{let T=(0,s.getConfiguration)(b),E=(0,l.getAppLogger)(T),D=await(0,f.readFile)(h,`utf-8`),O=await(0,f.readFile)(g,`utf-8`).catch(()=>``),k=e.readAsset(`./prompts/REVIEW_PROMPT.md`,`utf-8`).replaceAll(`{{localeName}}`,`${(0,o.formatLocale)(_,!1)}`).replaceAll(`{{baseLocaleName}}`,`${(0,o.formatLocale)(v,!1)}`).replace(`{{applicationContext}}`,y?.applicationContext??`-`).replace(`{{customInstructions}}`,x??`-`),A=[(0,l.colon)(`${l.ANSIColors.GREY_DARK}[${(0,o.formatPath)(h)}${l.ANSIColors.GREY_DARK}] `,{colSize:40}),`→ ${l.ANSIColors.RESET}`].join(``),j=[(0,l.colon)(`${l.ANSIColors.GREY_DARK}[${(0,o.formatPath)(h)}${l.ANSIColors.GREY_DARK}][${(0,o.formatLocale)(_)}${l.ANSIColors.GREY_DARK}] `,{colSize:40}),`→ ${l.ANSIColors.RESET}`].join(``),{englishBlocks:M,frenchBlocks:N,plan:P,segmentsToReview:F}=r.buildAlignmentPlan({englishText:D,frenchText:O,changedLines:S});if(E(`${A}Block-aware alignment complete. Total blocks: EN=${(0,l.colorizeNumber)(M.length)}, FR=${(0,l.colorizeNumber)(N.length)}`),E(`${A}Actions: reuse=${(0,l.colorizeNumber)(P.actions.filter(e=>e.kind===`reuse`).length)}, review=${(0,l.colorizeNumber)(P.actions.filter(e=>e.kind===`review`).length)}, new=${(0,l.colorizeNumber)(P.actions.filter(e=>e.kind===`insert_new`).length)}, delete=${(0,l.colorizeNumber)(P.actions.filter(e=>e.kind===`delete`).length)}`),F.length===0){E(`${A}No segments need review, reusing existing translation`),(0,d.mkdirSync)((0,c.dirname)(g),{recursive:!0}),(0,d.writeFileSync)(g,n.mergeReviewedSegments(P,N,new Map)),E(`${(0,l.colorize)(`✔`,l.ANSIColors.GREEN)} File ${(0,o.formatPath)(g)} updated successfully (no changes needed).`);return}E(`${A}Segments to review: ${(0,l.colorizeNumber)(F.length)}`);let I=new Map;for(let e of F){let n=F.indexOf(e)+1,r=e.englishBlock,s=()=>`**BLOCK ${n} of ${F.length}** is the base block in ${(0,o.formatLocale)(v,!1)} as reference.\n///chunksStart///\n`+r.content+`///chunksEnd///`,c=()=>`**BLOCK ${n} of ${F.length}** is the current block to review in ${(0,o.formatLocale)(_,!1)}.\n///chunksStart///\n`+(e.frenchBlockText??``)+`///chunksEnd///`,d=await(0,u.retryManager)(async()=>{let e=await i.chunkInference([{role:`system`,content:k},{role:`system`,content:s()},{role:`system`,content:c()},{role:`system`,content:`The next user message will be the **BLOCK ${(0,l.colorizeNumber)(n)} of ${(0,l.colorizeNumber)(F.length)}** that should be translated in ${(0,p.getLocaleName)(_,m.Locales.ENGLISH)} (${_}).`},{role:`user`,content:r.content}],y,T,C,w);E(`${j}${(0,l.colorizeNumber)(e.tokenUsed)} tokens used - Block ${(0,l.colorizeNumber)(n)} of ${(0,l.colorizeNumber)(F.length)}`);let o=t.sanitizeChunk(e?.fileContent,r.content);if(o=a.fixChunkStartEndChars(o,r.content),!t.validateTranslation(r.content,o,E))throw Error(`Validation failed for chunk (structure or length mismatch). Retrying...`);return o})();I.set(e.actionIndex,d)}let L=n.mergeReviewedSegments(P,N,I);(0,d.mkdirSync)((0,c.dirname)(g),{recursive:!0}),(0,d.writeFileSync)(g,L),E(`${(0,l.colorize)(`✔`,l.ANSIColors.GREEN)} File ${(0,o.formatPath)(g)} created/updated successfully.`)};exports.reviewFileBlockAware=h;
|
|
95
2
|
//# sourceMappingURL=reviewDocBlockAware.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reviewDocBlockAware.cjs","names":["readAsset","ANSIColors","buildAlignmentPlan","mergeReviewedSegments","chunkInference","Locales","sanitizeChunk","fixChunkStartEndChars","validateTranslation"],"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 { formatLocale, formatPath } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n retryManager,\n} from '@intlayer/config';\nimport { getLocaleName } from '@intlayer/core';\nimport { type Locale, Locales } from '@intlayer/types';\nimport { sanitizeChunk, validateTranslation } from '../translateDoc/validation';\nimport {\n buildAlignmentPlan,\n mergeReviewedSegments,\n} from '../translation-alignment/pipeline';\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 * This approach:\n * 1. Segments both English and French 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. Only sends changed/new blocks to AI for translation\n * 5. Handles reordering automatically\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) => {\n const configuration = getConfiguration(configOptions);\n const applicationLogger = getAppLogger(configuration);\n\n const englishText = await readFile(baseFilePath, 'utf-8');\n const frenchText = 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 { englishBlocks, frenchBlocks, plan, segmentsToReview } =\n buildAlignmentPlan({\n englishText,\n frenchText,\n changedLines,\n });\n\n applicationLogger(\n `${filePrefix}Block-aware alignment complete. Total blocks: EN=${colorizeNumber(englishBlocks.length)}, FR=${colorizeNumber(frenchBlocks.length)}`\n );\n applicationLogger(\n `${filePrefix}Actions: reuse=${colorizeNumber(plan.actions.filter((a) => a.kind === 'reuse').length)}, review=${colorizeNumber(plan.actions.filter((a) => a.kind === 'review').length)}, new=${colorizeNumber(plan.actions.filter((a) => a.kind === 'insert_new').length)}, delete=${colorizeNumber(plan.actions.filter((a) => a.kind === 'delete').length)}`\n );\n\n if (segmentsToReview.length === 0) {\n applicationLogger(\n `${filePrefix}No segments need review, reusing existing translation`\n );\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(\n outputFilePath,\n mergeReviewedSegments(plan, frenchBlocks, new Map())\n );\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} updated successfully (no changes needed).`\n );\n return;\n }\n\n applicationLogger(\n `${filePrefix}Segments to review: ${colorizeNumber(segmentsToReview.length)}`\n );\n\n // Review segments that need AI translation\n const reviewedSegmentsMap = new Map<number, string>();\n\n for (const segment of segmentsToReview) {\n const segmentNumber = segmentsToReview.indexOf(segment) + 1;\n const englishBlock = segment.englishBlock;\n\n const getBaseChunkContextPrompt = () =>\n `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the base block in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///\\n` +\n englishBlock.content +\n `///chunksEnd///`;\n\n const getFrenchChunkPrompt = () =>\n `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the current block to review in ${formatLocale(locale, false)}.\\n` +\n `///chunksStart///\\n` +\n (segment.frenchBlockText ?? '') +\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: getFrenchChunkPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **BLOCK ${colorizeNumber(segmentNumber)} of ${colorizeNumber(segmentsToReview.length)}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`,\n },\n { role: 'user', content: englishBlock.content },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n applicationLogger(\n `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Block ${colorizeNumber(segmentNumber)} of ${colorizeNumber(segmentsToReview.length)}`\n );\n\n // Sanitize artifacts (e.g. Markdown code block wrappers)\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n englishBlock.content\n );\n\n // Fix start/end characters\n processedChunk = fixChunkStartEndChars(\n processedChunk,\n englishBlock.content\n );\n\n // Validate Translation (YAML, Code fences, Length ratio)\n const isValid = validateTranslation(\n englishBlock.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\n // Merge reviewed segments back into final document\n const finalFrenchOutput = mergeReviewedSegments(\n plan,\n frenchBlocks,\n reviewedSegmentsMap\n );\n\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, finalFrenchOutput);\n\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} created/updated successfully.`\n );\n};\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"reviewDocBlockAware.cjs","names":["readAsset","ANSIColors","buildAlignmentPlan","mergeReviewedSegments","chunkInference","Locales","sanitizeChunk","fixChunkStartEndChars","validateTranslation"],"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 { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\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 { type Locale, Locales } from '@intlayer/types';\nimport { sanitizeChunk, validateTranslation } from '../translateDoc/validation';\nimport {\n buildAlignmentPlan,\n mergeReviewedSegments,\n} from '../translation-alignment/pipeline';\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 * This approach:\n * 1. Segments both English and French 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. Only sends changed/new blocks to AI for translation\n * 5. Handles reordering automatically\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) => {\n const configuration = getConfiguration(configOptions);\n const applicationLogger = getAppLogger(configuration);\n\n const englishText = await readFile(baseFilePath, 'utf-8');\n const frenchText = 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 { englishBlocks, frenchBlocks, plan, segmentsToReview } =\n buildAlignmentPlan({\n englishText,\n frenchText,\n changedLines,\n });\n\n applicationLogger(\n `${filePrefix}Block-aware alignment complete. Total blocks: EN=${colorizeNumber(englishBlocks.length)}, FR=${colorizeNumber(frenchBlocks.length)}`\n );\n applicationLogger(\n `${filePrefix}Actions: reuse=${colorizeNumber(plan.actions.filter((a) => a.kind === 'reuse').length)}, review=${colorizeNumber(plan.actions.filter((a) => a.kind === 'review').length)}, new=${colorizeNumber(plan.actions.filter((a) => a.kind === 'insert_new').length)}, delete=${colorizeNumber(plan.actions.filter((a) => a.kind === 'delete').length)}`\n );\n\n if (segmentsToReview.length === 0) {\n applicationLogger(\n `${filePrefix}No segments need review, reusing existing translation`\n );\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(\n outputFilePath,\n mergeReviewedSegments(plan, frenchBlocks, new Map())\n );\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} updated successfully (no changes needed).`\n );\n return;\n }\n\n applicationLogger(\n `${filePrefix}Segments to review: ${colorizeNumber(segmentsToReview.length)}`\n );\n\n // Review segments that need AI translation\n const reviewedSegmentsMap = new Map<number, string>();\n\n for (const segment of segmentsToReview) {\n const segmentNumber = segmentsToReview.indexOf(segment) + 1;\n const englishBlock = segment.englishBlock;\n\n const getBaseChunkContextPrompt = () =>\n `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the base block in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///\\n` +\n englishBlock.content +\n `///chunksEnd///`;\n\n const getFrenchChunkPrompt = () =>\n `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the current block to review in ${formatLocale(locale, false)}.\\n` +\n `///chunksStart///\\n` +\n (segment.frenchBlockText ?? '') +\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: getFrenchChunkPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **BLOCK ${colorizeNumber(segmentNumber)} of ${colorizeNumber(segmentsToReview.length)}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`,\n },\n { role: 'user', content: englishBlock.content },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n applicationLogger(\n `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Block ${colorizeNumber(segmentNumber)} of ${colorizeNumber(segmentsToReview.length)}`\n );\n\n // Sanitize artifacts (e.g. Markdown code block wrappers)\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n englishBlock.content\n );\n\n // Fix start/end characters\n processedChunk = fixChunkStartEndChars(\n processedChunk,\n englishBlock.content\n );\n\n // Validate Translation (YAML, Code fences, Length ratio)\n const isValid = validateTranslation(\n englishBlock.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\n // Merge reviewed segments back into final document\n const finalFrenchOutput = mergeReviewedSegments(\n plan,\n frenchBlocks,\n reviewedSegmentsMap\n );\n\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, finalFrenchOutput);\n\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} created/updated successfully.`\n );\n};\n"],"mappings":"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"}
|
package/dist/cjs/searchDoc.cjs
CHANGED
|
@@ -1,39 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let _intlayer_api = require("@intlayer/api");
|
|
4
|
-
let _intlayer_config = require("@intlayer/config");
|
|
5
|
-
|
|
6
|
-
//#region src/searchDoc.ts
|
|
7
|
-
const searchDoc = async ({ query, limit = 10, configOptions }) => {
|
|
8
|
-
const config = (0, _intlayer_config.getConfiguration)(configOptions);
|
|
9
|
-
const appLogger = (0, _intlayer_config.getAppLogger)(config);
|
|
10
|
-
try {
|
|
11
|
-
const { searchDoc } = (0, _intlayer_api.getSearchAPI)(void 0, config);
|
|
12
|
-
const response = await searchDoc({
|
|
13
|
-
input: query,
|
|
14
|
-
limit: limit.toString(),
|
|
15
|
-
returnContent: "true"
|
|
16
|
-
});
|
|
17
|
-
if (!response.data || !Array.isArray(response.data)) {
|
|
18
|
-
appLogger("No relevant chunks found.");
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const chunks = response.data;
|
|
22
|
-
appLogger(`Found ${(0, _intlayer_config.colorizeNumber)(chunks.length)} relevant chunks:`);
|
|
23
|
-
chunks.forEach((chunk) => {
|
|
24
|
-
appLogger("---");
|
|
25
|
-
appLogger(`${(0, _intlayer_config.colorizeKey)("File")}: ${chunk.fileKey}`);
|
|
26
|
-
appLogger(`${(0, _intlayer_config.colorizeKey)("Title")}: ${chunk.docName}`);
|
|
27
|
-
appLogger(`${(0, _intlayer_config.colorizeKey)("URL")}: ${chunk.docUrl}`);
|
|
28
|
-
appLogger(`${(0, _intlayer_config.colorizeKey)("Chunk")}: ${chunk.chunkNumber}`);
|
|
29
|
-
appLogger(`${(0, _intlayer_config.colorizeKey)("Content")}:`);
|
|
30
|
-
appLogger(chunk.content);
|
|
31
|
-
});
|
|
32
|
-
} catch (error) {
|
|
33
|
-
appLogger(`Search failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`, { level: "error" });
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
exports.searchDoc = searchDoc;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/api`),t=require(`@intlayer/config/node`),n=require(`@intlayer/config/logger`);const r=async({query:r,limit:i=10,configOptions:a})=>{let o=(0,t.getConfiguration)(a),s=(0,n.getAppLogger)(o);try{let{searchDoc:t}=(0,e.getSearchAPI)(void 0,o),a=await t({input:r,limit:i.toString(),returnContent:`true`});if(!a.data||!Array.isArray(a.data)){s(`No relevant chunks found.`);return}let c=a.data;s(`Found ${(0,n.colorizeNumber)(c.length)} relevant chunks:`),c.forEach(e=>{s(`---`),s(`${(0,n.colorizeKey)(`File`)}: ${e.fileKey}`),s(`${(0,n.colorizeKey)(`Title`)}: ${e.docName}`),s(`${(0,n.colorizeKey)(`URL`)}: ${e.docUrl}`),s(`${(0,n.colorizeKey)(`Chunk`)}: ${e.chunkNumber}`),s(`${(0,n.colorizeKey)(`Content`)}:`),s(e.content)})}catch(e){s(`Search failed: ${e instanceof Error?e.message:`An unknown error occurred`}`,{level:`error`})}};exports.searchDoc=r;
|
|
39
2
|
//# sourceMappingURL=searchDoc.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchDoc.cjs","names":[],"sources":["../../src/searchDoc.ts"],"sourcesContent":["import { getSearchAPI } from '@intlayer/api';\nimport {\n colorizeKey,\n colorizeNumber,\n type GetConfigurationOptions,\n
|
|
1
|
+
{"version":3,"file":"searchDoc.cjs","names":[],"sources":["../../src/searchDoc.ts"],"sourcesContent":["import { getSearchAPI } from '@intlayer/api';\nimport {\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\n\ninterface SearchDocOptions {\n query: string;\n limit?: number;\n configOptions?: GetConfigurationOptions;\n}\n\nexport const searchDoc = async ({\n query,\n limit = 10,\n configOptions,\n}: SearchDocOptions) => {\n const config = getConfiguration(configOptions);\n const appLogger = getAppLogger(config);\n\n try {\n const { searchDoc } = getSearchAPI(undefined, config);\n const response = await searchDoc({\n input: query,\n limit: limit.toString(),\n returnContent: 'true',\n });\n\n if (!response.data || !Array.isArray(response.data)) {\n appLogger('No relevant chunks found.');\n return;\n }\n\n const chunks = response.data;\n\n appLogger(`Found ${colorizeNumber(chunks.length)} relevant chunks:`);\n\n chunks.forEach((chunk: any) => {\n appLogger('---');\n appLogger(`${colorizeKey('File')}: ${chunk.fileKey}`);\n appLogger(`${colorizeKey('Title')}: ${chunk.docName}`);\n appLogger(`${colorizeKey('URL')}: ${chunk.docUrl}`);\n appLogger(`${colorizeKey('Chunk')}: ${chunk.chunkNumber}`);\n appLogger(`${colorizeKey('Content')}:`);\n appLogger(chunk.content);\n });\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n appLogger(`Search failed: ${errorMessage}`, { level: 'error' });\n }\n};\n"],"mappings":"sNAiBA,MAAa,EAAY,MAAO,CAC9B,QACA,QAAQ,GACR,mBACsB,CACtB,IAAM,GAAA,EAAA,EAAA,kBAA0B,EAAc,CACxC,GAAA,EAAA,EAAA,cAAyB,EAAO,CAEtC,GAAI,CACF,GAAM,CAAE,cAAA,EAAA,EAAA,cAA2B,IAAA,GAAW,EAAO,CAC/C,EAAW,MAAM,EAAU,CAC/B,MAAO,EACP,MAAO,EAAM,UAAU,CACvB,cAAe,OAChB,CAAC,CAEF,GAAI,CAAC,EAAS,MAAQ,CAAC,MAAM,QAAQ,EAAS,KAAK,CAAE,CACnD,EAAU,4BAA4B,CACtC,OAGF,IAAM,EAAS,EAAS,KAExB,EAAU,UAAA,EAAA,EAAA,gBAAwB,EAAO,OAAO,CAAC,mBAAmB,CAEpE,EAAO,QAAS,GAAe,CAC7B,EAAU,MAAM,CAChB,EAAU,IAAA,EAAA,EAAA,aAAe,OAAO,CAAC,IAAI,EAAM,UAAU,CACrD,EAAU,IAAA,EAAA,EAAA,aAAe,QAAQ,CAAC,IAAI,EAAM,UAAU,CACtD,EAAU,IAAA,EAAA,EAAA,aAAe,MAAM,CAAC,IAAI,EAAM,SAAS,CACnD,EAAU,IAAA,EAAA,EAAA,aAAe,QAAQ,CAAC,IAAI,EAAM,cAAc,CAC1D,EAAU,IAAA,EAAA,EAAA,aAAe,UAAU,CAAC,GAAG,CACvC,EAAU,EAAM,QAAQ,EACxB,OACK,EAAO,CAGd,EAAU,kBADR,aAAiB,MAAQ,EAAM,QAAU,8BACC,CAAE,MAAO,QAAS,CAAC"}
|
package/dist/cjs/test/index.cjs
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_test_listMissingTranslations = require('./listMissingTranslations.cjs');
|
|
3
|
-
const require_test_test = require('./test.cjs');
|
|
4
|
-
|
|
5
|
-
exports.listMissingTranslations = require_test_listMissingTranslations.listMissingTranslations;
|
|
6
|
-
exports.listMissingTranslationsWithConfig = require_test_listMissingTranslations.listMissingTranslationsWithConfig;
|
|
7
|
-
exports.testMissingTranslations = require_test_test.testMissingTranslations;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./listMissingTranslations.cjs`),t=require(`./test.cjs`);exports.listMissingTranslations=e.listMissingTranslations,exports.listMissingTranslationsWithConfig=e.listMissingTranslationsWithConfig,exports.testMissingTranslations=t.testMissingTranslations;
|
|
@@ -1,50 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let _intlayer_config = require("@intlayer/config");
|
|
4
|
-
let _intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
|
|
5
|
-
let _intlayer_core = require("@intlayer/core");
|
|
6
|
-
let _intlayer_dictionaries_entry = require("@intlayer/dictionaries-entry");
|
|
7
|
-
|
|
8
|
-
//#region src/test/listMissingTranslations.ts
|
|
9
|
-
const listMissingTranslationsWithConfig = (configuration) => {
|
|
10
|
-
const unmergedDictionariesRecord = (0, _intlayer_unmerged_dictionaries_entry.getUnmergedDictionaries)(configuration);
|
|
11
|
-
const mergedDictionaries = (0, _intlayer_dictionaries_entry.getDictionaries)(configuration);
|
|
12
|
-
const missingTranslations = [];
|
|
13
|
-
const { locales, requiredLocales } = configuration.internationalization;
|
|
14
|
-
const dictionariesKeys = Object.keys(unmergedDictionariesRecord);
|
|
15
|
-
for (const dictionaryKey of dictionariesKeys) {
|
|
16
|
-
const dictionaries = unmergedDictionariesRecord[dictionaryKey];
|
|
17
|
-
const multilingualDictionary = dictionaries.filter((dictionary) => !dictionary.locale);
|
|
18
|
-
for (const dictionary of multilingualDictionary) {
|
|
19
|
-
const missingLocales = (0, _intlayer_core.getMissingLocalesContentFromDictionary)(dictionary, locales);
|
|
20
|
-
if (missingLocales.length > 0) missingTranslations.push({
|
|
21
|
-
key: dictionaryKey,
|
|
22
|
-
id: dictionary.id,
|
|
23
|
-
filePath: dictionary.filePath,
|
|
24
|
-
locales: missingLocales
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
if (dictionaries.filter((dictionary) => dictionary.locale).length === 0) continue;
|
|
28
|
-
const mergedDictionary = mergedDictionaries[dictionaryKey];
|
|
29
|
-
const missingLocales = (0, _intlayer_core.getMissingLocalesContentFromDictionary)(mergedDictionary, locales);
|
|
30
|
-
if (missingLocales.length > 0) missingTranslations.push({
|
|
31
|
-
key: dictionaryKey,
|
|
32
|
-
locales: missingLocales
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
const missingLocalesSet = new Set(missingTranslations.flatMap((t) => t.locales));
|
|
36
|
-
const missingLocales = Array.from(missingLocalesSet);
|
|
37
|
-
return {
|
|
38
|
-
missingTranslations,
|
|
39
|
-
missingLocales,
|
|
40
|
-
missingRequiredLocales: missingLocales.filter((locale) => (requiredLocales ?? locales).includes(locale))
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
const listMissingTranslations = (configurationOptions) => {
|
|
44
|
-
return listMissingTranslationsWithConfig((0, _intlayer_config.getConfiguration)(configurationOptions));
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
exports.listMissingTranslations = listMissingTranslations;
|
|
49
|
-
exports.listMissingTranslationsWithConfig = listMissingTranslationsWithConfig;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/config/node`),t=require(`@intlayer/unmerged-dictionaries-entry`),n=require(`@intlayer/core/plugins`),r=require(`@intlayer/dictionaries-entry`);const i=e=>{let i=(0,t.getUnmergedDictionaries)(e),a=(0,r.getDictionaries)(e),o=[],{locales:s,requiredLocales:c}=e.internationalization,l=Object.keys(i);for(let e of l){let t=i[e],r=t.filter(e=>!e.locale);for(let t of r){let r=(0,n.getMissingLocalesContentFromDictionary)(t,s);r.length>0&&o.push({key:e,id:t.id,filePath:t.filePath,locales:r})}if(t.filter(e=>e.locale).length===0)continue;let c=a[e],l=(0,n.getMissingLocalesContentFromDictionary)(c,s);l.length>0&&o.push({key:e,locales:l})}let u=new Set(o.flatMap(e=>e.locales)),d=Array.from(u);return{missingTranslations:o,missingLocales:d,missingRequiredLocales:d.filter(e=>(c??s).includes(e))}},a=t=>i((0,e.getConfiguration)(t));exports.listMissingTranslations=a,exports.listMissingTranslationsWithConfig=i;
|
|
50
2
|
//# sourceMappingURL=listMissingTranslations.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listMissingTranslations.cjs","names":[],"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config';\nimport { getMissingLocalesContentFromDictionary } from '@intlayer/core';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, IntlayerConfig, Locale } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslationsWithConfig = (\n configuration: IntlayerConfig\n) => {\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n const mergedDictionaries = getDictionaries(configuration);\n\n const missingTranslations: {\n key: string;\n filePath?: string;\n id?: string;\n locales: Locale[];\n }[] = [];\n\n const { locales, requiredLocales } = configuration.internationalization;\n\n const dictionariesKeys = Object.keys(unmergedDictionariesRecord);\n\n for (const dictionaryKey of dictionariesKeys) {\n const dictionaries: Dictionary[] =\n unmergedDictionariesRecord[dictionaryKey];\n\n const multilingualDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => !dictionary.locale\n );\n\n // Test all by merging all dictionaries to ensure no per-locale dictionary is missing\n for (const dictionary of multilingualDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n dictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: dictionary.id,\n filePath: dictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n const perLocaleDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => dictionary.locale\n );\n\n if (perLocaleDictionary.length === 0) {\n continue;\n }\n\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n locales: missingLocales,\n });\n }\n }\n\n const missingLocalesSet = new Set(\n missingTranslations.flatMap((t) => t.locales)\n );\n const missingLocales = Array.from(missingLocalesSet);\n\n const missingRequiredLocales = missingLocales.filter((locale) =>\n (requiredLocales ?? locales).includes(locale)\n );\n\n return { missingTranslations, missingLocales, missingRequiredLocales };\n};\n\nexport const listMissingTranslations = (\n configurationOptions?: GetConfigurationOptions\n) => {\n const configuration = getConfiguration(configurationOptions);\n\n return listMissingTranslationsWithConfig(configuration);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"listMissingTranslations.cjs","names":[],"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { getMissingLocalesContentFromDictionary } from '@intlayer/core/plugins';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, IntlayerConfig, Locale } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslationsWithConfig = (\n configuration: IntlayerConfig\n) => {\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n const mergedDictionaries = getDictionaries(configuration);\n\n const missingTranslations: {\n key: string;\n filePath?: string;\n id?: string;\n locales: Locale[];\n }[] = [];\n\n const { locales, requiredLocales } = configuration.internationalization;\n\n const dictionariesKeys = Object.keys(unmergedDictionariesRecord);\n\n for (const dictionaryKey of dictionariesKeys) {\n const dictionaries: Dictionary[] =\n unmergedDictionariesRecord[dictionaryKey];\n\n const multilingualDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => !dictionary.locale\n );\n\n // Test all by merging all dictionaries to ensure no per-locale dictionary is missing\n for (const dictionary of multilingualDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n dictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: dictionary.id,\n filePath: dictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n const perLocaleDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => dictionary.locale\n );\n\n if (perLocaleDictionary.length === 0) {\n continue;\n }\n\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n locales: missingLocales,\n });\n }\n }\n\n const missingLocalesSet = new Set(\n missingTranslations.flatMap((t) => t.locales)\n );\n const missingLocales = Array.from(missingLocalesSet);\n\n const missingRequiredLocales = missingLocales.filter((locale) =>\n (requiredLocales ?? locales).includes(locale)\n );\n\n return { missingTranslations, missingLocales, missingRequiredLocales };\n};\n\nexport const listMissingTranslations = (\n configurationOptions?: GetConfigurationOptions\n) => {\n const configuration = getConfiguration(configurationOptions);\n\n return listMissingTranslationsWithConfig(configuration);\n};\n"],"mappings":"wRASA,MAAa,EACX,GACG,CACH,IAAM,GAAA,EAAA,EAAA,yBAAqD,EAAc,CACnE,GAAA,EAAA,EAAA,iBAAqC,EAAc,CAEnD,EAKA,EAAE,CAEF,CAAE,UAAS,mBAAoB,EAAc,qBAE7C,EAAmB,OAAO,KAAK,EAA2B,CAEhE,IAAK,IAAM,KAAiB,EAAkB,CAC5C,IAAM,EACJ,EAA2B,GAEvB,EAAuC,EAAa,OACvD,GAAe,CAAC,EAAW,OAC7B,CAGD,IAAK,IAAM,KAAc,EAAwB,CAC/C,IAAM,GAAA,EAAA,EAAA,wCACJ,EACA,EACD,CAEG,EAAe,OAAS,GAC1B,EAAoB,KAAK,CACvB,IAAK,EACL,GAAI,EAAW,GACf,SAAU,EAAW,SACrB,QAAS,EACV,CAAC,CAQN,GAJ0C,EAAa,OACpD,GAAe,EAAW,OAC5B,CAEuB,SAAW,EACjC,SAGF,IAAM,EAAmB,EAAmB,GAEtC,GAAA,EAAA,EAAA,wCACJ,EACA,EACD,CAEG,EAAe,OAAS,GAC1B,EAAoB,KAAK,CACvB,IAAK,EACL,QAAS,EACV,CAAC,CAIN,IAAM,EAAoB,IAAI,IAC5B,EAAoB,QAAS,GAAM,EAAE,QAAQ,CAC9C,CACK,EAAiB,MAAM,KAAK,EAAkB,CAMpD,MAAO,CAAE,sBAAqB,iBAAgB,uBAJf,EAAe,OAAQ,IACnD,GAAmB,GAAS,SAAS,EAAO,CAC9C,CAEqE,EAG3D,EACX,GAIO,GAAA,EAAA,EAAA,kBAFgC,EAAqB,CAEL"}
|
package/dist/cjs/test/test.cjs
CHANGED
|
@@ -1,54 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_test_listMissingTranslations = require('./listMissingTranslations.cjs');
|
|
4
|
-
let _intlayer_config = require("@intlayer/config");
|
|
5
|
-
let _intlayer_chokidar_build = require("@intlayer/chokidar/build");
|
|
6
|
-
let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
|
|
7
|
-
|
|
8
|
-
//#region src/test/test.ts
|
|
9
|
-
const testMissingTranslations = async (options) => {
|
|
10
|
-
const config = (0, _intlayer_config.getConfiguration)(options?.configOptions);
|
|
11
|
-
const { locales, requiredLocales } = config.internationalization;
|
|
12
|
-
const appLogger = (0, _intlayer_config.getAppLogger)(config);
|
|
13
|
-
if (options?.build === true) await (0, _intlayer_chokidar_build.prepareIntlayer)(config, { forceRun: true });
|
|
14
|
-
else if (typeof options?.build === "undefined") await (0, _intlayer_chokidar_build.prepareIntlayer)(config);
|
|
15
|
-
const result = require_test_listMissingTranslations.listMissingTranslations(options?.configOptions);
|
|
16
|
-
const maxKeyColSize = result.missingTranslations.map((t) => ` - ${t.key}`).reduce((max, t) => Math.max(max, t.length), 0);
|
|
17
|
-
const maxLocalesColSize = result.missingTranslations.map((t) => (0, _intlayer_chokidar_utils.formatLocale)(t.locales, false)).reduce((max, t) => Math.max(max, t.length), 0);
|
|
18
|
-
const formattedMissingTranslations = result.missingTranslations.map((translation) => [
|
|
19
|
-
(0, _intlayer_config.colon)(` - ${(0, _intlayer_config.colorizeKey)(translation.key)}`, {
|
|
20
|
-
colSize: maxKeyColSize,
|
|
21
|
-
maxSize: 40
|
|
22
|
-
}),
|
|
23
|
-
" - ",
|
|
24
|
-
(0, _intlayer_config.colon)((0, _intlayer_chokidar_utils.formatLocale)(translation.locales, _intlayer_config.ANSIColors.RED), {
|
|
25
|
-
colSize: maxLocalesColSize,
|
|
26
|
-
maxSize: 40
|
|
27
|
-
}),
|
|
28
|
-
translation.filePath ? ` - ${(0, _intlayer_chokidar_utils.formatPath)(translation.filePath)}` : "",
|
|
29
|
-
translation.id ? " - remote" : ""
|
|
30
|
-
].join(""));
|
|
31
|
-
appLogger(`Missing translations:`, { level: "info" });
|
|
32
|
-
formattedMissingTranslations.forEach((t) => {
|
|
33
|
-
appLogger(t, { level: "info" });
|
|
34
|
-
});
|
|
35
|
-
appLogger(`Locales: ${(0, _intlayer_chokidar_utils.formatLocale)(locales)}`);
|
|
36
|
-
appLogger(`Required locales: ${(0, _intlayer_chokidar_utils.formatLocale)(requiredLocales ?? locales)}`);
|
|
37
|
-
appLogger(`Missing locales: ${result.missingLocales.length === 0 ? (0, _intlayer_config.colorize)("-", _intlayer_config.ANSIColors.GREEN) : (0, _intlayer_chokidar_utils.formatLocale)(result.missingLocales, _intlayer_config.ANSIColors.RED)}`);
|
|
38
|
-
appLogger(`Missing required locales: ${result.missingRequiredLocales.length === 0 ? (0, _intlayer_config.colorize)("-", _intlayer_config.ANSIColors.GREEN) : (0, _intlayer_chokidar_utils.formatLocale)(result.missingRequiredLocales, _intlayer_config.ANSIColors.RED)}`);
|
|
39
|
-
appLogger(`Total missing locales: ${(0, _intlayer_config.colorizeNumber)(result.missingLocales.length, {
|
|
40
|
-
one: _intlayer_config.ANSIColors.RED,
|
|
41
|
-
other: _intlayer_config.ANSIColors.RED,
|
|
42
|
-
zero: _intlayer_config.ANSIColors.GREEN
|
|
43
|
-
})}`);
|
|
44
|
-
appLogger(`Total missing required locales: ${(0, _intlayer_config.colorizeNumber)(result.missingRequiredLocales.length, {
|
|
45
|
-
one: _intlayer_config.ANSIColors.RED,
|
|
46
|
-
other: _intlayer_config.ANSIColors.RED,
|
|
47
|
-
zero: _intlayer_config.ANSIColors.GREEN
|
|
48
|
-
})}`);
|
|
49
|
-
if (result.missingRequiredLocales.length > 0) process.exit(1);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
//#endregion
|
|
53
|
-
exports.testMissingTranslations = testMissingTranslations;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./listMissingTranslations.cjs`);let t=require(`@intlayer/chokidar/utils`),n=require(`@intlayer/config/node`),r=require(`@intlayer/config/logger`),i=require(`@intlayer/chokidar/build`);const a=async a=>{let o=(0,n.getConfiguration)(a?.configOptions),{locales:s,requiredLocales:c}=o.internationalization,l=(0,r.getAppLogger)(o);a?.build===!0?await(0,i.prepareIntlayer)(o,{forceRun:!0}):a?.build===void 0&&await(0,i.prepareIntlayer)(o);let u=e.listMissingTranslations(a?.configOptions),d=u.missingTranslations.map(e=>` - ${e.key}`).reduce((e,t)=>Math.max(e,t.length),0),f=u.missingTranslations.map(e=>(0,t.formatLocale)(e.locales,!1)).reduce((e,t)=>Math.max(e,t.length),0),p=u.missingTranslations.map(e=>[(0,r.colon)(` - ${(0,r.colorizeKey)(e.key)}`,{colSize:d,maxSize:40}),` - `,(0,r.colon)((0,t.formatLocale)(e.locales,r.ANSIColors.RED),{colSize:f,maxSize:40}),e.filePath?` - ${(0,t.formatPath)(e.filePath)}`:``,e.id?` - remote`:``].join(``));l(`Missing translations:`,{level:`info`}),p.forEach(e=>{l(e,{level:`info`})}),l(`Locales: ${(0,t.formatLocale)(s)}`),l(`Required locales: ${(0,t.formatLocale)(c??s)}`),l(`Missing locales: ${u.missingLocales.length===0?(0,r.colorize)(`-`,r.ANSIColors.GREEN):(0,t.formatLocale)(u.missingLocales,r.ANSIColors.RED)}`),l(`Missing required locales: ${u.missingRequiredLocales.length===0?(0,r.colorize)(`-`,r.ANSIColors.GREEN):(0,t.formatLocale)(u.missingRequiredLocales,r.ANSIColors.RED)}`),l(`Total missing locales: ${(0,r.colorizeNumber)(u.missingLocales.length,{one:r.ANSIColors.RED,other:r.ANSIColors.RED,zero:r.ANSIColors.GREEN})}`),l(`Total missing required locales: ${(0,r.colorizeNumber)(u.missingRequiredLocales.length,{one:r.ANSIColors.RED,other:r.ANSIColors.RED,zero:r.ANSIColors.GREEN})}`),u.missingRequiredLocales.length>0&&process.exit(1)};exports.testMissingTranslations=a;
|
|
54
2
|
//# sourceMappingURL=test.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.cjs","names":["listMissingTranslations","ANSIColors"],"sources":["../../../src/test/test.ts"],"sourcesContent":["import { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n type GetConfigurationOptions,\n
|
|
1
|
+
{"version":3,"file":"test.cjs","names":["listMissingTranslations","ANSIColors"],"sources":["../../../src/test/test.ts"],"sourcesContent":["import { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { listMissingTranslations } from './listMissingTranslations';\n\ntype ListMissingTranslationsOptions = {\n configOptions?: GetConfigurationOptions;\n build?: boolean;\n};\n\nexport const testMissingTranslations = async (\n options?: ListMissingTranslationsOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const { locales, requiredLocales } = config.internationalization;\n\n const appLogger = getAppLogger(config);\n\n if (options?.build === true) {\n await prepareIntlayer(config, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(config);\n }\n\n const result = listMissingTranslations(options?.configOptions);\n\n const maxKeyColSize = result.missingTranslations\n .map((t) => ` - ${t.key}`)\n .reduce((max, t) => Math.max(max, t.length), 0);\n const maxLocalesColSize = result.missingTranslations\n .map((t) => formatLocale(t.locales, false))\n .reduce((max, t) => Math.max(max, t.length), 0);\n\n const formattedMissingTranslations = result.missingTranslations.map(\n (translation) =>\n [\n colon(` - ${colorizeKey(translation.key)}`, {\n colSize: maxKeyColSize,\n maxSize: 40,\n }),\n ' - ',\n colon(formatLocale(translation.locales, ANSIColors.RED), {\n colSize: maxLocalesColSize,\n maxSize: 40,\n }),\n\n translation.filePath ? ` - ${formatPath(translation.filePath)}` : '',\n translation.id ? ' - remote' : '',\n ].join('')\n );\n\n appLogger(`Missing translations:`, {\n level: 'info',\n });\n\n formattedMissingTranslations.forEach((t) => {\n appLogger(t, {\n level: 'info',\n });\n });\n\n appLogger(`Locales: ${formatLocale(locales)}`);\n appLogger(`Required locales: ${formatLocale(requiredLocales ?? locales)}`);\n appLogger(\n `Missing locales: ${result.missingLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingLocales, ANSIColors.RED)}`\n );\n\n appLogger(\n `Missing required locales: ${result.missingRequiredLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingRequiredLocales, ANSIColors.RED)}`\n );\n appLogger(\n `Total missing locales: ${colorizeNumber(result.missingLocales.length, {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n })}`\n );\n appLogger(\n `Total missing required locales: ${colorizeNumber(\n result.missingRequiredLocales.length,\n {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n }\n )}`\n );\n\n if (result.missingRequiredLocales.length > 0) {\n process.exit(1);\n }\n};\n"],"mappings":"yTAqBA,MAAa,EAA0B,KACrC,IACG,CACH,IAAM,GAAA,EAAA,EAAA,kBAA0B,GAAS,cAAc,CACjD,CAAE,UAAS,mBAAoB,EAAO,qBAEtC,GAAA,EAAA,EAAA,cAAyB,EAAO,CAElC,GAAS,QAAU,GACrB,MAAA,EAAA,EAAA,iBAAsB,EAAQ,CAAE,SAAU,GAAM,CAAC,CACjC,GAAS,QAAU,QACnC,MAAA,EAAA,EAAA,iBAAsB,EAAO,CAG/B,IAAM,EAASA,EAAAA,wBAAwB,GAAS,cAAc,CAExD,EAAgB,EAAO,oBAC1B,IAAK,GAAM,MAAM,EAAE,MAAM,CACzB,QAAQ,EAAK,IAAM,KAAK,IAAI,EAAK,EAAE,OAAO,CAAE,EAAE,CAC3C,EAAoB,EAAO,oBAC9B,IAAK,IAAA,EAAA,EAAA,cAAmB,EAAE,QAAS,GAAM,CAAC,CAC1C,QAAQ,EAAK,IAAM,KAAK,IAAI,EAAK,EAAE,OAAO,CAAE,EAAE,CAE3C,EAA+B,EAAO,oBAAoB,IAC7D,GACC,aACQ,OAAA,EAAA,EAAA,aAAkB,EAAY,IAAI,GAAI,CAC1C,QAAS,EACT,QAAS,GACV,CAAC,CACF,qCACmB,EAAY,QAASC,EAAAA,WAAW,IAAI,CAAE,CACvD,QAAS,EACT,QAAS,GACV,CAAC,CAEF,EAAY,SAAW,OAAA,EAAA,EAAA,YAAiB,EAAY,SAAS,GAAK,GAClE,EAAY,GAAK,YAAc,GAChC,CAAC,KAAK,GAAG,CACb,CAED,EAAU,wBAAyB,CACjC,MAAO,OACR,CAAC,CAEF,EAA6B,QAAS,GAAM,CAC1C,EAAU,EAAG,CACX,MAAO,OACR,CAAC,EACF,CAEF,EAAU,aAAA,EAAA,EAAA,cAAyB,EAAQ,GAAG,CAC9C,EAAU,sBAAA,EAAA,EAAA,cAAkC,GAAmB,EAAQ,GAAG,CAC1E,EACE,oBAAoB,EAAO,eAAe,SAAW,GAAA,EAAA,EAAA,UAAa,IAAKA,EAAAA,WAAW,MAAM,EAAA,EAAA,EAAA,cAAgB,EAAO,eAAgBA,EAAAA,WAAW,IAAI,GAC/I,CAED,EACE,6BAA6B,EAAO,uBAAuB,SAAW,GAAA,EAAA,EAAA,UAAa,IAAKA,EAAAA,WAAW,MAAM,EAAA,EAAA,EAAA,cAAgB,EAAO,uBAAwBA,EAAAA,WAAW,IAAI,GACxK,CACD,EACE,2BAAA,EAAA,EAAA,gBAAyC,EAAO,eAAe,OAAQ,CACrE,IAAKA,EAAAA,WAAW,IAChB,MAAOA,EAAAA,WAAW,IAClB,KAAMA,EAAAA,WAAW,MAClB,CAAC,GACH,CACD,EACE,oCAAA,EAAA,EAAA,gBACE,EAAO,uBAAuB,OAC9B,CACE,IAAKA,EAAAA,WAAW,IAChB,MAAOA,EAAAA,WAAW,IAClB,KAAMA,EAAAA,WAAW,MAClB,CACF,GACF,CAEG,EAAO,uBAAuB,OAAS,GACzC,QAAQ,KAAK,EAAE"}
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_translateDoc_validation = require('./validation.cjs');
|
|
3
|
-
const require_translateDoc_translateFile = require('./translateFile.cjs');
|
|
4
|
-
const require_translateDoc_translateDoc = require('./translateDoc.cjs');
|
|
5
|
-
|
|
6
|
-
exports.sanitizeChunk = require_translateDoc_validation.sanitizeChunk;
|
|
7
|
-
exports.translateDoc = require_translateDoc_translateDoc.translateDoc;
|
|
8
|
-
exports.translateFile = require_translateDoc_translateFile.translateFile;
|
|
9
|
-
exports.validateTranslation = require_translateDoc_validation.validateTranslation;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./validation.cjs`),t=require(`./translateFile.cjs`),n=require(`./translateDoc.cjs`);exports.sanitizeChunk=e.sanitizeChunk,exports.translateDoc=n.translateDoc,exports.translateFile=t.translateFile,exports.validateTranslation=e.validateTranslation;
|
|
@@ -1,75 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_utils_setupAI = require('../utils/setupAI.cjs');
|
|
4
|
-
const require_utils_checkFileModifiedRange = require('../utils/checkFileModifiedRange.cjs');
|
|
5
|
-
const require_utils_getOutputFilePath = require('../utils/getOutputFilePath.cjs');
|
|
6
|
-
const require_translateDoc_translateFile = require('./translateFile.cjs');
|
|
7
|
-
let _intlayer_chokidar = require("@intlayer/chokidar");
|
|
8
|
-
let _intlayer_config = require("@intlayer/config");
|
|
9
|
-
let node_path = require("node:path");
|
|
10
|
-
let node_fs = require("node:fs");
|
|
11
|
-
let fast_glob = require("fast-glob");
|
|
12
|
-
fast_glob = require_runtime.__toESM(fast_glob);
|
|
13
|
-
let node_perf_hooks = require("node:perf_hooks");
|
|
14
|
-
|
|
15
|
-
//#region src/translateDoc/translateDoc.ts
|
|
16
|
-
const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLocale, aiOptions, nbSimultaneousFileProcessed = 20, configOptions, customInstructions, skipIfModifiedBefore, skipIfModifiedAfter, skipIfExists, gitOptions, flushStrategy = "incremental" }) => {
|
|
17
|
-
const configuration = (0, _intlayer_config.getConfiguration)(configOptions);
|
|
18
|
-
const appLogger = (0, _intlayer_config.getAppLogger)(configuration);
|
|
19
|
-
const maxConcurrentChunks = nbSimultaneousFileProcessed;
|
|
20
|
-
const globalChunkLimiter = (0, _intlayer_chokidar.pLimit)(maxConcurrentChunks);
|
|
21
|
-
let docList = await (0, fast_glob.default)(docPattern, { ignore: excludedGlobPattern });
|
|
22
|
-
const aiResult = await require_utils_setupAI.setupAI(configuration, aiOptions);
|
|
23
|
-
if (!aiResult?.hasAIAccess) return;
|
|
24
|
-
const { aiClient, aiConfig } = aiResult;
|
|
25
|
-
if (gitOptions) {
|
|
26
|
-
const gitChangedFiles = await (0, _intlayer_chokidar.listGitFiles)(gitOptions);
|
|
27
|
-
if (gitChangedFiles) docList = docList.filter((path) => gitChangedFiles.some((gitFile) => (0, node_path.join)(process.cwd(), path) === gitFile));
|
|
28
|
-
}
|
|
29
|
-
const batchStartTime = node_perf_hooks.performance.now();
|
|
30
|
-
appLogger(`Translating ${(0, _intlayer_config.colorizeNumber)(docList.length)} files to ${(0, _intlayer_config.colorizeNumber)(locales.length)} locales. \nGlobal Concurrency: ${(0, _intlayer_config.colorizeNumber)(maxConcurrentChunks)} chunks in parallel.`);
|
|
31
|
-
const errorState = {
|
|
32
|
-
count: 0,
|
|
33
|
-
maxErrors: 5,
|
|
34
|
-
shouldStop: false
|
|
35
|
-
};
|
|
36
|
-
await (0, _intlayer_chokidar.parallelize)(docList.flatMap((docPath) => locales.map((locale) => async () => {
|
|
37
|
-
if (errorState.shouldStop) return;
|
|
38
|
-
const absoluteBaseFilePath = (0, node_path.join)(configuration.content.baseDir, docPath);
|
|
39
|
-
const outputFilePath = require_utils_getOutputFilePath.getOutputFilePath(absoluteBaseFilePath, locale, baseLocale);
|
|
40
|
-
if (skipIfExists && (0, node_fs.existsSync)(outputFilePath)) return;
|
|
41
|
-
if (flushStrategy === "incremental" && !(0, node_fs.existsSync)(outputFilePath)) {
|
|
42
|
-
(0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
|
|
43
|
-
(0, node_fs.writeFileSync)(outputFilePath, "");
|
|
44
|
-
}
|
|
45
|
-
const fileModificationData = require_utils_checkFileModifiedRange.checkFileModifiedRange(outputFilePath, {
|
|
46
|
-
skipIfModifiedBefore,
|
|
47
|
-
skipIfModifiedAfter
|
|
48
|
-
});
|
|
49
|
-
if (fileModificationData.isSkipped) {
|
|
50
|
-
appLogger(fileModificationData.message);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
await require_translateDoc_translateFile.translateFile({
|
|
54
|
-
baseFilePath: absoluteBaseFilePath,
|
|
55
|
-
outputFilePath,
|
|
56
|
-
locale,
|
|
57
|
-
baseLocale,
|
|
58
|
-
configuration,
|
|
59
|
-
errorState,
|
|
60
|
-
aiOptions,
|
|
61
|
-
customInstructions,
|
|
62
|
-
aiClient,
|
|
63
|
-
aiConfig,
|
|
64
|
-
flushStrategy,
|
|
65
|
-
limit: globalChunkLimiter
|
|
66
|
-
});
|
|
67
|
-
})), (task) => task(), 50);
|
|
68
|
-
const batchDuration = ((node_perf_hooks.performance.now() - batchStartTime) / 1e3).toFixed(2);
|
|
69
|
-
if (errorState.count > 0) appLogger(`Finished with ${errorState.count} errors in ${batchDuration}s.`);
|
|
70
|
-
else appLogger(`${(0, _intlayer_config.colorize)("✔", _intlayer_config.ANSIColors.GREEN)} Batch completed successfully in ${(0, _intlayer_config.colorizeNumber)(batchDuration)}s.`);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
//#endregion
|
|
74
|
-
exports.translateDoc = translateDoc;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`../utils/setupAI.cjs`),n=require(`../utils/checkFileModifiedRange.cjs`),r=require(`../utils/getOutputFilePath.cjs`),i=require(`./translateFile.cjs`);let a=require(`@intlayer/chokidar/utils`),o=require(`@intlayer/config/node`),s=require(`node:path`),c=require(`@intlayer/chokidar/cli`),l=require(`@intlayer/config/logger`),u=require(`node:fs`),d=require(`fast-glob`);d=e.__toESM(d);let f=require(`node:perf_hooks`);const p=async({docPattern:e,locales:p,excludedGlobPattern:m,baseLocale:h,aiOptions:g,nbSimultaneousFileProcessed:_=20,configOptions:v,customInstructions:y,skipIfModifiedBefore:b,skipIfModifiedAfter:x,skipIfExists:S,gitOptions:C,flushStrategy:w=`incremental`})=>{let T=(0,o.getConfiguration)(v),E=(0,l.getAppLogger)(T),D=_,O=(0,a.pLimit)(D),k=await(0,d.default)(e,{ignore:m}),A=await t.setupAI(T,g);if(!A?.hasAIAccess)return;let{aiClient:j,aiConfig:M}=A;if(C){let e=await(0,c.listGitFiles)(C);e&&(k=k.filter(t=>e.some(e=>(0,s.join)(process.cwd(),t)===e)))}let N=f.performance.now();E(`Translating ${(0,l.colorizeNumber)(k.length)} files to ${(0,l.colorizeNumber)(p.length)} locales. \nGlobal Concurrency: ${(0,l.colorizeNumber)(D)} chunks in parallel.`);let P={count:0,maxErrors:5,shouldStop:!1};await(0,a.parallelize)(k.flatMap(e=>p.map(t=>async()=>{if(P.shouldStop)return;let a=(0,s.join)(T.content.baseDir,e),o=r.getOutputFilePath(a,t,h);if(S&&(0,u.existsSync)(o))return;w===`incremental`&&!(0,u.existsSync)(o)&&((0,u.mkdirSync)((0,s.dirname)(o),{recursive:!0}),(0,u.writeFileSync)(o,``));let c=n.checkFileModifiedRange(o,{skipIfModifiedBefore:b,skipIfModifiedAfter:x});if(c.isSkipped){E(c.message);return}await i.translateFile({baseFilePath:a,outputFilePath:o,locale:t,baseLocale:h,configuration:T,errorState:P,aiOptions:g,customInstructions:y,aiClient:j,aiConfig:M,flushStrategy:w,limit:O})})),e=>e(),50);let F=((f.performance.now()-N)/1e3).toFixed(2);P.count>0?E(`Finished with ${P.count} errors in ${F}s.`):E(`${(0,l.colorize)(`✔`,l.ANSIColors.GREEN)} Batch completed successfully in ${(0,l.colorizeNumber)(F)}s.`)};exports.translateDoc=p;
|
|
75
2
|
//# sourceMappingURL=translateDoc.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translateDoc.cjs","names":["setupAI","performance","getOutputFilePath","checkFileModifiedRange","translateFile","ANSIColors"],"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 { listGitFiles
|
|
1
|
+
{"version":3,"file":"translateDoc.cjs","names":["setupAI","performance","getOutputFilePath","checkFileModifiedRange","translateFile","ANSIColors"],"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 { listGitFiles } from '@intlayer/chokidar/cli';\nimport { parallelize, pLimit } from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { Locale } from '@intlayer/types';\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 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 const { aiClient, aiConfig } = aiResult;\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 // 2. 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.content.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 // 3. 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":"iiBAoBA,MAAa,EAAe,MAAO,CACjC,aACA,UACA,sBACA,aACA,YACA,8BAA8B,GAC9B,gBACA,qBACA,uBACA,sBACA,eACA,aACA,gBAAgB,iBACS,CACzB,IAAM,GAAA,EAAA,EAAA,kBAAiC,EAAc,CAC/C,GAAA,EAAA,EAAA,cAAyB,EAAc,CAKvC,EAAsB,EACtB,GAAA,EAAA,EAAA,QAA4B,EAAoB,CAElD,EAAoB,MAAA,EAAA,EAAA,SAAS,EAAY,CAC3C,OAAQ,EACT,CAAC,CAEI,EAAW,MAAMA,EAAAA,QAAQ,EAAe,EAAU,CACxD,GAAI,CAAC,GAAU,YAAa,OAC5B,GAAM,CAAE,WAAU,YAAa,EAE/B,GAAI,EAAY,CACd,IAAM,EAAkB,MAAA,EAAA,EAAA,cAAmB,EAAW,CAClD,IACF,EAAU,EAAQ,OAAQ,GACxB,EAAgB,KAAM,IAAA,EAAA,EAAA,MAAiB,QAAQ,KAAK,CAAE,EAAK,GAAK,EAAQ,CACzE,EAIL,IAAM,EAAiBC,EAAAA,YAAY,KAAK,CAExC,EACE,gBAAA,EAAA,EAAA,gBAA8B,EAAQ,OAAO,CAAC,aAAA,EAAA,EAAA,gBAA2B,EAAQ,OAAO,CAAC,mCAAA,EAAA,EAAA,gBACjD,EAAoB,CAAC,sBAC9D,CAED,IAAM,EAAyB,CAC7B,MAAO,EACP,UAAW,EACX,WAAY,GACb,CAyDD,MAAA,EAAA,EAAA,aArDiB,EAAQ,QAAS,GAChC,EAAQ,IAAK,GAAW,SAAY,CAClC,GAAI,EAAW,WAAY,OAE3B,IAAM,GAAA,EAAA,EAAA,MAA4B,EAAc,QAAQ,QAAS,EAAQ,CACnE,EAAiBC,EAAAA,kBACrB,EACA,EACA,EACD,CAGD,GAAI,IAAA,EAAA,EAAA,YAA2B,EAAe,CAAE,OAE5C,IAAkB,eAAiB,EAAA,EAAA,EAAA,YAAY,EAAe,IAChE,EAAA,EAAA,YAAA,EAAA,EAAA,SAAkB,EAAe,CAAE,CAAE,UAAW,GAAM,CAAC,EACvD,EAAA,EAAA,eAAc,EAAgB,GAAG,EAGnC,IAAM,EAAuBC,EAAAA,uBAAuB,EAAgB,CAClE,uBACA,sBACD,CAAC,CAEF,GAAI,EAAqB,UAAW,CAClC,EAAU,EAAqB,QAAQ,CACvC,OAIF,MAAMC,EAAAA,cAAc,CAClB,aAAc,EACd,iBACQ,SACR,aACA,gBACA,aACA,YACA,qBACA,WACA,WACA,gBACA,MAAO,EACR,CAAC,EACF,CACH,CAQ4B,GAAS,GAAM,CAFpB,GAEsC,CAG9D,IAAM,IADeH,EAAAA,YAAY,KAAK,CACC,GAAkB,KAAM,QAAQ,EAAE,CAErE,EAAW,MAAQ,EACrB,EAAU,iBAAiB,EAAW,MAAM,aAAa,EAAc,IAAI,CAE3E,EACE,IAAA,EAAA,EAAA,UAAY,IAAKI,EAAAA,WAAW,MAAM,CAAC,oCAAA,EAAA,EAAA,gBAAkD,EAAc,CAAC,IACrG"}
|