@intlayer/chokidar 5.8.1 → 6.0.0-canary.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 (219) hide show
  1. package/dist/cjs/chokidar/watcher.cjs +15 -20
  2. package/dist/cjs/chokidar/watcher.cjs.map +1 -1
  3. package/dist/cjs/fetchDistantDictionaries.cjs +18 -37
  4. package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
  5. package/dist/cjs/{fetchDistantDictionaryKeys.cjs → fetchDistantDictionaryKeysAndUpdateTimestamp.cjs} +11 -19
  6. package/dist/cjs/fetchDistantDictionaryKeysAndUpdateTimestamp.cjs.map +1 -0
  7. package/dist/cjs/filterInvalidDictionaries.cjs +70 -0
  8. package/dist/cjs/filterInvalidDictionaries.cjs.map +1 -0
  9. package/dist/cjs/getBuiltFetchDictionariesPath.cjs +52 -0
  10. package/dist/cjs/getBuiltFetchDictionariesPath.cjs.map +1 -0
  11. package/dist/cjs/getBuiltRemoteDictionariesPath.cjs +51 -0
  12. package/dist/cjs/getBuiltRemoteDictionariesPath.cjs.map +1 -0
  13. package/dist/cjs/index.cjs +13 -11
  14. package/dist/cjs/index.cjs.map +1 -1
  15. package/dist/cjs/loadDictionaries/index.cjs +4 -4
  16. package/dist/cjs/loadDictionaries/index.cjs.map +1 -1
  17. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +57 -17
  18. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
  19. package/dist/cjs/loadDictionaries/loadDictionaries.cjs +128 -53
  20. package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
  21. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +108 -0
  22. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -0
  23. package/dist/cjs/loadDictionaries/log.cjs +144 -0
  24. package/dist/cjs/loadDictionaries/log.cjs.map +1 -0
  25. package/dist/cjs/mergeDictionaries.cjs +18 -22
  26. package/dist/cjs/mergeDictionaries.cjs.map +1 -1
  27. package/dist/cjs/orderDictionaries.cjs +71 -0
  28. package/dist/cjs/orderDictionaries.cjs.map +1 -0
  29. package/dist/cjs/prepareContentDeclaration.cjs +4 -1
  30. package/dist/cjs/prepareContentDeclaration.cjs.map +1 -1
  31. package/dist/cjs/prepareIntlayer.cjs +9 -4
  32. package/dist/cjs/prepareIntlayer.cjs.map +1 -1
  33. package/dist/cjs/processPerLocaleDictionary.cjs.map +1 -1
  34. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs +22 -8
  35. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs.map +1 -1
  36. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.cjs +44 -42
  37. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.cjs.map +1 -1
  38. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.cjs +83 -0
  39. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.cjs.map +1 -0
  40. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.cjs +29 -21
  41. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.cjs.map +1 -1
  42. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.cjs +52 -0
  43. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.cjs.map +1 -0
  44. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.cjs +44 -29
  45. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.cjs.map +1 -1
  46. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs +39 -34
  47. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +1 -1
  48. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +4 -6
  49. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
  50. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +17 -16
  51. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -1
  52. package/dist/cjs/utils/formatter.cjs +50 -0
  53. package/dist/cjs/utils/formatter.cjs.map +1 -0
  54. package/dist/cjs/utils/parallelize.cjs +43 -0
  55. package/dist/cjs/utils/parallelize.cjs.map +1 -0
  56. package/dist/cjs/utils/runOnce.cjs +2 -1
  57. package/dist/cjs/utils/runOnce.cjs.map +1 -1
  58. package/dist/cjs/writeContentDeclaration/dictionaryStatus.cjs.map +1 -1
  59. package/dist/cjs/writeContentDeclaration/formatCode.cjs +7 -4
  60. package/dist/cjs/writeContentDeclaration/formatCode.cjs.map +1 -1
  61. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +6 -2
  62. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
  63. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +43 -25
  64. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
  65. package/dist/esm/chokidar/watcher.mjs +16 -21
  66. package/dist/esm/chokidar/watcher.mjs.map +1 -1
  67. package/dist/esm/fetchDistantDictionaries.mjs +24 -28
  68. package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
  69. package/dist/esm/fetchDistantDictionaryKeysAndUpdateTimestamp.mjs +21 -0
  70. package/dist/esm/fetchDistantDictionaryKeysAndUpdateTimestamp.mjs.map +1 -0
  71. package/dist/esm/filterInvalidDictionaries.mjs +40 -0
  72. package/dist/esm/filterInvalidDictionaries.mjs.map +1 -0
  73. package/dist/esm/getBuiltFetchDictionariesPath.mjs +18 -0
  74. package/dist/esm/getBuiltFetchDictionariesPath.mjs.map +1 -0
  75. package/dist/esm/getBuiltRemoteDictionariesPath.mjs +17 -0
  76. package/dist/esm/getBuiltRemoteDictionariesPath.mjs.map +1 -0
  77. package/dist/esm/index.mjs +10 -9
  78. package/dist/esm/index.mjs.map +1 -1
  79. package/dist/esm/loadDictionaries/index.mjs +2 -2
  80. package/dist/esm/loadDictionaries/index.mjs.map +1 -1
  81. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +61 -18
  82. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
  83. package/dist/esm/loadDictionaries/loadDictionaries.mjs +132 -53
  84. package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
  85. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +73 -0
  86. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -0
  87. package/dist/esm/loadDictionaries/log.mjs +125 -0
  88. package/dist/esm/loadDictionaries/log.mjs.map +1 -0
  89. package/dist/esm/mergeDictionaries.mjs +19 -23
  90. package/dist/esm/mergeDictionaries.mjs.map +1 -1
  91. package/dist/esm/orderDictionaries.mjs +37 -0
  92. package/dist/esm/orderDictionaries.mjs.map +1 -0
  93. package/dist/esm/prepareContentDeclaration.mjs +4 -1
  94. package/dist/esm/prepareContentDeclaration.mjs.map +1 -1
  95. package/dist/esm/prepareIntlayer.mjs +9 -4
  96. package/dist/esm/prepareIntlayer.mjs.map +1 -1
  97. package/dist/esm/processPerLocaleDictionary.mjs.map +1 -1
  98. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs +25 -9
  99. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -1
  100. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs +45 -43
  101. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs.map +1 -1
  102. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs +58 -0
  103. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs.map +1 -0
  104. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs +29 -21
  105. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs.map +1 -1
  106. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs +28 -0
  107. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs.map +1 -0
  108. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs +45 -30
  109. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs.map +1 -1
  110. package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +39 -34
  111. package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
  112. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +4 -6
  113. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
  114. package/dist/esm/transpiler/dictionary_to_type/createType.mjs +17 -16
  115. package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
  116. package/dist/esm/utils/formatter.mjs +15 -0
  117. package/dist/esm/utils/formatter.mjs.map +1 -0
  118. package/dist/esm/utils/parallelize.mjs +9 -0
  119. package/dist/esm/utils/parallelize.mjs.map +1 -0
  120. package/dist/esm/utils/runOnce.mjs +2 -1
  121. package/dist/esm/utils/runOnce.mjs.map +1 -1
  122. package/dist/esm/writeContentDeclaration/formatCode.mjs +8 -5
  123. package/dist/esm/writeContentDeclaration/formatCode.mjs.map +1 -1
  124. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +6 -2
  125. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
  126. package/dist/esm/writeContentDeclaration/writeJSFile.mjs +40 -22
  127. package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
  128. package/dist/types/chokidar/watcher.d.ts.map +1 -1
  129. package/dist/types/fetchDistantDictionaries.d.ts +2 -1
  130. package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
  131. package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts +3 -0
  132. package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts.map +1 -0
  133. package/dist/types/filterInvalidDictionaries.d.ts +3 -0
  134. package/dist/types/filterInvalidDictionaries.d.ts.map +1 -0
  135. package/dist/types/getBuiltFetchDictionariesPath.d.ts +5 -0
  136. package/dist/types/getBuiltFetchDictionariesPath.d.ts.map +1 -0
  137. package/dist/types/getBuiltRemoteDictionariesPath.d.ts +5 -0
  138. package/dist/types/getBuiltRemoteDictionariesPath.d.ts.map +1 -0
  139. package/dist/types/index.d.ts +4 -4
  140. package/dist/types/index.d.ts.map +1 -1
  141. package/dist/types/loadDictionaries/index.d.ts +2 -2
  142. package/dist/types/loadDictionaries/index.d.ts.map +1 -1
  143. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +4 -1
  144. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
  145. package/dist/types/loadDictionaries/loadDictionaries.d.ts +11 -1
  146. package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
  147. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +6 -0
  148. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -0
  149. package/dist/types/loadDictionaries/log.d.ts +19 -0
  150. package/dist/types/loadDictionaries/log.d.ts.map +1 -0
  151. package/dist/types/mergeDictionaries.d.ts +1 -1
  152. package/dist/types/mergeDictionaries.d.ts.map +1 -1
  153. package/dist/types/orderDictionaries.d.ts +10 -0
  154. package/dist/types/orderDictionaries.d.ts.map +1 -0
  155. package/dist/types/prepareContentDeclaration.d.ts.map +1 -1
  156. package/dist/types/prepareIntlayer.d.ts.map +1 -1
  157. package/dist/types/processPerLocaleDictionary.d.ts +1 -1
  158. package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +1 -0
  159. package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts.map +1 -1
  160. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +4 -3
  161. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +1 -1
  162. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts +1 -1
  163. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts.map +1 -1
  164. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts +23 -0
  165. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts.map +1 -0
  166. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts +1 -1
  167. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts.map +1 -1
  168. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts +19 -0
  169. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts.map +1 -0
  170. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.d.ts.map +1 -1
  171. package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts +1 -1
  172. package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts.map +1 -1
  173. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +1 -1
  174. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts.map +1 -1
  175. package/dist/types/transpiler/dictionary_to_type/createType.d.ts +1 -1
  176. package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +1 -1
  177. package/dist/types/utils/formatter.d.ts +4 -0
  178. package/dist/types/utils/formatter.d.ts.map +1 -0
  179. package/dist/types/utils/parallelize.d.ts +2 -0
  180. package/dist/types/utils/parallelize.d.ts.map +1 -0
  181. package/dist/types/utils/runOnce.d.ts +1 -1
  182. package/dist/types/utils/runOnce.d.ts.map +1 -1
  183. package/dist/types/writeContentDeclaration/dictionaryStatus.d.ts +1 -1
  184. package/dist/types/writeContentDeclaration/dictionaryStatus.d.ts.map +1 -1
  185. package/dist/types/writeContentDeclaration/formatCode.d.ts.map +1 -1
  186. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +1 -1
  187. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
  188. package/dist/types/writeContentDeclaration/writeJSFile.d.ts +1 -1
  189. package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -1
  190. package/package.json +17 -15
  191. package/dist/cjs/checkDictionaryChanges.cjs +0 -58
  192. package/dist/cjs/checkDictionaryChanges.cjs.map +0 -1
  193. package/dist/cjs/fetchDistantDictionaryKeys.cjs.map +0 -1
  194. package/dist/cjs/getFilteredLocalesContent.cjs +0 -70
  195. package/dist/cjs/getFilteredLocalesContent.cjs.map +0 -1
  196. package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs +0 -44
  197. package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs.map +0 -1
  198. package/dist/cjs/log.cjs +0 -296
  199. package/dist/cjs/log.cjs.map +0 -1
  200. package/dist/esm/checkDictionaryChanges.mjs +0 -37
  201. package/dist/esm/checkDictionaryChanges.mjs.map +0 -1
  202. package/dist/esm/fetchDistantDictionaryKeys.mjs +0 -29
  203. package/dist/esm/fetchDistantDictionaryKeys.mjs.map +0 -1
  204. package/dist/esm/getFilteredLocalesContent.mjs +0 -49
  205. package/dist/esm/getFilteredLocalesContent.mjs.map +0 -1
  206. package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs +0 -20
  207. package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs.map +0 -1
  208. package/dist/esm/log.mjs +0 -262
  209. package/dist/esm/log.mjs.map +0 -1
  210. package/dist/types/checkDictionaryChanges.d.ts +0 -3
  211. package/dist/types/checkDictionaryChanges.d.ts.map +0 -1
  212. package/dist/types/fetchDistantDictionaryKeys.d.ts +0 -3
  213. package/dist/types/fetchDistantDictionaryKeys.d.ts.map +0 -1
  214. package/dist/types/getFilteredLocalesContent.d.ts +0 -4
  215. package/dist/types/getFilteredLocalesContent.d.ts.map +0 -1
  216. package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts +0 -8
  217. package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts.map +0 -1
  218. package/dist/types/log.d.ts +0 -45
  219. package/dist/types/log.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import generator from '@babel/generator';\nimport * as babelParser from '@babel/parser';\nimport traverse, { NodePath } from '@babel/traverse';\nimport * as t from '@babel/types';\nimport { getAppLogger, logger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport {\n Dictionary,\n NodeType,\n TranslationContent,\n TypedNode,\n} from '@intlayer/core';\nimport { existsSync } from 'fs';\nimport { readFile, writeFile } from 'fs/promises';\nimport { extname } from 'path';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport { formatCode } from './formatCode';\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary\n): Promise<void> => {\n const appLogger = getAppLogger(configuration);\n\n const {\n key: dictionaryIdentifierKey,\n content: updatesToApply,\n locale,\n autoFilled,\n } = dictionary;\n const isPerLocaleDeclarationFile = typeof locale === 'string';\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath);\n\n let format = 'ts' as 'ts' | 'cjs' | 'esm';\n\n if (fileExtension === '.ts' || fileExtension === '.tsx') {\n format = 'ts';\n } else if (fileExtension === '.cjs' || fileExtension === '.cjsx') {\n format = 'cjs';\n } else {\n format = 'esm';\n }\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(\n dictionaryIdentifierKey,\n format,\n { locale, autoFilled }\n );\n\n await writeFile(filePath, template, 'utf-8');\n }\n\n let sourceCode: string;\n try {\n sourceCode = await readFile(filePath, 'utf-8');\n } catch (error) {\n const err = error as Error;\n appLogger(`Failed to read file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to read file ${filePath}: ${err.message}`);\n }\n\n const ast = babelParser.parse(sourceCode, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n tokens: true,\n });\n\n let dictionaryObjectPath: NodePath<t.ObjectExpression> | null = null;\n let dictionaryIdentifier: string | null = null;\n\n // First look for direct objects with the right key, regardless of variable assignments\n traverse(ast, {\n ObjectExpression(path) {\n if (dictionaryObjectPath) return; // Already found\n\n // Check if this object has a key property with the right value\n const keyProp = path.node.properties.find((prop) => {\n if (!t.isObjectProperty(prop)) return false;\n if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))\n return false;\n\n const keyName = t.isIdentifier(prop.key)\n ? prop.key.name\n : prop.key.value;\n\n if (keyName !== 'key' || !t.isStringLiteral(prop.value)) return false;\n\n // Unescape the value for comparison\n const propValue = prop.value.value;\n // Compare actual string content, not just raw representation\n return propValue === dictionaryIdentifierKey;\n });\n\n if (keyProp) {\n dictionaryObjectPath = path;\n path.stop();\n }\n },\n });\n\n // If not found directly, look for variable declarations and exports\n if (!dictionaryObjectPath) {\n appLogger(`Looking for variable declarations`, {\n isVerbose: true,\n });\n\n // Collect all variable declarations with objects\n const candidateVars: { id: string; path: NodePath<t.ObjectExpression> }[] =\n [];\n\n traverse(ast, {\n VariableDeclarator(path) {\n const { node } = path;\n if (!t.isIdentifier(node.id)) return;\n\n let objPath: NodePath<t.ObjectExpression> | null = null;\n\n // Direct object assignment\n if (node.init && t.isObjectExpression(node.init)) {\n objPath = path.get('init') as NodePath<t.ObjectExpression>;\n }\n // Object with TS type assertion (satisfies/as)\n else if (\n node.init &&\n (t.isTSAsExpression(node.init) || t.isTSTypeAssertion(node.init)) &&\n t.isObjectExpression(node.init.expression)\n ) {\n objPath = path.get('init.expression') as NodePath<t.ObjectExpression>;\n }\n\n if (objPath) {\n candidateVars.push({ id: node.id.name, path: objPath });\n }\n },\n });\n\n appLogger(`Found ${candidateVars.length} candidate variables`, {\n isVerbose: true,\n });\n\n // Check each candidate for the key property\n for (const { id, path } of candidateVars) {\n const keyProp = path.node.properties.find((prop) => {\n if (!t.isObjectProperty(prop)) return false;\n if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))\n return false;\n\n const keyName = t.isIdentifier(prop.key)\n ? prop.key.name\n : prop.key.value;\n return (\n keyName === 'key' &&\n t.isStringLiteral(prop.value) &&\n prop.value.value === dictionaryIdentifierKey\n );\n });\n\n if (keyProp) {\n appLogger(`Found match in variable: ${id}`);\n dictionaryObjectPath = path;\n dictionaryIdentifier = id;\n break;\n }\n }\n\n // If still not found, dump all object expressions for debugging\n if (!dictionaryObjectPath) {\n appLogger('Could not find dictionary object. Dumping all objects:', {\n isVerbose: true,\n });\n traverse(ast, {\n ObjectExpression(path) {\n const props = path.node.properties\n .map((prop) => {\n if (!t.isObjectProperty(prop)) return 'non-object-property';\n if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))\n return 'complex-key';\n\n const keyName = t.isIdentifier(prop.key)\n ? prop.key.name\n : prop.key.value;\n let valueDesc = 'unknown-value';\n\n if (t.isStringLiteral(prop.value)) {\n valueDesc = `\"${prop.value.value}\"`;\n }\n\n return `${keyName}: ${valueDesc}`;\n })\n .join(', ');\n\n appLogger(`Object: { ${props} }`);\n },\n });\n }\n }\n\n if (!dictionaryObjectPath) {\n throw new Error(\n `Could not find dictionary object with key '${dictionaryIdentifierKey}' in ${filePath}`\n );\n }\n\n // Find the 'content' property within the identified dictionary object\n const contentPropertyPath = (\n (dictionaryObjectPath as any).get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[]\n ).find((propPath) => {\n if (!propPath.isObjectProperty()) return false;\n const propNode = propPath.node;\n const keyName = t.isIdentifier(propNode.key)\n ? propNode.key.name\n : t.isStringLiteral(propNode.key)\n ? propNode.key.value\n : null;\n return keyName === 'content';\n });\n\n if (\n !contentPropertyPath ||\n !contentPropertyPath.isObjectProperty() ||\n !(contentPropertyPath.get('value') as NodePath).isObjectExpression()\n ) {\n throw new Error(\n `Could not find 'content' object property, or it's not an object, in dictionary in ${filePath}`\n );\n }\n\n const contentObjectPath = contentPropertyPath.get(\n 'value'\n ) as NodePath<t.ObjectExpression>;\n\n /**\n * Build a Babel Expression for any JSON-serializable value or TypedNode.\n * - Translation nodes become t({...}) or string literal in per-locale files\n * - Objects recurse to ObjectExpression\n * - Arrays recurse to ArrayExpression\n * - Strings/numbers/booleans/null to corresponding literals\n */\n const buildValueNodeFromData = (data: any): t.Expression => {\n // Translation typed node\n if ((data as TypedNode)?.nodeType === NodeType.Translation) {\n const translationContent = data as TranslationContent;\n if (\n isPerLocaleDeclarationFile &&\n typeof locale === 'string' &&\n translationContent?.[NodeType.Translation]?.[locale] !== undefined\n ) {\n return buildValueNodeFromData(\n translationContent[NodeType.Translation][locale]\n );\n }\n const translationsObj = t.objectExpression(\n Object.entries(translationContent?.[NodeType.Translation] ?? {}).map(\n ([langKey, langValue]) => {\n const keyNode = t.isValidIdentifier(langKey)\n ? t.identifier(langKey)\n : t.stringLiteral(langKey);\n return t.objectProperty(keyNode, buildValueNodeFromData(langValue));\n }\n )\n );\n return t.callExpression(t.identifier('t'), [translationsObj]);\n }\n\n // Arrays\n if (Array.isArray(data)) {\n return t.arrayExpression(data.map((el) => buildValueNodeFromData(el)));\n }\n\n // Objects (plain)\n if (data && typeof data === 'object') {\n const props = Object.entries(data).map(([k, v]) => {\n const key = t.isValidIdentifier(k)\n ? t.identifier(k)\n : t.stringLiteral(k);\n return t.objectProperty(key, buildValueNodeFromData(v));\n });\n return t.objectExpression(props);\n }\n\n // Primitives\n switch (typeof data) {\n case 'string':\n return t.stringLiteral(data);\n case 'number':\n return t.numericLiteral(data);\n case 'boolean':\n return t.booleanLiteral(data);\n default:\n return t.nullLiteral();\n }\n };\n\n /** Ensure an object property exists on a given object expression path. */\n const ensureObjectProperty = (\n objPath: NodePath<t.ObjectExpression>,\n key: string\n ): NodePath<t.ObjectProperty> => {\n const existing = (\n objPath.get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[]\n ).find((propPath) => {\n if (!propPath.isObjectProperty()) return false;\n const propNode = propPath.node;\n const keyName = t.isIdentifier(propNode.key)\n ? propNode.key.name\n : t.isStringLiteral(propNode.key)\n ? propNode.key.value\n : null;\n return keyName === key;\n }) as NodePath<t.ObjectProperty> | undefined;\n\n if (existing) return existing;\n\n const keyNode = t.isValidIdentifier(key)\n ? t.identifier(key)\n : t.stringLiteral(key);\n const newProp = t.objectProperty(keyNode, t.objectExpression([]));\n objPath.node.properties.push(newProp);\n\n // Return a fresh path for the newly pushed property\n const props = objPath.get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[];\n return props[props.length - 1] as NodePath<t.ObjectProperty>;\n };\n\n /** Recursively merge a JSON-like value into an ObjectExpression property path. */\n const mergeValueIntoProperty = (\n propPath: NodePath<t.ObjectProperty>,\n value: any,\n propKeyForLogs: string\n ) => {\n const valuePath = propPath.get('value') as NodePath;\n\n // Translation typed node → either update t() args or replace value\n if ((value as TypedNode)?.nodeType === NodeType.Translation) {\n const translationContent = value as TranslationContent;\n if (\n valuePath.isCallExpression() &&\n t.isIdentifier(valuePath.node.callee) &&\n valuePath.node.callee.name === 't'\n ) {\n // Replace argument with the full translations object (simpler and robust)\n const translationsObj = t.objectExpression(\n Object.entries(translationContent?.[NodeType.Translation] ?? {}).map(\n ([langKey, langValue]) =>\n t.objectProperty(\n t.isValidIdentifier(langKey)\n ? t.identifier(langKey)\n : t.stringLiteral(langKey),\n buildValueNodeFromData(langValue)\n )\n )\n );\n\n if (isPerLocaleDeclarationFile && typeof locale === 'string') {\n const localized =\n translationContent?.[NodeType.Translation]?.[locale];\n if (localized !== undefined) {\n valuePath.replaceWith(buildValueNodeFromData(localized));\n return;\n }\n }\n\n (valuePath.node as t.CallExpression).arguments = [translationsObj];\n return;\n }\n\n // Otherwise, replace with a fresh node\n valuePath.replaceWith(buildValueNodeFromData(value));\n return;\n }\n\n // Arrays → replace entirely\n if (Array.isArray(value)) {\n valuePath.replaceWith(buildValueNodeFromData(value));\n return;\n }\n\n // Objects → ensure object expression and recurse into each key\n if (value && typeof value === 'object') {\n if (!valuePath.isObjectExpression()) {\n valuePath.replaceWith(t.objectExpression([]));\n }\n const objPath = valuePath as NodePath<t.ObjectExpression>;\n for (const [k, v] of Object.entries(value)) {\n const childProp = ensureObjectProperty(objPath, k);\n mergeValueIntoProperty(childProp, v, `${propKeyForLogs}.${k}`);\n }\n return;\n }\n\n // Primitives → replace\n valuePath.replaceWith(buildValueNodeFromData(value));\n return;\n };\n\n // Apply updates to each entry specified in the JSON (now supports deep nesting)\n for (const [entryKeyToUpdate, newEntryData] of Object.entries(\n updatesToApply\n )) {\n let targetPropertyPath = (\n contentObjectPath.get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[]\n ).find((propPath) => {\n if (!propPath.isObjectProperty()) return false;\n const propNode = propPath.node;\n const keyName = t.isIdentifier(propNode.key)\n ? propNode.key.name\n : t.isStringLiteral(propNode.key)\n ? propNode.key.value\n : null;\n return keyName === entryKeyToUpdate;\n }) as NodePath<t.ObjectProperty> | undefined;\n\n if (!targetPropertyPath) {\n const keyNode = t.isValidIdentifier(entryKeyToUpdate)\n ? t.identifier(entryKeyToUpdate)\n : t.stringLiteral(entryKeyToUpdate);\n // By default create an empty object; merge will replace if needed\n const newProperty = t.objectProperty(keyNode, t.objectExpression([]));\n contentObjectPath.node.properties.push(newProperty);\n const props = contentObjectPath.get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[];\n targetPropertyPath = props[\n props.length - 1\n ] as NodePath<t.ObjectProperty>;\n }\n\n mergeValueIntoProperty(targetPropertyPath, newEntryData, entryKeyToUpdate);\n }\n\n // Generate JavaScript/TypeScript code from the modified AST\n const generatedCode = generator(ast, {\n retainLines: true,\n comments: true,\n jsescOption: {\n minimal: true, // This ensures Unicode characters are not escaped\n },\n }).code;\n\n let finalCode = generatedCode;\n\n finalCode = await formatCode(filePath, finalCode);\n\n // Write the modified code back to the file\n try {\n await writeFile(filePath, finalCode, 'utf-8');\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsB;AACtB,kBAA6B;AAC7B,sBAAmC;AACnC,QAAmB;AACnB,oBAAqC;AACrC,mBAA0B;AAC1B,kBAKO;AACP,gBAA2B;AAC3B,sBAAoC;AACpC,kBAAwB;AACxB,+CAAkD;AAClD,wBAA2B;AAQpB,MAAM,cAAc,OACzB,UACA,eACkB;AAClB,QAAM,gBAAY,4BAAa,aAAAA,OAAa;AAE5C,QAAM;AAAA,IACJ,KAAK;AAAA,IACL,SAAS;AAAA,IACT;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,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C,aAAa;AACnB,UAAI,CAAC,SAAS,iBAAiB,EAAG,QAAO;AACzC,YAAM,WAAW,SAAS;AAC1B,YAAM,UAAU,EAAE,aAAa,SAAS,GAAG,IACvC,SAAS,IAAI,OACb,EAAE,gBAAgB,SAAS,GAAG,IAC5B,SAAS,IAAI,QACb;AACN,aAAO,YAAY;AAAA,IACrB,CAAC;AAED,QAAI,CAAC,oBAAoB;AACvB,YAAM,UAAU,EAAE,kBAAkB,gBAAgB,IAChD,EAAE,WAAW,gBAAgB,IAC7B,EAAE,cAAc,gBAAgB;AAEpC,YAAM,cAAc,EAAE,eAAe,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC;AACpE,wBAAkB,KAAK,WAAW,KAAK,WAAW;AAClD,YAAM,QAAQ,kBAAkB,IAAI,YAAY;AAGhD,2BAAqB,MACnB,MAAM,SAAS,CACjB;AAAA,IACF;AAEA,2BAAuB,oBAAoB,cAAc,gBAAgB;AAAA,EAC3E;AAGA,QAAM,oBAAgB,iBAAAC,SAAU,KAAK;AAAA,IACnC,aAAa;AAAA,IACb,UAAU;AAAA,IACV,aAAa;AAAA,MACX,SAAS;AAAA;AAAA,IACX;AAAA,EACF,CAAC,EAAE;AAEH,MAAI,YAAY;AAEhB,cAAY,UAAM,8BAAW,UAAU,SAAS;AAGhD,MAAI;AACF,cAAM,2BAAU,UAAU,WAAW,OAAO;AAC5C,8BAAO,wBAAwB,QAAQ,IAAI;AAAA,MACzC,OAAO;AAAA,MACP,WAAW;AAAA,IACb,CAAC;AAAA,EACH,SAAS,OAAO;AACd,UAAM,MAAM;AACZ,8BAAO,iCAAiC,QAAQ,IAAI;AAAA,MAClD,OAAO;AAAA,IACT,CAAC;AACD,UAAM,IAAI,MAAM,gCAAgC,QAAQ,KAAK,IAAI,OAAO,EAAE;AAAA,EAC5E;AACF;","names":["configuration","traverse","generator"]}
1
+ {"version":3,"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import * as generate from '@babel/generator';\nimport * as babelParser from '@babel/parser';\nimport type { NodePath } from '@babel/traverse';\nimport * as babelTraverse from '@babel/traverse';\nimport * as t from '@babel/types';\nimport { getAppLogger, logger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport {\n Dictionary,\n NodeType,\n TranslationContent,\n TypedNode,\n} from '@intlayer/core';\nimport { existsSync } from 'fs';\nimport { readFile, writeFile } from 'fs/promises';\nimport { extname } from 'path';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport { formatCode } from './formatCode';\n\n/**\n * Updates a JavaScriptå/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary\n): Promise<void> => {\n // Ensure compatibility with various ESM/CJS interop shapes of @babel/traverse\n const normalizeTraverse = (mod: unknown) => {\n const candidate = mod as any;\n if (typeof candidate === 'function') return candidate;\n if (candidate?.default) {\n if (typeof candidate.default === 'function') return candidate.default;\n if (typeof candidate.default?.default === 'function')\n return candidate.default.default;\n if (typeof candidate.default?.traverse === 'function')\n return candidate.default.traverse;\n }\n if (typeof candidate?.traverse === 'function') return candidate.traverse;\n return candidate;\n };\n\n const traverse = normalizeTraverse(babelTraverse) as any;\n const appLogger = getAppLogger(configuration);\n\n const {\n key: dictionaryIdentifierKey,\n content: updatesToApply,\n locale,\n autoFilled,\n } = dictionary;\n const isPerLocaleDeclarationFile = typeof locale === 'string';\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath);\n\n let format = 'ts' as 'ts' | 'cjs' | 'esm';\n\n if (fileExtension === '.ts' || fileExtension === '.tsx') {\n format = 'ts';\n } else if (fileExtension === '.cjs' || fileExtension === '.cjsx') {\n format = 'cjs';\n } else {\n format = 'esm';\n }\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(\n dictionaryIdentifierKey,\n format,\n { locale, autoFilled }\n );\n\n await writeFile(filePath, template, 'utf-8');\n }\n\n let sourceCode: string;\n try {\n sourceCode = await readFile(filePath, 'utf-8');\n } catch (error) {\n const err = error as Error;\n appLogger(`Failed to read file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to read file ${filePath}: ${err.message}`);\n }\n\n const ast = babelParser.parse(sourceCode, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n tokens: true,\n });\n\n let dictionaryObjectPath: NodePath<t.ObjectExpression> | null = null;\n let dictionaryIdentifier: string | null = null;\n\n // First look for direct objects with the right key, regardless of variable assignments\n traverse(ast, {\n ObjectExpression(path: NodePath<t.ObjectExpression>) {\n if (dictionaryObjectPath) return; // Already found\n\n // Check if this object has a key property with the right value\n const keyProp = path.node.properties.find(\n (prop: t.ObjectProperty | t.SpreadElement | t.ObjectMethod) => {\n if (!t.isObjectProperty(prop)) return false;\n if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))\n return false;\n\n const keyName = t.isIdentifier(prop.key)\n ? prop.key.name\n : prop.key.value;\n\n if (keyName !== 'key' || !t.isStringLiteral(prop.value)) return false;\n\n // Unescape the value for comparison\n const propValue = prop.value.value;\n // Compare actual string content, not just raw representation\n return propValue === dictionaryIdentifierKey;\n }\n );\n\n if (keyProp) {\n dictionaryObjectPath = path;\n path.stop();\n }\n },\n });\n\n // If not found directly, look for variable declarations and exports\n if (!dictionaryObjectPath) {\n appLogger(`Looking for variable declarations`, {\n isVerbose: true,\n });\n\n // Collect all variable declarations with objects\n const candidateVars: { id: string; path: NodePath<t.ObjectExpression> }[] =\n [];\n\n traverse(ast, {\n VariableDeclarator(path: NodePath<t.VariableDeclarator>) {\n const { node } = path;\n if (!t.isIdentifier(node.id)) return;\n\n let objPath: NodePath<t.ObjectExpression> | null = null;\n\n // Direct object assignment\n if (node.init && t.isObjectExpression(node.init)) {\n objPath = path.get('init') as NodePath<t.ObjectExpression>;\n }\n // Object with TS type assertion (satisfies/as)\n else if (\n node.init &&\n (t.isTSAsExpression(node.init) || t.isTSTypeAssertion(node.init)) &&\n t.isObjectExpression(node.init.expression)\n ) {\n objPath = path.get('init.expression') as NodePath<t.ObjectExpression>;\n }\n\n if (objPath) {\n candidateVars.push({ id: node.id.name, path: objPath });\n }\n },\n });\n\n appLogger(`Found ${candidateVars.length} candidate variables`, {\n isVerbose: true,\n });\n\n // Check each candidate for the key property\n for (const { id, path } of candidateVars) {\n const keyProp = path.node.properties.find((prop) => {\n if (!t.isObjectProperty(prop)) return false;\n if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))\n return false;\n\n const keyName = t.isIdentifier(prop.key)\n ? prop.key.name\n : prop.key.value;\n return (\n keyName === 'key' &&\n t.isStringLiteral(prop.value) &&\n prop.value.value === dictionaryIdentifierKey\n );\n });\n\n if (keyProp) {\n appLogger(`Found match in variable: ${id}`);\n dictionaryObjectPath = path;\n dictionaryIdentifier = id;\n break;\n }\n }\n\n // If still not found, dump all object expressions for debugging\n if (!dictionaryObjectPath) {\n appLogger('Could not find dictionary object. Dumping all objects:', {\n isVerbose: true,\n });\n traverse(ast, {\n ObjectExpression(path: NodePath<t.ObjectExpression>) {\n const props = path.node.properties\n .map(\n (prop: t.ObjectProperty | t.SpreadElement | t.ObjectMethod) => {\n if (!t.isObjectProperty(prop)) return 'non-object-property';\n if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))\n return 'complex-key';\n\n const keyName = t.isIdentifier(prop.key)\n ? prop.key.name\n : prop.key.value;\n let valueDesc = 'unknown-value';\n\n if (t.isStringLiteral(prop.value)) {\n valueDesc = `\"${prop.value.value}\"`;\n }\n\n return `${keyName}: ${valueDesc}`;\n }\n )\n .join(', ');\n\n appLogger(`Object: { ${props} }`);\n },\n });\n }\n }\n\n if (!dictionaryObjectPath) {\n throw new Error(\n `Could not find dictionary object with key '${dictionaryIdentifierKey}' in ${filePath}`\n );\n }\n\n // Find the 'content' property within the identified dictionary object\n const contentPropertyPath = (\n (dictionaryObjectPath as any).get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[]\n ).find((propPath) => {\n if (!propPath.isObjectProperty()) return false;\n const propNode = propPath.node;\n const keyName = t.isIdentifier(propNode.key)\n ? propNode.key.name\n : t.isStringLiteral(propNode.key)\n ? propNode.key.value\n : null;\n return keyName === 'content';\n });\n\n if (\n !contentPropertyPath ||\n !contentPropertyPath.isObjectProperty() ||\n !(contentPropertyPath.get('value') as NodePath).isObjectExpression()\n ) {\n throw new Error(\n `Could not find 'content' object property, or it's not an object, in dictionary in ${filePath}`\n );\n }\n\n const contentObjectPath = contentPropertyPath.get(\n 'value'\n ) as NodePath<t.ObjectExpression>;\n\n /**\n * Build a Babel Expression for any JSON-serializable value or TypedNode.\n * - Translation nodes become t({...}) or string literal in per-locale files\n * - Objects recurse to ObjectExpression\n * - Arrays recurse to ArrayExpression\n * - Strings/numbers/booleans/null to corresponding literals\n */\n const buildValueNodeFromData = (data: any): t.Expression => {\n // Translation typed node\n if ((data as TypedNode)?.nodeType === NodeType.Translation) {\n const translationContent = data as TranslationContent;\n if (\n isPerLocaleDeclarationFile &&\n typeof locale === 'string' &&\n translationContent?.[NodeType.Translation]?.[locale] !== undefined\n ) {\n return buildValueNodeFromData(\n translationContent[NodeType.Translation][locale]\n );\n }\n const translationsObj = t.objectExpression(\n Object.entries(translationContent?.[NodeType.Translation] ?? {}).map(\n ([langKey, langValue]) => {\n const keyNode = t.isValidIdentifier(langKey)\n ? t.identifier(langKey)\n : t.stringLiteral(langKey);\n return t.objectProperty(keyNode, buildValueNodeFromData(langValue));\n }\n )\n );\n return t.callExpression(t.identifier('t'), [translationsObj]);\n }\n\n // Arrays\n if (Array.isArray(data)) {\n return t.arrayExpression(data.map((el) => buildValueNodeFromData(el)));\n }\n\n // Objects (plain)\n if (data && typeof data === 'object') {\n const props = Object.entries(data).map(([k, v]) => {\n const key = t.isValidIdentifier(k)\n ? t.identifier(k)\n : t.stringLiteral(k);\n return t.objectProperty(key, buildValueNodeFromData(v));\n });\n return t.objectExpression(props);\n }\n\n // Primitives\n switch (typeof data) {\n case 'string':\n return t.stringLiteral(data);\n case 'number':\n return t.numericLiteral(data);\n case 'boolean':\n return t.booleanLiteral(data);\n default:\n return t.nullLiteral();\n }\n };\n\n /** Ensure an object property exists on a given object expression path. */\n const ensureObjectProperty = (\n objPath: NodePath<t.ObjectExpression>,\n key: string\n ): NodePath<t.ObjectProperty> => {\n const existing = (\n objPath.get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[]\n ).find((propPath) => {\n if (!propPath.isObjectProperty()) return false;\n const propNode = propPath.node;\n const keyName = t.isIdentifier(propNode.key)\n ? propNode.key.name\n : t.isStringLiteral(propNode.key)\n ? propNode.key.value\n : null;\n return keyName === key;\n }) as NodePath<t.ObjectProperty> | undefined;\n\n if (existing) return existing;\n\n const keyNode = t.isValidIdentifier(key)\n ? t.identifier(key)\n : t.stringLiteral(key);\n const newProp = t.objectProperty(keyNode, t.objectExpression([]));\n objPath.node.properties.push(newProp);\n\n // Return a fresh path for the newly pushed property\n const props = objPath.get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[];\n return props[props.length - 1] as NodePath<t.ObjectProperty>;\n };\n\n /** Recursively merge a JSON-like value into an ObjectExpression property path. */\n const mergeValueIntoProperty = (\n propPath: NodePath<t.ObjectProperty>,\n value: any,\n propKeyForLogs: string\n ) => {\n const valuePath = propPath.get('value') as NodePath;\n\n // Translation typed node → either update t() args or replace value\n if ((value as TypedNode)?.nodeType === NodeType.Translation) {\n const translationContent = value as TranslationContent;\n if (\n valuePath.isCallExpression() &&\n t.isIdentifier(valuePath.node.callee) &&\n valuePath.node.callee.name === 't'\n ) {\n // Replace argument with the full translations object (simpler and robust)\n const translationsObj = t.objectExpression(\n Object.entries(translationContent?.[NodeType.Translation] ?? {}).map(\n ([langKey, langValue]) =>\n t.objectProperty(\n t.isValidIdentifier(langKey)\n ? t.identifier(langKey)\n : t.stringLiteral(langKey),\n buildValueNodeFromData(langValue)\n )\n )\n );\n\n if (isPerLocaleDeclarationFile && typeof locale === 'string') {\n const localized =\n translationContent?.[NodeType.Translation]?.[locale];\n if (localized !== undefined) {\n valuePath.replaceWith(buildValueNodeFromData(localized));\n return;\n }\n }\n\n (valuePath.node as t.CallExpression).arguments = [translationsObj];\n return;\n }\n\n // Otherwise, replace with a fresh node\n valuePath.replaceWith(buildValueNodeFromData(value));\n return;\n }\n\n // Arrays → replace entirely\n if (Array.isArray(value)) {\n valuePath.replaceWith(buildValueNodeFromData(value));\n return;\n }\n\n // Objects → ensure object expression and recurse into each key\n if (value && typeof value === 'object') {\n if (!valuePath.isObjectExpression()) {\n valuePath.replaceWith(t.objectExpression([]));\n }\n const objPath = valuePath as NodePath<t.ObjectExpression>;\n for (const [k, v] of Object.entries(value)) {\n const childProp = ensureObjectProperty(objPath, k);\n mergeValueIntoProperty(childProp, v, `${propKeyForLogs}.${k}`);\n }\n return;\n }\n\n // Primitives → replace\n valuePath.replaceWith(buildValueNodeFromData(value));\n return;\n };\n\n // Apply updates to each entry specified in the JSON (now supports deep nesting)\n for (const [entryKeyToUpdate, newEntryData] of Object.entries(\n updatesToApply\n )) {\n let targetPropertyPath = (\n contentObjectPath.get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[]\n ).find((propPath) => {\n if (!propPath.isObjectProperty()) return false;\n const propNode = propPath.node;\n const keyName = t.isIdentifier(propNode.key)\n ? propNode.key.name\n : t.isStringLiteral(propNode.key)\n ? propNode.key.value\n : null;\n return keyName === entryKeyToUpdate;\n }) as NodePath<t.ObjectProperty> | undefined;\n\n if (!targetPropertyPath) {\n const keyNode = t.isValidIdentifier(entryKeyToUpdate)\n ? t.identifier(entryKeyToUpdate)\n : t.stringLiteral(entryKeyToUpdate);\n // By default create an empty object; merge will replace if needed\n const newProperty = t.objectProperty(keyNode, t.objectExpression([]));\n contentObjectPath.node.properties.push(newProperty);\n const props = contentObjectPath.get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[];\n targetPropertyPath = props[\n props.length - 1\n ] as NodePath<t.ObjectProperty>;\n }\n\n mergeValueIntoProperty(targetPropertyPath, newEntryData, entryKeyToUpdate);\n }\n\n // Generate JavaScript/TypeScript code from the modified AST\n const generatedCode = generate.generate(ast, {\n retainLines: true,\n comments: true,\n jsescOption: {\n minimal: true, // This ensures Unicode characters are not escaped\n },\n }).code;\n\n let finalCode = generatedCode;\n\n finalCode = await formatCode(filePath, finalCode);\n\n // Write the modified code back to the file\n try {\n await writeFile(filePath, finalCode, 'utf-8');\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAA0B;AAC1B,kBAA6B;AAE7B,oBAA+B;AAC/B,QAAmB;AACnB,oBAAqC;AACrC,mBAA0B;AAC1B,kBAKO;AACP,gBAA2B;AAC3B,sBAAoC;AACpC,kBAAwB;AACxB,+CAAkD;AAClD,wBAA2B;AAQpB,MAAM,cAAc,OACzB,UACA,eACkB;AAElB,QAAM,oBAAoB,CAAC,QAAiB;AAC1C,UAAM,YAAY;AAClB,QAAI,OAAO,cAAc,WAAY,QAAO;AAC5C,QAAI,WAAW,SAAS;AACtB,UAAI,OAAO,UAAU,YAAY,WAAY,QAAO,UAAU;AAC9D,UAAI,OAAO,UAAU,SAAS,YAAY;AACxC,eAAO,UAAU,QAAQ;AAC3B,UAAI,OAAO,UAAU,SAAS,aAAa;AACzC,eAAO,UAAU,QAAQ;AAAA,IAC7B;AACA,QAAI,OAAO,WAAW,aAAa,WAAY,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AA,MAClD,OAAO;AAAA,IACT,CAAC;AACD,UAAM,IAAI,MAAM,gCAAgC,QAAQ,KAAK,IAAI,OAAO,EAAE;AAAA,EAC5E;AACF;","names":["configuration"]}
@@ -2,7 +2,7 @@ import {
2
2
  getAppLogger,
3
3
  getConfiguration
4
4
  } from "@intlayer/config";
5
- import { basename, relative } from "path";
5
+ import { basename } from "path";
6
6
  import { watch as chokidarWatch } from "chokidar";
7
7
  import { getBuiltDictionariesPath } from "../getBuiltDictionariesPath.mjs";
8
8
  import { listDictionaries } from "../listDictionariesPath.mjs";
@@ -14,24 +14,21 @@ import {
14
14
  createModuleAugmentation,
15
15
  createTypes
16
16
  } from "../transpiler/dictionary_to_type/index.mjs";
17
+ import { formatPath } from "../utils/formatter.mjs";
17
18
  const recentlyAddedFiles = /* @__PURE__ */ new Set();
18
19
  const handleAdditionalContentDeclarationFile = async (filePath, configuration) => {
19
20
  const config = configuration ?? getConfiguration();
20
21
  const appLogger = getAppLogger(config);
21
- const { content } = config;
22
- appLogger(
23
- `Additional file detected: ${relative(content.baseDir, filePath)}`,
24
- {
25
- isVerbose: true
26
- }
27
- );
22
+ appLogger(`Additional file detected: ${formatPath(filePath)}`, {
23
+ isVerbose: true
24
+ });
28
25
  const localeDictionaries = await loadLocalDictionaries(filePath);
29
- const dictionariesOutput = await buildDictionary(localeDictionaries);
26
+ const dictionariesOutput = await buildDictionary(localeDictionaries, config);
30
27
  const dictionariesPaths = Object.values(
31
28
  dictionariesOutput?.mergedDictionaries ?? {}
32
29
  ).map((dictionary) => dictionary.dictionaryPath);
33
- createTypes(dictionariesPaths);
34
- createDictionaryEntryPoint();
30
+ await createTypes(dictionariesPaths);
31
+ await createDictionaryEntryPoint();
35
32
  appLogger("Dictionaries built", {
36
33
  isVerbose: true
37
34
  });
@@ -43,22 +40,21 @@ const handleAdditionalContentDeclarationFile = async (filePath, configuration) =
43
40
  const handleUnlikedContentDeclarationFile = async (filePath, configuration) => {
44
41
  const config = configuration ?? getConfiguration();
45
42
  const appLogger = getAppLogger(config);
46
- const { content } = config;
47
- appLogger(`Unlinked detected: ${relative(content.baseDir, filePath)}`, {
43
+ appLogger(`Unlinked detected: ${formatPath(filePath)}`, {
48
44
  isVerbose: true
49
45
  });
50
46
  const files = listDictionaries(configuration);
51
47
  const localeDictionaries = await loadLocalDictionaries(files);
52
- const dictionariesOutput = await buildDictionary(localeDictionaries);
48
+ const dictionariesOutput = await buildDictionary(localeDictionaries, config);
53
49
  const dictionariesPaths = Object.values(
54
50
  dictionariesOutput?.mergedDictionaries ?? {}
55
51
  ).map((dictionary) => dictionary.dictionaryPath);
56
- createTypes(dictionariesPaths);
57
- createDictionaryEntryPoint();
52
+ await createTypes(dictionariesPaths);
53
+ await createDictionaryEntryPoint();
58
54
  appLogger("Dictionaries rebuilt", {
59
55
  isVerbose: true
60
56
  });
61
- createModuleAugmentation();
57
+ await createModuleAugmentation();
62
58
  appLogger("Module augmentation built", {
63
59
  isVerbose: true
64
60
  });
@@ -66,12 +62,11 @@ const handleUnlikedContentDeclarationFile = async (filePath, configuration) => {
66
62
  const handleContentDeclarationFileChange = async (filePath, configuration) => {
67
63
  const config = configuration ?? getConfiguration();
68
64
  const appLogger = getAppLogger(config);
69
- const { content } = config;
70
- appLogger(`Change detected: ${relative(content.baseDir, filePath)}`, {
65
+ appLogger(`Change detected: ${formatPath(filePath)}`, {
71
66
  isVerbose: true
72
67
  });
73
68
  const localeDictionaries = await loadLocalDictionaries(filePath);
74
- const dictionariesOutput = await buildDictionary(localeDictionaries);
69
+ const dictionariesOutput = await buildDictionary(localeDictionaries, config);
75
70
  const updatedDictionariesPaths = Object.values(
76
71
  dictionariesOutput?.mergedDictionaries ?? {}
77
72
  ).map((dictionary) => dictionary.dictionaryPath);
@@ -83,7 +78,7 @@ const handleContentDeclarationFileChange = async (filePath, configuration) => {
83
78
  if (updatedDictionariesPaths.some(
84
79
  (updatedDictionaryPath) => !allDictionariesPaths.includes(updatedDictionaryPath)
85
80
  )) {
86
- createDictionaryEntryPoint();
81
+ await createDictionaryEntryPoint();
87
82
  appLogger("Dictionary list built", {
88
83
  isVerbose: true
89
84
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import {\n GetConfigurationOptions,\n type IntlayerConfig,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { basename, relative } from 'path';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { getBuiltDictionariesPath } from '../getBuiltDictionariesPath';\nimport { listDictionaries } from '../listDictionariesPath';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { prepareIntlayer } from '../prepareIntlayer';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from '../transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createModuleAugmentation,\n createTypes,\n} from '../transpiler/dictionary_to_type/index';\n\nconst recentlyAddedFiles = new Set<string>();\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const config = configuration ?? getConfiguration();\n const appLogger = getAppLogger(config);\n const { content } = config;\n\n // Process the file with the functionToRun\n appLogger(\n `Additional file detected: ${relative(content.baseDir, filePath)}`,\n {\n isVerbose: true,\n }\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint();\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleUnlikedContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const config = configuration ?? getConfiguration();\n const appLogger = getAppLogger(config);\n const { content } = config;\n\n // Process the file with the functionToRun\n appLogger(`Unlinked detected: ${relative(content.baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const files: string[] = listDictionaries(configuration);\n\n const localeDictionaries = await loadLocalDictionaries(files);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint();\n\n appLogger('Dictionaries rebuilt', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const config = configuration ?? getConfiguration();\n const appLogger = getAppLogger(config);\n const { content } = config;\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${relative(content.baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries);\n const updatedDictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n const allDictionariesPaths: string[] = getBuiltDictionariesPath();\n\n createTypes(updatedDictionariesPaths);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some(\n (updatedDictionaryPath) =>\n !allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n createDictionaryEntryPoint();\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n }\n};\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n configOptions?: GetConfigurationOptions;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration = options?.configuration ?? getConfiguration();\n const appLogger = getAppLogger(configuration);\n\n const { watch: isWatchMode, watchedFilesPatternWithPath } =\n configuration.content;\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('add', async (filePath) => {\n const fileName = basename(filePath);\n recentlyAddedFiles.add(fileName);\n\n await handleAdditionalContentDeclarationFile(filePath, configuration);\n\n setTimeout(() => recentlyAddedFiles.delete(fileName), 1000); // Allow time for unlink to trigger if it's a move\n })\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('unlink', async (filePath) => {\n setTimeout(async () => {\n const fileName = basename(filePath);\n\n if (recentlyAddedFiles.has(fileName)) {\n // The file was moved, so ignore unlink\n return;\n }\n\n await handleUnlikedContentDeclarationFile(filePath, configuration);\n }, 300); // Allow time for unlink to trigger if it's a move\n })\n .on('error', async (error) => {\n appLogger('Watcher error: ' + error, {\n level: 'error',\n });\n\n appLogger('Restarting watcher');\n\n await prepareIntlayer(configuration);\n });\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n\n await prepareIntlayer(configuration);\n\n if (configuration.content.watch || options.persistent) {\n // Start watching (assuming watch is also async)\n watch({ ...options, configuration });\n }\n};\n"],"mappings":"AAAA;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAU,gBAAgB;AAEnC,SAA+B,SAAS,qBAAqB;AAC7D,SAAS,gCAAgC;AACzC,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,MAAM,qBAAqB,oBAAI,IAAY;AAEpC,MAAM,yCAAyC,OACpD,UACA,kBACG;AACH,QAAM,SAAS,iBAAiB,iBAAiB;AACjD,QAAM,YAAY,aAAa,M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AAElC,UAAI,mBAAmB,IAAI,QAAQ,GAAG;AAEpC;AAAA,MACF;AAEA,YAAM,oCAAoC,UAAU,aAAa;AAAA,IACnE,GAAG,GAAG;AAAA,EACR,CAAC,EACA,GAAG,SAAS,OAAO,UAAU;AAC5B,cAAU,oBAAoB,OAAO;AAAA,MACnC,OAAO;AAAA,IACT,CAAC;AAED,cAAU,oBAAoB;AAE9B,UAAM,gBAAgB,aAAa;AAAA,EACrC,CAAC;AACL;AAEO,MAAM,wBAAwB,OAAO,YAA2B;AACrE,QAAM,gBACJ,SAAS,iBAAiB,iBAAiB,SAAS,aAAa;AAEnE,QAAM,gBAAgB,aAAa;AAEnC,MAAI,cAAc,QAAQ,SAAS,QAAQ,YAAY;AAErD,UAAM,EAAE,GAAG,SAAS,cAAc,CAAC;AAAA,EACrC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import {\n GetConfigurationOptions,\n type IntlayerConfig,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { basename } from 'path';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { getBuiltDictionariesPath } from '../getBuiltDictionariesPath';\nimport { listDictionaries } from '../listDictionariesPath';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { prepareIntlayer } from '../prepareIntlayer';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from '../transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createModuleAugmentation,\n createTypes,\n} from '../transpiler/dictionary_to_type/index';\nimport { formatPath } from '../utils/formatter';\n\nconst recentlyAddedFiles = new Set<string>();\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const config = configuration ?? getConfiguration();\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Additional file detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n await createTypes(dictionariesPaths);\n\n await createDictionaryEntryPoint();\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleUnlikedContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const config = configuration ?? getConfiguration();\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Unlinked detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const files: string[] = listDictionaries(configuration);\n\n const localeDictionaries = await loadLocalDictionaries(files);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n await createTypes(dictionariesPaths);\n\n await createDictionaryEntryPoint();\n\n appLogger('Dictionaries rebuilt', {\n isVerbose: true,\n });\n\n await createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const config = configuration ?? getConfiguration();\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n const updatedDictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n const allDictionariesPaths: string[] = getBuiltDictionariesPath();\n\n createTypes(updatedDictionariesPaths);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some(\n (updatedDictionaryPath) =>\n !allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n await createDictionaryEntryPoint();\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n }\n};\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n configOptions?: GetConfigurationOptions;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration = options?.configuration ?? getConfiguration();\n const appLogger = getAppLogger(configuration);\n\n const { watch: isWatchMode, watchedFilesPatternWithPath } =\n configuration.content;\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('add', async (filePath) => {\n const fileName = basename(filePath);\n recentlyAddedFiles.add(fileName);\n\n await handleAdditionalContentDeclarationFile(filePath, configuration);\n\n setTimeout(() => recentlyAddedFiles.delete(fileName), 1000); // Allow time for unlink to trigger if it's a move\n })\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('unlink', async (filePath) => {\n setTimeout(async () => {\n const fileName = basename(filePath);\n\n if (recentlyAddedFiles.has(fileName)) {\n // The file was moved, so ignore unlink\n return;\n }\n\n await handleUnlikedContentDeclarationFile(filePath, configuration);\n }, 300); // Allow time for unlink to trigger if it's a move\n })\n .on('error', async (error) => {\n appLogger('Watcher error: ' + error, {\n level: 'error',\n });\n\n appLogger('Restarting watcher');\n\n await prepareIntlayer(configuration);\n });\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n\n await prepareIntlayer(configuration);\n\n if (configuration.content.watch || options.persistent) {\n // Start watching (assuming watch is also async)\n watch({ ...options, configuration });\n }\n};\n"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AC7B,UAAM,WAAW,SAAS,QAAQ;AAClC,uBAAmB,IAAI,QAAQ;AAE/B,UAAM,uCAAuC,UAAU,aAAa;AAEpE,eAAW,MAAM,mBAAmB,OAAO,QAAQ,GAAG,GAAI;AAAA,EAC5D,CAAC,EACA;AAAA,IACC;AAAA,IACA,OAAO,aACL,MAAM,mCAAmC,UAAU,aAAa;AAAA,EACpE,EACC,GAAG,UAAU,OAAO,aAAa;AAChC,eAAW,YAAY;AACrB,YAAM,WAAW,SAAS,QAAQ;AAElC,UAAI,mBAAmB,IAAI,QAAQ,GAAG;AAEpC;AAAA,MACF;AAEA,YAAM,oCAAoC,UAAU,aAAa;AAAA,IACnE,GAAG,GAAG;AAAA,EACR,CAAC,EACA,GAAG,SAAS,OAAO,UAAU;AAC5B,cAAU,oBAAoB,OAAO;AAAA,MACnC,OAAO;AAAA,IACT,CAAC;AAED,cAAU,oBAAoB;AAE9B,UAAM,gBAAgB,aAAa;AAAA,EACrC,CAAC;AACL;AAEO,MAAM,wBAAwB,OAAO,YAA2B;AACrE,QAAM,gBACJ,SAAS,iBAAiB,iBAAiB,SAAS,aAAa;AAEnE,QAAM,gBAAgB,aAAa;AAEnC,MAAI,cAAc,QAAQ,SAAS,QAAQ,YAAY;AAErD,UAAM,EAAE,GAAG,SAAS,cAAc,CAAC;AAAA,EACrC;AACF;","names":[]}
@@ -1,8 +1,12 @@
1
1
  import { getDictionaryAPI, getOAuthAPI } from "@intlayer/api";
2
- import { getAppLogger, getConfiguration } from "@intlayer/config";
3
- import pLimit from "p-limit";
4
- import { logger } from "./log.mjs";
5
- const fetchDistantDictionaries = async (options) => {
2
+ import {
3
+ ANSIColors,
4
+ colorize,
5
+ getAppLogger,
6
+ getConfiguration
7
+ } from "@intlayer/config";
8
+ import { parallelize } from "./utils/parallelize.mjs";
9
+ const fetchDistantDictionaries = async (options, onStatusUpdate) => {
6
10
  const config = getConfiguration();
7
11
  const appLogger = getAppLogger(config);
8
12
  try {
@@ -17,13 +21,12 @@ const fetchDistantDictionaries = async (options) => {
17
21
  const oAuth2TokenResult = await authAPI.getOAuth2AccessToken();
18
22
  const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
19
23
  const distantDictionariesKeys = options.dictionaryKeys;
20
- const limit = pLimit(5);
21
24
  const processDictionary = async (dictionaryKey) => {
22
- logger.updateStatus([
25
+ onStatusUpdate?.([
23
26
  {
24
27
  dictionaryKey,
25
- type: "distant",
26
- status: { status: "fetching" }
28
+ type: "remote",
29
+ status: "fetching"
27
30
  }
28
31
  ]);
29
32
  try {
@@ -42,42 +45,35 @@ const fetchDistantDictionaries = async (options) => {
42
45
  if (!distantDictionary) {
43
46
  throw new Error(`Dictionary ${dictionaryKey} not found on remote`);
44
47
  }
45
- logger.updateStatus([
46
- { dictionaryKey, type: "distant", status: { status: "imported" } }
48
+ onStatusUpdate?.([
49
+ { dictionaryKey, type: "remote", status: "fetched" }
47
50
  ]);
48
51
  return distantDictionary;
49
52
  } catch (error) {
50
- logger.updateStatus([
53
+ onStatusUpdate?.([
51
54
  {
52
55
  dictionaryKey,
53
- type: "distant",
54
- status: {
55
- status: "error",
56
- error,
57
- errorMessage: `${options?.logPrefix ?? ""}Error fetching dictionary ${dictionaryKey}: ${error}`
58
- }
56
+ type: "remote",
57
+ status: "error",
58
+ error: `Error fetching dictionary ${dictionaryKey}: ${error}`
59
59
  }
60
60
  ]);
61
61
  return void 0;
62
62
  }
63
63
  };
64
- const fetchPromises = distantDictionariesKeys.map(
65
- (dictionaryKey) => limit(async () => await processDictionary(dictionaryKey))
64
+ const result = await parallelize(
65
+ distantDictionariesKeys,
66
+ async (dictionaryKey) => await processDictionary(dictionaryKey)
66
67
  );
67
- const result = await Promise.all(fetchPromises);
68
- const statuses = logger.getStatuses();
69
- for (const statusObj of statuses) {
70
- const currentState = statusObj.state.find((s) => s.type === "distant");
71
- if (currentState && currentState.errorMessage) {
72
- appLogger(currentState.errorMessage, { level: "error" });
73
- }
74
- }
75
68
  const filteredResult = result.filter(
76
69
  (dict) => dict !== void 0
77
70
  );
78
71
  return filteredResult;
79
72
  } catch (error) {
80
- appLogger(error, { level: "error" });
73
+ appLogger(
74
+ `${colorize("\u2717", ANSIColors.RED)} Failed to fetch distant dictionaries`,
75
+ { level: "error" }
76
+ );
81
77
  return [];
82
78
  }
83
79
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fetchDistantDictionaries.ts"],"sourcesContent":["import { getDictionaryAPI, getOAuthAPI } from '@intlayer/api';\n// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { getAppLogger, getConfiguration } from '@intlayer/config';\nimport pLimit from 'p-limit';\nimport { logger } from './log';\n\ntype FetchDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n logPrefix?: string;\n};\n\n/**\n * Fetch distant dictionaries and update the logger with their statuses.\n */\nexport const fetchDistantDictionaries = async (\n options: FetchDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n const config = getConfiguration();\n const appLogger = getAppLogger(config);\n try {\n const { clientId, clientSecret } = config.editor;\n const authAPI = getOAuthAPI(config);\n const dictionaryAPI = getDictionaryAPI(undefined, config);\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 oAuth2TokenResult = await authAPI.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n const distantDictionariesKeys = options.dictionaryKeys;\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Limit the number of concurrent requests\n\n const processDictionary = async (\n dictionaryKey: string\n ): Promise<DictionaryAPI | undefined> => {\n logger.updateStatus([\n {\n dictionaryKey,\n type: 'distant',\n status: { status: 'fetching' },\n },\n ]);\n\n try {\n // Fetch the dictionary\n const getDictionaryResult = await dictionaryAPI.getDictionary(\n 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(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n logger.updateStatus([\n { dictionaryKey, type: 'distant', status: { status: 'imported' } },\n ]);\n\n return distantDictionary;\n } catch (error) {\n logger.updateStatus([\n {\n dictionaryKey,\n type: 'distant',\n status: {\n status: 'error',\n error: error as Error,\n errorMessage: `${options?.logPrefix ?? ''}Error fetching dictionary ${dictionaryKey}: ${error}`,\n },\n },\n ]);\n return undefined;\n }\n };\n\n const fetchPromises = distantDictionariesKeys.map((dictionaryKey) =>\n limit(async () => await processDictionary(dictionaryKey))\n );\n\n const result = await Promise.all(fetchPromises);\n\n // Output any error messages\n const statuses = logger.getStatuses();\n for (const statusObj of statuses) {\n const currentState = statusObj.state.find((s) => s.type === 'distant');\n if (currentState && currentState.errorMessage) {\n appLogger(currentState.errorMessage, { level: 'error' });\n }\n }\n\n // Remove undefined values\n const filteredResult = result.filter(\n (dict): dict is DictionaryAPI => dict !== undefined\n );\n\n return filteredResult;\n } catch (error) {\n appLogger(error, { level: 'error' });\n return [];\n }\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,mBAAmB;AAG9C,SAAS,cAAc,wBAAwB;AAC/C,OAAO,YAAY;AACnB,SAAS,cAAc;AAWhB,MAAM,2BAA2B,OACtC,YAC6B;AAC7B,QAAM,SAAS,iBAAiB;AAChC,QAAM,YAAY,aAAa,MAAM;AACrC,MAAI;AACF,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAC1C,UAAM,UAAU,YAAY,MAAM;AAClC,UAAM,gBAAgB,iBAAiB,QAAW,MAAM;AAExD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,MAAM,QAAQ,qBAAqB;AAE7D,UAAM,oBAAoB,kBAAkB,MAAM;AAEl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AAa,cAAc,EAAE,OAAO,QAAQ,CAAC;AAAA,MACzD;AAAA,IACF;AAGA,UAAM,iBAAiB,OAAO;AAAA,MAC5B,CAAC,SAAgC,SAAS;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,cAAU,OAAO,EAAE,OAAO,QAAQ,CAAC;AACnC,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/fetchDistantDictionaries.ts"],"sourcesContent":["import { getDictionaryAPI, getOAuthAPI } from '@intlayer/api';\n// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport {\n ANSIColors,\n colorize,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { DictionariesStatus } from './loadDictionaries';\nimport { parallelize } from './utils/parallelize';\n\ntype FetchDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n logPrefix?: string;\n};\n\n/**\n * Fetch distant dictionaries and update the logger with their statuses.\n */\nexport const fetchDistantDictionaries = async (\n options: FetchDistantDictionariesOptions,\n onStatusUpdate?: (status: DictionariesStatus[]) => void\n): Promise<DictionaryAPI[]> => {\n const config = getConfiguration();\n const appLogger = getAppLogger(config);\n try {\n const { clientId, clientSecret } = config.editor;\n const authAPI = getOAuthAPI(config);\n const dictionaryAPI = getDictionaryAPI(undefined, config);\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 oAuth2TokenResult = await authAPI.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n const distantDictionariesKeys = options.dictionaryKeys;\n\n // Process dictionaries in parallel with a concurrency limit\n\n const processDictionary = async (\n dictionaryKey: string\n ): Promise<DictionaryAPI | undefined> => {\n onStatusUpdate?.([\n {\n dictionaryKey,\n type: 'remote',\n status: 'fetching',\n },\n ]);\n\n try {\n // Fetch the dictionary\n const getDictionaryResult = await dictionaryAPI.getDictionary(\n 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(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n onStatusUpdate?.([\n { dictionaryKey, type: 'remote', status: 'fetched' },\n ]);\n\n return distantDictionary;\n } catch (error) {\n onStatusUpdate?.([\n {\n dictionaryKey,\n type: 'remote',\n status: 'error',\n error: `Error fetching dictionary ${dictionaryKey}: ${error}`,\n },\n ]);\n return undefined;\n }\n };\n\n const result = await parallelize(\n distantDictionariesKeys,\n async (dictionaryKey) => await processDictionary(dictionaryKey)\n );\n\n // Remove undefined values\n const filteredResult = result.filter(\n (dict: DictionaryAPI | undefined): dict is DictionaryAPI =>\n dict !== undefined\n );\n\n return filteredResult;\n } catch (error) {\n appLogger(\n `${colorize('✗', ANSIColors.RED)} Failed to fetch distant dictionaries`,\n { level: 'error' }\n );\n return [];\n }\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,mBAAmB;AAG9C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,mBAAmB;AAWrB,MAAM,2BAA2B,OACtC,SACA,mBAC6B;AAC7B,QAAM,SAAS,iBAAiB;AAChC,QAAM,YAAY,aAAa,MAAM;AACrC,MAAI;AACF,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAC1C,UAAM,UAAU,YAAY,MAAM;AAClC,UAAM,gBAAgB,iBAAiB,QAAW,MAAM;AAExD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,MAAM,QAAQ,qBAAqB;AAE7D,UAAM,oBAAoB,kBAAkB,MAAM;AAElD,UAAM,0BAA0B,QAAQ;AAIxC,UAAM,oBAAoB,OACxB,kBACuC;AACvC,uBAAiB;AAAA,QACf;AAAA,UACE;AAAA,UACA,MAAM;AAAA,UACN,QAAQ;AAAA,QACV;AAAA,MACF,CAAC;AAED,UAAI;AAEF,cAAM,sBAAsB,MAAM,cAAc;AAAA,UAC9C;AAAA,UACA;AAAA,UACA;AAAA,YACE,GAAI,qBAAqB;AAAA,cACvB,SAAS;AAAA,gBACP,eAAe,UAAU,iBAAiB;AAAA,cAC5C;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAEA,cAAM,oBAAoB,oBAAoB;AAE9C,YAAI,CAAC,mBAAmB;AACtB,gBAAM,IAAI,MAAM,cAAc,aAAa,sBAAsB;AAAA,QACnE;AAEA,yBAAiB;AAAA,UACf,EAAE,eAAe,MAAM,UAAU,QAAQ,UAAU;AAAA,QACrD,CAAC;AAED,eAAO;AAAA,MACT,SAAS,OAAO;AACd,yBAAiB;AAAA,UACf;AAAA,YACE;AAAA,YACA,MAAM;AAAA,YACN,QAAQ;AAAA,YACR,OAAO,6BAA6B,aAAa,KAAK,KAAK;AAAA,UAC7D;AAAA,QACF,CAAC;AACD,eAAO;AAAA,MACT;AAAA,IACF;AAEA,UAAM,SAAS,MAAM;AAAA,MACnB;AAAA,MACA,OAAO,kBAAkB,MAAM,kBAAkB,aAAa;AAAA,IAChE;AAGA,UAAM,iBAAiB,OAAO;AAAA,MAC5B,CAAC,SACC,SAAS;AAAA,IACb;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd;AAAA,MACE,GAAG,SAAS,UAAK,WAAW,GAAG,CAAC;AAAA,MAChC,EAAE,OAAO,QAAQ;AAAA,IACnB;AACA,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
@@ -0,0 +1,21 @@
1
+ import { getIntlayerAPIProxy } from "@intlayer/api";
2
+ import { getConfiguration } from "@intlayer/config";
3
+ const fetchDistantDictionaryKeysAndUpdateTimestamp = async (configuration = getConfiguration()) => {
4
+ const { clientId, clientSecret } = configuration.editor;
5
+ if (!clientId || !clientSecret) {
6
+ throw new Error(
7
+ "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
8
+ );
9
+ }
10
+ const intlayerAPI = getIntlayerAPIProxy(void 0, configuration);
11
+ const getDictionariesKeysResult = await intlayerAPI.dictionary.getDictionariesUpdateTimestamp();
12
+ if (!getDictionariesKeysResult.data) {
13
+ throw new Error("No distant dictionaries found");
14
+ }
15
+ const distantDictionariesUpdateTimeStamp = getDictionariesKeysResult.data;
16
+ return distantDictionariesUpdateTimeStamp;
17
+ };
18
+ export {
19
+ fetchDistantDictionaryKeysAndUpdateTimestamp
20
+ };
21
+ //# sourceMappingURL=fetchDistantDictionaryKeysAndUpdateTimestamp.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/fetchDistantDictionaryKeysAndUpdateTimestamp.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\nimport { getConfiguration, type IntlayerConfig } from '@intlayer/config';\n\nexport const fetchDistantDictionaryKeysAndUpdateTimestamp = async (\n configuration: IntlayerConfig = getConfiguration()\n): Promise<Record<string, number>> => {\n const { clientId, clientSecret } = configuration.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 = getIntlayerAPIProxy(undefined, configuration);\n\n // Get the list of dictionary keys\n const getDictionariesKeysResult =\n await intlayerAPI.dictionary.getDictionariesUpdateTimestamp();\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n const distantDictionariesUpdateTimeStamp: Record<string, number> =\n getDictionariesKeysResult.data;\n\n // Apply any filtering if needed\n return distantDictionariesUpdateTimeStamp;\n};\n"],"mappings":"AAAA,SAAS,2BAA2B;AACpC,SAAS,wBAA6C;AAE/C,MAAM,+CAA+C,OAC1D,gBAAgC,iBAAiB,MACb;AACpC,QAAM,EAAE,UAAU,aAAa,IAAI,cAAc;AAEjD,MAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,cAAc,oBAAoB,QAAW,aAAa;AAGhE,QAAM,4BACJ,MAAM,YAAY,WAAW,+BAA+B;AAE9D,MAAI,CAAC,0BAA0B,MAAM;AACnC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AAEA,QAAM,qCACJ,0BAA0B;AAG5B,SAAO;AACT;","names":[]}
@@ -0,0 +1,40 @@
1
+ import configuration from "@intlayer/config/built";
2
+ import {
3
+ colorizeKey,
4
+ colorizePath,
5
+ getAppLogger
6
+ } from "@intlayer/config/client";
7
+ import { formatPath } from "./utils/formatter.mjs";
8
+ const filterInvalidDictionaries = (dictionaries) => {
9
+ const appLogger = getAppLogger(configuration);
10
+ return (dictionaries ?? [])?.filter((dictionary) => {
11
+ if (!dictionary) return false;
12
+ const isLocal = Boolean(dictionary.location === "locale");
13
+ const location = isLocal ? "Local" : "Remote";
14
+ const hasKey = Boolean(dictionary.key);
15
+ const hasContent = Boolean(dictionary.content);
16
+ if (!hasKey) {
17
+ appLogger(`${location} dictionary has no key`, {
18
+ level: "error"
19
+ });
20
+ appLogger(JSON.stringify(dictionary, null, 2), {
21
+ level: "error"
22
+ });
23
+ return false;
24
+ }
25
+ if (!hasContent) {
26
+ appLogger(
27
+ `${location} dictionary ${colorizeKey(dictionary.key)} has no content - ${dictionary.filePath ? formatPath(dictionary.filePath) : colorizePath("Remote")}`,
28
+ {
29
+ level: "error"
30
+ }
31
+ );
32
+ return false;
33
+ }
34
+ return true;
35
+ });
36
+ };
37
+ export {
38
+ filterInvalidDictionaries
39
+ };
40
+ //# sourceMappingURL=filterInvalidDictionaries.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/filterInvalidDictionaries.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n colorizeKey,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport { formatPath } from './utils/formatter';\n\nexport const filterInvalidDictionaries = (\n dictionaries: (Dictionary | undefined)[] | undefined\n): Dictionary[] => {\n const appLogger = getAppLogger(configuration);\n\n return (dictionaries ?? [])?.filter((dictionary) => {\n if (!dictionary) return false;\n\n const isLocal = Boolean(dictionary.location === 'locale');\n const location = isLocal ? 'Local' : 'Remote';\n const hasKey = Boolean(dictionary.key);\n const hasContent = Boolean(dictionary.content);\n\n if (!hasKey) {\n appLogger(`${location} dictionary has no key`, {\n level: 'error',\n });\n appLogger(JSON.stringify(dictionary, null, 2), {\n level: 'error',\n });\n return false;\n }\n\n if (!hasContent) {\n appLogger(\n `${location} dictionary ${colorizeKey(dictionary.key)} has no content - ${dictionary.filePath ? formatPath(dictionary.filePath) : colorizePath('Remote')}`,\n {\n level: 'error',\n }\n );\n return false;\n }\n\n return true;\n }) as Dictionary[];\n};\n"],"mappings":"AAAA,OAAO,mBAAmB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,kBAAkB;AAEpB,MAAM,4BAA4B,CACvC,iBACiB;AACjB,QAAM,YAAY,aAAa,aAAa;AAE5C,UAAQ,gBAAgB,CAAC,IAAI,OAAO,CAAC,eAAe;AAClD,QAAI,CAAC,WAAY,QAAO;AAExB,UAAM,UAAU,QAAQ,WAAW,aAAa,QAAQ;AACxD,UAAM,WAAW,UAAU,UAAU;AACrC,UAAM,SAAS,QAAQ,WAAW,GAAG;AACrC,UAAM,aAAa,QAAQ,WAAW,OAAO;AAE7C,QAAI,CAAC,QAAQ;AACX,gBAAU,GAAG,QAAQ,0BAA0B;AAAA,QAC7C,OAAO;AAAA,MACT,CAAC;AACD,gBAAU,KAAK,UAAU,YAAY,MAAM,CAAC,GAAG;AAAA,QAC7C,OAAO;AAAA,MACT,CAAC;AACD,aAAO;AAAA,IACT;AAEA,QAAI,CAAC,YAAY;AACf;AAAA,QACE,GAAG,QAAQ,eAAe,YAAY,WAAW,GAAG,CAAC,qBAAqB,WAAW,WAAW,WAAW,WAAW,QAAQ,IAAI,aAAa,QAAQ,CAAC;AAAA,QACxJ;AAAA,UACE,OAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,CAAC;AACH;","names":[]}
@@ -0,0 +1,18 @@
1
+ import { getConfiguration, normalizePath } from "@intlayer/config";
2
+ import fg from "fast-glob";
3
+ import { existsSync, mkdirSync } from "fs";
4
+ const getBuiltFetchDictionariesPath = (configuration = getConfiguration(), format = "esm") => {
5
+ const { fetchDictionariesDir, mainDir } = configuration.content;
6
+ if (!existsSync(mainDir)) {
7
+ mkdirSync(mainDir, { recursive: true });
8
+ }
9
+ const extension = format === "cjs" ? "cjs" : "mjs";
10
+ const dictionariesPath = fg.sync(
11
+ `${normalizePath(fetchDictionariesDir)}/**/*.${extension}`
12
+ );
13
+ return dictionariesPath;
14
+ };
15
+ export {
16
+ getBuiltFetchDictionariesPath
17
+ };
18
+ //# sourceMappingURL=getBuiltFetchDictionariesPath.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/getBuiltFetchDictionariesPath.ts"],"sourcesContent":["import { getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync } from 'fs';\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const getBuiltFetchDictionariesPath = (\n configuration = getConfiguration(),\n format: 'cjs' | 'esm' = 'esm'\n) => {\n const { fetchDictionariesDir, mainDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n\n const dictionariesPath: string[] = fg.sync(\n `${normalizePath(fetchDictionariesDir)}/**/*.${extension}`\n );\n\n return dictionariesPath;\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,qBAAqB;AAChD,OAAO,QAAQ;AACf,SAAS,YAAY,iBAAiB;AAK/B,MAAM,gCAAgC,CAC3C,gBAAgB,iBAAiB,GACjC,SAAwB,UACrB;AACH,QAAM,EAAE,sBAAsB,QAAQ,IAAI,cAAc;AAGxD,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,QAAM,mBAA6B,GAAG;AAAA,IACpC,GAAG,cAAc,oBAAoB,CAAC,SAAS,SAAS;AAAA,EAC1D;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,17 @@
1
+ import { getConfiguration, normalizePath } from "@intlayer/config";
2
+ import fg from "fast-glob";
3
+ import { existsSync, mkdirSync } from "fs";
4
+ const getBuiltRemoteDictionariesPath = (configuration = getConfiguration()) => {
5
+ const { remoteDictionariesDir, mainDir } = configuration.content;
6
+ if (!existsSync(mainDir)) {
7
+ mkdirSync(mainDir, { recursive: true });
8
+ }
9
+ const dictionariesPath = fg.sync(
10
+ `${normalizePath(remoteDictionariesDir)}/**/*.json`
11
+ );
12
+ return dictionariesPath;
13
+ };
14
+ export {
15
+ getBuiltRemoteDictionariesPath
16
+ };
17
+ //# sourceMappingURL=getBuiltRemoteDictionariesPath.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/getBuiltRemoteDictionariesPath.ts"],"sourcesContent":["import { getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync } from 'fs';\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const getBuiltRemoteDictionariesPath = (\n configuration = getConfiguration()\n) => {\n const { remoteDictionariesDir, mainDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = fg.sync(\n `${normalizePath(remoteDictionariesDir)}/**/*.json`\n );\n\n return dictionariesPath;\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,qBAAqB;AAChD,OAAO,QAAQ;AACf,SAAS,YAAY,iBAAiB;AAK/B,MAAM,iCAAiC,CAC5C,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,EAAE,uBAAuB,QAAQ,IAAI,cAAc;AAGzD,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,GAAG;AAAA,IACpC,GAAG,cAAc,qBAAqB,CAAC;AAAA,EACzC;AAEA,SAAO;AACT;","names":[]}
@@ -1,4 +1,3 @@
1
- import { checkDictionaryChanges } from "./checkDictionaryChanges.mjs";
2
1
  import {
3
2
  buildAndWatchIntlayer,
4
3
  handleAdditionalContentDeclarationFile,
@@ -7,10 +6,9 @@ import {
7
6
  } from "./chokidar/watcher.mjs";
8
7
  import { cleanOutputDir } from "./cleanOutputDir.mjs";
9
8
  import { fetchDistantDictionaries } from "./fetchDistantDictionaries.mjs";
10
- import { fetchDistantDictionaryKeys } from "./fetchDistantDictionaryKeys.mjs";
9
+ import { fetchDistantDictionaryKeysAndUpdateTimestamp } from "./fetchDistantDictionaryKeysAndUpdateTimestamp.mjs";
11
10
  import { getBuiltDictionariesPath } from "./getBuiltDictionariesPath.mjs";
12
11
  import { getBuiltUnmergedDictionariesPath } from "./getBuiltUnmergedDictionariesPath.mjs";
13
- import { getFilteredLocalesContent } from "./getFilteredLocalesContent.mjs";
14
12
  import { listDictionaries } from "./listDictionariesPath.mjs";
15
13
  import {
16
14
  listGitFiles,
@@ -18,8 +16,8 @@ import {
18
16
  } from "./listGitFiles.mjs";
19
17
  import {
20
18
  loadDictionaries,
21
- loadDistantDictionaries,
22
- loadLocalDictionaries
19
+ loadLocalDictionaries,
20
+ loadRemoteDictionaries
23
21
  } from "./loadDictionaries/index.mjs";
24
22
  import { mergeDictionaries } from "./mergeDictionaries.mjs";
25
23
  import { prepareContentDeclaration } from "./prepareContentDeclaration.mjs";
@@ -32,8 +30,10 @@ import {
32
30
  generateDictionaryListContent
33
31
  } from "./transpiler/dictionary_to_main/index.mjs";
34
32
  import { createModuleAugmentation } from "./transpiler/dictionary_to_type/createModuleAugmentation.mjs";
33
+ import { formatLocale, formatPath } from "./utils/formatter.mjs";
35
34
  import { getFileHash } from "./utils/getFileHash.mjs";
36
35
  import { kebabCaseToCamelCase } from "./utils/kebabCaseToCamelCase.mjs";
36
+ import { parallelize } from "./utils/parallelize.mjs";
37
37
  import { resolveObjectPromises } from "./utils/resolveObjectPromises.mjs";
38
38
  import { runOnce } from "./utils/runOnce.mjs";
39
39
  import { sortAlphabetically } from "./utils/sortAlphabetically.mjs";
@@ -43,17 +43,17 @@ import {
43
43
  export {
44
44
  buildAndWatchIntlayer,
45
45
  buildDictionary,
46
- checkDictionaryChanges,
47
46
  cleanOutputDir,
48
47
  createDictionaryEntryPoint,
49
48
  createModuleAugmentation,
50
49
  fetchDistantDictionaries,
51
- fetchDistantDictionaryKeys,
50
+ fetchDistantDictionaryKeysAndUpdateTimestamp,
51
+ formatLocale,
52
+ formatPath,
52
53
  generateDictionaryListContent,
53
54
  getBuiltDictionariesPath,
54
55
  getBuiltUnmergedDictionariesPath,
55
56
  getFileHash,
56
- getFilteredLocalesContent,
57
57
  handleAdditionalContentDeclarationFile,
58
58
  handleContentDeclarationFileChange,
59
59
  kebabCaseToCamelCase,
@@ -61,9 +61,10 @@ export {
61
61
  listGitFiles,
62
62
  listGitLines,
63
63
  loadDictionaries,
64
- loadDistantDictionaries,
65
64
  loadLocalDictionaries,
65
+ loadRemoteDictionaries,
66
66
  mergeDictionaries,
67
+ parallelize,
67
68
  prepareContentDeclaration,
68
69
  prepareIntlayer,
69
70
  processPerLocaleDictionary,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { checkDictionaryChanges } from './checkDictionaryChanges';\nexport {\n buildAndWatchIntlayer,\n handleAdditionalContentDeclarationFile,\n handleContentDeclarationFileChange,\n watch,\n} from './chokidar/watcher';\nexport { cleanOutputDir } from './cleanOutputDir';\nexport { fetchDistantDictionaries } from './fetchDistantDictionaries';\nexport { fetchDistantDictionaryKeys } from './fetchDistantDictionaryKeys';\nexport { getBuiltDictionariesPath } from './getBuiltDictionariesPath';\nexport { getBuiltUnmergedDictionariesPath } from './getBuiltUnmergedDictionariesPath';\nexport { getFilteredLocalesContent } from './getFilteredLocalesContent';\nexport { listDictionaries } from './listDictionariesPath';\nexport {\n listGitFiles,\n listGitLines,\n type DiffMode,\n type ListGitFilesOptions,\n type ListGitLinesOptions,\n} from './listGitFiles';\nexport {\n loadDictionaries,\n loadDistantDictionaries,\n loadLocalDictionaries,\n} from './loadDictionaries/index';\nexport { mergeDictionaries } from './mergeDictionaries';\nexport { prepareContentDeclaration } from './prepareContentDeclaration';\nexport { prepareIntlayer } from './prepareIntlayer';\nexport { processPerLocaleDictionary } from './processPerLocaleDictionary';\nexport { reduceDictionaryContent } from './reduceDictionaryContent/reduceDictionaryContent';\nexport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nexport {\n createDictionaryEntryPoint,\n generateDictionaryListContent,\n} from './transpiler/dictionary_to_main';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\nexport { getFileHash } from './utils/getFileHash';\nexport { kebabCaseToCamelCase } from './utils/kebabCaseToCamelCase';\nexport { resolveObjectPromises } from './utils/resolveObjectPromises';\nexport { runOnce } from './utils/runOnce';\nexport { sortAlphabetically } from './utils/sortAlphabetically';\nexport {\n writeContentDeclaration,\n type DictionaryStatus,\n} from './writeContentDeclaration';\n"],"mappings":"AAAA,SAAS,8BAA8B;AACvC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,gCAAgC;AACzC,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,wCAAwC;AACjD,SAAS,iCAAiC;AAC1C,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;AAClC,SAAS,iCAAiC;AAC1C,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C,SAAS,+BAA+B;AACxC,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,gCAAgC;AACzC,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AACrC,SAAS,6BAA6B;AACtC,SAAS,eAAe;AACxB,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,OAEK;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n buildAndWatchIntlayer,\n handleAdditionalContentDeclarationFile,\n handleContentDeclarationFileChange,\n watch,\n} from './chokidar/watcher';\nexport { cleanOutputDir } from './cleanOutputDir';\nexport { fetchDistantDictionaries } from './fetchDistantDictionaries';\nexport { fetchDistantDictionaryKeysAndUpdateTimestamp } from './fetchDistantDictionaryKeysAndUpdateTimestamp';\nexport { getBuiltDictionariesPath } from './getBuiltDictionariesPath';\nexport { getBuiltUnmergedDictionariesPath } from './getBuiltUnmergedDictionariesPath';\nexport { listDictionaries } from './listDictionariesPath';\nexport {\n listGitFiles,\n listGitLines,\n type DiffMode,\n type ListGitFilesOptions,\n type ListGitLinesOptions,\n} from './listGitFiles';\nexport {\n loadDictionaries,\n loadLocalDictionaries,\n loadRemoteDictionaries,\n} from './loadDictionaries/index';\nexport { mergeDictionaries } from './mergeDictionaries';\nexport { prepareContentDeclaration } from './prepareContentDeclaration';\nexport { prepareIntlayer } from './prepareIntlayer';\nexport { processPerLocaleDictionary } from './processPerLocaleDictionary';\nexport { reduceDictionaryContent } from './reduceDictionaryContent/reduceDictionaryContent';\nexport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nexport {\n createDictionaryEntryPoint,\n generateDictionaryListContent,\n} from './transpiler/dictionary_to_main';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\nexport { formatLocale, formatPath } from './utils/formatter';\nexport { getFileHash } from './utils/getFileHash';\nexport { kebabCaseToCamelCase } from './utils/kebabCaseToCamelCase';\nexport { parallelize } from './utils/parallelize';\nexport { resolveObjectPromises } from './utils/resolveObjectPromises';\nexport { runOnce } from './utils/runOnce';\nexport { sortAlphabetically } from './utils/sortAlphabetically';\nexport {\n writeContentDeclaration,\n type DictionaryStatus,\n} from './writeContentDeclaration';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,gCAAgC;AACzC,SAAS,oDAAoD;AAC7D,SAAS,gCAAgC;AACzC,SAAS,wCAAwC;AACjD,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;AAClC,SAAS,iCAAiC;AAC1C,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C,SAAS,+BAA+B;AACxC,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,gCAAgC;AACzC,SAAS,cAAc,kBAAkB;AACzC,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AACtC,SAAS,eAAe;AACxB,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,OAEK;","names":[]}
@@ -1,5 +1,5 @@
1
+ export * from "./loadContentDeclaration.mjs";
1
2
  export * from "./loadDictionaries.mjs";
2
- export * from "./loadDistantDictionaries.mjs";
3
3
  export * from "./loadLocalDictionaries.mjs";
4
- export * from "./loadContentDeclaration.mjs";
4
+ export * from "./loadRemoteDictionaries.mjs";
5
5
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/loadDictionaries/index.ts"],"sourcesContent":["export * from './loadDictionaries';\nexport * from './loadDistantDictionaries';\nexport * from './loadLocalDictionaries';\nexport * from './loadContentDeclaration';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/loadDictionaries/index.ts"],"sourcesContent":["export * from './loadContentDeclaration';\nexport * from './loadDictionaries';\nexport * from './loadLocalDictionaries';\nexport * from './loadRemoteDictionaries';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}