@intlayer/cli 6.0.2 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +249 -56
  2. package/dist/cjs/build.cjs +8 -0
  3. package/dist/cjs/build.cjs.map +1 -1
  4. package/dist/cjs/cli.cjs +32 -5
  5. package/dist/cjs/cli.cjs.map +1 -1
  6. package/dist/cjs/fill/index.cjs +114 -59
  7. package/dist/cjs/fill/index.cjs.map +1 -1
  8. package/dist/cjs/index.cjs +4 -2
  9. package/dist/cjs/index.cjs.map +1 -1
  10. package/dist/cjs/liveSync.cjs +6 -30
  11. package/dist/cjs/liveSync.cjs.map +1 -1
  12. package/dist/cjs/pull.cjs +1 -1
  13. package/dist/cjs/pull.cjs.map +1 -1
  14. package/dist/cjs/push/pullLog.cjs.map +1 -0
  15. package/dist/cjs/{push.cjs → push/push.cjs} +2 -2
  16. package/dist/cjs/push/push.cjs.map +1 -0
  17. package/dist/cjs/reviewDoc.cjs +148 -96
  18. package/dist/cjs/reviewDoc.cjs.map +1 -1
  19. package/dist/cjs/test/index.cjs +2 -0
  20. package/dist/cjs/test/index.cjs.map +1 -1
  21. package/dist/cjs/translateDoc.cjs +39 -42
  22. package/dist/cjs/translateDoc.cjs.map +1 -1
  23. package/dist/cjs/utils/mapChunksBetweenFiles.cjs +145 -0
  24. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -0
  25. package/dist/cjs/watch.cjs +42 -0
  26. package/dist/cjs/watch.cjs.map +1 -0
  27. package/dist/esm/build.mjs +12 -1
  28. package/dist/esm/build.mjs.map +1 -1
  29. package/dist/esm/cli.mjs +32 -5
  30. package/dist/esm/cli.mjs.map +1 -1
  31. package/dist/esm/fill/index.mjs +114 -59
  32. package/dist/esm/fill/index.mjs.map +1 -1
  33. package/dist/esm/index.mjs +2 -1
  34. package/dist/esm/index.mjs.map +1 -1
  35. package/dist/esm/liveSync.mjs +10 -31
  36. package/dist/esm/liveSync.mjs.map +1 -1
  37. package/dist/esm/pull.mjs +1 -1
  38. package/dist/esm/pull.mjs.map +1 -1
  39. package/dist/esm/push/pullLog.mjs.map +1 -0
  40. package/dist/esm/{push.mjs → push/push.mjs} +2 -2
  41. package/dist/esm/push/push.mjs.map +1 -0
  42. package/dist/esm/reviewDoc.mjs +151 -97
  43. package/dist/esm/reviewDoc.mjs.map +1 -1
  44. package/dist/esm/test/index.mjs +2 -0
  45. package/dist/esm/test/index.mjs.map +1 -1
  46. package/dist/esm/translateDoc.mjs +41 -43
  47. package/dist/esm/translateDoc.mjs.map +1 -1
  48. package/dist/esm/utils/mapChunksBetweenFiles.mjs +121 -0
  49. package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -0
  50. package/dist/esm/watch.mjs +21 -0
  51. package/dist/esm/watch.mjs.map +1 -0
  52. package/dist/types/build.d.ts +2 -0
  53. package/dist/types/build.d.ts.map +1 -1
  54. package/dist/types/cli.d.ts.map +1 -1
  55. package/dist/types/fill/index.d.ts.map +1 -1
  56. package/dist/types/index.d.ts +2 -1
  57. package/dist/types/index.d.ts.map +1 -1
  58. package/dist/types/liveSync.d.ts +1 -1
  59. package/dist/types/liveSync.d.ts.map +1 -1
  60. package/dist/types/push/pullLog.d.ts.map +1 -0
  61. package/dist/types/push/push.d.ts.map +1 -0
  62. package/dist/types/reviewDoc.d.ts +2 -2
  63. package/dist/types/reviewDoc.d.ts.map +1 -1
  64. package/dist/types/test/index.d.ts.map +1 -1
  65. package/dist/types/translateDoc.d.ts.map +1 -1
  66. package/dist/types/utils/mapChunksBetweenFiles.d.ts +12 -0
  67. package/dist/types/utils/mapChunksBetweenFiles.d.ts.map +1 -0
  68. package/dist/types/watch.d.ts +13 -0
  69. package/dist/types/watch.d.ts.map +1 -0
  70. package/package.json +21 -21
  71. package/dist/cjs/pullLog.cjs.map +0 -1
  72. package/dist/cjs/push.cjs.map +0 -1
  73. package/dist/esm/pullLog.mjs.map +0 -1
  74. package/dist/esm/push.mjs.map +0 -1
  75. package/dist/types/pullLog.d.ts.map +0 -1
  76. package/dist/types/push.d.ts.map +0 -1
  77. /package/dist/cjs/{pullLog.cjs → push/pullLog.cjs} +0 -0
  78. /package/dist/esm/{pullLog.mjs → push/pullLog.mjs} +0 -0
  79. /package/dist/types/{pullLog.d.ts → push/pullLog.d.ts} +0 -0
  80. /package/dist/types/{push.d.ts → push/push.d.ts} +0 -0
@@ -1,7 +1,9 @@
1
1
  import {
2
2
  formatLocale,
3
3
  formatPath,
4
- listGitFiles
4
+ listGitFiles,
5
+ listGitLines,
6
+ parallelize
5
7
  } from "@intlayer/chokidar";
6
8
  import {
7
9
  ANSIColors,
@@ -17,7 +19,6 @@ import { getLocaleName } from "@intlayer/core";
17
19
  import fg from "fast-glob";
18
20
  import { mkdirSync, writeFileSync } from "fs";
19
21
  import { readFile } from "fs/promises";
20
- import pLimit from "p-limit";
21
22
  import { dirname, join, relative } from "path";
22
23
  import { fileURLToPath } from "url";
23
24
  import { chunkText } from "./utils/calculateChunks.mjs";
@@ -27,10 +28,12 @@ import { chunkInference } from "./utils/chunkInference.mjs";
27
28
  import { fixChunkStartEndChars } from "./utils/fixChunkStartEndChars.mjs";
28
29
  import { getChunk } from "./utils/getChunk.mjs";
29
30
  import { getOutputFilePath } from "./utils/getOutputFilePath.mjs";
31
+ import { mapChunksBetweenFiles } from "./utils/mapChunksBetweenFiles.mjs";
30
32
  const isESModule = typeof import.meta.url === "string";
31
33
  const dir = isESModule ? dirname(fileURLToPath(import.meta.url)) : __dirname;
32
- const reviewFile = async (baseFilePath, outputFilePath, locale, baseLocale, aiOptions, configuration = getConfiguration(), customInstructions, changedLines) => {
34
+ const reviewFile = async (baseFilePath, outputFilePath, locale, baseLocale, aiOptions, configOptions, customInstructions, changedLines) => {
33
35
  try {
36
+ const configuration = getConfiguration(configOptions);
34
37
  const appLogger = getAppLogger(configuration, {
35
38
  config: {
36
39
  prefix: ""
@@ -41,79 +44,124 @@ const reviewFile = async (baseFilePath, outputFilePath, locale, baseLocale, aiOp
41
44
  let updatedFileContent = fileToReviewContent;
42
45
  let fileResultContent = "";
43
46
  const basePrompt = (await readFile(join(dir, "./prompts/REVIEW_PROMPT.md"), "utf-8")).replaceAll("{{localeName}}", `${formatLocale(locale, false)}`).replaceAll("{{baseLocaleName}}", `${formatLocale(baseLocale, false)}`).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
44
- const baseChunks = chunkText(basedFileContent, 800, 0);
45
47
  const filePrexixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;
46
48
  const filePrefix = [
47
49
  colon(filePrexixText, { colSize: 40 }),
48
50
  `\u2192 ${ANSIColors.RESET}`
49
51
  ].join("");
50
52
  const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;
51
- const prefix = [colon(prefixText, { colSize: 40 })].join("");
52
- appLogger(
53
- `${filePrefix}Base file splitted into ${colorizeNumber(baseChunks.length)} chunks`
54
- );
55
- for await (const [i, baseChunk] of baseChunks.entries()) {
56
- const baseChunkContext = baseChunk;
57
- if (changedLines) {
58
- const hasChangedLinesInChunk = changedLines.some(
59
- (line) => line > baseChunkContext.lineStart && line < baseChunkContext.lineStart + baseChunkContext.lineLength
60
- );
61
- if (!hasChangedLinesInChunk) {
53
+ const prefix = [
54
+ colon(prefixText, { colSize: 40 }),
55
+ `\u2192 ${ANSIColors.RESET}`
56
+ ].join("");
57
+ if (changedLines && changedLines.length > 0) {
58
+ appLogger(
59
+ `${filePrefix}Using optimization with ${colorizeNumber(changedLines.length)} changed lines`
60
+ );
61
+ const chunkMappings = mapChunksBetweenFiles(
62
+ basedFileContent,
63
+ updatedFileContent,
64
+ 800,
65
+ changedLines
66
+ );
67
+ appLogger(
68
+ `${filePrefix}Base file mapped to ${colorizeNumber(chunkMappings.length)} chunk mappings`
69
+ );
70
+ for await (const [i, mapping] of chunkMappings.entries()) {
71
+ const { baseChunk, updatedChunk, hasChanges } = mapping;
72
+ if (!hasChanges && updatedChunk) {
62
73
  appLogger(
63
- `No git changed lines found for chunk ${colorizeNumber(i + 1)}`
74
+ `${prefix}No changes found for chunk ${colorizeNumber(i + 1)}, preserving existing translation`
64
75
  );
65
- const chunkWithNoChange = getChunk(updatedFileContent, {
66
- lineStart: baseChunkContext.lineStart,
67
- lineLength: baseChunkContext.lineLength
76
+ const existingChunk = getChunk(fileToReviewContent, {
77
+ lineStart: updatedChunk.lineStart,
78
+ lineLength: updatedChunk.lineLength
68
79
  });
69
- fileResultContent += chunkWithNoChange;
80
+ fileResultContent += existingChunk;
81
+ continue;
82
+ }
83
+ if (!updatedChunk) {
84
+ appLogger(
85
+ `${prefix}Chunk ${colorizeNumber(i + 1)} was deleted, skipping`
86
+ );
70
87
  continue;
71
88
  }
89
+ const baseChunkContext = baseChunk;
90
+ const getBaseChunkContextPrompt = () => `**CHUNK ${i + 1} of ${chunkMappings.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.
91
+ ///chunksStart///` + baseChunkContext.content + `///chunksEnd///`;
92
+ const getChunkToReviewPrompt = () => `**CHUNK ${i + 1} of ${chunkMappings.length}** is the current chunk to review in ${formatLocale(locale, false)}.
93
+ ///chunksStart///` + updatedChunk.content + `///chunksEnd///`;
94
+ let reviewedChunkResult = await retryManager(async () => {
95
+ const result = await chunkInference(
96
+ [
97
+ { role: "system", content: basePrompt },
98
+ { role: "system", content: getBaseChunkContextPrompt() },
99
+ { role: "system", content: getChunkToReviewPrompt() },
100
+ {
101
+ role: "system",
102
+ content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunkMappings.length)}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`
103
+ },
104
+ { role: "user", content: baseChunkContext.content }
105
+ ],
106
+ aiOptions,
107
+ configuration
108
+ );
109
+ appLogger(
110
+ `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Chunk ${colorizeNumber(i + 1)} of ${colorizeNumber(chunkMappings.length)}`
111
+ );
112
+ const fixedReviewedChunkResult = fixChunkStartEndChars(
113
+ result?.fileContent,
114
+ baseChunkContext.content
115
+ );
116
+ return fixedReviewedChunkResult;
117
+ })();
118
+ fileResultContent += reviewedChunkResult;
72
119
  }
73
- const getBaseChunkContextPrompt = () => `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.
120
+ } else {
121
+ appLogger(`${filePrefix}Processing all chunks (no optimization)`);
122
+ const baseChunks = chunkText(basedFileContent, 800, 0);
123
+ appLogger(
124
+ `${filePrefix}Base file splitted into ${colorizeNumber(baseChunks.length)} chunks`
125
+ );
126
+ for await (const [i, baseChunk] of baseChunks.entries()) {
127
+ const baseChunkContext = baseChunk;
128
+ const getBaseChunkContextPrompt = () => `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.
74
129
  ///chunksStart///` + (baseChunks[i - 1]?.content ?? "") + baseChunkContext.content + (baseChunks[i + 1]?.content ?? "") + `///chunksEnd///`;
75
- const getChunkToReviewPrompt = () => `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the current chunk to review in ${formatLocale(locale, false)} as reference.
130
+ const getChunkToReviewPrompt = () => `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the current chunk to review in ${formatLocale(locale, false)} as reference.
76
131
  ///chunksStart///` + getChunk(updatedFileContent, {
77
- lineStart: baseChunks[i - 1]?.lineStart ?? 0,
78
- lineLength: (baseChunks[i - 1]?.lineLength ?? 0) + baseChunkContext.lineLength + (baseChunks[i + 1]?.lineLength ?? 0)
79
- }) + `///chunksEnd///`;
80
- let reviewedChunkResult = await retryManager(async () => {
81
- const result = await chunkInference(
82
- [
83
- { role: "system", content: basePrompt },
84
- { role: "system", content: getBaseChunkContextPrompt() },
85
- { role: "system", content: getChunkToReviewPrompt() },
86
- {
87
- role: "system",
88
- content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(baseChunks.length)}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`
89
- },
90
- { role: "user", content: baseChunkContext.content }
91
- ],
92
- aiOptions,
93
- configuration
94
- );
95
- appLogger(
96
- [
97
- `${prefix}`,
98
- `${ANSIColors.GREY_DARK}[Chunk `,
99
- colorizeNumber(i + 1),
100
- `${ANSIColors.GREY_DARK} of `,
101
- colorizeNumber(baseChunks.length),
102
- `${ANSIColors.GREY_DARK}] \u2192${ANSIColors.RESET} `,
103
- `${colorizeNumber(result.tokenUsed)} tokens used`
104
- ].join("")
105
- );
106
- const fixedReviewedChunkResult = fixChunkStartEndChars(
107
- result?.fileContent,
108
- baseChunkContext.content
132
+ lineStart: baseChunks[i - 1]?.lineStart ?? 0,
133
+ lineLength: (baseChunks[i - 1]?.lineLength ?? 0) + baseChunkContext.lineLength + (baseChunks[i + 1]?.lineLength ?? 0)
134
+ }) + `///chunksEnd///`;
135
+ let reviewedChunkResult = await retryManager(async () => {
136
+ const result = await chunkInference(
137
+ [
138
+ { role: "system", content: basePrompt },
139
+ { role: "system", content: getBaseChunkContextPrompt() },
140
+ { role: "system", content: getChunkToReviewPrompt() },
141
+ {
142
+ role: "system",
143
+ content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(baseChunks.length)}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`
144
+ },
145
+ { role: "user", content: baseChunkContext.content }
146
+ ],
147
+ aiOptions,
148
+ configuration
149
+ );
150
+ appLogger(
151
+ `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Chunk ${colorizeNumber(i + 1)} of ${colorizeNumber(baseChunks.length)}`
152
+ );
153
+ const fixedReviewedChunkResult = fixChunkStartEndChars(
154
+ result?.fileContent,
155
+ baseChunkContext.content
156
+ );
157
+ return fixedReviewedChunkResult;
158
+ })();
159
+ updatedFileContent = updatedFileContent.replace(
160
+ baseChunkContext.content,
161
+ reviewedChunkResult
109
162
  );
110
- return fixedReviewedChunkResult;
111
- })();
112
- updatedFileContent = updatedFileContent.replace(
113
- baseChunkContext.content,
114
- reviewedChunkResult
115
- );
116
- fileResultContent += reviewedChunkResult;
163
+ fileResultContent += reviewedChunkResult;
164
+ }
117
165
  }
118
166
  mkdirSync(dirname(outputFilePath), { recursive: true });
119
167
  writeFileSync(outputFilePath, fileResultContent);
@@ -155,7 +203,6 @@ const reviewDoc = async ({
155
203
  );
156
204
  nbSimultaneousFileProcessed = 10;
157
205
  }
158
- const limit = pLimit(nbSimultaneousFileProcessed ?? 3);
159
206
  let docList = fg.sync(docPattern, {
160
207
  ignore: excludedGlobPattern
161
208
  });
@@ -174,44 +221,51 @@ const reviewDoc = async ({
174
221
  appLogger(`Reviewing ${colorizeNumber(docList.length)} files:`);
175
222
  appLogger(docList.map((path) => ` - ${formatPath(path)}
176
223
  `));
177
- const tasks = docList.map(
178
- (docPath) => locales.flatMap(
179
- (locale) => limit(async () => {
180
- appLogger(
181
- `Reviewing file: ${formatPath(docPath)} to ${formatLocale(locale)}`
182
- );
183
- const absoluteBaseFilePath = join(
184
- configuration.content.baseDir,
185
- docPath
186
- );
187
- const outputFilePath = getOutputFilePath(
188
- absoluteBaseFilePath,
189
- locale,
190
- baseLocale
191
- );
192
- const fileModificationData = checkFileModifiedRange(outputFilePath, {
193
- skipIfModifiedBefore,
194
- skipIfModifiedAfter
195
- });
196
- if (fileModificationData.isSkipped) {
197
- appLogger(fileModificationData.message);
198
- return;
199
- }
200
- let changedLines = void 0;
201
- await reviewFile(
224
+ const allTasks = docList.flatMap(
225
+ (docPath) => locales.map((locale) => async () => {
226
+ appLogger(
227
+ `Reviewing file: ${formatPath(docPath)} to ${formatLocale(locale)}`
228
+ );
229
+ const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);
230
+ const outputFilePath = getOutputFilePath(
231
+ absoluteBaseFilePath,
232
+ locale,
233
+ baseLocale
234
+ );
235
+ const fileModificationData = checkFileModifiedRange(outputFilePath, {
236
+ skipIfModifiedBefore,
237
+ skipIfModifiedAfter
238
+ });
239
+ if (fileModificationData.isSkipped) {
240
+ appLogger(fileModificationData.message);
241
+ return;
242
+ }
243
+ let changedLines = void 0;
244
+ if (gitOptions) {
245
+ const gitChangedLines = await listGitLines(
202
246
  absoluteBaseFilePath,
203
- outputFilePath,
204
- locale,
205
- baseLocale,
206
- aiOptions,
207
- configuration,
208
- customInstructions,
209
- changedLines
247
+ gitOptions
210
248
  );
211
- })
212
- )
249
+ appLogger(`Git changed lines: ${gitChangedLines.join(", ")}`);
250
+ changedLines = gitChangedLines;
251
+ }
252
+ await reviewFile(
253
+ absoluteBaseFilePath,
254
+ outputFilePath,
255
+ locale,
256
+ baseLocale,
257
+ aiOptions,
258
+ configOptions,
259
+ customInstructions,
260
+ changedLines
261
+ );
262
+ })
263
+ );
264
+ await parallelize(
265
+ allTasks,
266
+ (task) => task(),
267
+ nbSimultaneousFileProcessed ?? 3
213
268
  );
214
- await Promise.all(tasks);
215
269
  };
216
270
  export {
217
271
  reviewDoc,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/reviewDoc.ts"],"sourcesContent":["import { AIOptions } from '@intlayer/api'; // OAuth handled by API proxy\nimport {\n formatLocale,\n formatPath,\n listGitFiles,\n ListGitFilesOptions,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n IntlayerConfig,\n Locales,\n retryManager,\n} from '@intlayer/config';\nimport { getLocaleName } from '@intlayer/core';\nimport fg from 'fast-glob';\nimport { mkdirSync, writeFileSync } from 'fs';\nimport { readFile } from 'fs/promises';\nimport pLimit from 'p-limit';\nimport { dirname, join, relative } from 'path';\nimport { fileURLToPath } from 'url';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkAIAccess } from './utils/checkAccess';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getChunk } from './utils/getChunk';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst dir = isESModule ? dirname(fileURLToPath(import.meta.url)) : __dirname;\n\n/**\n * Translate a single file for a given locale\n */\nexport const reviewFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locales,\n baseLocale: Locales,\n aiOptions?: AIOptions,\n configuration: IntlayerConfig = getConfiguration(),\n customInstructions?: string,\n changedLines?: number[]\n) => {\n try {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n const basedFileContent = await readFile(baseFilePath, 'utf-8');\n const fileToReviewContent = await readFile(outputFilePath, 'utf-8');\n\n let updatedFileContent = fileToReviewContent;\n let fileResultContent = '';\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = (\n await readFile(join(dir, './prompts/REVIEW_PROMPT.md'), 'utf-8')\n )\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const baseChunks = chunkText(basedFileContent, 800, 0);\n\n const filePrexixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrexixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [colon(prefixText, { colSize: 40 })].join('');\n\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(baseChunks.length)} chunks`\n );\n\n for await (const [i, baseChunk] of baseChunks.entries()) {\n const baseChunkContext = baseChunk;\n\n if (changedLines) {\n const hasChangedLinesInChunk = changedLines.some(\n (line) =>\n line > baseChunkContext.lineStart &&\n line < baseChunkContext.lineStart + baseChunkContext.lineLength\n );\n\n if (!hasChangedLinesInChunk) {\n appLogger(\n `No git changed lines found for chunk ${colorizeNumber(i + 1)}`\n );\n\n const chunkWithNoChange = getChunk(updatedFileContent, {\n lineStart: baseChunkContext.lineStart,\n lineLength: baseChunkContext.lineLength,\n });\n\n fileResultContent += chunkWithNoChange;\n\n continue;\n }\n }\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (baseChunks[i - 1]?.content ?? '') +\n baseChunkContext.content +\n (baseChunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const getChunkToReviewPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the current chunk to review in ${formatLocale(locale, false)} as reference.\\n` +\n `///chunksStart///` +\n getChunk(updatedFileContent, {\n lineStart: baseChunks[i - 1]?.lineStart ?? 0,\n lineLength:\n (baseChunks[i - 1]?.lineLength ?? 0) +\n baseChunkContext.lineLength +\n (baseChunks[i + 1]?.lineLength ?? 0),\n }) +\n `///chunksEnd///`;\n\n // Make the actual translation call\n let reviewedChunkResult = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n { role: 'system', content: getBaseChunkContextPrompt() },\n { role: 'system', content: getChunkToReviewPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(baseChunks.length)}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`,\n },\n { role: 'user', content: baseChunkContext.content },\n ],\n aiOptions,\n configuration\n );\n\n appLogger(\n [\n `${prefix}`,\n `${ANSIColors.GREY_DARK}[Chunk `,\n colorizeNumber(i + 1),\n `${ANSIColors.GREY_DARK} of `,\n colorizeNumber(baseChunks.length),\n `${ANSIColors.GREY_DARK}] →${ANSIColors.RESET} `,\n `${colorizeNumber(result.tokenUsed)} tokens used`,\n ].join('')\n );\n\n const fixedReviewedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n baseChunkContext.content\n );\n\n return fixedReviewedChunkResult;\n })();\n\n updatedFileContent = updatedFileContent.replace(\n baseChunkContext.content,\n reviewedChunkResult\n );\n\n fileResultContent += reviewedChunkResult;\n }\n\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype ReviewDocOptions = {\n docPattern: string[];\n locales: Locales[];\n excludedGlobPattern: string[];\n baseLocale: Locales;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main audit function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then audits them to each locale in LOCALE_LIST.\n */\nexport const reviewDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n gitOptions,\n}: ReviewDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n const hasCMSAuth = await checkAIAccess(configuration, aiOptions);\n\n if (!hasCMSAuth) return;\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n const limit = pLimit(nbSimultaneousFileProcessed ?? 3);\n\n let docList: string[] = fg.sync(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Reviewing ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Reviewing ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n const tasks = docList.map((docPath) =>\n locales.flatMap((locale) =>\n limit(async () => {\n appLogger(\n `Reviewing file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(\n configuration.content.baseDir,\n docPath\n );\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\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 let changedLines: number[] | undefined = undefined;\n // Disabled for now because it's leading to file format issues\n // if (gitOptions) {\n // const gitChangedLines = await listGitLines(\n // absoluteBaseFilePath,\n // gitOptions\n // );\n\n // appLogger(`Git changed lines: ${gitChangedLines.join(', ')}`);\n\n // changedLines = gitChangedLines;\n // }\n\n await reviewFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locales,\n baseLocale,\n aiOptions,\n configuration,\n customInstructions,\n changedLines\n );\n })\n )\n );\n\n await Promise.all(tasks);\n};\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,OAAO,QAAQ;AACf,SAAS,WAAW,qBAAqB;AACzC,SAAS,gBAAgB;AACzB,OAAO,YAAY;AACnB,SAAS,SAAS,MAAM,gBAAgB;AACxC,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,8BAA8B;AACvC,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,gBAAgB;AACzB,SAAS,yBAAyB;AAElC,MAAM,aAAa,OAAO,YAAY,QAAQ;AAE9C,MAAM,MAAM,aAAa,QAAQ,cAAc,YAAY,GAAG,CAAC,IAAI;AAK5D,MAAM,aAAa,OACxB,cACA,gBACA,QACA,YACA,WACA,gBAAgC,iBAAiB,GACjD,oBACA,iBACG;AACH,MAAI;AACF,UAAM,YAAY,aAAa,eAAe;AAAA,MAC5C,QAAQ;AAAA,QACN,QAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAED,UAAM,mBAAmB,MAAM,SAAS,cAAc,OAAO;AAC7D,UAAM,sBAAsB,MAAM,SAAS,gBAAgB,OAAO;AAElE,QAAI,qBAAqB;AACzB,QAAI,oBAAoB;AAGxB,UAAM,cACJ,MAAM,SAAS,KAAK,KAAK,4BAA4B,GAAG,OAAO,GAE9D,WAAW,kBAAkB,GAAG,aAAa,QAAQ,KAAK,CAAC,EAAE,EAC7D,WAAW,sBAAsB,GAAG,aAAa,YAAY,KAAK,CAAC,EAAE,EACrE,QAAQ,0BAA0B,W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AAAA,IACF;AAAA,EACF;AAIA,YAAU,kBAAkB,aAAa,UAAU,CAAC,EAAE;AACtD;AAAA,IACE,aAAa,eAAe,QAAQ,MAAM,CAAC,eAAe,aAAa,OAAO,CAAC;AAAA,EACjF;AAEA,YAAU,aAAa,eAAe,QAAQ,MAAM,CAAC,SAAS;AAC9D,YAAU,QAAQ,IAAI,CAAC,SAAS,MAAM,WAAW,IAAI,CAAC;AAAA,CAAI,CAAC;AAE3D,QAAM,QAAQ,QAAQ;AAAA,IAAI,CAAC,YACzB,QAAQ;AAAA,MAAQ,CAAC,WACf,MAAM,YAAY;AAChB;AAAA,UACE,mBAAmB,WAAW,OAAO,CAAC,OAAO,aAAa,MAAM,CAAC;AAAA,QACnE;AAEA,cAAM,uBAAuB;AAAA,UAC3B,cAAc,QAAQ;AAAA,UACtB;AAAA,QACF;AACA,cAAM,iBAAiB;AAAA,UACrB;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,cAAM,uBAAuB,uBAAuB,gBAAgB;AAAA,UAClE;AAAA,UACA;AAAA,QACF,CAAC;AAED,YAAI,qBAAqB,WAAW;AAClC,oBAAU,qBAAqB,OAAO;AACtC;AAAA,QACF;AAEA,YAAI,eAAqC;AAazC,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,QAAQ,IAAI,KAAK;AACzB;","names":[]}
1
+ {"version":3,"sources":["../../src/reviewDoc.ts"],"sourcesContent":["import { AIOptions } from '@intlayer/api'; // OAuth handled by API proxy\nimport {\n formatLocale,\n formatPath,\n listGitFiles,\n ListGitFilesOptions,\n listGitLines,\n parallelize,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n Locales,\n retryManager,\n} from '@intlayer/config';\nimport { getLocaleName } from '@intlayer/core';\nimport fg from 'fast-glob';\nimport { mkdirSync, writeFileSync } from 'fs';\nimport { readFile } from 'fs/promises';\nimport { dirname, join, relative } from 'path';\nimport { fileURLToPath } from 'url';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkAIAccess } from './utils/checkAccess';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getChunk } from './utils/getChunk';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\nimport { mapChunksBetweenFiles } from './utils/mapChunksBetweenFiles';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst dir = isESModule ? dirname(fileURLToPath(import.meta.url)) : __dirname;\n\n/**\n * Translate a single file for a given locale\n */\nexport const reviewFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locales,\n baseLocale: Locales,\n aiOptions?: AIOptions,\n configOptions?: GetConfigurationOptions,\n customInstructions?: string,\n changedLines?: number[]\n) => {\n try {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n const basedFileContent = await readFile(baseFilePath, 'utf-8');\n const fileToReviewContent = await readFile(outputFilePath, 'utf-8');\n\n let updatedFileContent = fileToReviewContent;\n let fileResultContent = '';\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = (\n await readFile(join(dir, './prompts/REVIEW_PROMPT.md'), 'utf-8')\n )\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrexixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrexixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\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 // FIXED: Use proper chunk mapping when changed lines are available\n if (changedLines && changedLines.length > 0) {\n appLogger(\n `${filePrefix}Using optimization with ${colorizeNumber(changedLines.length)} changed lines`\n );\n\n // Map chunks between base and updated files properly\n const chunkMappings = mapChunksBetweenFiles(\n basedFileContent,\n updatedFileContent,\n 800,\n changedLines\n );\n\n appLogger(\n `${filePrefix}Base file mapped to ${colorizeNumber(chunkMappings.length)} chunk mappings`\n );\n\n for await (const [i, mapping] of chunkMappings.entries()) {\n const { baseChunk, updatedChunk, hasChanges } = mapping;\n\n if (!hasChanges && updatedChunk) {\n // No changes detected, use the existing translated content\n appLogger(\n `${prefix}No changes found for chunk ${colorizeNumber(i + 1)}, preserving existing translation`\n );\n\n // Extract the corresponding chunk from the existing translated file\n const existingChunk = getChunk(fileToReviewContent, {\n lineStart: updatedChunk.lineStart,\n lineLength: updatedChunk.lineLength,\n });\n\n fileResultContent += existingChunk;\n continue;\n }\n\n if (!updatedChunk) {\n // Chunk was completely deleted, skip it\n appLogger(\n `${prefix}Chunk ${colorizeNumber(i + 1)} was deleted, skipping`\n );\n continue;\n }\n\n // Process chunks with changes\n const baseChunkContext = baseChunk;\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} of ${chunkMappings.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n baseChunkContext.content +\n `///chunksEnd///`;\n\n const getChunkToReviewPrompt = () =>\n `**CHUNK ${i + 1} of ${chunkMappings.length}** is the current chunk to review in ${formatLocale(locale, false)}.\\n` +\n `///chunksStart///` +\n updatedChunk.content +\n `///chunksEnd///`;\n\n // Make the actual translation call\n let reviewedChunkResult = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n { role: 'system', content: getBaseChunkContextPrompt() },\n { role: 'system', content: getChunkToReviewPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunkMappings.length)}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`,\n },\n { role: 'user', content: baseChunkContext.content },\n ],\n aiOptions,\n configuration\n );\n\n appLogger(\n `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Chunk ${colorizeNumber(i + 1)} of ${colorizeNumber(chunkMappings.length)}`\n );\n\n const fixedReviewedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n baseChunkContext.content\n );\n\n return fixedReviewedChunkResult;\n })();\n\n fileResultContent += reviewedChunkResult;\n }\n } else {\n // FALLBACK: Process all chunks when no optimization is available\n appLogger(`${filePrefix}Processing all chunks (no optimization)`);\n\n const baseChunks = chunkText(basedFileContent, 800, 0);\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(baseChunks.length)} chunks`\n );\n\n for await (const [i, baseChunk] of baseChunks.entries()) {\n const baseChunkContext = baseChunk;\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (baseChunks[i - 1]?.content ?? '') +\n baseChunkContext.content +\n (baseChunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const getChunkToReviewPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the current chunk to review in ${formatLocale(locale, false)} as reference.\\n` +\n `///chunksStart///` +\n getChunk(updatedFileContent, {\n lineStart: baseChunks[i - 1]?.lineStart ?? 0,\n lineLength:\n (baseChunks[i - 1]?.lineLength ?? 0) +\n baseChunkContext.lineLength +\n (baseChunks[i + 1]?.lineLength ?? 0),\n }) +\n `///chunksEnd///`;\n\n // Make the actual translation call\n let reviewedChunkResult = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n { role: 'system', content: getBaseChunkContextPrompt() },\n { role: 'system', content: getChunkToReviewPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(baseChunks.length)}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`,\n },\n { role: 'user', content: baseChunkContext.content },\n ],\n aiOptions,\n configuration\n );\n\n appLogger(\n `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Chunk ${colorizeNumber(i + 1)} of ${colorizeNumber(baseChunks.length)}`\n );\n\n const fixedReviewedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n baseChunkContext.content\n );\n\n return fixedReviewedChunkResult;\n })();\n\n updatedFileContent = updatedFileContent.replace(\n baseChunkContext.content,\n reviewedChunkResult\n );\n\n fileResultContent += reviewedChunkResult;\n }\n }\n\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype ReviewDocOptions = {\n docPattern: string[];\n locales: Locales[];\n excludedGlobPattern: string[];\n baseLocale: Locales;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main audit function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then audits them to each locale in LOCALE_LIST.\n */\nexport const reviewDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n gitOptions,\n}: ReviewDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n const hasCMSAuth = await checkAIAccess(configuration, aiOptions);\n\n if (!hasCMSAuth) return;\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n let docList: string[] = fg.sync(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Reviewing ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Reviewing ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n // Create all tasks to be processed\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n appLogger(\n `Reviewing file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\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 let changedLines: number[] | undefined = undefined;\n // FIXED: Enable git optimization that was previously commented out\n if (gitOptions) {\n const gitChangedLines = await listGitLines(\n absoluteBaseFilePath,\n gitOptions\n );\n\n appLogger(`Git changed lines: ${gitChangedLines.join(', ')}`);\n changedLines = gitChangedLines;\n }\n\n await reviewFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locales,\n baseLocale,\n aiOptions,\n configOptions,\n customInstructions,\n changedLines\n );\n })\n );\n\n await parallelize(\n allTasks,\n (task) => task(),\n nbSimultaneousFileProcessed ?? 3\n );\n};\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,OAAO,QAAQ;AACf,SAAS,WAAW,qBAAqB;AACzC,SAAS,gBAAgB;AACzB,SAAS,SAAS,MAAM,gBAAgB;AACxC,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,8BAA8B;AACvC,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,gBAAgB;AACzB,SAAS,yBAAyB;AAClC,SAAS,6BAA6B;AAEtC,MAAM,aAAa,OAAO,YAAY,QAAQ;AAE9C,MAAM,MAAM,aAAa,QAAQ,cAAc,YAAY,GAAG,CAAC,IAAI;AAK5D,MAAM,aAAa,OACxB,cACA,gBACA,QACA,YACA,WACA,eACA,oBACA,iBACG;AACH,MAAI;AACF,UAAM,gBAAgB,iBAAiB,aAAa;AACpD,UAAM,YAAY,aAAa,eAAe;AAAA,MAC5C,QAAQ;AAAA,QACN,QAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAED,UAAM,mBAAmB,MAAM,SAAS,cAAc,OAAO;AAC7D,UAAM,sBAAsB,MAAM,SAAS,gBAAgB,OAAO;AAElE,QAAI,qBAAqB;AACzB,QAAI,o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,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM;AAAA,IACJ;AAAA,IACA,CAAC,SAAS,KAAK;AAAA,IACf,+BAA+B;AAAA,EACjC;AACF;","names":[]}
@@ -53,6 +53,7 @@ const testMissingTranslations = (options) => {
53
53
  );
54
54
  appLogger(
55
55
  `Total missing locales: ${colorizeNumber(result.missingLocales.length, {
56
+ one: ANSIColors.RED,
56
57
  other: ANSIColors.RED,
57
58
  zero: ANSIColors.GREEN
58
59
  })}`
@@ -61,6 +62,7 @@ const testMissingTranslations = (options) => {
61
62
  `Total missing required locales: ${colorizeNumber(
62
63
  result.missingRequiredLocales.length,
63
64
  {
65
+ one: ANSIColors.RED,
64
66
  other: ANSIColors.RED,
65
67
  zero: ANSIColors.GREEN
66
68
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/test/index.ts"],"sourcesContent":["import { formatLocale, formatPath } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\nimport { listMissingTranslations } from './listMissingTranslations';\n\nexport { listMissingTranslations };\n\ntype ListMissingTranslationsOptions = {\n configOptions?: GetConfigurationOptions;\n};\n\nexport const testMissingTranslations = (\n options?: ListMissingTranslationsOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const { locales, requiredLocales } = config.internationalization;\n\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n const result = listMissingTranslations(undefined, 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) : '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 other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n })}`\n );\n appLogger(\n `Total missing required locales: ${colorizeNumber(\n result.missingRequiredLocales.length,\n {\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n }\n )}`\n );\n};\n"],"mappings":"AAAA,SAAS,cAAc,kBAAkB;AACzC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,+BAA+B;AAQjC,MAAM,0BAA0B,CACrC,YACG;AACH,QAAM,SAAS,iBAAiB,SAAS,aAAa;AACtD,QAAM,EAAE,SAAS,gBAAgB,IAAI,OAAO;AAE5C,QAAM,YAAY,aAAa,QAAQ;AAAA,IACrC,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,SAAS,wBAAwB,QAAW,SAAS,aAAa;AAExE,QAAM,gBAAgB,OAAO,oBAC1B,IAAI,CAAC,MAAM,MAAM,EAAE,GAAG,EAAE,EACxB,OAA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,CAAC;AAAA,EACJ;AACA;AAAA,IACE,mCAAmC;AAAA,MACjC,OAAO,uBAAuB;AAAA,MAC9B;AAAA,QACE,OAAO,WAAW;AAAA,QAClB,MAAM,WAAW;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/test/index.ts"],"sourcesContent":["import { formatLocale, formatPath } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\nimport { listMissingTranslations } from './listMissingTranslations';\n\nexport { listMissingTranslations };\n\ntype ListMissingTranslationsOptions = {\n configOptions?: GetConfigurationOptions;\n};\n\nexport const testMissingTranslations = (\n options?: ListMissingTranslationsOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const { locales, requiredLocales } = config.internationalization;\n\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n const result = listMissingTranslations(undefined, 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) : '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"],"mappings":"AAAA,SAAS,cAAc,kBAAkB;AACzC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,+BAA+B;AAQjC,MAAM,0BAA0B,CACrC,YACG;AACH,QAAM,SAAS,iBAAiB,SAAS,aAAa;AACtD,QAAM,EAAE,SAAS,gBAAgB,IAAI,OAAO;AAE5C,QAAM,YAAY,aAAa,QAAQ;AAAA,IACrC,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,SAAS,wBAAwB,QAAW,SAAS,aAAa;AAExE,QAAM,gBAAgB,OAAO,oBAC1B,IAAI,CAAC,MAAM,MAAM,EAAE,GAAG,EAAE,EACxB,OAAO,CAAC,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,MAAM,GAAG,CAAC;AAChD,QAAM,oBAAoB,OAAO,oBAC9B,IAAI,CAAC,MAAM,aAAa,EAAE,SAAS,KAAK,CAAC,EACzC,OAAO,CAAC,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,MAAM,GAAG,CAAC;AAEhD,QAAM,+BAA+B,OAAO,oBAAoB;AAAA,IAC9D,CAAC,gBACC;AAAA,MACE,MAAM,MAAM,YA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listGitFiles,
5
+ parallelize
5
6
  } from "@intlayer/chokidar";
6
7
  import {
7
8
  ANSIColors,
@@ -15,7 +16,6 @@ import {
15
16
  import fg from "fast-glob";
16
17
  import { existsSync, mkdirSync, writeFileSync } from "fs";
17
18
  import { readFile } from "fs/promises";
18
- import pLimit from "p-limit";
19
19
  import { dirname, join, relative } from "path";
20
20
  import { fileURLToPath } from "url";
21
21
  import { chunkText } from "./utils/calculateChunks.mjs";
@@ -133,7 +133,6 @@ const translateDoc = async ({
133
133
  );
134
134
  nbSimultaneousFileProcessed = 10;
135
135
  }
136
- const limit = pLimit(nbSimultaneousFileProcessed ?? 3);
137
136
  let docList = fg.sync(docPattern, {
138
137
  ignore: excludedGlobPattern
139
138
  });
@@ -154,47 +153,46 @@ const translateDoc = async ({
154
153
  appLogger(`Translating ${colorizeNumber(docList.length)} files:`);
155
154
  appLogger(docList.map((path) => ` - ${formatPath(path)}
156
155
  `));
157
- const tasks = docList.map(
158
- (docPath) => locales.flatMap(
159
- (locale) => limit(async () => {
160
- appLogger(
161
- `Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`
162
- );
163
- const absoluteBaseFilePath = join(
164
- configuration.content.baseDir,
165
- docPath
166
- );
167
- const outputFilePath = getOutputFilePath(
168
- absoluteBaseFilePath,
169
- locale,
170
- baseLocale
171
- );
172
- if (!existsSync(outputFilePath)) {
173
- appLogger(`File ${outputFilePath} does not exist, creating it...`);
174
- mkdirSync(dirname(outputFilePath), { recursive: true });
175
- writeFileSync(outputFilePath, "");
176
- }
177
- const fileModificationData = checkFileModifiedRange(outputFilePath, {
178
- skipIfModifiedBefore,
179
- skipIfModifiedAfter
180
- });
181
- if (fileModificationData.isSkipped) {
182
- appLogger(fileModificationData.message);
183
- return;
184
- }
185
- await translateFile(
186
- absoluteBaseFilePath,
187
- outputFilePath,
188
- locale,
189
- baseLocale,
190
- aiOptions,
191
- configuration,
192
- customInstructions
193
- );
194
- })
195
- )
156
+ const allTasks = docList.flatMap(
157
+ (docPath) => locales.map((locale) => async () => {
158
+ appLogger(
159
+ `Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`
160
+ );
161
+ const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);
162
+ const outputFilePath = getOutputFilePath(
163
+ absoluteBaseFilePath,
164
+ locale,
165
+ baseLocale
166
+ );
167
+ if (!existsSync(outputFilePath)) {
168
+ appLogger(`File ${outputFilePath} does not exist, creating it...`);
169
+ mkdirSync(dirname(outputFilePath), { recursive: true });
170
+ writeFileSync(outputFilePath, "");
171
+ }
172
+ const fileModificationData = checkFileModifiedRange(outputFilePath, {
173
+ skipIfModifiedBefore,
174
+ skipIfModifiedAfter
175
+ });
176
+ if (fileModificationData.isSkipped) {
177
+ appLogger(fileModificationData.message);
178
+ return;
179
+ }
180
+ await translateFile(
181
+ absoluteBaseFilePath,
182
+ outputFilePath,
183
+ locale,
184
+ baseLocale,
185
+ aiOptions,
186
+ configuration,
187
+ customInstructions
188
+ );
189
+ })
190
+ );
191
+ await parallelize(
192
+ allTasks,
193
+ (task) => task(),
194
+ nbSimultaneousFileProcessed ?? 3
196
195
  );
197
- await Promise.all(tasks);
198
196
  };
199
197
  export {
200
198
  translateDoc,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/translateDoc.ts"],"sourcesContent":["import { AIOptions } from '@intlayer/api';\nimport {\n formatLocale,\n formatPath,\n listGitFiles,\n ListGitFilesOptions,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n IntlayerConfig,\n Locales,\n retryManager,\n} from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { readFile } from 'fs/promises';\nimport pLimit from 'p-limit';\nimport { dirname, join, relative } from 'path';\nimport { fileURLToPath } from 'url';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkAIAccess } from './utils/checkAccess';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getChunk } from './utils/getChunk';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst dir = isESModule ? dirname(fileURLToPath(import.meta.url)) : __dirname;\n\n/**\n * Translate a single file for a given locale\n */\nexport const translateFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locales,\n baseLocale: Locales,\n aiOptions?: AIOptions,\n configuration: IntlayerConfig = getConfiguration(),\n customInstructions?: string\n) => {\n try {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n // Determine the target locale file path\n const fileContent = await readFile(baseFilePath, 'utf-8');\n let fileResultContent = fileContent;\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = (\n await readFile(join(dir, './prompts/TRANSLATE_PROMPT.md'), 'utf-8')\n )\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrexixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrexixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\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 // 1. Chunk the file by number of lines instead of characters\n const chunks = chunkText(fileContent);\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(chunks.length)} chunks`\n );\n\n for await (const [i, chunk] of chunks.entries()) {\n const isFirstChunk = i === 0;\n\n // Build the chunk-specific prompt\n const getPrevChunkPrompt = () =>\n `**CHUNK ${i} of ${chunks.length}** that has been translated in ${formatLocale(locale)}:\\n` +\n `///chunkStart///` +\n getChunk(fileResultContent, chunks[i - 1]) +\n `///chunkEnd///`;\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (chunks[i - 1]?.content ?? '') +\n chunks[i].content +\n (chunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Make the actual translation call\n let chunkTranslation = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n\n { role: 'system', content: getBaseChunkContextPrompt() },\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}** in ${formatLocale(baseLocale, false)} to translate in ${formatLocale(locale, false)}:`,\n },\n { role: 'user', content: fileToTranslateCurrentChunk },\n ],\n aiOptions,\n configuration\n );\n\n appLogger(\n [\n `${prefix}`,\n `${ANSIColors.GREY_DARK}[Chunk `,\n colorizeNumber(i + 1),\n `${ANSIColors.GREY_DARK} of `,\n colorizeNumber(chunks.length),\n `${ANSIColors.GREY_DARK}] →${ANSIColors.RESET} `,\n `${colorizeNumber(result.tokenUsed)} tokens used`,\n ].join('')\n );\n\n const fixedTranslatedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n\n return fixedTranslatedChunkResult;\n })();\n\n // Replace the chunk in the file content\n fileResultContent = fileResultContent.replace(\n fileToTranslateCurrentChunk,\n chunkTranslation\n );\n }\n\n // 4. Write the final translation to the appropriate file path\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype TranslateDocOptions = {\n docPattern: string[];\n locales: Locales[];\n excludedGlobPattern: string[];\n baseLocale: Locales;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main translate function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then translates them to each locale in LOCALE_LIST.\n */\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n gitOptions,\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n const limit = pLimit(nbSimultaneousFileProcessed ?? 3);\n\n let docList: string[] = fg.sync(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const hasCMSAuth = await checkAIAccess(configuration, aiOptions);\n\n if (!hasCMSAuth) return;\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Translating ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Translating ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n const tasks = docList.map((docPath) =>\n locales.flatMap((locale) =>\n limit(async () => {\n appLogger(\n `Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(\n configuration.content.baseDir,\n docPath\n );\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // check if the file exist, otherwise create it\n if (!existsSync(outputFilePath)) {\n appLogger(`File ${outputFilePath} does not exist, creating it...`);\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 await translateFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locales,\n baseLocale,\n aiOptions,\n configuration,\n customInstructions\n );\n })\n )\n );\n\n await Promise.all(tasks);\n};\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,OACK;AACP,OAAO,QAAQ;AACf,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,gBAAgB;AACzB,OAAO,YAAY;AACnB,SAAS,SAAS,MAAM,gBAAgB;AACxC,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,8BAA8B;AACvC,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,gBAAgB;AACzB,SAAS,yBAAyB;AAEl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,IAAI,GAAG,IAAI,MAAM,OAAO;AAAA,MACzE;AAAA,IACF;AAAA,EACF;AAIA,YAAU,kBAAkB,aAAa,UAAU,CAAC,EAAE;AACtD;AAAA,IACE,eAAe,eAAe,QAAQ,MAAM,CAAC,eAAe,aAAa,OAAO,CAAC;AAAA,EACnF;AAEA,YAAU,eAAe,eAAe,QAAQ,MAAM,CAAC,SAAS;AAChE,YAAU,QAAQ,IAAI,CAAC,SAAS,MAAM,WAAW,IAAI,CAAC;AAAA,CAAI,CAAC;AAE3D,QAAM,QAAQ,QAAQ;AAAA,IAAI,CAAC,YACzB,QAAQ;AAAA,MAAQ,CAAC,WACf,MAAM,YAAY;AAChB;AAAA,UACE,qBAAqB,WAAW,OAAO,CAAC,OAAO,aAAa,MAAM,CAAC;AAAA,QACrE;AAEA,cAAM,uBAAuB;AAAA,UAC3B,cAAc,QAAQ;AAAA,UACtB;AAAA,QACF;AACA,cAAM,iBAAiB;AAAA,UACrB;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAGA,YAAI,CAAC,WAAW,cAAc,GAAG;AAC/B,oBAAU,QAAQ,cAAc,iCAAiC;AACjE,oBAAU,QAAQ,cAAc,GAAG,EAAE,WAAW,KAAK,CAAC;AACtD,wBAAc,gBAAgB,EAAE;AAAA,QAClC;AAEA,cAAM,uBAAuB,uBAAuB,gBAAgB;AAAA,UAClE;AAAA,UACA;AAAA,QACF,CAAC;AAED,YAAI,qBAAqB,WAAW;AAClC,oBAAU,qBAAqB,OAAO;AACtC;AAAA,QACF;AAEA,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,QAAQ,IAAI,KAAK;AACzB;","names":[]}
1
+ {"version":3,"sources":["../../src/translateDoc.ts"],"sourcesContent":["import { AIOptions } from '@intlayer/api';\nimport {\n formatLocale,\n formatPath,\n listGitFiles,\n ListGitFilesOptions,\n parallelize,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n IntlayerConfig,\n Locales,\n retryManager,\n} from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { readFile } from 'fs/promises';\nimport { dirname, join, relative } from 'path';\nimport { fileURLToPath } from 'url';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkAIAccess } from './utils/checkAccess';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getChunk } from './utils/getChunk';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst dir = isESModule ? dirname(fileURLToPath(import.meta.url)) : __dirname;\n\n/**\n * Translate a single file for a given locale\n */\nexport const translateFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locales,\n baseLocale: Locales,\n aiOptions?: AIOptions,\n configuration: IntlayerConfig = getConfiguration(),\n customInstructions?: string\n) => {\n try {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n // Determine the target locale file path\n const fileContent = await readFile(baseFilePath, 'utf-8');\n let fileResultContent = fileContent;\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = (\n await readFile(join(dir, './prompts/TRANSLATE_PROMPT.md'), 'utf-8')\n )\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrexixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrexixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\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 // 1. Chunk the file by number of lines instead of characters\n const chunks = chunkText(fileContent);\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(chunks.length)} chunks`\n );\n\n for await (const [i, chunk] of chunks.entries()) {\n const isFirstChunk = i === 0;\n\n // Build the chunk-specific prompt\n const getPrevChunkPrompt = () =>\n `**CHUNK ${i} of ${chunks.length}** that has been translated in ${formatLocale(locale)}:\\n` +\n `///chunkStart///` +\n getChunk(fileResultContent, chunks[i - 1]) +\n `///chunkEnd///`;\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (chunks[i - 1]?.content ?? '') +\n chunks[i].content +\n (chunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Make the actual translation call\n let chunkTranslation = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n\n { role: 'system', content: getBaseChunkContextPrompt() },\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}** in ${formatLocale(baseLocale, false)} to translate in ${formatLocale(locale, false)}:`,\n },\n { role: 'user', content: fileToTranslateCurrentChunk },\n ],\n aiOptions,\n configuration\n );\n\n appLogger(\n [\n `${prefix}`,\n `${ANSIColors.GREY_DARK}[Chunk `,\n colorizeNumber(i + 1),\n `${ANSIColors.GREY_DARK} of `,\n colorizeNumber(chunks.length),\n `${ANSIColors.GREY_DARK}] →${ANSIColors.RESET} `,\n `${colorizeNumber(result.tokenUsed)} tokens used`,\n ].join('')\n );\n\n const fixedTranslatedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n\n return fixedTranslatedChunkResult;\n })();\n\n // Replace the chunk in the file content\n fileResultContent = fileResultContent.replace(\n fileToTranslateCurrentChunk,\n chunkTranslation\n );\n }\n\n // 4. Write the final translation to the appropriate file path\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype TranslateDocOptions = {\n docPattern: string[];\n locales: Locales[];\n excludedGlobPattern: string[];\n baseLocale: Locales;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main translate function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then translates them to each locale in LOCALE_LIST.\n */\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n gitOptions,\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n let docList: string[] = fg.sync(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const hasCMSAuth = await checkAIAccess(configuration, aiOptions);\n\n if (!hasCMSAuth) return;\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Translating ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Translating ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n // Create all tasks to be processed\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n appLogger(\n `Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // check if the file exist, otherwise create it\n if (!existsSync(outputFilePath)) {\n appLogger(`File ${outputFilePath} does not exist, creating it...`);\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 await translateFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locales,\n baseLocale,\n aiOptions,\n configuration,\n customInstructions\n );\n })\n );\n\n await parallelize(\n allTasks,\n (task) => task(),\n nbSimultaneousFileProcessed ?? 3\n );\n};\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP;AAAA,E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