@intlayer/cli 9.0.0-canary.11 → 9.0.0-canary.13
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/auth/login.cjs +2 -2
- package/dist/cjs/auth/login.cjs.map +1 -1
- package/dist/cjs/build.cjs +6 -6
- package/dist/cjs/build.cjs.map +1 -1
- package/dist/cjs/ci.cjs +2 -2
- package/dist/cjs/ci.cjs.map +1 -1
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/config.cjs +2 -2
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/extract.cjs +7 -7
- package/dist/cjs/extract.cjs.map +1 -1
- package/dist/cjs/fill/fill.cjs +11 -11
- package/dist/cjs/fill/fill.cjs.map +1 -1
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs +2 -2
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
- package/dist/cjs/fill/formatFillData.cjs +3 -3
- package/dist/cjs/fill/formatFillData.cjs.map +1 -1
- package/dist/cjs/fill/listTranslationsTasks.cjs +2 -2
- package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -1
- package/dist/cjs/fill/translateDictionary.cjs +7 -7
- package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
- package/dist/cjs/fill/writeFill.cjs +5 -5
- package/dist/cjs/fill/writeFill.cjs.map +1 -1
- package/dist/cjs/getTargetDictionary.cjs +2 -2
- package/dist/cjs/getTargetDictionary.cjs.map +1 -1
- package/dist/cjs/init.cjs +41 -5
- package/dist/cjs/init.cjs.map +1 -1
- package/dist/cjs/initBuildOptimization.cjs +6 -6
- package/dist/cjs/initBuildOptimization.cjs.map +1 -1
- package/dist/cjs/initCompiler.cjs +3 -3
- package/dist/cjs/initCompiler.cjs.map +1 -1
- package/dist/cjs/initMCP.cjs +3 -3
- package/dist/cjs/initMCP.cjs.map +1 -1
- package/dist/cjs/initSkills.cjs +11 -11
- package/dist/cjs/initSkills.cjs.map +1 -1
- package/dist/cjs/listContentDeclaration.cjs +4 -4
- package/dist/cjs/listContentDeclaration.cjs.map +1 -1
- package/dist/cjs/listProjects.cjs +2 -2
- package/dist/cjs/listProjects.cjs.map +1 -1
- package/dist/cjs/liveSync.cjs +4 -4
- package/dist/cjs/liveSync.cjs.map +1 -1
- package/dist/cjs/pull.cjs +6 -6
- package/dist/cjs/pull.cjs.map +1 -1
- package/dist/cjs/push/pullLog.cjs.map +1 -1
- package/dist/cjs/push/push.cjs +13 -13
- package/dist/cjs/push/push.cjs.map +1 -1
- package/dist/cjs/pushConfig.cjs +2 -2
- package/dist/cjs/pushConfig.cjs.map +1 -1
- package/dist/cjs/reviewDoc/reviewDoc.cjs +16 -16
- package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
- package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +11 -11
- package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
- package/dist/cjs/reviewDoc/reviewDocLog.cjs +7 -7
- package/dist/cjs/reviewDoc/reviewDocLog.cjs.map +1 -1
- package/dist/cjs/scan.cjs +5 -5
- package/dist/cjs/scan.cjs.map +1 -1
- package/dist/cjs/searchDoc.cjs +2 -2
- package/dist/cjs/searchDoc.cjs.map +1 -1
- package/dist/cjs/test/listMissingTranslations.cjs +2 -2
- package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
- package/dist/cjs/test/test.cjs +11 -11
- package/dist/cjs/test/test.cjs.map +1 -1
- package/dist/cjs/translateDoc/translateDoc.cjs +6 -6
- package/dist/cjs/translateDoc/translateDoc.cjs.map +1 -1
- package/dist/cjs/translateDoc/translateFile.cjs +5 -5
- package/dist/cjs/translateDoc/translateFile.cjs.map +1 -1
- package/dist/cjs/utils/calculateChunks.cjs +4 -4
- package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
- package/dist/cjs/utils/getOutputFilePath.cjs +2 -2
- package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs +4 -4
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
- package/dist/cjs/watch.cjs +6 -6
- package/dist/cjs/watch.cjs.map +1 -1
- package/dist/esm/auth/login.mjs +1 -1
- package/dist/esm/auth/login.mjs.map +1 -1
- package/dist/esm/build.mjs +3 -3
- package/dist/esm/build.mjs.map +1 -1
- package/dist/esm/ci.mjs +1 -1
- package/dist/esm/ci.mjs.map +1 -1
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/config.mjs +1 -1
- package/dist/esm/config.mjs.map +1 -1
- package/dist/esm/extract.mjs +3 -3
- package/dist/esm/extract.mjs.map +1 -1
- package/dist/esm/fill/fill.mjs +3 -3
- package/dist/esm/fill/fill.mjs.map +1 -1
- package/dist/esm/fill/formatAutoFilledFilePath.mjs +1 -1
- package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
- package/dist/esm/fill/formatFillData.mjs +1 -1
- package/dist/esm/fill/formatFillData.mjs.map +1 -1
- package/dist/esm/fill/listTranslationsTasks.mjs +1 -1
- package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -1
- package/dist/esm/fill/translateDictionary.mjs +1 -1
- package/dist/esm/fill/translateDictionary.mjs.map +1 -1
- package/dist/esm/fill/writeFill.mjs +2 -2
- package/dist/esm/fill/writeFill.mjs.map +1 -1
- package/dist/esm/getTargetDictionary.mjs +1 -1
- package/dist/esm/getTargetDictionary.mjs.map +1 -1
- package/dist/esm/init.mjs +37 -1
- package/dist/esm/init.mjs.map +1 -1
- package/dist/esm/initBuildOptimization.mjs +1 -1
- package/dist/esm/initBuildOptimization.mjs.map +1 -1
- package/dist/esm/initCompiler.mjs +1 -1
- package/dist/esm/initCompiler.mjs.map +1 -1
- package/dist/esm/initMCP.mjs +1 -1
- package/dist/esm/initMCP.mjs.map +1 -1
- package/dist/esm/initSkills.mjs +1 -1
- package/dist/esm/initSkills.mjs.map +1 -1
- package/dist/esm/listContentDeclaration.mjs +2 -2
- package/dist/esm/listContentDeclaration.mjs.map +1 -1
- package/dist/esm/listProjects.mjs +1 -1
- package/dist/esm/listProjects.mjs.map +1 -1
- package/dist/esm/liveSync.mjs +2 -2
- package/dist/esm/liveSync.mjs.map +1 -1
- package/dist/esm/pull.mjs +3 -3
- package/dist/esm/pull.mjs.map +1 -1
- package/dist/esm/push/pullLog.mjs.map +1 -1
- package/dist/esm/push/push.mjs +3 -3
- package/dist/esm/push/push.mjs.map +1 -1
- package/dist/esm/pushConfig.mjs +1 -1
- package/dist/esm/pushConfig.mjs.map +1 -1
- package/dist/esm/reviewDoc/reviewDoc.mjs +3 -3
- package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
- package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +2 -2
- package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
- package/dist/esm/reviewDoc/reviewDocLog.mjs +2 -2
- package/dist/esm/reviewDoc/reviewDocLog.mjs.map +1 -1
- package/dist/esm/scan.mjs +1 -1
- package/dist/esm/scan.mjs.map +1 -1
- package/dist/esm/searchDoc.mjs +1 -1
- package/dist/esm/searchDoc.mjs.map +1 -1
- package/dist/esm/test/listMissingTranslations.mjs +1 -1
- package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
- package/dist/esm/test/test.mjs +2 -2
- package/dist/esm/test/test.mjs.map +1 -1
- package/dist/esm/translateDoc/translateDoc.mjs +2 -2
- package/dist/esm/translateDoc/translateDoc.mjs.map +1 -1
- package/dist/esm/translateDoc/translateFile.mjs +1 -1
- package/dist/esm/translateDoc/translateFile.mjs.map +1 -1
- package/dist/esm/utils/calculateChunks.mjs +1 -1
- package/dist/esm/utils/calculateChunks.mjs.map +1 -1
- package/dist/esm/utils/getOutputFilePath.mjs +1 -1
- package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
- package/dist/esm/utils/mapChunksBetweenFiles.mjs +1 -1
- package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
- package/dist/esm/watch.mjs +3 -3
- package/dist/esm/watch.mjs.map +1 -1
- package/dist/types/fill/fill.d.ts +1 -1
- package/dist/types/fill/translateDictionary.d.ts +2 -2
- package/dist/types/fill/translateDictionary.d.ts.map +1 -1
- package/dist/types/getTargetDictionary.d.ts +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/init.d.ts +1 -1
- package/dist/types/init.d.ts.map +1 -1
- package/dist/types/initMCP.d.ts +1 -1
- package/dist/types/initSkills.d.ts +1 -1
- package/dist/types/listProjects.d.ts +1 -1
- package/dist/types/push/pullLog.d.ts +1 -1
- package/dist/types/push/push.d.ts +1 -1
- package/dist/types/reviewDoc/reviewDoc.d.ts +1 -1
- package/dist/types/reviewDoc/reviewDoc.d.ts.map +1 -1
- package/dist/types/reviewDoc/reviewDocLog.d.ts +1 -1
- package/dist/types/scan.d.ts.map +1 -1
- package/dist/types/translateDoc/translateDoc.d.ts.map +1 -1
- package/dist/types/translateDoc/types.d.ts +1 -1
- package/package.json +13 -13
|
@@ -6,14 +6,14 @@ const require_utils_chunkInference = require('../utils/chunkInference.cjs');
|
|
|
6
6
|
const require_utils_fixChunkStartEndChars = require('../utils/fixChunkStartEndChars.cjs');
|
|
7
7
|
let node_fs = require("node:fs");
|
|
8
8
|
let node_path = require("node:path");
|
|
9
|
-
let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
|
|
10
9
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
11
10
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
12
11
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
13
12
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
13
|
+
let _intlayer_engine_utils = require("@intlayer/engine/utils");
|
|
14
14
|
let node_fs_promises = require("node:fs/promises");
|
|
15
15
|
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
16
|
-
let
|
|
16
|
+
let _intlayer_engine_docReview = require("@intlayer/engine/docReview");
|
|
17
17
|
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
18
18
|
let _intlayer_types_locales = require("@intlayer/types/locales");
|
|
19
19
|
|
|
@@ -37,10 +37,10 @@ const reviewFileBlockAware = async (baseFilePath, outputFilePath, locale, baseLo
|
|
|
37
37
|
} });
|
|
38
38
|
const baseText = await (0, node_fs_promises.readFile)(baseFilePath, "utf-8");
|
|
39
39
|
const targetText = await (0, node_fs_promises.readFile)(outputFilePath, "utf-8").catch(() => "");
|
|
40
|
-
const basePrompt = require__utils_asset.readAsset("./prompts/REVIEW_PROMPT.md", "utf-8").replaceAll("{{localeName}}", `${(0,
|
|
41
|
-
const filePrefix = [(0, _intlayer_config_logger.colon)(`${_intlayer_config_colors.GREY_DARK}[${(0,
|
|
42
|
-
const prefix = [(0, _intlayer_config_logger.colon)(`${_intlayer_config_colors.GREY_DARK}[${(0,
|
|
43
|
-
const { baseBlocks, targetBlocks, plan, segmentsToReview } = (0,
|
|
40
|
+
const basePrompt = require__utils_asset.readAsset("./prompts/REVIEW_PROMPT.md", "utf-8").replaceAll("{{localeName}}", `${(0, _intlayer_engine_utils.formatLocale)(locale, false)}`).replaceAll("{{baseLocaleName}}", `${(0, _intlayer_engine_utils.formatLocale)(baseLocale, false)}`).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
|
|
41
|
+
const filePrefix = [(0, _intlayer_config_logger.colon)(`${_intlayer_config_colors.GREY_DARK}[${(0, _intlayer_engine_utils.formatPath)(baseFilePath)}${_intlayer_config_colors.GREY_DARK}] `, { colSize: 40 }), `→ ${_intlayer_config_colors.RESET}`].join("");
|
|
42
|
+
const prefix = [(0, _intlayer_config_logger.colon)(`${_intlayer_config_colors.GREY_DARK}[${(0, _intlayer_engine_utils.formatPath)(baseFilePath)}${_intlayer_config_colors.GREY_DARK}][${(0, _intlayer_engine_utils.formatLocale)(locale)}${_intlayer_config_colors.GREY_DARK}] `, { colSize: 40 }), `→ ${_intlayer_config_colors.RESET}`].join("");
|
|
43
|
+
const { baseBlocks, targetBlocks, plan, segmentsToReview } = (0, _intlayer_engine_docReview.buildAlignmentPlan)({
|
|
44
44
|
baseText,
|
|
45
45
|
targetText,
|
|
46
46
|
changedLines
|
|
@@ -51,7 +51,7 @@ const reviewFileBlockAware = async (baseFilePath, outputFilePath, locale, baseLo
|
|
|
51
51
|
const reviewedSegmentsMap = /* @__PURE__ */ new Map();
|
|
52
52
|
for (const [actionIndex, action] of plan.actions.entries()) if (action.kind === "delete") reviewedSegmentsMap.set(actionIndex, "");
|
|
53
53
|
const writeCurrentState = () => {
|
|
54
|
-
const output = (0,
|
|
54
|
+
const output = (0, _intlayer_engine_docReview.mergeReviewedSegments)(plan, targetBlocks, reviewedSegmentsMap);
|
|
55
55
|
(0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
|
|
56
56
|
(0, node_fs.writeFileSync)(outputFilePath, output);
|
|
57
57
|
};
|
|
@@ -64,7 +64,7 @@ const reviewFileBlockAware = async (baseFilePath, outputFilePath, locale, baseLo
|
|
|
64
64
|
applicationLogger(`${filePrefix}No segments need review, reusing existing translation`);
|
|
65
65
|
writeCurrentState();
|
|
66
66
|
}
|
|
67
|
-
applicationLogger(`${(0, _intlayer_config_logger.colorize)("✔", _intlayer_config_colors.GREEN)} File ${(0,
|
|
67
|
+
applicationLogger(`${(0, _intlayer_config_logger.colorize)("✔", _intlayer_config_colors.GREEN)} File ${(0, _intlayer_engine_utils.formatPath)(outputFilePath)} updated successfully (no AI changes needed).`);
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
70
|
applicationLogger(`${filePrefix}Segments to review: ${(0, _intlayer_config_logger.colorizeNumber)(segmentsToReview.length)} (processing bottom-up)`);
|
|
@@ -74,8 +74,8 @@ const reviewFileBlockAware = async (baseFilePath, outputFilePath, locale, baseLo
|
|
|
74
74
|
})).reverse();
|
|
75
75
|
for (const { segment, displayNumber } of segmentsBottomUp) {
|
|
76
76
|
const baseBlock = segment.baseBlock;
|
|
77
|
-
const getBaseChunkContextPrompt = () => `**BLOCK ${displayNumber} of ${segmentsToReview.length}** is the base block in ${(0,
|
|
78
|
-
const getTargetChunkPrompt = () => `**BLOCK ${displayNumber} of ${segmentsToReview.length}** is the current block to review in ${(0,
|
|
77
|
+
const getBaseChunkContextPrompt = () => `**BLOCK ${displayNumber} of ${segmentsToReview.length}** is the base block in ${(0, _intlayer_engine_utils.formatLocale)(baseLocale, false)} as reference.\n///chunksStart///\n` + baseBlock.content + `///chunksEnd///`;
|
|
78
|
+
const getTargetChunkPrompt = () => `**BLOCK ${displayNumber} of ${segmentsToReview.length}** is the current block to review in ${(0, _intlayer_engine_utils.formatLocale)(locale, false)}.\n///chunksStart///\n` + (segment.targetBlockText ?? "") + `///chunksEnd///`;
|
|
79
79
|
const reviewedChunkResult = await (0, _intlayer_config_utils.retryManager)(async () => {
|
|
80
80
|
const result = await require_utils_chunkInference.chunkInference([
|
|
81
81
|
{
|
|
@@ -107,7 +107,7 @@ const reviewFileBlockAware = async (baseFilePath, outputFilePath, locale, baseLo
|
|
|
107
107
|
reviewedSegmentsMap.set(segment.actionIndex, reviewedChunkResult);
|
|
108
108
|
writeCurrentState();
|
|
109
109
|
}
|
|
110
|
-
applicationLogger(`${(0, _intlayer_config_logger.colorize)("✔", _intlayer_config_colors.GREEN)} File ${(0,
|
|
110
|
+
applicationLogger(`${(0, _intlayer_config_logger.colorize)("✔", _intlayer_config_colors.GREEN)} File ${(0, _intlayer_engine_utils.formatPath)(outputFilePath)} created/updated successfully.`);
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reviewDocBlockAware.cjs","names":["readAsset","ANSIColors","chunkInference","ENGLISH","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 {\n buildAlignmentPlan,\n mergeReviewedSegments,\n} from '@intlayer/chokidar/docReview';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\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 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 */\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({\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 deleteCount = plan.actions.filter((a) => a.kind === 'delete').length;\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(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(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;\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,uBAAuB,OAClC,cACA,gBACA,QACA,YACA,WACA,eACA,oBACA,cACA,UACA,aACG;CACH,MAAM,4DAAiC,cAAc;CACrD,MAAM,8DAAiC,EACrC,KAAK;EAAE,GAAG,cAAc;EAAK,QAAQ;EAAI,EAC1C,CAAC;CAEF,MAAM,WAAW,qCAAe,cAAc,QAAQ;CACtD,MAAM,aAAa,qCAAe,gBAAgB,QAAQ,CAAC,YAAY,GAAG;CAE1E,MAAM,aAAaA,+BAAU,8BAA8B,QAAQ,CAChE,WAAW,kBAAkB,8CAAgB,QAAQ,MAAM,GAAG,CAC9D,WAAW,sBAAsB,8CAAgB,YAAY,MAAM,GAAG,CACtE,QAAQ,0BAA0B,WAAW,sBAAsB,IAAI,CACvE,QAAQ,0BAA0B,sBAAsB,IAAI;CAG/D,MAAM,aAAa,oCACX,GAFkBC,wBAAW,UAAU,4CAAc,aAAa,GAAGA,wBAAW,UAAU,KAE1E,EAAE,SAAS,IAAI,CAAC,EACtC,KAAKA,wBAAW,QACjB,CAAC,KAAK,GAAG;CAEV,MAAM,SAAS,oCACP,GAFcA,wBA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"version":3,"file":"reviewDocBlockAware.cjs","names":["readAsset","ANSIColors","chunkInference","ENGLISH","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 * 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} 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 */\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({\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 deleteCount = plan.actions.filter((a) => a.kind === 'delete').length;\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(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(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;\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,uBAAuB,OAClC,cACA,gBACA,QACA,YACA,WACA,eACA,oBACA,cACA,UACA,aACG;CACH,MAAM,4DAAiC,cAAc;CACrD,MAAM,8DAAiC,EACrC,KAAK;EAAE,GAAG,cAAc;EAAK,QAAQ;EAAI,EAC1C,CAAC;CAEF,MAAM,WAAW,qCAAe,cAAc,QAAQ;CACtD,MAAM,aAAa,qCAAe,gBAAgB,QAAQ,CAAC,YAAY,GAAG;CAE1E,MAAM,aAAaA,+BAAU,8BAA8B,QAAQ,CAChE,WAAW,kBAAkB,4CAAgB,QAAQ,MAAM,GAAG,CAC9D,WAAW,sBAAsB,4CAAgB,YAAY,MAAM,GAAG,CACtE,QAAQ,0BAA0B,WAAW,sBAAsB,IAAI,CACvE,QAAQ,0BAA0B,sBAAsB,IAA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AM,IAAI,MACR,0EACD;AAGH,UAAO;IACP,EAAE;AAEJ,sBAAoB,IAAI,QAAQ,aAAa,oBAAoB;AAGjE,qBAAmB;;AAGrB,mBACE,yCAAY,KAAKL,wBAAW,MAAM,CAAC,+CAAmB,eAAe,CAAC,gCACvE"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
|
-
let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
|
|
5
4
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
6
5
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
6
|
+
let _intlayer_engine_utils = require("@intlayer/engine/utils");
|
|
7
7
|
let node_fs_promises = require("node:fs/promises");
|
|
8
|
-
let
|
|
8
|
+
let _intlayer_engine_docReview = require("@intlayer/engine/docReview");
|
|
9
9
|
|
|
10
10
|
//#region src/reviewDoc/reviewDocLog.ts
|
|
11
11
|
/**
|
|
@@ -29,16 +29,16 @@ const logReviewFileBlocks = async (baseFilePath, outputFilePath, locale, baseLoc
|
|
|
29
29
|
...(0, _intlayer_config_node.getConfiguration)(configOptions).log,
|
|
30
30
|
prefix: ""
|
|
31
31
|
} });
|
|
32
|
-
const report = (0,
|
|
32
|
+
const report = (0, _intlayer_engine_docReview.buildReviewReport)({
|
|
33
33
|
baseText: await (0, node_fs_promises.readFile)(baseFilePath, "utf-8"),
|
|
34
34
|
targetText: (0, node_fs.existsSync)(outputFilePath) ? await (0, node_fs_promises.readFile)(outputFilePath, "utf-8").catch(() => "") : "",
|
|
35
35
|
changedLines
|
|
36
36
|
});
|
|
37
|
-
const formatted = (0,
|
|
38
|
-
baseLabel: (0,
|
|
39
|
-
targetLabel: (0,
|
|
37
|
+
const formatted = (0, _intlayer_engine_docReview.formatReviewReport)(report, {
|
|
38
|
+
baseLabel: (0, _intlayer_engine_utils.formatLocale)(baseLocale),
|
|
39
|
+
targetLabel: (0, _intlayer_engine_utils.formatLocale)(locale)
|
|
40
40
|
});
|
|
41
|
-
appLogger(`${(0,
|
|
41
|
+
appLogger(`${(0, _intlayer_engine_utils.formatPath)(baseFilePath)} → ${(0, _intlayer_engine_utils.formatLocale)(locale)}`);
|
|
42
42
|
for (const line of formatted.split("\n")) appLogger(line);
|
|
43
43
|
return report;
|
|
44
44
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reviewDocLog.cjs","names":[],"sources":["../../../src/reviewDoc/reviewDocLog.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport {
|
|
1
|
+
{"version":3,"file":"reviewDocLog.cjs","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 * Log-only review of a single file/locale pair.\n *\n * Instead of calling an AI to translate the changed blocks, this compares the\n * base document with its translation and logs the blocks that need attention\n * (with their line ranges and content) so another agent or a human can generate\n * the missing translations.\n *\n * @param baseFilePath - Absolute path of the base (source) document.\n * @param outputFilePath - Absolute path of the target (translated) 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 * @param changedLines - 1-based base line numbers that changed (from git), if any.\n * @returns The structured review report.\n */\nexport const logReviewFileBlocks = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n configOptions?: GetConfigurationOptions,\n changedLines?: number[]\n): Promise<ReviewReport> => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger({ log: { ...configuration.log, prefix: '' } });\n\n const baseText = await readFile(baseFilePath, 'utf-8');\n const targetText = existsSync(outputFilePath)\n ? await readFile(outputFilePath, 'utf-8').catch(() => '')\n : '';\n\n const report = buildReviewReport({ baseText, targetText, changedLines });\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 return report;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,sBAAsB,OACjC,cACA,gBACA,QACA,YACA,eACA,iBAC0B;CAE1B,MAAM,sDAAyB,EAAE,KAAK;EAAE,+CADD,cACiB,CAAC;EAAK,QAAQ;EAAI,EAAE,CAAC;CAO7E,MAAM,2DAA2B;EAAE,+CALH,cAAc,QAAQ;EAKT,oCAJf,eAAe,GACzC,qCAAe,gBAAgB,QAAQ,CAAC,YAAY,GAAG,GACvD;EAEqD;EAAc,CAAC;CAExE,MAAM,+DAA+B,QAAQ;EAC3C,oDAAwB,WAAW;EACnC,sDAA0B,OAAO;EAClC,CAAC;AAEF,WAAU,0CAAc,aAAa,CAAC,8CAAkB,OAAO,GAAG;AAClE,MAAK,MAAM,QAAQ,UAAU,MAAM,KAAK,CACtC,WAAU,KAAK;AAGjB,QAAO"}
|
package/dist/cjs/scan.cjs
CHANGED
|
@@ -4,7 +4,7 @@ let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
|
4
4
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
5
5
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
6
6
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
7
|
-
let
|
|
7
|
+
let _intlayer_engine_scan = require("@intlayer/engine/scan");
|
|
8
8
|
|
|
9
9
|
//#region src/scan.ts
|
|
10
10
|
/** Human-readable labels for each scorable check type. */
|
|
@@ -46,14 +46,14 @@ const scoreColor = (score) => {
|
|
|
46
46
|
*/
|
|
47
47
|
const scan = async (url, options = {}) => {
|
|
48
48
|
const appLogger = (0, _intlayer_config_logger.getAppLogger)((0, _intlayer_config_node.getConfiguration)(options.configOptions));
|
|
49
|
-
const result = await (0,
|
|
49
|
+
const result = await (0, _intlayer_engine_scan.scanWebsite)(url, { deep: options.deep });
|
|
50
50
|
if (options.json) {
|
|
51
51
|
appLogger(JSON.stringify(result, null, 2));
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
appLogger(`\n🔍 Scanned ${(0, _intlayer_config_logger.colorize)(result.url, _intlayer_config_colors.GREY_LIGHT)} ${(0, _intlayer_config_logger.colorize)(`(${result.mode} mode)`, _intlayer_config_colors.GREY)}\n`);
|
|
55
55
|
appLogger(`Score: ${(0, _intlayer_config_logger.colorize)(`${result.score}/100`, scoreColor(result.score))}`);
|
|
56
|
-
appLogger(`Page size: ${(0, _intlayer_config_logger.colorize)((0,
|
|
56
|
+
appLogger(`Page size: ${(0, _intlayer_config_logger.colorize)((0, _intlayer_engine_scan.formatSize)(result.totalPageSize), _intlayer_config_colors.BLUE)} ${(0, _intlayer_config_logger.colorize)(`(HTML ${(0, _intlayer_engine_scan.formatSize)(result.htmlSize)})`, _intlayer_config_colors.GREY)}`);
|
|
57
57
|
if (result.locales.length > 0) appLogger(`Locales: ${(0, _intlayer_config_logger.colorize)(result.locales.join(", "), _intlayer_config_colors.GREEN)}`);
|
|
58
58
|
appLogger("\nChecks:");
|
|
59
59
|
for (const event of result.events) {
|
|
@@ -65,8 +65,8 @@ const scan = async (url, options = {}) => {
|
|
|
65
65
|
if (result.bundle && result.bundle.totalLocaleSize > 0) {
|
|
66
66
|
const { bundle } = result;
|
|
67
67
|
appLogger("\nBundle locale weight:");
|
|
68
|
-
appLogger(` Translations shipped: ${(0, _intlayer_config_logger.colorize)((0,
|
|
69
|
-
appLogger(` Unused (other locales): ${(0, _intlayer_config_logger.colorize)(`${(0,
|
|
68
|
+
appLogger(` Translations shipped: ${(0, _intlayer_config_logger.colorize)((0, _intlayer_engine_scan.formatSize)(bundle.totalLocaleSize), _intlayer_config_colors.BLUE)}`);
|
|
69
|
+
appLogger(` Unused (other locales): ${(0, _intlayer_config_logger.colorize)(`${(0, _intlayer_engine_scan.formatSize)(bundle.totalUnusedLocaleSize)} (${bundle.unusedPercentOfLocale}%)`, bundle.unusedPercentOfLocale > 30 ? _intlayer_config_colors.RED : bundle.unusedPercentOfLocale > 0 ? _intlayer_config_colors.YELLOW : _intlayer_config_colors.GREEN)}`);
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
|
package/dist/cjs/scan.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.cjs","names":["ANSIColors"],"sources":["../../src/scan.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"scan.cjs","names":["ANSIColors"],"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;CAC1B;AAED,MAAM,cAAc,WAAwC;AAC1D,KAAI,WAAW,UAAW,8CAAgB,KAAKA,wBAAW,MAAM;AAChE,KAAI,WAAW,UAAW,8CAAgB,KAAKA,wBAAW,OAAO;AACjE,8CAAgB,KAAKA,wBAAW,IAAI;;AAGtC,MAAM,cAAc,UAAkB;AACpC,KAAI,SAAS,GAAI,QAAOA,wBAAW;AACnC,KAAI,SAAS,GAAI,QAAOA,wBAAW;AACnC,QAAOA,wBAAW;;;;;;;;;;;AAYpB,MAAa,OAAO,OAClB,KACA,UAA8B,EAAE,KACd;CAElB,MAAM,kGADiC,QAAQ,cACH,CAAC;CAE7C,MAAM,SAAS,6CAAkB,KAAK,EAAE,MAAM,QAAQ,MAAM,CAAC;AAE7D,KAAI,QAAQ,MAAM;AAChB,YAAU,KAAK,UAAU,QAAQ,MAAM,EAAE,CAAC;AAC1C;;AAGF,WACE,sDAAyB,OAAO,KAAKA,wBAAW,WAAW,CAAC,yCAC1D,IAAI,OAAO,KAAK,SAChBA,wBAAW,KACZ,CAAC,IACH;AAED,WACE,gDAAmB,GAAG,OAAO,MAAM,OAAO,WAAW,OAAO,MAAM,CAAC,GACpE;AACD,WACE,0FAAkC,OAAO,cAAc,EAAEA,wBAAW,KAAK,CAAC,yCACxE,+CAAoB,OAAO,SAAS,CAAC,IACrCA,wBAAW,KACZ,GACF;AACD,KAAI,OAAO,QAAQ,SAAS,EAC1B,WACE,kDAAqB,OAAO,QAAQ,KAAK,KAAK,EAAEA,wBAAW,MAAM,GAClE;AAGH,WAAU,YAAY;AACtB,MAAK,MAAM,SAAS,OAAO,QAAQ;EACjC,MAAM,OAAO,MAAM,KAAK,MAAM,KAAK,CAAC;AAEpC,MAAI,CAAC,KAAM;EAEX,MAAM,QAAQ,YAAY,SAAS;AACnC,YAAU,KAAK,WAAW,MAAM,OAAO,CAAC,GAAG,QAAQ;;AAGrD,KAAI,OAAO,UAAU,OAAO,OAAO,kBAAkB,GAAG;EACtD,MAAM,EAAE,WAAW;AACnB,YAAU,0BAA0B;AACpC,YACE,uGAA+C,OAAO,gBAAgB,EAAEA,wBAAW,KAAK,GACzF;AACD,YACE,mEACE,yCAAc,OAAO,sBAAsB,CAAC,IAAI,OAAO,sBAAsB,KAC7E,OAAO,wBAAwB,KAC3BA,wBAAW,MACX,OAAO,wBAAwB,IAC7BA,wBAAW,SACXA,wBAAW,MAClB,GACF"}
|
package/dist/cjs/searchDoc.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let _intlayer_chokidar_cli = require("@intlayer/chokidar/cli");
|
|
4
3
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
5
4
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
5
|
+
let _intlayer_engine_cli = require("@intlayer/engine/cli");
|
|
6
6
|
let _intlayer_api = require("@intlayer/api");
|
|
7
7
|
|
|
8
8
|
//#region src/searchDoc.ts
|
|
9
9
|
const searchDoc = async ({ query, limit = 10, configOptions }) => {
|
|
10
10
|
const config = (0, _intlayer_config_node.getConfiguration)(configOptions);
|
|
11
|
-
(0,
|
|
11
|
+
(0, _intlayer_engine_cli.logConfigDetails)(configOptions);
|
|
12
12
|
const appLogger = (0, _intlayer_config_logger.getAppLogger)(config);
|
|
13
13
|
try {
|
|
14
14
|
const { searchDoc } = (0, _intlayer_api.getSearchAPI)(void 0, config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchDoc.cjs","names":[],"sources":["../../src/searchDoc.ts"],"sourcesContent":["import { getSearchAPI } from '@intlayer/api';\nimport {
|
|
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';\nimport { logConfigDetails } from '@intlayer/engine/cli';\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 logConfigDetails(configOptions);\n\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":";;;;;;;;AAkBA,MAAa,YAAY,OAAO,EAC9B,OACA,QAAQ,IACR,oBACsB;CACtB,MAAM,qDAA0B,cAAc;AAC9C,4CAAiB,cAAc;CAE/B,MAAM,sDAAyB,OAAO;AAEtC,KAAI;EACF,MAAM,EAAE,8CAA2B,QAAW,OAAO;EACrD,MAAM,WAAW,MAAM,UAAU;GAC/B,OAAO;GACP,OAAO,MAAM,UAAU;GACvB,eAAe;GAChB,CAAC;AAEF,MAAI,CAAC,SAAS,QAAQ,CAAC,MAAM,QAAQ,SAAS,KAAK,EAAE;AACnD,aAAU,4BAA4B;AACtC;;EAGF,MAAM,SAAS,SAAS;AAExB,YAAU,qDAAwB,OAAO,OAAO,CAAC,mBAAmB;AAEpE,SAAO,SAAS,UAAe;AAC7B,aAAU,MAAM;AAChB,aAAU,4CAAe,OAAO,CAAC,IAAI,MAAM,UAAU;AACrD,aAAU,4CAAe,QAAQ,CAAC,IAAI,MAAM,UAAU;AACtD,aAAU,4CAAe,MAAM,CAAC,IAAI,MAAM,SAAS;AACnD,aAAU,4CAAe,QAAQ,CAAC,IAAI,MAAM,cAAc;AAC1D,aAAU,4CAAe,UAAU,CAAC,GAAG;AACvC,aAAU,MAAM,QAAQ;IACxB;UACK,OAAO;AAGd,YAAU,kBADR,iBAAiB,QAAQ,MAAM,UAAU,+BACC,EAAE,OAAO,SAAS,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let _intlayer_chokidar_cli = require("@intlayer/chokidar/cli");
|
|
4
3
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
4
|
+
let _intlayer_engine_cli = require("@intlayer/engine/cli");
|
|
5
5
|
let _intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
|
|
6
6
|
let _intlayer_core_plugins = require("@intlayer/core/plugins");
|
|
7
7
|
let _intlayer_dictionaries_entry = require("@intlayer/dictionaries-entry");
|
|
@@ -57,7 +57,7 @@ const listMissingTranslationsWithConfig = (configuration) => {
|
|
|
57
57
|
};
|
|
58
58
|
const listMissingTranslations = (configurationOptions) => {
|
|
59
59
|
const configuration = (0, _intlayer_config_node.getConfiguration)(configurationOptions);
|
|
60
|
-
(0,
|
|
60
|
+
(0, _intlayer_engine_cli.logConfigDetails)(configurationOptions);
|
|
61
61
|
return listMissingTranslationsWithConfig(configuration);
|
|
62
62
|
};
|
|
63
63
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listMissingTranslations.cjs","names":[],"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import {
|
|
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 { logConfigDetails } from '@intlayer/engine/cli';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\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 // Use the union of keys from both unmerged and merged dictionaries so that\n // dictionaries compiled only as merged (no per-locale split) are still checked.\n const dictionariesKeys = new Set([\n ...Object.keys(unmergedDictionariesRecord),\n ...Object.keys(mergedDictionaries),\n ]);\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 there are no unmerged dictionaries for this key, fall back to the\n // merged dictionary directly (covers the case where the dict was compiled\n // as merged-only and unmerged_dictionaries.cjs is empty for this key).\n if (dictionaries.length === 0) {\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n if (mergedDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: mergedDictionary.id,\n filePath: mergedDictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n continue;\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(\n (missingTranslation) => missingTranslation.locales\n )\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 logConfigDetails(configurationOptions);\n\n return listMissingTranslationsWithConfig(configuration);\n};\n"],"mappings":";;;;;;;;;AAYA,MAAa,qCACX,kBACG;CACH,MAAM,gGAAqD,cAAc;CACzE,MAAM,uEAAqC,cAAc;CAEzD,MAAM,sBAKA,EAAE;CAER,MAAM,EAAE,SAAS,oBAAoB,cAAc;CAInD,MAAM,mBAAmB,IAAI,IAAI,CAC/B,GAAG,OAAO,KAAK,2BAA2B,EAC1C,GAAG,OAAO,KAAK,mBAAmB,CACnC,CAAC;AAEF,MAAK,MAAM,iBAAiB,kBAAkB;EAC5C,MAAM,eACJ,2BAA2B,kBAAkB,EAAE;EAEjD,MAAM,yBAAuC,aAAa,QACvD,eAAe,CAAC,WAAW,OAC7B;AAGD,OAAK,MAAM,cAAc,wBAAwB;GAC/C,MAAM,oFACJ,YACA,QACD;AAED,OAAI,eAAe,SAAS,EAC1B,qBAAoB,KAAK;IACvB,KAAK;IACL,IAAI,WAAW;IACf,UAAU,WAAW;IACrB,SAAS;IACV,CAAC;;EAIN,MAAM,sBAAoC,aAAa,QACpD,eAAe,WAAW,OAC5B;AAKD,MAAI,aAAa,WAAW,GAAG;GAC7B,MAAM,mBAAmB,mBAAmB;AAE5C,OAAI,kBAAkB;IACpB,MAAM,oFACJ,kBACA,QACD;AAED,QAAI,eAAe,SAAS,EAC1B,qBAAoB,KAAK;KACvB,KAAK;KACL,IAAI,iBAAiB;KACrB,UAAU,iBAAiB;KAC3B,SAAS;KACV,CAAC;;AAIN;;AAGF,MAAI,oBAAoB,WAAW,EACjC;EAGF,MAAM,mBAAmB,mBAAmB;EAE5C,MAAM,oFACJ,kBACA,QACD;AAED,MAAI,eAAe,SAAS,EAC1B,qBAAoB,KAAK;GACvB,KAAK;GACL,SAAS;GACV,CAAC;;CAIN,MAAM,oBAAoB,IAAI,IAC5B,oBAAoB,SACjB,uBAAuB,mBAAmB,QAC5C,CACF;CACD,MAAM,iBAAiB,MAAM,KAAK,kBAAkB;AAMpD,QAAO;EAAE;EAAqB;EAAgB,wBAJf,eAAe,QAAQ,YACnD,mBAAmB,SAAS,SAAS,OAAO,CAGqB;EAAE;;AAGxE,MAAa,2BACX,yBACG;CACH,MAAM,4DAAiC,qBAAqB;AAC5D,4CAAiB,qBAAqB;AAEtC,QAAO,kCAAkC,cAAc"}
|
package/dist/cjs/test/test.cjs
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_test_listMissingTranslations = require('./listMissingTranslations.cjs');
|
|
4
|
-
let _intlayer_chokidar_build = require("@intlayer/chokidar/build");
|
|
5
|
-
let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
|
|
6
4
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
7
5
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
8
6
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
9
7
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
8
|
+
let _intlayer_engine_build = require("@intlayer/engine/build");
|
|
9
|
+
let _intlayer_engine_utils = require("@intlayer/engine/utils");
|
|
10
10
|
|
|
11
11
|
//#region src/test/test.ts
|
|
12
12
|
const testMissingTranslations = async (options) => {
|
|
13
13
|
const config = (0, _intlayer_config_node.getConfiguration)(options?.configOptions);
|
|
14
14
|
const { locales, requiredLocales } = config.internationalization;
|
|
15
15
|
const appLogger = (0, _intlayer_config_logger.getAppLogger)(config);
|
|
16
|
-
if (options?.build === true) await (0,
|
|
17
|
-
else if (typeof options?.build === "undefined") await (0,
|
|
16
|
+
if (options?.build === true) await (0, _intlayer_engine_build.prepareIntlayer)(config, { forceRun: true });
|
|
17
|
+
else if (typeof options?.build === "undefined") await (0, _intlayer_engine_build.prepareIntlayer)(config);
|
|
18
18
|
const result = require_test_listMissingTranslations.listMissingTranslations(options?.configOptions);
|
|
19
19
|
const maxKeyColSize = result.missingTranslations.map((t) => ` - ${t.key}`).reduce((max, t) => Math.max(max, t.length), 0);
|
|
20
|
-
const maxLocalesColSize = result.missingTranslations.map((t) => (0,
|
|
20
|
+
const maxLocalesColSize = result.missingTranslations.map((t) => (0, _intlayer_engine_utils.formatLocale)(t.locales, false)).reduce((max, t) => Math.max(max, t.length), 0);
|
|
21
21
|
const formattedMissingTranslations = result.missingTranslations.map((translation) => [
|
|
22
22
|
(0, _intlayer_config_logger.colon)(` - ${(0, _intlayer_config_logger.colorizeKey)(translation.key)}`, {
|
|
23
23
|
colSize: maxKeyColSize,
|
|
24
24
|
maxSize: 40
|
|
25
25
|
}),
|
|
26
26
|
" - ",
|
|
27
|
-
(0, _intlayer_config_logger.colon)((0,
|
|
27
|
+
(0, _intlayer_config_logger.colon)((0, _intlayer_engine_utils.formatLocale)(translation.locales, _intlayer_config_colors.RED), {
|
|
28
28
|
colSize: maxLocalesColSize,
|
|
29
29
|
maxSize: 40
|
|
30
30
|
}),
|
|
31
|
-
translation.filePath ? ` - ${(0,
|
|
31
|
+
translation.filePath ? ` - ${(0, _intlayer_engine_utils.formatPath)(translation.filePath)}` : "",
|
|
32
32
|
translation.id ? " - remote" : ""
|
|
33
33
|
].join(""));
|
|
34
34
|
appLogger(`Missing translations:`, { level: "info" });
|
|
35
35
|
formattedMissingTranslations.forEach((t) => {
|
|
36
36
|
appLogger(t, { level: "info" });
|
|
37
37
|
});
|
|
38
|
-
appLogger(`Locales: ${(0,
|
|
39
|
-
appLogger(`Required locales: ${(0,
|
|
40
|
-
appLogger(`Missing locales: ${result.missingLocales.length === 0 ? (0, _intlayer_config_logger.colorize)("-", _intlayer_config_colors.GREEN) : (0,
|
|
41
|
-
appLogger(`Missing required locales: ${result.missingRequiredLocales.length === 0 ? (0, _intlayer_config_logger.colorize)("-", _intlayer_config_colors.GREEN) : (0,
|
|
38
|
+
appLogger(`Locales: ${(0, _intlayer_engine_utils.formatLocale)(locales)}`);
|
|
39
|
+
appLogger(`Required locales: ${(0, _intlayer_engine_utils.formatLocale)(requiredLocales ?? locales)}`);
|
|
40
|
+
appLogger(`Missing locales: ${result.missingLocales.length === 0 ? (0, _intlayer_config_logger.colorize)("-", _intlayer_config_colors.GREEN) : (0, _intlayer_engine_utils.formatLocale)(result.missingLocales, _intlayer_config_colors.RED)}`);
|
|
41
|
+
appLogger(`Missing required locales: ${result.missingRequiredLocales.length === 0 ? (0, _intlayer_config_logger.colorize)("-", _intlayer_config_colors.GREEN) : (0, _intlayer_engine_utils.formatLocale)(result.missingRequiredLocales, _intlayer_config_colors.RED)}`);
|
|
42
42
|
appLogger(`Total missing locales: ${(0, _intlayer_config_logger.colorizeNumber)(result.missingLocales.length, {
|
|
43
43
|
one: _intlayer_config_colors.RED,
|
|
44
44
|
other: _intlayer_config_colors.RED,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.cjs","names":["listMissingTranslations","ANSIColors"],"sources":["../../../src/test/test.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"test.cjs","names":["listMissingTranslations","ANSIColors"],"sources":["../../../src/test/test.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport {\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 { prepareIntlayer } from '@intlayer/engine/build';\nimport { formatLocale, formatPath } from '@intlayer/engine/utils';\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.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IAAI,GAC/I;AAED,WACE,6BAA6B,OAAO,uBAAuB,WAAW,0CAAa,KAAKA,wBAAW,MAAM,4CAAgB,OAAO,wBAAwBA,wBAAW,IAAI,GACxK;AACD,WACE,sEAAyC,OAAO,eAAe,QAAQ;EACrE,KAAKA,wBAAW;EAChB,OAAOA,wBAAW;EAClB,MAAMA,wBAAW;EAClB,CAAC,GACH;AACD,WACE,+EACE,OAAO,uBAAuB,QAC9B;EACE,KAAKA,wBAAW;EAChB,OAAOA,wBAAW;EAClB,MAAMA,wBAAW;EAClB,CACF,GACF;AAED,KAAI,OAAO,uBAAuB,SAAS,EACzC,SAAQ,KAAK,EAAE"}
|
|
@@ -6,12 +6,12 @@ const require_utils_checkFileModifiedRange = require('../utils/checkFileModified
|
|
|
6
6
|
const require_translateDoc_translateFile = require('./translateFile.cjs');
|
|
7
7
|
let node_fs = require("node:fs");
|
|
8
8
|
let node_path = require("node:path");
|
|
9
|
-
let _intlayer_chokidar_cli = require("@intlayer/chokidar/cli");
|
|
10
|
-
let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
|
|
11
9
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
12
10
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
13
11
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
14
12
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
13
|
+
let _intlayer_engine_cli = require("@intlayer/engine/cli");
|
|
14
|
+
let _intlayer_engine_utils = require("@intlayer/engine/utils");
|
|
15
15
|
let fast_glob = require("fast-glob");
|
|
16
16
|
fast_glob = require_runtime.__toESM(fast_glob);
|
|
17
17
|
let node_perf_hooks = require("node:perf_hooks");
|
|
@@ -19,10 +19,10 @@ let node_perf_hooks = require("node:perf_hooks");
|
|
|
19
19
|
//#region src/translateDoc/translateDoc.ts
|
|
20
20
|
const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLocale, aiOptions, nbSimultaneousFileProcessed = 20, configOptions, customInstructions, skipIfModifiedBefore, skipIfModifiedAfter, skipIfExists, gitOptions, flushStrategy = "incremental" }) => {
|
|
21
21
|
const configuration = (0, _intlayer_config_node.getConfiguration)(configOptions);
|
|
22
|
-
(0,
|
|
22
|
+
(0, _intlayer_engine_cli.logConfigDetails)(configOptions);
|
|
23
23
|
const appLogger = (0, _intlayer_config_logger.getAppLogger)(configuration);
|
|
24
24
|
const maxConcurrentChunks = nbSimultaneousFileProcessed;
|
|
25
|
-
const globalChunkLimiter = (0,
|
|
25
|
+
const globalChunkLimiter = (0, _intlayer_engine_utils.pLimit)(maxConcurrentChunks);
|
|
26
26
|
let docList = await (0, fast_glob.default)(docPattern, { ignore: excludedGlobPattern });
|
|
27
27
|
const aiResult = await require_utils_setupAI.setupAI(configuration, aiOptions);
|
|
28
28
|
if (!aiResult?.hasAIAccess) return;
|
|
@@ -35,7 +35,7 @@ const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLoca
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
if (gitOptions) {
|
|
38
|
-
const gitChangedFiles = await (0,
|
|
38
|
+
const gitChangedFiles = await (0, _intlayer_engine_cli.listGitFiles)(gitOptions);
|
|
39
39
|
if (gitChangedFiles) docList = docList.filter((path) => gitChangedFiles.some((gitFile) => (0, node_path.join)(process.cwd(), path) === gitFile));
|
|
40
40
|
}
|
|
41
41
|
const batchStartTime = node_perf_hooks.performance.now();
|
|
@@ -45,7 +45,7 @@ const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLoca
|
|
|
45
45
|
maxErrors: 5,
|
|
46
46
|
shouldStop: false
|
|
47
47
|
};
|
|
48
|
-
await (0,
|
|
48
|
+
await (0, _intlayer_engine_utils.parallelize)(docList.flatMap((docPath) => locales.map((locale) => async () => {
|
|
49
49
|
if (errorState.shouldStop) return;
|
|
50
50
|
const absoluteBaseFilePath = (0, node_path.join)(configuration.system.baseDir, docPath);
|
|
51
51
|
const outputFilePath = require_utils_getOutputFilePath.getOutputFilePath(absoluteBaseFilePath, locale, baseLocale);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translateDoc.cjs","names":["setupAI","x","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';\
|
|
1
|
+
{"version":3,"file":"translateDoc.cjs","names":["setupAI","x","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 * 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,4DAAiC,cAAc;AACrD,4CAAiB,cAAc;CAE/B,MAAM,sDAAyB,cAAc;CAK7C,MAAM,sBAAsB;CAC5B,MAAM,wDAA4B,oBAAoB;CAEtD,IAAI,UAAoB,6BAAS,YAAY,EAC3C,QAAQ,qBACT,CAAC;CAEF,MAAM,WAAW,MAAMA,8BAAQ,eAAe,UAAU;AACxD,KAAI,CAAC,UAAU,YAAa;CAE5B,MAAM,EAAE,UAAU,UAAU,eAAe;AAC3C,KAAI,cAAc,YAAY,UAAU;EACtC,MAAM,EAAE,aAAa,UAAU,MAAM,SAAS,iBAAiB,SAAS;AACxE,MAAI,CAAC,aAAa;AAChB,aAAU,GAAGC,0BAAE,GAAG,QAAQ;AAC1B;;;AAIJ,KAAI,YAAY;EACd,MAAM,kBAAkB,6CAAmB,WAAW;AACtD,MAAI,gBACF,WAAU,QAAQ,QAAQ,SACxB,gBAAgB,MAAM,gCAAiB,QAAQ,KAAK,EAAE,KAAK,KAAK,QAAQ,CACzE;;CAIL,MAAM,iBAAiBC,4BAAY,KAAK;AAExC,WACE,2DAA8B,QAAQ,OAAO,CAAC,wDAA2B,QAAQ,OAAO,CAAC,8EACjD,oBAAoB,CAAC,sBAC9D;CAED,MAAM,aAAyB;EAC7B,OAAO;EACP,WAAW;EACX,YAAY;EACb;AAyDD,+CArDiB,QAAQ,SAAS,YAChC,QAAQ,KAAK,WAAW,YAAY;AAClC,MAAI,WAAW,WAAY;EAE3B,MAAM,2CAA4B,cAAc,OAAO,SAAS,QAAQ;EACxE,MAAM,iBAAiBC,kDACrB,sBACA,QACA,WACD;AAGD,MAAI,wCAA2B,eAAe,CAAE;AAEhD,MAAI,kBAAkB,iBAAiB,yBAAY,eAAe,EAAE;AAClE,iDAAkB,eAAe,EAAE,EAAE,WAAW,MAAM,CAAC;AACvD,8BAAc,gBAAgB,GAAG;;EAGnC,MAAM,uBAAuBC,4DAAuB,gBAAgB;GAClE;GACA;GACD,CAAC;AAEF,MAAI,qBAAqB,WAAW;AAClC,aAAU,qBAAqB,QAAQ;AACvC;;AAIF,QAAMC,iDAAc;GAClB,cAAc;GACd;GACQ;GACR;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,OAAO;GACR,CAAC;GACF,CASsB,GAAG,SAAS,MAAM,EAAE,GAAgB;CAG9D,MAAM,kBADeH,4BAAY,KACG,GAAG,kBAAkB,KAAM,QAAQ,EAAE;AAEzE,KAAI,WAAW,QAAQ,EACrB,WAAU,iBAAiB,WAAW,MAAM,aAAa,cAAc,IAAI;KAE3E,WACE,yCAAY,KAAKI,wBAAW,MAAM,CAAC,+EAAkD,cAAc,CAAC,IACrG"}
|
|
@@ -6,10 +6,10 @@ const require_utils_chunkInference = require('../utils/chunkInference.cjs');
|
|
|
6
6
|
const require_utils_fixChunkStartEndChars = require('../utils/fixChunkStartEndChars.cjs');
|
|
7
7
|
const require_utils_calculateChunks = require('../utils/calculateChunks.cjs');
|
|
8
8
|
let node_path = require("node:path");
|
|
9
|
-
let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
|
|
10
9
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
11
10
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
12
11
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
12
|
+
let _intlayer_engine_utils = require("@intlayer/engine/utils");
|
|
13
13
|
let node_fs_promises = require("node:fs/promises");
|
|
14
14
|
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
15
15
|
let node_perf_hooks = require("node:perf_hooks");
|
|
@@ -22,10 +22,10 @@ const translateFile = async ({ baseFilePath, outputFilePath, locale, baseLocale,
|
|
|
22
22
|
try {
|
|
23
23
|
const chunks = require_utils_calculateChunks.chunkText(await (0, node_fs_promises.readFile)(baseFilePath, "utf-8"));
|
|
24
24
|
const totalChunks = chunks.length;
|
|
25
|
-
const filePrefix = `${(0, _intlayer_config_logger.colon)(`${_intlayer_config_colors.GREY_DARK}[${(0,
|
|
26
|
-
const prefix = `${(0, _intlayer_config_logger.colon)(`${_intlayer_config_colors.GREY_DARK}[${(0,
|
|
25
|
+
const filePrefix = `${(0, _intlayer_config_logger.colon)(`${_intlayer_config_colors.GREY_DARK}[${(0, _intlayer_engine_utils.formatPath)(baseFilePath)}${_intlayer_config_colors.GREY_DARK}] `, { colSize: 40 })}${_intlayer_config_colors.RESET}`;
|
|
26
|
+
const prefix = `${(0, _intlayer_config_logger.colon)(`${_intlayer_config_colors.GREY_DARK}[${(0, _intlayer_engine_utils.formatPath)(baseFilePath)}${_intlayer_config_colors.GREY_DARK}][${(0, _intlayer_engine_utils.formatLocale)(locale)}${_intlayer_config_colors.GREY_DARK}] `, { colSize: 40 })}${_intlayer_config_colors.RESET}`;
|
|
27
27
|
appLogger(`${filePrefix}Split into ${(0, _intlayer_config_logger.colorizeNumber)(totalChunks)} chunks. Queuing...`);
|
|
28
|
-
const basePrompt = require__utils_asset.readAsset("./prompts/TRANSLATE_PROMPT.md", "utf-8").replaceAll("{{localeName}}", `${(0,
|
|
28
|
+
const basePrompt = require__utils_asset.readAsset("./prompts/TRANSLATE_PROMPT.md", "utf-8").replaceAll("{{localeName}}", `${(0, _intlayer_engine_utils.formatLocale)(locale, false)}`).replaceAll("{{baseLocaleName}}", `${(0, _intlayer_engine_utils.formatLocale)(baseLocale, false)}`).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
|
|
29
29
|
const translatedParts = new Array(totalChunks).fill("");
|
|
30
30
|
const runTask = limit ?? ((fn) => fn());
|
|
31
31
|
const tasks = chunks.map((chunk, i) => runTask(async () => {
|
|
@@ -89,7 +89,7 @@ const translateFile = async ({ baseFilePath, outputFilePath, locale, baseLocale,
|
|
|
89
89
|
}
|
|
90
90
|
const totalDuration = ((node_perf_hooks.performance.now() - fileStartTime) / 1e3).toFixed(2);
|
|
91
91
|
const relativePath = (0, node_path.relative)(configuration.system.baseDir, outputFilePath);
|
|
92
|
-
appLogger(`${(0, _intlayer_config_logger.colorize)("✔", _intlayer_config_colors.GREEN)} File ${(0,
|
|
92
|
+
appLogger(`${(0, _intlayer_config_logger.colorize)("✔", _intlayer_config_colors.GREEN)} File ${(0, _intlayer_engine_utils.formatPath)(relativePath)} completed in ${(0, _intlayer_config_logger.colorizeNumber)(totalDuration)}s.`);
|
|
93
93
|
return fullContent;
|
|
94
94
|
} catch (error) {
|
|
95
95
|
errorState.count++;
|