@intlayer/cli 5.5.10 → 5.6.0

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 (190) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/cli.cjs +83 -9
  3. package/dist/cjs/cli.cjs.map +1 -1
  4. package/dist/cjs/cli.test.cjs +435 -0
  5. package/dist/cjs/cli.test.cjs.map +1 -0
  6. package/dist/cjs/fill.cjs +8 -12
  7. package/dist/cjs/fill.cjs.map +1 -1
  8. package/dist/cjs/index.cjs +5 -1
  9. package/dist/cjs/index.cjs.map +1 -1
  10. package/dist/cjs/prompts/REVIEW_PROMPT.md +37 -0
  11. package/dist/cjs/prompts/TRANSLATE_PROMPT.md +38 -0
  12. package/dist/cjs/pull.cjs +10 -2
  13. package/dist/cjs/pull.cjs.map +1 -1
  14. package/dist/cjs/pushConfig.cjs +5 -1
  15. package/dist/cjs/pushConfig.cjs.map +1 -1
  16. package/dist/cjs/reviewDoc.cjs +229 -0
  17. package/dist/cjs/reviewDoc.cjs.map +1 -0
  18. package/dist/cjs/translateDoc.cjs +211 -0
  19. package/dist/cjs/translateDoc.cjs.map +1 -0
  20. package/dist/cjs/utils/calculateChunks.cjs +120 -0
  21. package/dist/cjs/utils/calculateChunks.cjs.map +1 -0
  22. package/dist/cjs/utils/calculateChunks.test.cjs +104 -0
  23. package/dist/cjs/utils/calculateChunks.test.cjs.map +1 -0
  24. package/dist/cjs/utils/calculrateChunkTest.md +9 -0
  25. package/dist/cjs/utils/checkAIAccess.cjs +40 -0
  26. package/dist/cjs/utils/checkAIAccess.cjs.map +1 -0
  27. package/dist/cjs/utils/checkFileModifiedRange.cjs +97 -0
  28. package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -0
  29. package/dist/cjs/utils/checkFileModifiedRange.test.cjs +175 -0
  30. package/dist/cjs/utils/checkFileModifiedRange.test.cjs.map +1 -0
  31. package/dist/cjs/utils/checkLastUpdateTime.cjs +33 -0
  32. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -0
  33. package/dist/cjs/utils/chunkInference.cjs +58 -0
  34. package/dist/cjs/utils/chunkInference.cjs.map +1 -0
  35. package/dist/cjs/utils/fixChunkStartEndChars.cjs +47 -0
  36. package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -0
  37. package/dist/cjs/utils/fixChunkStartEndChars.test.cjs +81 -0
  38. package/dist/cjs/utils/fixChunkStartEndChars.test.cjs.map +1 -0
  39. package/dist/cjs/utils/formatTimeDiff.cjs +46 -0
  40. package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -0
  41. package/dist/cjs/utils/formatTimeDiff.test.cjs +32 -0
  42. package/dist/cjs/utils/formatTimeDiff.test.cjs.map +1 -0
  43. package/dist/cjs/utils/getChunk.cjs +77 -0
  44. package/dist/cjs/utils/getChunk.cjs.map +1 -0
  45. package/dist/cjs/utils/getChunk.test.cjs +46 -0
  46. package/dist/cjs/utils/getChunk.test.cjs.map +1 -0
  47. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +36 -0
  48. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -0
  49. package/dist/cjs/utils/getOutputFilePath.cjs +89 -0
  50. package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -0
  51. package/dist/cjs/utils/getOutputFilePath.test.cjs +73 -0
  52. package/dist/cjs/utils/getOutputFilePath.test.cjs.map +1 -0
  53. package/dist/cjs/utils/getParentPackageJSON.cjs +47 -0
  54. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -0
  55. package/dist/cjs/utils/listSpecialChars.cjs +78 -0
  56. package/dist/cjs/utils/listSpecialChars.cjs.map +1 -0
  57. package/dist/cjs/utils/listSpecialChars.test.cjs +58 -0
  58. package/dist/cjs/utils/listSpecialChars.test.cjs.map +1 -0
  59. package/dist/cjs/utils/reorderParagraphs.cjs +125 -0
  60. package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -0
  61. package/dist/cjs/utils/reorderParagraphs.test.cjs +71 -0
  62. package/dist/cjs/utils/reorderParagraphs.test.cjs.map +1 -0
  63. package/dist/cjs/utils/splitTextByLine.cjs +35 -0
  64. package/dist/cjs/utils/splitTextByLine.cjs.map +1 -0
  65. package/dist/cjs/utils/splitTextByLine.test.cjs +14 -0
  66. package/dist/cjs/utils/splitTextByLine.test.cjs.map +1 -0
  67. package/dist/esm/cli.mjs +84 -10
  68. package/dist/esm/cli.mjs.map +1 -1
  69. package/dist/esm/cli.test.mjs +412 -0
  70. package/dist/esm/cli.test.mjs.map +1 -0
  71. package/dist/esm/fill.mjs +8 -12
  72. package/dist/esm/fill.mjs.map +1 -1
  73. package/dist/esm/index.mjs +2 -0
  74. package/dist/esm/index.mjs.map +1 -1
  75. package/dist/esm/prompts/REVIEW_PROMPT.md +37 -0
  76. package/dist/esm/prompts/TRANSLATE_PROMPT.md +38 -0
  77. package/dist/esm/pull.mjs +10 -2
  78. package/dist/esm/pull.mjs.map +1 -1
  79. package/dist/esm/pushConfig.mjs +5 -1
  80. package/dist/esm/pushConfig.mjs.map +1 -1
  81. package/dist/esm/reviewDoc.mjs +198 -0
  82. package/dist/esm/reviewDoc.mjs.map +1 -0
  83. package/dist/esm/translateDoc.mjs +180 -0
  84. package/dist/esm/translateDoc.mjs.map +1 -0
  85. package/dist/esm/utils/calculateChunks.mjs +96 -0
  86. package/dist/esm/utils/calculateChunks.mjs.map +1 -0
  87. package/dist/esm/utils/calculateChunks.test.mjs +103 -0
  88. package/dist/esm/utils/calculateChunks.test.mjs.map +1 -0
  89. package/dist/esm/utils/calculrateChunkTest.md +9 -0
  90. package/dist/esm/utils/checkAIAccess.mjs +16 -0
  91. package/dist/esm/utils/checkAIAccess.mjs.map +1 -0
  92. package/dist/esm/utils/checkFileModifiedRange.mjs +73 -0
  93. package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -0
  94. package/dist/esm/utils/checkFileModifiedRange.test.mjs +181 -0
  95. package/dist/esm/utils/checkFileModifiedRange.test.mjs.map +1 -0
  96. package/dist/esm/utils/checkLastUpdateTime.mjs +9 -0
  97. package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -0
  98. package/dist/esm/utils/chunkInference.mjs +34 -0
  99. package/dist/esm/utils/chunkInference.mjs.map +1 -0
  100. package/dist/esm/utils/fixChunkStartEndChars.mjs +23 -0
  101. package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -0
  102. package/dist/esm/utils/fixChunkStartEndChars.test.mjs +80 -0
  103. package/dist/esm/utils/fixChunkStartEndChars.test.mjs.map +1 -0
  104. package/dist/esm/utils/formatTimeDiff.mjs +22 -0
  105. package/dist/esm/utils/formatTimeDiff.mjs.map +1 -0
  106. package/dist/esm/utils/formatTimeDiff.test.mjs +31 -0
  107. package/dist/esm/utils/formatTimeDiff.test.mjs.map +1 -0
  108. package/dist/esm/utils/getChunk.mjs +53 -0
  109. package/dist/esm/utils/getChunk.mjs.map +1 -0
  110. package/dist/esm/utils/getChunk.test.mjs +45 -0
  111. package/dist/esm/utils/getChunk.test.mjs.map +1 -0
  112. package/dist/esm/utils/getIsFileUpdatedRecently.mjs +12 -0
  113. package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -0
  114. package/dist/esm/utils/getOutputFilePath.mjs +65 -0
  115. package/dist/esm/utils/getOutputFilePath.mjs.map +1 -0
  116. package/dist/esm/utils/getOutputFilePath.test.mjs +72 -0
  117. package/dist/esm/utils/getOutputFilePath.test.mjs.map +1 -0
  118. package/dist/esm/utils/getParentPackageJSON.mjs +23 -0
  119. package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -0
  120. package/dist/esm/utils/listSpecialChars.mjs +54 -0
  121. package/dist/esm/utils/listSpecialChars.mjs.map +1 -0
  122. package/dist/esm/utils/listSpecialChars.test.mjs +57 -0
  123. package/dist/esm/utils/listSpecialChars.test.mjs.map +1 -0
  124. package/dist/esm/utils/reorderParagraphs.mjs +101 -0
  125. package/dist/esm/utils/reorderParagraphs.mjs.map +1 -0
  126. package/dist/esm/utils/reorderParagraphs.test.mjs +70 -0
  127. package/dist/esm/utils/reorderParagraphs.test.mjs.map +1 -0
  128. package/dist/esm/utils/splitTextByLine.mjs +11 -0
  129. package/dist/esm/utils/splitTextByLine.mjs.map +1 -0
  130. package/dist/esm/utils/splitTextByLine.test.mjs +13 -0
  131. package/dist/esm/utils/splitTextByLine.test.mjs.map +1 -0
  132. package/dist/types/cli.d.ts.map +1 -1
  133. package/dist/types/cli.test.d.ts +2 -0
  134. package/dist/types/cli.test.d.ts.map +1 -0
  135. package/dist/types/fill.d.ts.map +1 -1
  136. package/dist/types/index.d.ts +3 -0
  137. package/dist/types/index.d.ts.map +1 -1
  138. package/dist/types/pull.d.ts.map +1 -1
  139. package/dist/types/pushConfig.d.ts.map +1 -1
  140. package/dist/types/reviewDoc.d.ts +27 -0
  141. package/dist/types/reviewDoc.d.ts.map +1 -0
  142. package/dist/types/translateDoc.d.ts +27 -0
  143. package/dist/types/translateDoc.d.ts.map +1 -0
  144. package/dist/types/utils/calculateChunks.d.ts +9 -0
  145. package/dist/types/utils/calculateChunks.d.ts.map +1 -0
  146. package/dist/types/utils/calculateChunks.test.d.ts +2 -0
  147. package/dist/types/utils/calculateChunks.test.d.ts.map +1 -0
  148. package/dist/types/utils/checkAIAccess.d.ts +4 -0
  149. package/dist/types/utils/checkAIAccess.d.ts.map +1 -0
  150. package/dist/types/utils/checkFileModifiedRange.d.ts +11 -0
  151. package/dist/types/utils/checkFileModifiedRange.d.ts.map +1 -0
  152. package/dist/types/utils/checkFileModifiedRange.test.d.ts +2 -0
  153. package/dist/types/utils/checkFileModifiedRange.test.d.ts.map +1 -0
  154. package/dist/types/utils/checkLastUpdateTime.d.ts +9 -0
  155. package/dist/types/utils/checkLastUpdateTime.d.ts.map +1 -0
  156. package/dist/types/utils/chunkInference.d.ts +12 -0
  157. package/dist/types/utils/chunkInference.d.ts.map +1 -0
  158. package/dist/types/utils/fixChunkStartEndChars.d.ts +2 -0
  159. package/dist/types/utils/fixChunkStartEndChars.d.ts.map +1 -0
  160. package/dist/types/utils/fixChunkStartEndChars.test.d.ts +2 -0
  161. package/dist/types/utils/fixChunkStartEndChars.test.d.ts.map +1 -0
  162. package/dist/types/utils/formatTimeDiff.d.ts +2 -0
  163. package/dist/types/utils/formatTimeDiff.d.ts.map +1 -0
  164. package/dist/types/utils/formatTimeDiff.test.d.ts +2 -0
  165. package/dist/types/utils/formatTimeDiff.test.d.ts.map +1 -0
  166. package/dist/types/utils/getChunk.d.ts +9 -0
  167. package/dist/types/utils/getChunk.d.ts.map +1 -0
  168. package/dist/types/utils/getChunk.test.d.ts +2 -0
  169. package/dist/types/utils/getChunk.test.d.ts.map +1 -0
  170. package/dist/types/utils/getIsFileUpdatedRecently.d.ts +5 -0
  171. package/dist/types/utils/getIsFileUpdatedRecently.d.ts.map +1 -0
  172. package/dist/types/utils/getOutputFilePath.d.ts +26 -0
  173. package/dist/types/utils/getOutputFilePath.d.ts.map +1 -0
  174. package/dist/types/utils/getOutputFilePath.test.d.ts +2 -0
  175. package/dist/types/utils/getOutputFilePath.test.d.ts.map +1 -0
  176. package/dist/types/utils/getParentPackageJSON.d.ts +32 -0
  177. package/dist/types/utils/getParentPackageJSON.d.ts.map +1 -0
  178. package/dist/types/utils/listSpecialChars.d.ts +10 -0
  179. package/dist/types/utils/listSpecialChars.d.ts.map +1 -0
  180. package/dist/types/utils/listSpecialChars.test.d.ts +2 -0
  181. package/dist/types/utils/listSpecialChars.test.d.ts.map +1 -0
  182. package/dist/types/utils/reorderParagraphs.d.ts +8 -0
  183. package/dist/types/utils/reorderParagraphs.d.ts.map +1 -0
  184. package/dist/types/utils/reorderParagraphs.test.d.ts +2 -0
  185. package/dist/types/utils/reorderParagraphs.test.d.ts.map +1 -0
  186. package/dist/types/utils/splitTextByLine.d.ts +2 -0
  187. package/dist/types/utils/splitTextByLine.d.ts.map +1 -0
  188. package/dist/types/utils/splitTextByLine.test.d.ts +2 -0
  189. package/dist/types/utils/splitTextByLine.test.d.ts.map +1 -0
  190. package/package.json +15 -13
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './build';\nexport * from './cli';\nexport * from './fill';\nexport * from './listContentDeclaration';\nexport * from './pull';\nexport * from './push';\nexport * from './pushConfig';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,oBAAd;AACA,0BAAc,kBADd;AAEA,0BAAc,mBAFd;AAGA,0BAAc,qCAHd;AAIA,0BAAc,mBAJd;AAKA,0BAAc,mBALd;AAMA,0BAAc,yBANd;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type * from '@intlayer/chokidar';\nexport * from './build';\nexport * from './cli';\nexport * from './fill';\nexport * from './listContentDeclaration';\nexport * from './pull';\nexport * from './push';\nexport * from './pushConfig';\nexport * from './reviewDoc';\nexport * from './translateDoc';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AACA,0BAAc,oBADd;AAEA,0BAAc,kBAFd;AAGA,0BAAc,mBAHd;AAIA,0BAAc,qCAJd;AAKA,0BAAc,mBALd;AAMA,0BAAc,mBANd;AAOA,0BAAc,yBAPd;AAQA,0BAAc,wBARd;AASA,0BAAc,2BATd;","names":[]}
@@ -0,0 +1,37 @@
1
+ You are an expert in internationalisation, technical documentation and multilingual content auditing. Your task is to **audit an existing translation** against its {{baseLocaleName}} source and make it fully up-to-date.
2
+
3
+ # Base instructions
4
+
5
+ 1. **Goal of the audit**
6
+
7
+ - Insert any **missing paragraphs, lists, tables, code blocks or images** that have been introduced in the base file since the last translation.
8
+ - **Correct spelling, grammar, punctuation or Markdown syntax errors** that may exist in the current translation.
9
+ - Keep all **code blocks** and **variable names** in the same language as the base file, but translate the **comments** inside the code blocks to {{localeName}}. Example: `internationalization: {` should stay `internationalization: {`. You should not replace the `z` by a `s`.
10
+ - Do **not** change sentences that are already correct. Do not reflow or re-word translated sentences unless it is strictly necessary for correctness.
11
+ - To ensure all characters are included in the reviewed content, you should use "///chunkStart///" and "///chunkEnd///" to delimit the chunk of the reviewed content. You should not use "---" or "```" to delimit the chunk of the reviewed content.
12
+
13
+ 2. **Output requirements**
14
+
15
+ - Return **only the full, updated file content in {{localeName}}** ‑ no explanations or surrounding code fences.
16
+ - All existing correct content must remain **byte-for-byte identical** unless a fix is required (see above).
17
+ - New or updated content must be placed in the correct position so that the overall structure mirrors the English file.
18
+ - If overlapping chunks are found, you should include the exact same content than provided in the user message.
19
+
20
+ 3. **Locales**
21
+
22
+ - Source locale: {{baseLocaleName}}
23
+ - Target locale: {{localeName}}
24
+
25
+ 4. **Output Example:**
26
+
27
+ Entry (en - English (US)): "///chunkStart/// - Here the translated content///chunkEnd///"
28
+ Entry (fr - French): "///chunkStart/// - Ici le contenu trraduit ce mardi 25 juin 2025///chunkEnd///"
29
+ Expected Output (fr - French): "///chunkStart/// - Ici le contenu traduit///chunkEnd///"
30
+
31
+ # Custom instructions
32
+
33
+ {{customInstructions}}
34
+
35
+ # Application context
36
+
37
+ {{applicationContext}}
@@ -0,0 +1,38 @@
1
+ You are an expert in internationalization and content management. Your task is to translate the following documentation into {{localeName}}.
2
+
3
+ # Base instructions
4
+
5
+ 1. **Requirement:**
6
+
7
+ - You should only translate the text, and titles of the file.
8
+ - You should not alter the structure of the file.
9
+ - You should not alter the code logic of code elements.
10
+ - You should consider the context of the solution (Intlayer), and write for the user of the solution (developer).
11
+ - In the code elements, the naming of the variables should be made in the same language as the base file. But the comments should be in {{localeName}}.
12
+ - You should return the translated file in {{localeName}} without any additional comments or explanations.
13
+ - To ensure all characters are included in the translated content, you should use "///chunkStart///" and "///chunkEnd///" to delimit the translated content. You should not use "---" or "```" to delimit the translated content.
14
+ - Anyway the length of the chunk to translate, you should translate the whole chunk and do not skip any part. You should ensure that each part of the chunk is translated.
15
+ - Each title should be translated and present in the output file.
16
+ - Each listing point should be translated and present in the output file.
17
+ - Each code element should be translated and present in the output file.
18
+ - Each image should be translated and present in the output file.
19
+ - Each link should be translated and present in the output file.
20
+ - If overlapping chunks are found, you should include the exact same content than provided in the user message.
21
+
22
+ 2. **Locales:**
23
+
24
+ - Base file locale: {{baseLocaleName}}
25
+ - Desired Final file language: {{localeName}}
26
+
27
+ 3. **Output Example:**
28
+
29
+ Entry (en - English (US)): "///chunkStart/// - Here the translated content///chunkEnd///"
30
+ Expected Output (fr - French): "///chunkStart/// - Ici le contenu traduit///chunkEnd///"
31
+
32
+ # Custom instructions
33
+
34
+ {{customInstructions}}
35
+
36
+ # Application context
37
+
38
+ {{applicationContext}}
package/dist/cjs/pull.cjs CHANGED
@@ -58,7 +58,11 @@ const pull = async (options) => {
58
58
  const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();
59
59
  const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
60
60
  const getDictionariesKeysResult = await intlayerAPI.dictionary.getDictionariesKeys({
61
- headers: { Authorization: `Bearer ${oAuth2AccessToken}` }
61
+ ...oAuth2AccessToken && {
62
+ headers: {
63
+ Authorization: `Bearer ${oAuth2AccessToken}`
64
+ }
65
+ }
62
66
  });
63
67
  if (!getDictionariesKeysResult.data) {
64
68
  throw new Error("No distant dictionaries found");
@@ -98,7 +102,11 @@ const pull = async (options) => {
98
102
  statusObj.dictionaryKey,
99
103
  void 0,
100
104
  {
101
- headers: { Authorization: `Bearer ${oAuth2AccessToken}` }
105
+ ...oAuth2AccessToken && {
106
+ headers: {
107
+ Authorization: `Bearer ${oAuth2AccessToken}`
108
+ }
109
+ }
102
110
  }
103
111
  );
104
112
  const distantDictionary = getDictionaryResult.data;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/pull.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\nimport {\n writeContentDeclaration,\n type DictionaryStatus,\n} from '@intlayer/chokidar';\nimport {\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\n\nimport type { Dictionary } from '@intlayer/core';\nimport pLimit from 'p-limit';\nimport * as readline from 'readline';\n\ntype PullOptions = {\n dictionaries?: string[];\n newDictionariesPath?: string;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionaryKey: string;\n status: DictionaryStatus;\n icon: string;\n index: number;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nconst spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\nconst RESET = '\\x1b[0m';\nconst GREEN = '\\x1b[32m';\nconst RED = '\\x1b[31m';\nconst BLUE = '\\x1b[34m';\nconst GREY = '\\x1b[90m';\nconst YELLOW = '\\x1b[33m';\nconst GREY_DARK = '\\x1b[90m';\n\n/**\n * Fetch distant dictionaries and write them locally,\n * with progress indicators and concurrency control.\n */\nexport const pull = async (options?: PullOptions): Promise<void> => {\n const appLogger = getAppLogger(options?.configOptions?.override);\n\n try {\n const config = getConfiguration(options?.configOptions);\n const { clientId, clientSecret } = config.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Get the list of dictionary keys\n const getDictionariesKeysResult =\n await intlayerAPI.dictionary.getDictionariesKeys({\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n });\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n let distantDictionariesKeys: string[] = getDictionariesKeysResult.data;\n\n if (options?.dictionaries) {\n // Filter the dictionaries from the provided list of IDs\n distantDictionariesKeys = distantDictionariesKeys.filter(\n (dictionaryKey) => options.dictionaries!.includes(dictionaryKey)\n );\n }\n\n // Check if dictionaries list is empty\n if (distantDictionariesKeys.length === 0) {\n appLogger('No dictionaries to fetch', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Fetching dictionaries:');\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] =\n distantDictionariesKeys.map((dictionaryKey, index) => ({\n dictionaryKey,\n icon: getStatusIcon('pending'),\n status: 'pending',\n index,\n spinnerFrameIndex: 0,\n }));\n\n // Output initial statuses\n for (const statusObj of dictionariesStatuses) {\n process.stdout.write(getStatusLine(statusObj) + '\\n');\n }\n\n // Start spinner timer\n const spinnerTimer = setInterval(() => {\n updateAllStatusLines(dictionariesStatuses);\n }, 100); // Update every 100ms\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Limit the number of concurrent requests\n\n const successfullyFetchedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n statusObj.status = 'fetching';\n try {\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n statusObj.dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(\n `Dictionary ${statusObj.dictionaryKey} not found on remote`\n );\n }\n\n // Now, write the dictionary to local file\n const { status } = await writeContentDeclaration(\n distantDictionary,\n config,\n options?.newDictionariesPath\n );\n\n statusObj.status = status;\n\n successfullyFetchedDictionaries.push(distantDictionary);\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;\n }\n };\n\n const fetchPromises = dictionariesStatuses.map((statusObj) =>\n limit(() => processDictionary(statusObj))\n );\n\n await Promise.all(fetchPromises);\n\n // Stop the spinner timer\n clearInterval(spinnerTimer);\n\n // Update statuses one last time\n updateAllStatusLines(dictionariesStatuses);\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n\nconst getStatusIcon = (status: string): string => {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n fetching: '', // Spinner handled separately\n 'up-to-date': '✔',\n updated: '✔',\n fetched: '✔',\n error: '✖',\n };\n return statusIcons[status] ?? '';\n};\n\nconst getStatusLine = (statusObj: DictionariesStatus): string => {\n let icon = getStatusIcon(statusObj.status);\n let colorStart = '';\n let colorEnd = '';\n\n if (statusObj.status === 'fetching') {\n // Use spinner frame\n icon = spinnerFrames[statusObj.spinnerFrameIndex! % spinnerFrames.length];\n colorStart = BLUE;\n colorEnd = RESET;\n } else if (statusObj.status === 'error') {\n colorStart = RED;\n colorEnd = RESET;\n } else if (\n statusObj.status === 'fetched' ||\n statusObj.status === 'imported' ||\n statusObj.status === 'updated' ||\n statusObj.status === 'up-to-date'\n ) {\n colorStart = GREEN;\n colorEnd = RESET;\n } else if (\n statusObj.status === 'reimported in JSON' ||\n statusObj.status === 'reimported in new location'\n ) {\n colorStart = YELLOW;\n colorEnd = RESET;\n } else {\n colorStart = GREY;\n colorEnd = RESET;\n }\n\n return `- ${statusObj.dictionaryKey} ${GREY_DARK}[${colorStart}${icon}${statusObj.status}${GREY_DARK}]${colorEnd}`;\n};\n\nconst updateAllStatusLines = (dictionariesStatuses: DictionariesStatus[]) => {\n // Move cursor up to the first status line\n readline.moveCursor(process.stdout, 0, -dictionariesStatuses.length);\n for (const statusObj of dictionariesStatuses) {\n // Clear the line\n readline.clearLine(process.stdout, 0);\n\n if (statusObj.status === 'fetching') {\n // Update spinner frame\n statusObj.spinnerFrameIndex =\n (statusObj.spinnerFrameIndex! + 1) % spinnerFrames.length;\n }\n\n // Write the status line\n process.stdout.write(getStatusLine(statusObj) + '\\n');\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA+B;AAC/B,sBAGO;AACP,oBAIO;AAGP,qBAAmB;AACnB,e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ayerAPI } from '@intlayer/api';\nimport {\n writeContentDeclaration,\n type DictionaryStatus,\n} from '@intlayer/chokidar';\nimport {\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\n\nimport type { Dictionary } from '@intlayer/core';\nimport pLimit from 'p-limit';\nimport * as readline from 'readline';\n\ntype PullOptions = {\n dictionaries?: string[];\n newDictionariesPath?: string;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionaryKey: string;\n status: DictionaryStatus;\n icon: string;\n index: number;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nconst spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\nconst RESET = '\\x1b[0m';\nconst GREEN = '\\x1b[32m';\nconst RED = '\\x1b[31m';\nconst BLUE = '\\x1b[34m';\nconst GREY = '\\x1b[90m';\nconst YELLOW = '\\x1b[33m';\nconst GREY_DARK = '\\x1b[90m';\n\n/**\n * Fetch distant dictionaries and write them locally,\n * with progress indicators and concurrency control.\n */\nexport const pull = async (options?: PullOptions): Promise<void> => {\n const appLogger = getAppLogger(options?.configOptions?.override);\n\n try {\n const config = getConfiguration(options?.configOptions);\n const { clientId, clientSecret } = config.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Get the list of dictionary keys\n const getDictionariesKeysResult =\n await intlayerAPI.dictionary.getDictionariesKeys({\n ...(oAuth2AccessToken && {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }),\n });\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n let distantDictionariesKeys: string[] = getDictionariesKeysResult.data;\n\n if (options?.dictionaries) {\n // Filter the dictionaries from the provided list of IDs\n distantDictionariesKeys = distantDictionariesKeys.filter(\n (dictionaryKey) => options.dictionaries!.includes(dictionaryKey)\n );\n }\n\n // Check if dictionaries list is empty\n if (distantDictionariesKeys.length === 0) {\n appLogger('No dictionaries to fetch', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Fetching dictionaries:');\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] =\n distantDictionariesKeys.map((dictionaryKey, index) => ({\n dictionaryKey,\n icon: getStatusIcon('pending'),\n status: 'pending',\n index,\n spinnerFrameIndex: 0,\n }));\n\n // Output initial statuses\n for (const statusObj of dictionariesStatuses) {\n process.stdout.write(getStatusLine(statusObj) + '\\n');\n }\n\n // Start spinner timer\n const spinnerTimer = setInterval(() => {\n updateAllStatusLines(dictionariesStatuses);\n }, 100); // Update every 100ms\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Limit the number of concurrent requests\n\n const successfullyFetchedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n statusObj.status = 'fetching';\n try {\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n statusObj.dictionaryKey,\n undefined,\n {\n ...(oAuth2AccessToken && {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }),\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(\n `Dictionary ${statusObj.dictionaryKey} not found on remote`\n );\n }\n\n // Now, write the dictionary to local file\n const { status } = await writeContentDeclaration(\n distantDictionary,\n config,\n options?.newDictionariesPath\n );\n\n statusObj.status = status;\n\n successfullyFetchedDictionaries.push(distantDictionary);\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;\n }\n };\n\n const fetchPromises = dictionariesStatuses.map((statusObj) =>\n limit(() => processDictionary(statusObj))\n );\n\n await Promise.all(fetchPromises);\n\n // Stop the spinner timer\n clearInterval(spinnerTimer);\n\n // Update statuses one last time\n updateAllStatusLines(dictionariesStatuses);\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n\nconst getStatusIcon = (status: string): string => {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n fetching: '', // Spinner handled separately\n 'up-to-date': '✔',\n updated: '✔',\n fetched: '✔',\n error: '✖',\n };\n return statusIcons[status] ?? '';\n};\n\nconst getStatusLine = (statusObj: DictionariesStatus): string => {\n let icon = getStatusIcon(statusObj.status);\n let colorStart = '';\n let colorEnd = '';\n\n if (statusObj.status === 'fetching') {\n // Use spinner frame\n icon = spinnerFrames[statusObj.spinnerFrameIndex! % spinnerFrames.length];\n colorStart = BLUE;\n colorEnd = RESET;\n } else if (statusObj.status === 'error') {\n colorStart = RED;\n colorEnd = RESET;\n } else if (\n statusObj.status === 'fetched' ||\n statusObj.status === 'imported' ||\n statusObj.status === 'updated' ||\n statusObj.status === 'up-to-date'\n ) {\n colorStart = GREEN;\n colorEnd = RESET;\n } else if (\n statusObj.status === 'reimported in JSON' ||\n statusObj.status === 'reimported in new location'\n ) {\n colorStart = YELLOW;\n colorEnd = RESET;\n } else {\n colorStart = GREY;\n colorEnd = RESET;\n }\n\n return `- ${statusObj.dictionaryKey} ${GREY_DARK}[${colorStart}${icon}${statusObj.status}${GREY_DARK}]${colorEnd}`;\n};\n\nconst updateAllStatusLines = (dictionariesStatuses: DictionariesStatus[]) => {\n // Move cursor up to the first status line\n readline.moveCursor(process.stdout, 0, -dictionariesStatuses.length);\n for (const statusObj of dictionariesStatuses) {\n // Clear the line\n readline.clearLine(process.stdout, 0);\n\n if (statusObj.status === 'fetching') {\n // Update spinner frame\n statusObj.spinnerFrameIndex =\n (statusObj.spinnerFrameIndex! + 1) % spinnerFrames.length;\n }\n\n // Write the status line\n process.stdout.write(getStatusLine(statusObj) + '\\n');\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA+B;AAC/B,sBAGO;AACP,oBAIO;AAGP,qBAAmB;AACnB,eAA0B;AAkB1B,MAAM,gBAAgB,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAEvE,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,MAAM;AACZ,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,SAAS;AACf,MAAM,YAAY;AAMX,MAAM,OAAO,OAAO,YAAyC;AAClE,QAAM,gBAAY,4BAAa,SAAS,eAAe,QAAQ;AAE/D,MAAI;AACF,UAAM,aAAS,gCAAiB,SAAS,aAAa;AACtD,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAE1C,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,kBAAc,2BAAe,QAAW,MAAM;AAEpD,UAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,UAAM,oBAAoB,kBAAkB,MAAM;AAGlD,UAAM,4BACJ,MAAM,YAAY,WAAW,oBAAoB;AAAA,MAC/C,GAAI,qBAAqB;AAAA,QACvB,SAAS;AAAA,UACP,eAAe,UAAU,iBAAiB;AAAA,QAC5C;AAAA,MACF;AAAA,IACF,CAAC;AAEH,QAAI,CAAC,0BAA0B,MAAM;AACnC,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACjD;AAEA,QAAI,0BAAoC,0BAA0B;AAElE,QAAI,SAAS,cAAc;AAEzB,gCAA0B,wBAAwB;AAAA,QAChD,CAAC,kBAAkB,QAAQ,aAAc,SAAS,aAAa;AAA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AA+C;AAE3E,WAAS,WAAW,QAAQ,QAAQ,GAAG,CAAC,qBAAqB,MAAM;AACnE,aAAW,aAAa,sBAAsB;AAE5C,aAAS,UAAU,QAAQ,QAAQ,CAAC;AAEpC,QAAI,UAAU,WAAW,YAAY;AAEnC,gBAAU,qBACP,UAAU,oBAAqB,KAAK,cAAc;AAAA,IACvD;AAGA,YAAQ,OAAO,MAAM,cAAc,SAAS,IAAI,IAAI;AAAA,EACtD;AACF;","names":["pLimit"]}
@@ -43,7 +43,11 @@ const pushConfig = async (options) => {
43
43
  const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();
44
44
  const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
45
45
  const getDictionariesKeysResult = await intlayerAPI.project.pushProjectConfiguration(config, {
46
- headers: { Authorization: `Bearer ${oAuth2AccessToken}` }
46
+ ...oAuth2AccessToken && {
47
+ headers: {
48
+ Authorization: `Bearer ${oAuth2AccessToken}`
49
+ }
50
+ }
47
51
  });
48
52
  if (!getDictionariesKeysResult.data) {
49
53
  throw new Error("Error pushing project configuration");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/pushConfig.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\nimport {\n getAppLogger,\n getConfiguration,\n type GetConfigurationOptions,\n} from '@intlayer/config';\n\ntype PushOptions = {\n logPrefix?: string;\n configOptions?: GetConfigurationOptions;\n};\n\nexport const pushConfig = async (options?: PushOptions) => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config);\n\n const { clientId, clientSecret } = config.editor;\n\n if (!clientId || !clientSecret) {\n appLogger(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.',\n {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n }\n );\n return;\n }\n\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Get the list of dictionary keys\n const getDictionariesKeysResult =\n await intlayerAPI.project.pushProjectConfiguration(config, {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n });\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('Error pushing project configuration');\n }\n\n appLogger('Project configuration pushed successfully', {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n appLogger(JSON.stringify(getDictionariesKeysResult.data, null, 2), {\n config: {\n prefix: options?.logPrefix,\n },\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA+B;AAC/B,oBAIO;AAOA,MAAM,aAAa,OAAO,YAA0B;AACzD,QAAM,aAAS,gCAAiB,SAAS,aAAa;AACtD,QAAM,gBAAY,4BAAa,MAAM;AAErC,QAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAE1C,MAAI,CAAC,YAAY,CAAC,cAAc;AAC9B;AAAA,MACE;AAAA,MACA;AAAA,QACE,OAAO;AAAA,QACP,QAAQ;AAAA,UACN,QAAQ,SAAS;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AACA;AAAA,EACF;AAEA,QAAM,kBAAc,2BAAe,QAAW,MAAM;AAEpD,QAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,QAAM,oBAAoB,kBAAkB,MAAM;AAGlD,QAAM,4BACJ,MAAM,YAAY,QAAQ,yBAAyB,QAAQ;AAAA,IACzD,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,EAC1D,CAAC;AAEH,MAAI,CAAC,0BAA0B,MAAM;AACnC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAEA,YAAU,6CAA6C;AAAA,IACrD,QAAQ;AAAA,MACN,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF,CAAC;AAED,YAAU,KAAK,UAAU,0BAA0B,MAAM,MAAM,CAAC,GAAG;AAAA,IACjE,QAAQ;AAAA,MACN,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/pushConfig.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\nimport {\n getAppLogger,\n getConfiguration,\n type GetConfigurationOptions,\n} from '@intlayer/config';\n\ntype PushOptions = {\n logPrefix?: string;\n configOptions?: GetConfigurationOptions;\n};\n\nexport const pushConfig = async (options?: PushOptions) => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config);\n\n const { clientId, clientSecret } = config.editor;\n\n if (!clientId || !clientSecret) {\n appLogger(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.',\n {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n }\n );\n return;\n }\n\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Get the list of dictionary keys\n const getDictionariesKeysResult =\n await intlayerAPI.project.pushProjectConfiguration(config, {\n ...(oAuth2AccessToken && {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }),\n });\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('Error pushing project configuration');\n }\n\n appLogger('Project configuration pushed successfully', {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n appLogger(JSON.stringify(getDictionariesKeysResult.data, null, 2), {\n config: {\n prefix: options?.logPrefix,\n },\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA+B;AAC/B,oBAIO;AAOA,MAAM,aAAa,OAAO,YAA0B;AACzD,QAAM,aAAS,gCAAiB,SAAS,aAAa;AACtD,QAAM,gBAAY,4BAAa,MAAM;AAErC,QAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAE1C,MAAI,CAAC,YAAY,CAAC,cAAc;AAC9B;AAAA,MACE;AAAA,MACA;AAAA,QACE,OAAO;AAAA,QACP,QAAQ;AAAA,UACN,QAAQ,SAAS;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AACA;AAAA,EACF;AAEA,QAAM,kBAAc,2BAAe,QAAW,MAAM;AAEpD,QAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,QAAM,oBAAoB,kBAAkB,MAAM;AAGlD,QAAM,4BACJ,MAAM,YAAY,QAAQ,yBAAyB,QAAQ;AAAA,IACzD,GAAI,qBAAqB;AAAA,MACvB,SAAS;AAAA,QACP,eAAe,UAAU,iBAAiB;AAAA,MAC5C;AAAA,IACF;AAAA,EACF,CAAC;AAEH,MAAI,CAAC,0BAA0B,MAAM;AACnC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAEA,YAAU,6CAA6C;AAAA,IACrD,QAAQ;AAAA,MACN,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF,CAAC;AAED,YAAU,KAAK,UAAU,0BAA0B,MAAM,MAAM,CAAC,GAAG;AAAA,IACjE,QAAQ;AAAA,MACN,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var reviewDoc_exports = {};
30
+ __export(reviewDoc_exports, {
31
+ reviewDoc: () => reviewDoc,
32
+ reviewFile: () => reviewFile
33
+ });
34
+ module.exports = __toCommonJS(reviewDoc_exports);
35
+ var import_api = require("@intlayer/api");
36
+ var import_chokidar = require("@intlayer/chokidar");
37
+ var import_config = require("@intlayer/config");
38
+ var import_core = require("@intlayer/core");
39
+ var import_fast_glob = __toESM(require("fast-glob"));
40
+ var import_fs = require("fs");
41
+ var import_promises = require("fs/promises");
42
+ var import_p_limit = __toESM(require("p-limit"));
43
+ var import_path = require("path");
44
+ var import_url = require("url");
45
+ var import_calculateChunks = require('./utils/calculateChunks.cjs');
46
+ var import_checkAIAccess = require('./utils/checkAIAccess.cjs');
47
+ var import_checkFileModifiedRange = require('./utils/checkFileModifiedRange.cjs');
48
+ var import_chunkInference = require('./utils/chunkInference.cjs');
49
+ var import_fixChunkStartEndChars = require('./utils/fixChunkStartEndChars.cjs');
50
+ var import_getChunk = require('./utils/getChunk.cjs');
51
+ var import_getOutputFilePath = require('./utils/getOutputFilePath.cjs');
52
+ const import_meta = {};
53
+ const isESModule = typeof import_meta.url === "string";
54
+ const dir = isESModule ? (0, import_path.dirname)((0, import_url.fileURLToPath)(import_meta.url)) : __dirname;
55
+ const reviewFile = async (baseFilePath, outputFilePath, locale, baseLocale, aiOptions, configOptions, oAuth2AccessToken, customInstructions, changedLines) => {
56
+ try {
57
+ const configuration = (0, import_config.getConfiguration)(configOptions);
58
+ const appLogger = (0, import_config.getAppLogger)(configuration);
59
+ const basedFileContent = await (0, import_promises.readFile)(baseFilePath, "utf-8");
60
+ const fileToReviewContent = await (0, import_promises.readFile)(outputFilePath, "utf-8");
61
+ let updatedFileContent = fileToReviewContent;
62
+ let fileResultContent = "";
63
+ const basePrompt = (await (0, import_promises.readFile)((0, import_path.join)(dir, "./prompts/REVIEW_PROMPT.md"), "utf-8")).replaceAll(
64
+ "{{localeName}}",
65
+ `${(0, import_core.getLocaleName)(locale, import_config.Locales.ENGLISH)} (${locale})`
66
+ ).replaceAll(
67
+ "{{baseLocaleName}}",
68
+ `${(0, import_core.getLocaleName)(baseLocale, import_config.Locales.ENGLISH)} (${baseLocale})`
69
+ ).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
70
+ const baseChunks = (0, import_calculateChunks.chunkText)(basedFileContent, 800, 0);
71
+ appLogger(` Base file splitted into ${baseChunks.length} chunks`);
72
+ for await (const [i, baseChunk] of baseChunks.entries()) {
73
+ const baseChunkContext = baseChunk;
74
+ if (changedLines) {
75
+ const hasChangedLinesInChunk = changedLines.some(
76
+ (line) => line > baseChunkContext.lineStart && line < baseChunkContext.lineStart + baseChunkContext.lineLength
77
+ );
78
+ if (!hasChangedLinesInChunk) {
79
+ appLogger(`No git changed lines found for chunk ${i + 1}`);
80
+ const chunkWithNoChange = (0, import_getChunk.getChunk)(updatedFileContent, {
81
+ lineStart: baseChunkContext.lineStart,
82
+ lineLength: baseChunkContext.lineLength
83
+ });
84
+ fileResultContent += chunkWithNoChange;
85
+ continue;
86
+ }
87
+ }
88
+ const getBaseChunkContextPrompt = () => `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the base chunk in ${(0, import_core.getLocaleName)(baseLocale, import_config.Locales.ENGLISH)} (${baseLocale}) as reference.
89
+ ///chunksStart///` + (baseChunks[i - 1]?.content ?? "") + baseChunkContext.content + (baseChunks[i + 1]?.content ?? "") + `///chunksEnd///`;
90
+ const getChunkToReviewPrompt = () => `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the current chunk to review in ${(0, import_core.getLocaleName)(locale, import_config.Locales.ENGLISH)} (${locale}) as reference.
91
+ ///chunksStart///` + (0, import_getChunk.getChunk)(updatedFileContent, {
92
+ lineStart: baseChunks[i - 1]?.lineStart ?? 0,
93
+ lineLength: (baseChunks[i - 1]?.lineLength ?? 0) + baseChunkContext.lineLength + (baseChunks[i + 1]?.lineLength ?? 0)
94
+ }) + `///chunksEnd///`;
95
+ let reviewedChunkResult = await (0, import_config.retryManager)(async () => {
96
+ const result = await (0, import_chunkInference.chunkInference)(
97
+ [
98
+ { role: "system", content: basePrompt },
99
+ { role: "system", content: getBaseChunkContextPrompt() },
100
+ { role: "system", content: getChunkToReviewPrompt() },
101
+ {
102
+ role: "system",
103
+ content: `The next user message will be the **CHUNK ${i + 1} of ${baseChunks.length}** that should be translated in ${(0, import_core.getLocaleName)(locale, import_config.Locales.ENGLISH)} (${locale}).`
104
+ },
105
+ { role: "user", content: baseChunkContext.content }
106
+ ],
107
+ aiOptions,
108
+ oAuth2AccessToken
109
+ );
110
+ appLogger(
111
+ ` -> ${result.tokenUsed} tokens used - CHUNK ${i + 1} of ${baseChunks.length}`
112
+ );
113
+ const fixedReviewedChunkResult = (0, import_fixChunkStartEndChars.fixChunkStartEndChars)(
114
+ result?.fileContent,
115
+ baseChunkContext.content
116
+ );
117
+ return fixedReviewedChunkResult;
118
+ })();
119
+ updatedFileContent = updatedFileContent.replace(
120
+ baseChunkContext.content,
121
+ reviewedChunkResult
122
+ );
123
+ fileResultContent += reviewedChunkResult;
124
+ }
125
+ (0, import_fs.mkdirSync)((0, import_path.dirname)(outputFilePath), { recursive: true });
126
+ (0, import_fs.writeFileSync)(outputFilePath, fileResultContent);
127
+ appLogger(` File ${outputFilePath} created/updated successfully.`);
128
+ } catch (error) {
129
+ console.error(error);
130
+ }
131
+ };
132
+ const reviewDoc = async ({
133
+ docPattern,
134
+ locales,
135
+ excludedGlobPattern,
136
+ baseLocale,
137
+ aiOptions,
138
+ nbSimultaneousFileProcessed,
139
+ configOptions,
140
+ customInstructions,
141
+ skipIfModifiedBefore,
142
+ skipIfModifiedAfter,
143
+ gitOptions
144
+ }) => {
145
+ const configuration = (0, import_config.getConfiguration)(configOptions);
146
+ const appLogger = (0, import_config.getAppLogger)(configuration);
147
+ if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {
148
+ appLogger(
149
+ `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`
150
+ );
151
+ nbSimultaneousFileProcessed = 10;
152
+ }
153
+ const limit = (0, import_p_limit.default)(nbSimultaneousFileProcessed ?? 3);
154
+ let docList = import_fast_glob.default.sync(docPattern, {
155
+ ignore: excludedGlobPattern
156
+ });
157
+ if (gitOptions) {
158
+ const gitChangedFiles = await (0, import_chokidar.listGitFiles)(gitOptions);
159
+ if (gitChangedFiles) {
160
+ docList = docList.filter(
161
+ (path) => gitChangedFiles.some((gitFile) => (0, import_path.join)(process.cwd(), path) === gitFile)
162
+ );
163
+ }
164
+ }
165
+ (0, import_checkAIAccess.checkAIAccess)(configuration, aiOptions);
166
+ let oAuth2AccessToken;
167
+ if (configuration.editor.clientId) {
168
+ const intlayerAuthAPI = (0, import_api.getAuthAPI)(void 0, configuration);
169
+ const oAuth2TokenResult = await intlayerAuthAPI.getOAuth2AccessToken();
170
+ oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
171
+ }
172
+ appLogger(
173
+ `Base locale is ${(0, import_core.getLocaleName)(baseLocale, import_config.Locales.ENGLISH)} (${baseLocale})`
174
+ );
175
+ appLogger(
176
+ `Reviewing ${locales.length} locales: [ ${locales.map((locale) => `${(0, import_core.getLocaleName)(locale, import_config.Locales.ENGLISH)} (${locale})`).join(", ")} ]`
177
+ );
178
+ appLogger(`Reviewing ${docList.length} files:`);
179
+ appLogger(docList.map((path) => ` - ${path}
180
+ `));
181
+ const tasks = docList.map(
182
+ (docPath) => locales.flatMap(
183
+ (locale) => limit(async () => {
184
+ appLogger(
185
+ `Reviewing file: ${docPath} to ${(0, import_core.getLocaleName)(
186
+ locale,
187
+ import_config.Locales.ENGLISH
188
+ )} (${locale})`
189
+ );
190
+ const absoluteBaseFilePath = (0, import_path.join)(
191
+ configuration.content.baseDir,
192
+ docPath
193
+ );
194
+ const outputFilePath = (0, import_getOutputFilePath.getOutputFilePath)(
195
+ absoluteBaseFilePath,
196
+ locale,
197
+ baseLocale
198
+ );
199
+ const fileModificationData = (0, import_checkFileModifiedRange.checkFileModifiedRange)(outputFilePath, {
200
+ skipIfModifiedBefore,
201
+ skipIfModifiedAfter
202
+ });
203
+ if (fileModificationData.isSkipped) {
204
+ appLogger(fileModificationData.message);
205
+ return;
206
+ }
207
+ let changedLines = void 0;
208
+ await reviewFile(
209
+ absoluteBaseFilePath,
210
+ outputFilePath,
211
+ locale,
212
+ baseLocale,
213
+ aiOptions,
214
+ configOptions,
215
+ oAuth2AccessToken,
216
+ customInstructions,
217
+ changedLines
218
+ );
219
+ })
220
+ )
221
+ );
222
+ await Promise.all(tasks);
223
+ };
224
+ // Annotate the CommonJS export names for ESM import in node:
225
+ 0 && (module.exports = {
226
+ reviewDoc,
227
+ reviewFile
228
+ });
229
+ //# sourceMappingURL=reviewDoc.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/reviewDoc.ts"],"sourcesContent":["import { AIOptions, getAuthAPI } from '@intlayer/api'; // Importing only getAiAPI for now\nimport { listGitFiles, ListGitFilesOptions } from '@intlayer/chokidar';\nimport {\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 pLimit from 'p-limit';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkAIAccess } from './utils/checkAIAccess';\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 configOptions?: GetConfigurationOptions,\n oAuth2AccessToken?: string,\n customInstructions?: string,\n changedLines?: number[]\n) => {\n try {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration);\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(\n '{{localeName}}',\n `${getLocaleName(locale, Locales.ENGLISH)} (${locale})`\n )\n .replaceAll(\n '{{baseLocaleName}}',\n `${getLocaleName(baseLocale, Locales.ENGLISH)} (${baseLocale})`\n )\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const baseChunks = chunkText(basedFileContent, 800, 0);\n\n appLogger(` Base file splitted into ${baseChunks.length} chunks`);\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(`No git changed lines found for chunk ${i + 1}`);\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 ${getLocaleName(baseLocale, Locales.ENGLISH)} (${baseLocale}) 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 ${getLocaleName(locale, Locales.ENGLISH)} (${locale}) 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 ${i + 1} of ${baseChunks.length}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`,\n },\n { role: 'user', content: baseChunkContext.content },\n ],\n aiOptions,\n oAuth2AccessToken\n );\n\n appLogger(\n ` -> ${result.tokenUsed} tokens used - CHUNK ${i + 1} of ${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 mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n appLogger(` File ${outputFilePath} created/updated successfully.`);\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\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 checkAIAccess(configuration, aiOptions);\n\n let oAuth2AccessToken: string | undefined;\n if (configuration.editor.clientId) {\n const intlayerAuthAPI = getAuthAPI(undefined, configuration);\n const oAuth2TokenResult = await intlayerAuthAPI.getOAuth2AccessToken();\n\n oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n }\n\n appLogger(\n `Base locale is ${getLocaleName(baseLocale, Locales.ENGLISH)} (${baseLocale})`\n );\n appLogger(\n `Reviewing ${locales.length} locales: [ ${locales\n .map((locale) => `${getLocaleName(locale, Locales.ENGLISH)} (${locale})`)\n .join(', ')} ]`\n );\n\n appLogger(`Reviewing ${docList.length} files:`);\n appLogger(docList.map((path) => ` - ${path}\\n`));\n\n const tasks = docList.map((docPath) =>\n locales.flatMap((locale) =>\n limit(async () => {\n appLogger(\n `Reviewing file: ${docPath} to ${getLocaleName(\n locale,\n Locales.ENGLISH\n )} (${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 configOptions,\n oAuth2AccessToken,\n customInstructions,\n changedLines\n );\n })\n )\n );\n\n await Promise.all(tasks);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAsC;AACtC,sBAAkD;AA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