@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/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { getBuiltDictionariesPath } from '../../getBuiltDictionariesPath';\nimport { getBuiltDynamicDictionariesPath } from '../../getBuiltDynamicDictionariesPath';\nimport { getBuiltUnmergedDictionariesPath } from '../../getBuiltUnmergedDictionariesPath';\nimport { generateDictionaryListContent } from './generateDictionaryListContent';\n\nconst filterDictionaries = (paths: string[], keys?: string[]) => {\n if (!keys) return paths;\n return paths.filter((path) =>\n keys.some((key) => path.endsWith(`${key}.json`))\n );\n};\n\nconst writeDictionaryFiles = (\n paths: string[],\n fileName: string,\n format: 'cjs' | 'esm',\n configuration = getConfiguration()\n) => {\n const content = generateDictionaryListContent(paths, format, configuration);\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n\n const { mainDir } = configuration.content;\n\n writeFileSync(resolve(mainDir, `${fileName}.${extension}`), content);\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryEntryPoint = (\n configuration = getConfiguration(),\n dictionariesKeys?: string[],\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n) => {\n const { 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 = filterDictionaries(\n getBuiltDictionariesPath(configuration),\n dictionariesKeys\n );\n\n for (const format of formats) {\n writeDictionaryFiles(\n dictionariesPath,\n 'dictionaries',\n format,\n configuration\n );\n }\n\n const unmergedDictionariesPath =\n getBuiltUnmergedDictionariesPath(configuration);\n\n for (const format of formats) {\n writeDictionaryFiles(\n unmergedDictionariesPath,\n 'unmerged_dictionaries',\n format,\n configuration\n );\n }\n\n for (const format of formats) {\n const dynamicDictionariesPathCJS = getBuiltDynamicDictionariesPath(\n configuration,\n format\n );\n\n writeDictionaryFiles(\n dynamicDictionariesPathCJS,\n 'dynamic_dictionaries',\n format,\n configuration\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AACjC,gBAAqD;AACrD,kBAAwB;AACxB,sCAAyC;AACzC,6CAAgD;AAChD,8CAAiD;AACjD,2CAA8C;AAE9C,MAAM,qBAAqB,CAAC,OAAiB,SAAoB;AAC/D,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,MAAM;AAAA,IAAO,CAAC,SACnB,KAAK,KAAK,CAAC,QAAQ,KAAK,SAAS,GAAG,GAAG,OAAO,CAAC;AAAA,EACjD;AACF;AAEA,MAAM,uBAAuB,CAC3B,OACA,UACA,QACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,cAAU,oEAA8B,OAAO,QAAQ,aAAa;AAC1E,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,mCAAc,qBAAQ,SAAS,GAAG,QAAQ,IAAI,SAAS,EAAE,GAAG,OAAO;AACrE;AAKO,MAAM,6BAA6B,CACxC,oBAAgB,gCAAiB,GACjC,kBACA,UAA6B,CAAC,OAAO,KAAK,MACvC;AACH,QAAM,EAAE,QAAQ,IAAI,cAAc;AAGlC,MAAI,KAAC,sBAAW,OAAO,GAAG;AACxB,6BAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAAmB;AAAA,QACvB,0DAAyB,aAAa;AAAA,IACtC;AAAA,EACF;AAEA,aAAW,UAAU,SAAS;AAC5B;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,+BACJ,0EAAiC,aAAa;AAEhD,aAAW,UAAU,SAAS;AAC5B;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,aAAW,UAAU,SAAS;AAC5B,UAAM,iCAA6B;AAAA,MACjC;AAAA,MACA;AAAA,IACF;AAEA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getBuiltDictionariesPath } from '../../getBuiltDictionariesPath';\nimport { getBuiltDynamicDictionariesPath } from '../../getBuiltDynamicDictionariesPath';\nimport { getBuiltFetchDictionariesPath } from '../../getBuiltFetchDictionariesPath';\nimport { getBuiltRemoteDictionariesPath } from '../../getBuiltRemoteDictionariesPath';\nimport { getBuiltUnmergedDictionariesPath } from '../../getBuiltUnmergedDictionariesPath';\nimport { parallelize } from '../../utils/parallelize';\nimport { generateDictionaryListContent } from './generateDictionaryListContent';\n\nconst filterDictionaries = (paths: string[], keys?: string[]) => {\n if (!keys) return paths;\n return paths.filter((path) =>\n keys.some((key) => path.endsWith(`${key}.json`))\n );\n};\n\nconst writeDictionaryFiles = async (\n paths: string[],\n fileName: string,\n format: 'cjs' | 'esm',\n configuration = getConfiguration()\n) => {\n const content = generateDictionaryListContent(paths, format, configuration);\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n\n const { mainDir } = configuration.content;\n\n await writeFile(resolve(mainDir, `${fileName}.${extension}`), content);\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryEntryPoint = async (\n configuration = getConfiguration(),\n dictionariesKeys?: string[],\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n) => {\n const { mainDir } = configuration.content;\n\n await mkdir(mainDir, { recursive: true });\n\n const remoteDictionariesPath = getBuiltRemoteDictionariesPath(configuration);\n const dictionariesPath = filterDictionaries(\n getBuiltDictionariesPath(configuration),\n dictionariesKeys\n );\n const unmergedDictionariesPath =\n getBuiltUnmergedDictionariesPath(configuration);\n\n const writeOperations = [\n ...formats.map((format) => ({\n paths: remoteDictionariesPath,\n fileName: 'remote_dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: dictionariesPath,\n fileName: 'dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: unmergedDictionariesPath,\n fileName: 'unmerged_dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: getBuiltDynamicDictionariesPath(configuration, format),\n fileName: 'dynamic_dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: getBuiltFetchDictionariesPath(configuration, format),\n fileName: 'fetch_dictionaries' as const,\n format,\n })),\n ];\n\n await parallelize(writeOperations, async ({ paths, fileName, format }) =>\n writeDictionaryFiles(paths, fileName, format, configuration)\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AACjC,sBAAiC;AACjC,kBAAwB;AACxB,sCAAyC;AACzC,6CAAgD;AAChD,2CAA8C;AAC9C,4CAA+C;AAC/C,8CAAiD;AACjD,yBAA4B;AAC5B,2CAA8C;AAE9C,MAAM,qBAAqB,CAAC,OAAiB,SAAoB;AAC/D,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,MAAM;AAAA,IAAO,CAAC,SACnB,KAAK,KAAK,CAAC,QAAQ,KAAK,SAAS,GAAG,GAAG,OAAO,CAAC;AAAA,EACjD;AACF;AAEA,MAAM,uBAAuB,OAC3B,OACA,UACA,QACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,cAAU,oEAA8B,OAAO,QAAQ,aAAa;AAC1E,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,YAAM,+BAAU,qBAAQ,SAAS,GAAG,QAAQ,IAAI,SAAS,EAAE,GAAG,OAAO;AACvE;AAKO,MAAM,6BAA6B,OACxC,oBAAgB,gCAAiB,GACjC,kBACA,UAA6B,CAAC,OAAO,KAAK,MACvC;AACH,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,YAAM,uBAAM,SAAS,EAAE,WAAW,KAAK,CAAC;AAExC,QAAM,6BAAyB,sEAA+B,aAAa;AAC3E,QAAM,mBAAmB;AAAA,QACvB,0DAAyB,aAAa;AAAA,IACtC;AAAA,EACF;AACA,QAAM,+BACJ,0EAAiC,aAAa;AAEhD,QAAM,kBAAkB;AAAA,IACtB,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,WAAO,wEAAgC,eAAe,MAAM;AAAA,MAC5D,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,WAAO,oEAA8B,eAAe,MAAM;AAAA,MAC1D,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,YAAM;AAAA,IAAY;AAAA,IAAiB,OAAO,EAAE,OAAO,UAAU,OAAO,MAClE,qBAAqB,OAAO,UAAU,QAAQ,aAAa;AAAA,EAC7D;AACF;","names":[]}
@@ -34,7 +34,7 @@ __export(createModuleAugmentation_exports, {
34
34
  module.exports = __toCommonJS(createModuleAugmentation_exports);
35
35
  var import_config = require("@intlayer/config");
36
36
  var import_fast_glob = __toESM(require("fast-glob"));
37
- var import_fs = require("fs");
37
+ var import_promises = require("fs/promises");
38
38
  var import_path = require("path");
39
39
  var import_getFileHash = require('../../utils/getFileHash.cjs');
40
40
  var import_kebabCaseToCamelCase = require('../../utils/kebabCaseToCamelCase.cjs');
@@ -90,11 +90,9 @@ ${formattedDictionaryMap}
90
90
  fileContent += `}`;
91
91
  return fileContent;
92
92
  };
93
- const createModuleAugmentation = (configuration = (0, import_config.getConfiguration)()) => {
93
+ const createModuleAugmentation = async (configuration = (0, import_config.getConfiguration)()) => {
94
94
  const { moduleAugmentationDir, typesDir } = configuration.content;
95
- if (!(0, import_fs.existsSync)(moduleAugmentationDir)) {
96
- (0, import_fs.mkdirSync)(moduleAugmentationDir, { recursive: true });
97
- }
95
+ await (0, import_promises.mkdir)(moduleAugmentationDir, { recursive: true });
98
96
  const dictionariesTypesDefinitions = import_fast_glob.default.sync(
99
97
  (0, import_config.normalizePath)(`${typesDir}/*.ts`),
100
98
  {
@@ -102,7 +100,7 @@ const createModuleAugmentation = (configuration = (0, import_config.getConfigura
102
100
  }
103
101
  );
104
102
  const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);
105
- (0, import_fs.writeFileSync)((0, import_path.join)(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
103
+ await (0, import_promises.writeFile)((0, import_path.join)(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
106
104
  };
107
105
  // Annotate the CommonJS export names for ESM import in node:
108
106
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { Locales, getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, join, relative } from 'path';\nimport { getFileHash } from '../../utils/getFileHash';\nimport { kebabCaseToCamelCase } from '../../utils/kebabCaseToCamelCase';\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\nconst formatLocales = (locales: Locales[]): string =>\n locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (\n typeFiles: string[],\n configuration = getConfiguration()\n): string => {\n const { content, internationalization } = configuration;\n const { moduleAugmentationDir } = content;\n const { locales, requiredLocales, strictMode } = internationalization;\n\n let fileContent =\n \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id (without the extension)\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n fileContent += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n });\n\n fileContent += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": typeof ${dictionary.hash};`)\n .join('\\n');\n\n const requiredLocalesValues =\n requiredLocales.length > 0\n ? requiredLocales.filter((locale) =>\n locales.map((locale) => String(locale)).includes(String(locale))\n )\n : locales;\n\n const formattedLocales = formatLocales(locales);\n const formattedRequiredLocales = formatLocales(requiredLocalesValues);\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<DeclaredLocales, Content> {}`\n : strictMode === 'inclusive'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n fileContent += `declare module 'intlayer' {\\n`;\n fileContent += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n fileContent += ` type DeclaredLocales = ${formattedLocales};\\n`;\n fileContent += ` type RequiredLocales = ${formattedRequiredLocales};\\n`;\n fileContent += ` type ExtractedLocales = Extract<Locales, RequiredLocales>;\\n`;\n fileContent += ` type ExcludedLocales = Exclude<Locales, RequiredLocales>;\\n`;\n fileContent += ` ${strictModeRecord}\\n`;\n fileContent += `}`;\n\n return fileContent;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = (\n configuration = getConfiguration()\n) => {\n const { moduleAugmentationDir, typesDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionariesTypesDefinitions: string[] = fg.sync(\n normalizePath(`${typesDir}/*.ts`),\n {\n ignore: ['**/*.d.ts'],\n }\n );\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyD;AACzD,uBAAe;AACf,gBAAqD;AACrD,kBAAkD;AAClD,yBAA4B;AAC5B,kCAAqC;AAE9B,MAAM,cAAc,CAAC,QAC1B,OAAG,kDAAqB,GAAG,CAAC;AAE9B,MAAM,gBAAgB,CAAC,YACrB,QACG,IAAI,CAAC,WAAW;AACf,aAAW,OAAO,uBAAS;AACzB,QAAI,sBAAQ,GAA2B,MAAM,QAAQ;AACnD,aAAO,WAAW,GAAG;AAAA,IACvB;AAAA,EACF;AACF,CAAC,EACA,KAAK,KAAK;AAKf,MAAM,2BAA2B,CAC/B,WACA,oBAAgB,gCAAiB,MACtB;AACX,QAAM,EAAE,SAAS,qBAAqB,IAAI;AAC1C,QAAM,EAAE,sBAAsB,IAAI;AAClC,QAAM,EAAE,SAAS,iBAAiB,WAAW,IAAI;AAEjD,MAAI,cACF;AAEF,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,SAAK,sBAAS,uBAAuB,cAAc,CAAC;AAAA,IAClE,QAAI,sBAAS,oBAAgB,qBAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,QAAI,gCAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,mBAAe,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AAAA,EAC3E,CAAC;AAED,iBAAe;AAGf,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,aAAa,WAAW,IAAI,GAAG,EACxE,KAAK,IAAI;AAEZ,QAAM,wBACJ,gBAAgB,SAAS,IACrB,gBAAgB;AAAA,IAAO,CAAC,WACtB,QAAQ,IAAI,CAACA,YAAW,OAAOA,OAAM,CAAC,EAAE,SAAS,OAAO,MAAM,CAAC;AAAA,EACjE,IACA;AAEN,QAAM,mBAAmB,cAAc,OAAO;AAC9C,QAAM,2BAA2B,cAAc,qBAAqB;AAEpE,QAAM,mBACJ,eAAe,WACX,kFACA,eAAe,cACb,8HACA;AAsBR,iBAAe;AAAA;AACf,iBAAe;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACxF,iBAAe,4BAA4B,gBAAgB;AAAA;AAC3D,iBAAe,4BAA4B,wBAAwB;AAAA;AACnE,iBAAe;AAAA;AACf,iBAAe;AAAA;AACf,iBAAe,KAAK,gBAAgB;AAAA;AACpC,iBAAe;AAEf,SAAO;AACT;AAKO,MAAM,2BAA2B,CACtC,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,uBAAuB,SAAS,IAAI,cAAc;AAG1D,MAAI,KAAC,sBAAW,qBAAqB,GAAG;AACtC,6BAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,+BAAyC,iBAAAC,QAAG;AAAA,QAChD,6BAAc,GAAG,QAAQ,OAAO;AAAA,IAChC;AAAA,MACE,QAAQ,CAAC,WAAW;AAAA,IACtB;AAAA,EACF;AAGA,QAAM,YAAY,yBAAyB,4BAA4B;AACvE,mCAAc,kBAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["locale","fg"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { Locales, getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { basename, extname, join, relative } from 'path';\nimport { getFileHash } from '../../utils/getFileHash';\nimport { kebabCaseToCamelCase } from '../../utils/kebabCaseToCamelCase';\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\nconst formatLocales = (locales: Locales[]): string =>\n locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (\n typeFiles: string[],\n configuration = getConfiguration()\n): string => {\n const { content, internationalization } = configuration;\n const { moduleAugmentationDir } = content;\n const { locales, requiredLocales, strictMode } = internationalization;\n\n let fileContent =\n \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id (without the extension)\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n fileContent += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n });\n\n fileContent += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": typeof ${dictionary.hash};`)\n .join('\\n');\n\n const requiredLocalesValues =\n requiredLocales.length > 0\n ? requiredLocales.filter((locale) =>\n locales.map((locale) => String(locale)).includes(String(locale))\n )\n : locales;\n\n const formattedLocales = formatLocales(locales);\n const formattedRequiredLocales = formatLocales(requiredLocalesValues);\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<DeclaredLocales, Content> {}`\n : strictMode === 'inclusive'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n fileContent += `declare module 'intlayer' {\\n`;\n fileContent += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n fileContent += ` type DeclaredLocales = ${formattedLocales};\\n`;\n fileContent += ` type RequiredLocales = ${formattedRequiredLocales};\\n`;\n fileContent += ` type ExtractedLocales = Extract<Locales, RequiredLocales>;\\n`;\n fileContent += ` type ExcludedLocales = Exclude<Locales, RequiredLocales>;\\n`;\n fileContent += ` ${strictModeRecord}\\n`;\n fileContent += `}`;\n\n return fileContent;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = async (\n configuration = getConfiguration()\n) => {\n const { moduleAugmentationDir, typesDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n await mkdir(moduleAugmentationDir, { recursive: true });\n\n const dictionariesTypesDefinitions: string[] = fg.sync(\n normalizePath(`${typesDir}/*.ts`),\n {\n ignore: ['**/*.d.ts'],\n }\n );\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n await writeFile(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyD;AACzD,uBAAe;AACf,sBAAiC;AACjC,kBAAkD;AAClD,yBAA4B;AAC5B,kCAAqC;AAE9B,MAAM,cAAc,CAAC,QAC1B,OAAG,kDAAqB,GAAG,CAAC;AAE9B,MAAM,gBAAgB,CAAC,YACrB,QACG,IAAI,CAAC,WAAW;AACf,aAAW,OAAO,uBAAS;AACzB,QAAI,sBAAQ,GAA2B,MAAM,QAAQ;AACnD,aAAO,WAAW,GAAG;AAAA,IACvB;AAAA,EACF;AACF,CAAC,EACA,KAAK,KAAK;AAKf,MAAM,2BAA2B,CAC/B,WACA,oBAAgB,gCAAiB,MACtB;AACX,QAAM,EAAE,SAAS,qBAAqB,IAAI;AAC1C,QAAM,EAAE,sBAAsB,IAAI;AAClC,QAAM,EAAE,SAAS,iBAAiB,WAAW,IAAI;AAEjD,MAAI,cACF;AAEF,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,SAAK,sBAAS,uBAAuB,cAAc,CAAC;AAAA,IAClE,QAAI,sBAAS,oBAAgB,qBAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,QAAI,gCAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,mBAAe,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AAAA,EAC3E,CAAC;AAED,iBAAe;AAGf,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,aAAa,WAAW,IAAI,GAAG,EACxE,KAAK,IAAI;AAEZ,QAAM,wBACJ,gBAAgB,SAAS,IACrB,gBAAgB;AAAA,IAAO,CAAC,WACtB,QAAQ,IAAI,CAACA,YAAW,OAAOA,OAAM,CAAC,EAAE,SAAS,OAAO,MAAM,CAAC;AAAA,EACjE,IACA;AAEN,QAAM,mBAAmB,cAAc,OAAO;AAC9C,QAAM,2BAA2B,cAAc,qBAAqB;AAEpE,QAAM,mBACJ,eAAe,WACX,kFACA,eAAe,cACb,8HACA;AAsBR,iBAAe;AAAA;AACf,iBAAe;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACxF,iBAAe,4BAA4B,gBAAgB;AAAA;AAC3D,iBAAe,4BAA4B,wBAAwB;AAAA;AACnE,iBAAe;AAAA;AACf,iBAAe;AAAA;AACf,iBAAe,KAAK,gBAAgB;AAAA;AACpC,iBAAe;AAEf,SAAO;AACT;AAKO,MAAM,2BAA2B,OACtC,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,uBAAuB,SAAS,IAAI,cAAc;AAG1D,YAAM,uBAAM,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAEtD,QAAM,+BAAyC,iBAAAC,QAAG;AAAA,QAChD,6BAAc,GAAG,QAAQ,OAAO;AAAA,IAChC;AAAA,MACE,QAAQ,CAAC,WAAW;AAAA,IACtB;AAAA,EACF;AAGA,QAAM,YAAY,yBAAyB,4BAA4B;AACvE,YAAM,+BAAU,kBAAK,uBAAuB,eAAe,GAAG,SAAS;AACzE;","names":["locale","fg"]}
@@ -23,8 +23,9 @@ __export(createType_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(createType_exports);
25
25
  var import_config = require("@intlayer/config");
26
- var import_fs = require("fs");
26
+ var import_promises = require("fs/promises");
27
27
  var import_path = require("path");
28
+ var import_parallelize = require('../../utils/parallelize.cjs');
28
29
  const requireUncached = (module2) => {
29
30
  delete import_config.ESMxCJSRequire.cache[import_config.ESMxCJSRequire.resolve(module2)];
30
31
  return (0, import_config.ESMxCJSRequire)(module2);
@@ -35,23 +36,23 @@ const generateTypeScriptType = (dictionary) => {
35
36
  export default ${jsonString} as const;
36
37
  `;
37
38
  };
38
- const createTypes = (dictionariesPaths, configuration = (0, import_config.getConfiguration)()) => {
39
+ const createTypes = async (dictionariesPaths, configuration = (0, import_config.getConfiguration)()) => {
39
40
  const { typesDir } = configuration.content;
40
- const resultTypesPaths = [];
41
- if (!(0, import_fs.existsSync)(typesDir)) {
42
- (0, import_fs.mkdirSync)(typesDir, { recursive: true });
43
- }
44
- for (const dictionaryPath of dictionariesPaths) {
45
- const dictionary = requireUncached(dictionaryPath);
46
- if (!dictionary.key) {
47
- continue;
41
+ await (0, import_promises.mkdir)(typesDir, { recursive: true });
42
+ const results = await (0, import_parallelize.parallelize)(
43
+ dictionariesPaths,
44
+ async (dictionaryPath) => {
45
+ const dictionary = requireUncached(dictionaryPath);
46
+ if (!dictionary.key) {
47
+ return void 0;
48
+ }
49
+ const typeDefinition = generateTypeScriptType(dictionary);
50
+ const outputPath = (0, import_path.resolve)(typesDir, `${dictionary.key}.ts`);
51
+ await (0, import_promises.writeFile)(outputPath, typeDefinition);
52
+ return outputPath;
48
53
  }
49
- const typeDefinition = generateTypeScriptType(dictionary);
50
- const outputPath = (0, import_path.resolve)(typesDir, `${dictionary.key}.ts`);
51
- (0, import_fs.writeFileSync)(outputPath, typeDefinition);
52
- resultTypesPaths.push(outputPath);
53
- }
54
- return resultTypesPaths;
54
+ );
55
+ return results.filter(Boolean);
55
56
  };
56
57
  // Annotate the CommonJS export names for ESM import in node:
57
58
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n getConfiguration,\n IntlayerConfig,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\n\nconst requireUncached = (module: string) => {\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];\n return ESMxCJSRequire(module);\n};\n\nexport const generateTypeScriptType = (dictionary: Dictionary) => {\n const jsonString = JSON.stringify(dictionary, null, 2);\n\n return `/* eslint-disable */\\nexport default ${jsonString} as const;\\n`;\n};\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = (\n dictionariesPaths: string[],\n configuration: IntlayerConfig = getConfiguration()\n): string[] => {\n const { typesDir } = configuration.content;\n const resultTypesPaths: string[] = [];\n\n // Create type folders if they don't exist\n if (!existsSync(typesDir)) {\n mkdirSync(typesDir, { recursive: true });\n }\n\n for (const dictionaryPath of dictionariesPaths) {\n const dictionary: Dictionary = requireUncached(dictionaryPath);\n\n if (!dictionary.key) {\n // Skip dictionary if it doesn't have a key, if not exported as default etc\n continue;\n }\n\n const typeDefinition: string = generateTypeScriptType(dictionary);\n\n const outputPath: string = resolve(typesDir, `${dictionary.key}.ts`);\n\n writeFileSync(outputPath, typeDefinition);\n\n resultTypesPaths.push(outputPath);\n }\n\n return resultTypesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAIO;AAEP,gBAAqD;AACrD,kBAAwB;AAExB,MAAM,kBAAkB,CAACA,YAAmB;AAC1C,SAAO,6BAAe,MAAM,6BAAe,QAAQA,OAAM,CAAC;AAC1D,aAAO,8BAAeA,OAAM;AAC9B;AAEO,MAAM,yBAAyB,CAAC,eAA2B;AAChE,QAAM,aAAa,KAAK,UAAU,YAAY,MAAM,CAAC;AAErD,SAAO;AAAA,iBAAwC,UAAU;AAAA;AAC3D;AAIO,MAAM,cAAc,CACzB,mBACA,oBAAgC,gCAAiB,MACpC;AACb,QAAM,EAAE,SAAS,IAAI,cAAc;AACnC,QAAM,mBAA6B,CAAC;AAGpC,MAAI,KAAC,sBAAW,QAAQ,GAAG;AACzB,6BAAU,UAAU,EAAE,WAAW,KAAK,CAAC;AAAA,EACzC;AAEA,aAAW,kBAAkB,mBAAmB;AAC9C,UAAM,aAAyB,gBAAgB,cAAc;AAE7D,QAAI,CAAC,WAAW,KAAK;AAEnB;AAAA,IACF;AAEA,UAAM,iBAAyB,uBAAuB,UAAU;AAEhE,UAAM,iBAAqB,qBAAQ,UAAU,GAAG,WAAW,GAAG,KAAK;AAEnE,iCAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":["module"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n getConfiguration,\n IntlayerConfig,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { parallelize } from '../../utils/parallelize';\n\nconst requireUncached = (module: string) => {\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];\n return ESMxCJSRequire(module);\n};\n\nexport const generateTypeScriptType = (dictionary: Dictionary) => {\n const jsonString = JSON.stringify(dictionary, null, 2);\n\n return `/* eslint-disable */\\nexport default ${jsonString} as const;\\n`;\n};\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = async (\n dictionariesPaths: string[],\n configuration: IntlayerConfig = getConfiguration()\n): Promise<string[]> => {\n const { typesDir } = configuration.content;\n\n // Create type folders if they don't exist\n await mkdir(typesDir, { recursive: true });\n\n const results = await parallelize(\n dictionariesPaths,\n async (dictionaryPath): Promise<string | undefined> => {\n const dictionary: Dictionary = requireUncached(dictionaryPath);\n\n if (!dictionary.key) {\n return undefined;\n }\n\n const typeDefinition: string = generateTypeScriptType(dictionary);\n\n const outputPath: string = resolve(typesDir, `${dictionary.key}.ts`);\n\n await writeFile(outputPath, typeDefinition);\n\n return outputPath;\n }\n );\n\n return results.filter(Boolean) as string[];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAIO;AAEP,sBAAiC;AACjC,kBAAwB;AACxB,yBAA4B;AAE5B,MAAM,kBAAkB,CAACA,YAAmB;AAC1C,SAAO,6BAAe,MAAM,6BAAe,QAAQA,OAAM,CAAC;AAC1D,aAAO,8BAAeA,OAAM;AAC9B;AAEO,MAAM,yBAAyB,CAAC,eAA2B;AAChE,QAAM,aAAa,KAAK,UAAU,YAAY,MAAM,CAAC;AAErD,SAAO;AAAA,iBAAwC,UAAU;AAAA;AAC3D;AAIO,MAAM,cAAc,OACzB,mBACA,oBAAgC,gCAAiB,MAC3B;AACtB,QAAM,EAAE,SAAS,IAAI,cAAc;AAGnC,YAAM,uBAAM,UAAU,EAAE,WAAW,KAAK,CAAC;AAEzC,QAAM,UAAU,UAAM;AAAA,IACpB;AAAA,IACA,OAAO,mBAAgD;AACrD,YAAM,aAAyB,gBAAgB,cAAc;AAE7D,UAAI,CAAC,WAAW,KAAK;AACnB,eAAO;AAAA,MACT;AAEA,YAAM,iBAAyB,uBAAuB,UAAU;AAEhE,YAAM,iBAAqB,qBAAQ,UAAU,GAAG,WAAW,GAAG,KAAK;AAEnE,gBAAM,2BAAU,YAAY,cAAc;AAE1C,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO,QAAQ,OAAO,OAAO;AAC/B;","names":["module"]}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var formatter_exports = {};
30
+ __export(formatter_exports, {
31
+ formatLocale: () => formatLocale,
32
+ formatPath: () => formatPath
33
+ });
34
+ module.exports = __toCommonJS(formatter_exports);
35
+ var import_config = require("@intlayer/config");
36
+ var import_built = __toESM(require("@intlayer/config/built"));
37
+ var import_core = require("@intlayer/core");
38
+ var import_path = require("path");
39
+ const formatPath = (path, color) => [path].flat().map(
40
+ (path2) => path2.startsWith("/") ? (0, import_path.relative)(import_built.default.content.baseDir, path2) : path2
41
+ ).map(
42
+ (relativePath) => color === false ? relativePath : (0, import_config.colorizePath)(relativePath, color)
43
+ ).join(`, `);
44
+ const formatLocale = (locale, color = import_config.ANSIColors.GREEN) => [locale].flat().map((locale2) => `${(0, import_core.getLocaleName)(locale2, import_config.Locales.ENGLISH)} (${locale2})`).map((text) => color === false ? text : (0, import_config.colorize)(text, color)).join(`, `);
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ formatLocale,
48
+ formatPath
49
+ });
50
+ //# sourceMappingURL=formatter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/formatter.ts"],"sourcesContent":["import { ANSIColors, colorize, colorizePath, Locales } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { getLocaleName } from '@intlayer/core';\nimport { relative } from 'path';\n\nexport const formatPath = (\n path: string | string[],\n color?: ANSIColors | false\n) =>\n [path]\n .flat()\n .map((path) =>\n path.startsWith('/')\n ? relative(configuration.content.baseDir, path)\n : path\n )\n .map((relativePath) =>\n color === false ? relativePath : colorizePath(relativePath, color)\n )\n .join(`, `);\n\nexport const formatLocale = (\n locale: Locales | Locales[],\n color: ANSIColors | false = ANSIColors.GREEN\n) =>\n [locale]\n .flat()\n .map((locale) => `${getLocaleName(locale, Locales.ENGLISH)} (${locale})`)\n .map((text) => (color === false ? text : colorize(text, color)))\n .join(`, `);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4D;AAC5D,mBAA0B;AAC1B,kBAA8B;AAC9B,kBAAyB;AAElB,MAAM,aAAa,CACxB,MACA,UAEA,CAAC,IAAI,EACF,KAAK,EACL;AAAA,EAAI,CAACA,UACJA,MAAK,WAAW,GAAG,QACf,sBAAS,aAAAC,QAAc,QAAQ,SAASD,KAAI,IAC5CA;AACN,EACC;AAAA,EAAI,CAAC,iBACJ,UAAU,QAAQ,mBAAe,4BAAa,cAAc,KAAK;AACnE,EACC,KAAK,IAAI;AAEP,MAAM,eAAe,CAC1B,QACA,QAA4B,yBAAW,UAEvC,CAAC,MAAM,EACJ,KAAK,EACL,IAAI,CAACE,YAAW,OAAG,2BAAcA,SAAQ,sBAAQ,OAAO,CAAC,KAAKA,OAAM,GAAG,EACvE,IAAI,CAAC,SAAU,UAAU,QAAQ,WAAO,wBAAS,MAAM,KAAK,CAAE,EAC9D,KAAK,IAAI;","names":["path","configuration","locale"]}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var parallelize_exports = {};
30
+ __export(parallelize_exports, {
31
+ parallelize: () => parallelize
32
+ });
33
+ module.exports = __toCommonJS(parallelize_exports);
34
+ var import_p_limit = __toESM(require("p-limit"));
35
+ const parallelize = async (items, callback, parallelLimit = 10) => {
36
+ const limit = (0, import_p_limit.default)(parallelLimit);
37
+ return Promise.all(items.map((item) => limit(() => callback(item))));
38
+ };
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ parallelize
42
+ });
43
+ //# sourceMappingURL=parallelize.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/parallelize.ts"],"sourcesContent":["import pLimit from 'p-limit';\n\nexport const parallelize = async <T, R>(\n items: T[],\n callback: (item: T) => Promise<R>,\n parallelLimit: number = 10\n): Promise<R[]> => {\n const limit = pLimit(parallelLimit);\n return Promise.all(items.map((item) => limit(() => callback(item))));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAmB;AAEZ,MAAM,cAAc,OACzB,OACA,UACA,gBAAwB,OACP;AACjB,QAAM,YAAQ,eAAAA,SAAO,aAAa;AAClC,SAAO,QAAQ,IAAI,MAAM,IAAI,CAAC,SAAS,MAAM,MAAM,SAAS,IAAI,CAAC,CAAC,CAAC;AACrE;","names":["pLimit"]}
@@ -23,7 +23,7 @@ __export(runOnce_exports, {
23
23
  module.exports = __toCommonJS(runOnce_exports);
24
24
  var import_promises = require("fs/promises");
25
25
  var import_path = require("path");
26
- const runOnce = async (sentinelFilePath, callback, cacheTimeoutMs = 60 * 1e3) => {
26
+ const runOnce = async (sentinelFilePath, callback, onIsCached, cacheTimeoutMs = 60 * 1e3) => {
27
27
  const currentTimestamp = Date.now();
28
28
  const timeoutDuration = cacheTimeoutMs;
29
29
  try {
@@ -32,6 +32,7 @@ const runOnce = async (sentinelFilePath, callback, cacheTimeoutMs = 60 * 1e3) =>
32
32
  if (sentinelAge > timeoutDuration) {
33
33
  await (0, import_promises.unlink)(sentinelFilePath);
34
34
  } else {
35
+ await onIsCached?.();
35
36
  return;
36
37
  }
37
38
  } catch (err) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/runOnce.ts"],"sourcesContent":["import { mkdir, stat, unlink, writeFile } from 'fs/promises';\nimport { dirname } from 'path';\n\n/**\n * Ensures a callback function runs only once within a specified time window across multiple processes.\n * Uses a sentinel file to coordinate execution and prevent duplicate work.\n *\n * @param sentinelFilePath - Path to the sentinel file used for coordination\n * @param callback - The function to execute (should be async)\n * @param cacheTimeoutMs - Time window in milliseconds during which the sentinel is considered valid (default: 60000ms = 1 minute)\n *\n * @example\n * ```typescript\n * await runPrepareIntlayerOnce(\n * '/tmp/intlayer-sentinel',\n * async () => {\n * // Your initialization logic here\n * await prepareIntlayer();\n * },\n * 30 * 1000 // 30 seconds cache\n * );\n * ```\n *\n * @throws {Error} When there are unexpected filesystem errors\n */\nexport const runOnce = async (\n sentinelFilePath: string,\n callback: () => void | Promise<void>,\n cacheTimeoutMs: number = 60 * 1000 // 1 minute in milliseconds\n) => {\n const currentTimestamp = Date.now();\n const timeoutDuration = cacheTimeoutMs;\n\n try {\n // Check if sentinel file exists and get its stats\n const sentinelStats = await stat(sentinelFilePath);\n const sentinelAge = currentTimestamp - sentinelStats.mtime.getTime();\n\n // If sentinel is older than the timeout, delete it and rebuild\n if (sentinelAge > timeoutDuration) {\n await unlink(sentinelFilePath);\n // Fall through to create new sentinel and rebuild\n } else {\n // Sentinel is recent, no need to rebuild\n return;\n }\n } catch (err: any) {\n if (err.code === 'ENOENT') {\n // File doesn't exist, continue to create it\n } else {\n throw err; // unexpected FS error\n }\n }\n\n try {\n // Ensure the directory exists before writing the file\n await mkdir(dirname(sentinelFilePath), { recursive: true });\n\n // O_EXCL ensures only the *first* process can create the file\n await writeFile(sentinelFilePath, String(currentTimestamp), { flag: 'wx' });\n } catch (err: any) {\n if (err.code === 'EEXIST') {\n // Another process already created it → we're done\n return;\n }\n throw err; // unexpected FS error\n }\n\n await callback();\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA+C;AAC/C,kBAAwB;AAwBjB,MAAM,UAAU,OACrB,kBACA,UACA,iBAAyB,KAAK,QAC3B;AACH,QAAM,mBAAmB,KAAK,IAAI;AAClC,QAAM,kBAAkB;AAExB,MAAI;AAEF,UAAM,gBAAgB,UAAM,sBAAK,gBAAgB;AACjD,UAAM,cAAc,mBAAmB,cAAc,MAAM,QAAQ;AAGnE,QAAI,cAAc,iBAAiB;AACjC,gBAAM,wBAAO,gBAAgB;AAAA,IAE/B,OAAO;AAEL;AAAA,IACF;AAAA,EACF,SAAS,KAAU;AACjB,QAAI,IAAI,SAAS,UAAU;AAAA,IAE3B,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF;AAEA,MAAI;AAEF,cAAM,2BAAM,qBAAQ,gBAAgB,GAAG,EAAE,WAAW,KAAK,CAAC;AAG1D,cAAM,2BAAU,kBAAkB,OAAO,gBAAgB,GAAG,EAAE,MAAM,KAAK,CAAC;AAAA,EAC5E,SAAS,KAAU;AACjB,QAAI,IAAI,SAAS,UAAU;AAEzB;AAAA,IACF;AACA,UAAM;AAAA,EACR;AAEA,QAAM,SAAS;AACjB;","names":[]}
1
+ {"version":3,"sources":["../../../src/utils/runOnce.ts"],"sourcesContent":["import { mkdir, stat, unlink, writeFile } from 'fs/promises';\nimport { dirname } from 'path';\n\n/**\n * Ensures a callback function runs only once within a specified time window across multiple processes.\n * Uses a sentinel file to coordinate execution and prevent duplicate work.\n *\n * @param sentinelFilePath - Path to the sentinel file used for coordination\n * @param callback - The function to execute (should be async)\n * @param cacheTimeoutMs - Time window in milliseconds during which the sentinel is considered valid (default: 60000ms = 1 minute)\n *\n * @example\n * ```typescript\n * await runPrepareIntlayerOnce(\n * '/tmp/intlayer-sentinel',\n * async () => {\n * // Your initialization logic here\n * await prepareIntlayer();\n * },\n * 30 * 1000 // 30 seconds cache\n * );\n * ```\n *\n * @throws {Error} When there are unexpected filesystem errors\n */\nexport const runOnce = async (\n sentinelFilePath: string,\n callback: () => void | Promise<void>,\n onIsCached?: () => void | Promise<void>,\n cacheTimeoutMs: number = 60 * 1000 // 1 minute in milliseconds\n) => {\n const currentTimestamp = Date.now();\n const timeoutDuration = cacheTimeoutMs;\n\n try {\n // Check if sentinel file exists and get its stats\n const sentinelStats = await stat(sentinelFilePath);\n const sentinelAge = currentTimestamp - sentinelStats.mtime.getTime();\n\n // If sentinel is older than the timeout, delete it and rebuild\n if (sentinelAge > timeoutDuration) {\n await unlink(sentinelFilePath);\n // Fall through to create new sentinel and rebuild\n } else {\n await onIsCached?.();\n // Sentinel is recent, no need to rebuild\n return;\n }\n } catch (err: any) {\n if (err.code === 'ENOENT') {\n // File doesn't exist, continue to create it\n } else {\n throw err; // unexpected FS error\n }\n }\n\n try {\n // Ensure the directory exists before writing the file\n await mkdir(dirname(sentinelFilePath), { recursive: true });\n\n // O_EXCL ensures only the *first* process can create the file\n await writeFile(sentinelFilePath, String(currentTimestamp), { flag: 'wx' });\n } catch (err: any) {\n if (err.code === 'EEXIST') {\n // Another process already created it → we're done\n return;\n }\n throw err; // unexpected FS error\n }\n\n await callback();\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA+C;AAC/C,kBAAwB;AAwBjB,MAAM,UAAU,OACrB,kBACA,UACA,YACA,iBAAyB,KAAK,QAC3B;AACH,QAAM,mBAAmB,KAAK,IAAI;AAClC,QAAM,kBAAkB;AAExB,MAAI;AAEF,UAAM,gBAAgB,UAAM,sBAAK,gBAAgB;AACjD,UAAM,cAAc,mBAAmB,cAAc,MAAM,QAAQ;AAGnE,QAAI,cAAc,iBAAiB;AACjC,gBAAM,wBAAO,gBAAgB;AAAA,IAE/B,OAAO;AACL,YAAM,aAAa;AAEnB;AAAA,IACF;AAAA,EACF,SAAS,KAAU;AACjB,QAAI,IAAI,SAAS,UAAU;AAAA,IAE3B,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF;AAEA,MAAI;AAEF,cAAM,2BAAM,qBAAQ,gBAAgB,GAAG,EAAE,WAAW,KAAK,CAAC;AAG1D,cAAM,2BAAU,kBAAkB,OAAO,gBAAgB,GAAG,EAAE,MAAM,KAAK,CAAC;AAAA,EAC5E,SAAS,KAAU;AACjB,QAAI,IAAI,SAAS,UAAU;AAEzB;AAAA,IACF;AACA,UAAM;AAAA,EACR;AAEA,QAAM,SAAS;AACjB;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/writeContentDeclaration/dictionaryStatus.ts"],"sourcesContent":["export type DictionaryStatus =\n | 'pending'\n | 'fetching'\n | 'up-to-date'\n | 'replaced'\n | 'updated'\n | 'fetched'\n | 'unknown'\n | 'error'\n | 'imported'\n | 'reimported in JSON'\n | 'reimported in new location';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/writeContentDeclaration/dictionaryStatus.ts"],"sourcesContent":["export type DictionaryStatus =\n | 'pending'\n | 'fetching'\n | 'up-to-date'\n | 'replaced'\n | 'updated'\n | 'fetched'\n | 'unknown'\n | 'error'\n | 'imported'\n | 'reimported in JSON'\n | 'new content file';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -50,10 +50,13 @@ const formatCode = async (filePath, code) => {
50
50
  // Explicitly provide the filepath so Prettier can infer the parser
51
51
  });
52
52
  const relativePath = (0, import_path.relative)(import_built.default.content.baseDir, filePath);
53
- appLogger(`Applied Prettier formatting to ${relativePath}`, {
54
- level: "info",
55
- isVerbose: true
56
- });
53
+ appLogger(
54
+ `Applied Prettier formatting to ${import_config.ANSIColors.GREY}${relativePath}${import_config.ANSIColors.RESET}`,
55
+ {
56
+ level: "info",
57
+ isVerbose: true
58
+ }
59
+ );
57
60
  return formattedCode;
58
61
  } catch (error) {
59
62
  const err = error;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/writeContentDeclaration/formatCode.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { relative } from 'path';\n\nexport const formatCode = async (filePath: string, code: string) => {\n const appLogger = getAppLogger(configuration);\n // Try to import prettier if it exists\n let prettier: any;\n try {\n prettier = require('prettier');\n } catch (error) {\n // Prettier is not installed, continue without it\n }\n\n // Apply Prettier formatting if it's available\n if (prettier) {\n try {\n // Try to find a prettier config file\n const prettierConfig = await prettier.resolveConfig(filePath ?? '');\n\n // Format the code with Prettier\n const formattedCode = await prettier.format(code, {\n ...prettierConfig,\n filepath: filePath, // Explicitly provide the filepath so Prettier can infer the parser\n });\n\n const relativePath = relative(configuration.content.baseDir, filePath);\n\n appLogger(`Applied Prettier formatting to ${relativePath}`, {\n level: 'info',\n isVerbose: true,\n });\n\n return formattedCode;\n } catch (error) {\n const err = error as Error;\n appLogger(\n `Failed to apply Prettier formatting to ${filePath}: ${err.message}`,\n {\n level: 'warn',\n isVerbose: true,\n }\n );\n // Continue with unformatted code on prettier error\n }\n }\n\n return code;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6B;AAC7B,mBAA0B;AAC1B,kBAAyB;AAElB,MAAM,aAAa,OAAO,UAAkB,SAAiB;AAClE,QAAM,gBAAY,4BAAa,aAAAA,OAAa;AAE5C,MAAI;AACJ,MAAI;AACF,eAAW,QAAQ,UAAU;AAAA,EAC/B,SAAS,OAAO;AAAA,EAEhB;AAGA,MAAI,UAAU;AACZ,QAAI;AAEF,YAAM,iBAAiB,MAAM,SAAS,cAAc,YAAY,EAAE;AAGlE,YAAM,gBAAgB,MAAM,SAAS,OAAO,MAAM;AAAA,QAChD,GAAG;AAAA,QACH,UAAU;AAAA;AAAA,MACZ,CAAC;AAED,YAAM,mBAAe,sBAAS,aAAAA,QAAc,QAAQ,SAAS,QAAQ;AAErE,gBAAU,kCAAkC,YAAY,IAAI;AAAA,QAC1D,OAAO;AAAA,QACP,WAAW;AAAA,MACb,CAAC;AAED,aAAO;AAAA,IACT,SAAS,OAAO;AACd,YAAM,MAAM;AACZ;AAAA,QACE,0CAA0C,QAAQ,KAAK,IAAI,OAAO;AAAA,QAClE;AAAA,UACE,OAAO;AAAA,UACP,WAAW;AAAA,QACb;AAAA,MACF;AAAA,IAEF;AAAA,EACF;AAEA,SAAO;AACT;","names":["configuration"]}
1
+ {"version":3,"sources":["../../../src/writeContentDeclaration/formatCode.ts"],"sourcesContent":["import { ANSIColors, getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { relative } from 'path';\n\nexport const formatCode = async (filePath: string, code: string) => {\n const appLogger = getAppLogger(configuration);\n // Try to import prettier if it exists\n let prettier: any;\n try {\n prettier = require('prettier');\n } catch (error) {\n // Prettier is not installed, continue without it\n }\n\n // Apply Prettier formatting if it's available\n if (prettier) {\n try {\n // Try to find a prettier config file\n const prettierConfig = await prettier.resolveConfig(filePath ?? '');\n\n // Format the code with Prettier\n const formattedCode = await prettier.format(code, {\n ...prettierConfig,\n filepath: filePath, // Explicitly provide the filepath so Prettier can infer the parser\n });\n\n const relativePath = relative(configuration.content.baseDir, filePath);\n\n appLogger(\n `Applied Prettier formatting to ${ANSIColors.GREY}${relativePath}${ANSIColors.RESET}`,\n {\n level: 'info',\n isVerbose: true,\n }\n );\n\n return formattedCode;\n } catch (error) {\n const err = error as Error;\n appLogger(\n `Failed to apply Prettier formatting to ${filePath}: ${err.message}`,\n {\n level: 'warn',\n isVerbose: true,\n }\n );\n // Continue with unformatted code on prettier error\n }\n }\n\n return code;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyC;AACzC,mBAA0B;AAC1B,kBAAyB;AAElB,MAAM,aAAa,OAAO,UAAkB,SAAiB;AAClE,QAAM,gBAAY,4BAAa,aAAAA,OAAa;AAE5C,MAAI;AACJ,MAAI;AACF,eAAW,QAAQ,UAAU;AAAA,EAC/B,SAAS,OAAO;AAAA,EAEhB;AAGA,MAAI,UAAU;AACZ,QAAI;AAEF,YAAM,iBAAiB,MAAM,SAAS,cAAc,YAAY,EAAE;AAGlE,YAAM,gBAAgB,MAAM,SAAS,OAAO,MAAM;AAAA,QAChD,GAAG;AAAA,QACH,UAAU;AAAA;AAAA,MACZ,CAAC;AAED,YAAM,mBAAe,sBAAS,aAAAA,QAAc,QAAQ,SAAS,QAAQ;AAErE;AAAA,QACE,kCAAkC,yBAAW,IAAI,GAAG,YAAY,GAAG,yBAAW,KAAK;AAAA,QACnF;AAAA,UACE,OAAO;AAAA,UACP,WAAW;AAAA,QACb;AAAA,MACF;AAEA,aAAO;AAAA,IACT,SAAS,OAAO;AACd,YAAM,MAAM;AACZ;AAAA,QACE,0CAA0C,QAAQ,KAAK,IAAI,OAAO;AAAA,QAClE;AAAA,UACE,OAAO;AAAA,UACP,WAAW;AAAA,QACb;AAAA,MACF;AAAA,IAEF;AAAA,EACF;AAEA,SAAO;AACT;","names":["configuration"]}
@@ -32,6 +32,7 @@ __export(writeContentDeclaration_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(writeContentDeclaration_exports);
34
34
  var import_built = __toESM(require("@intlayer/config/built"));
35
+ var import_client = require("@intlayer/config/client");
35
36
  var import_unmerged_dictionaries_entry = __toESM(require("@intlayer/unmerged-dictionaries-entry"));
36
37
  var import_deep_equal = __toESM(require("deep-equal"));
37
38
  var import_fs = require("fs");
@@ -74,7 +75,7 @@ const writeContentDeclaration = async (dictionary, config = import_built.default
74
75
  formattedContentDeclaration
75
76
  );
76
77
  return {
77
- status: "reimported in new location",
78
+ status: "new content file",
78
79
  path: contentDeclarationPath
79
80
  };
80
81
  }
@@ -114,7 +115,10 @@ const writeFileWithDirectories = async (filePath, data) => {
114
115
  await (0, import_writeJSFile.writeJSFile)(filePath, data);
115
116
  }
116
117
  } catch (error) {
117
- throw new Error(`Error writing file to ${filePath}: ${error}`);
118
+ console.error(data);
119
+ throw new Error(
120
+ `${import_client.x} Error writing file to ${(0, import_client.colorizePath)(filePath)}: ${error}`
121
+ );
118
122
  }
119
123
  };
120
124
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/unmerged-dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport { existsSync } from 'fs';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { dirname, extname } from 'path';\nimport { prepareContentDeclaration } from '../prepareContentDeclaration';\nimport type { DictionaryStatus } from './dictionaryStatus';\nimport { writeJSFile } from './writeJSFile';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nconst formatContentDeclaration = async (dictionary: Dictionary) => {\n // Clean Markdown, Insertion, File, etc. node metadata\n const preparedContentDeclaration =\n await prepareContentDeclaration(dictionary);\n\n // Remove the filePath from the dictionary and set $schema\n const { filePath, $schema, ...dictionaryWithoutPath } =\n preparedContentDeclaration;\n\n const formattedContentDeclaration = {\n $schema: 'https://intlayer.org/schema.json',\n ...dictionaryWithoutPath,\n };\n\n return formattedContentDeclaration;\n};\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n config: IntlayerConfig = configuration,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const { content } = config;\n const { baseDir } = content;\n\n const newDictionaryRelativeLocationPath =\n newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = (\n dictionariesRecord[dictionary.key] as Dictionary[]\n ).filter((el) => el.filePath === dictionary.filePath);\n\n const filePath = dictionary.filePath;\n const formattedContentDeclaration =\n await formatContentDeclaration(dictionary);\n\n if (existingDictionary) {\n // Compare existing dictionary with distant dictionary\n if (deepEqual(existingDictionary, dictionary)) {\n // Up to date, nothing to do\n return {\n status: 'up-to-date',\n path: filePath!,\n };\n } else {\n if (filePath) {\n await writeFileWithDirectories(filePath, formattedContentDeclaration);\n\n return { status: 'updated', path: filePath };\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration\n );\n\n return {\n status: 'reimported in new location',\n path: contentDeclarationPath,\n };\n }\n }\n } else {\n // No existing dictionary, write to new location\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await mkdir(dir, { recursive: true });\n }\n\n const extention = extname(filePath);\n const acceptedExtensions = configuration.content.fileExtensions.map(\n (extention) => extname(extention)\n );\n\n if (!acceptedExtensions.includes(extention)) {\n throw new Error(\n `Invalid file extension: ${extention}, file: ${filePath}`\n );\n }\n\n if (extention === '.json') {\n const jsonDictionary = JSON.stringify(data, null, 2);\n\n // Write the file\n await writeFile(filePath, jsonDictionary);\n } else {\n await writeJSFile(filePath, data as unknown as Dictionary);\n }\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAG1B,yCAA+B;AAC/B,wBAAsB;AACtB,gBAA2B;AAC3B,sBAAiC;AACjC,kBAAiC;AACjC,uCAA0C;AAE1C,yBAA4B;AAE5B,MAAM,8BAA8B;AAEpC,MAAM,2BAA2B,OAAO,eAA2B;AAEjE,QAAM,6BACJ,UAAM,4DAA0B,UAAU;AAG5C,QAAM,EAAE,UAAU,SAAS,GAAG,sBAAsB,IAClD;AAEF,QAAM,8BAA8B;AAAA,IAClC,SAAS;AAAA,IACT,GAAG;AAAA,EACL;AAEA,SAAO;AACT;AAEO,MAAM,0BAA0B,OACrC,YACA,SAAyB,aAAAA,SACzB,wBACwD;AACxD,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,EAAE,QAAQ,IAAI;AAEpB,QAAM,oCACJ,uBAAuB;AACzB,QAAM,4BAA4B,GAAG,OAAO,IAAI,iCAAiC;AAEjF,QAAM,qBACJ,mCAAAC,QAAmB,WAAW,GAAG,EACjC,OAAO,CAAC,OAAO,GAAG,aAAa,WAAW,QAAQ;AAEpD,QAAM,WAAW,WAAW;AAC5B,QAAM,8BACJ,MAAM,yBAAyB,UAAU;AAE3C,MAAI,oBAAoB;AAEtB,YAAI,kBAAAC,SAAU,oBAAoB,UAAU,GAAG;AAE7C,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,MACR;AAAA,IACF,OAAO;AACL,UAAI,UAAU;AACZ,cAAM,yBAAyB,UAAU,2BAA2B;AAEpE,eAAO,EAAE,QAAQ,WAAW,MAAM,SAAS;AAAA,MAC7C,OAAO;AAEL,cAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAE7E,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,QACF;AAEA,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAE7E,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,IACF;AAEA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,OAC/B,UACA,SACkB;AAClB,MAAI;AAEF,UAAM,UAAM,qBAAQ,QAAQ;AAG5B,UAAM,sBAAkB,sBAAW,GAAG;AAEtC,QAAI,CAAC,iBAAiB;AAEpB,gBAAM,uBAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACtC;AAEA,UAAM,gBAAY,qBAAQ,QAAQ;AAClC,UAAM,qBAAqB,aAAAF,QAAc,QAAQ,eAAe;AAAA,MAC9D,CAACG,mBAAc,qBAAQA,UAAS;AAAA,IAClC;AAEA,QAAI,CAAC,mBAAmB,SAAS,SAAS,GAAG;AAC3C,YAAM,IAAI;AAAA,QACR,2BAA2B,SAAS,WAAW,QAAQ;AAAA,MACzD;AAAA,IACF;AAEA,QAAI,cAAc,SAAS;AACzB,YAAM,iBAAiB,KAAK,UAAU,MAAM,MAAM,CAAC;AAGnD,gBAAM,2BAAU,UAAU,cAAc;AAAA,IAC1C,OAAO;AACL,gBAAM,gCAAY,UAAU,IAA6B;AAAA,IAC3D;AAAA,EACF,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,EAC/D;AACF;","names":["configuration","dictionariesRecord","deepEqual","extention"]}
1
+ {"version":3,"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { colorizePath, x, type IntlayerConfig } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/unmerged-dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport { existsSync } from 'fs';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { dirname, extname } from 'path';\nimport { prepareContentDeclaration } from '../prepareContentDeclaration';\nimport type { DictionaryStatus } from './dictionaryStatus';\nimport { writeJSFile } from './writeJSFile';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nconst formatContentDeclaration = async (dictionary: Dictionary) => {\n // Clean Markdown, Insertion, File, etc. node metadata\n const preparedContentDeclaration =\n await prepareContentDeclaration(dictionary);\n\n // Remove the filePath from the dictionary and set $schema\n const { filePath, $schema, ...dictionaryWithoutPath } =\n preparedContentDeclaration;\n\n const formattedContentDeclaration = {\n $schema: 'https://intlayer.org/schema.json',\n ...dictionaryWithoutPath,\n };\n\n return formattedContentDeclaration;\n};\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n config: IntlayerConfig = configuration,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const { content } = config;\n const { baseDir } = content;\n\n const newDictionaryRelativeLocationPath =\n newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = (\n dictionariesRecord[dictionary.key] as Dictionary[]\n ).filter((el) => el.filePath === dictionary.filePath);\n\n const filePath = dictionary.filePath;\n const formattedContentDeclaration =\n await formatContentDeclaration(dictionary);\n\n if (existingDictionary) {\n // Compare existing dictionary with distant dictionary\n if (deepEqual(existingDictionary, dictionary)) {\n // Up to date, nothing to do\n return {\n status: 'up-to-date',\n path: filePath!,\n };\n } else {\n if (filePath) {\n await writeFileWithDirectories(filePath, formattedContentDeclaration);\n\n return { status: 'updated', path: filePath };\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration\n );\n\n return {\n status: 'new content file',\n path: contentDeclarationPath,\n };\n }\n }\n } else {\n // No existing dictionary, write to new location\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await mkdir(dir, { recursive: true });\n }\n\n const extention = extname(filePath);\n const acceptedExtensions = configuration.content.fileExtensions.map(\n (extention) => extname(extention)\n );\n\n if (!acceptedExtensions.includes(extention)) {\n throw new Error(\n `Invalid file extension: ${extention}, file: ${filePath}`\n );\n }\n\n if (extention === '.json') {\n const jsonDictionary = JSON.stringify(data, null, 2);\n\n // Write the file\n await writeFile(filePath, jsonDictionary);\n } else {\n await writeJSFile(filePath, data as unknown as Dictionary);\n }\n } catch (error) {\n console.error(data);\n\n throw new Error(\n `${x} Error writing file to ${colorizePath(filePath)}: ${error}`\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,oBAAqD;AAErD,yCAA+B;AAC/B,wBAAsB;AACtB,gBAA2B;AAC3B,sBAAiC;AACjC,kBAAiC;AACjC,uCAA0C;AAE1C,yBAA4B;AAE5B,MAAM,8BAA8B;AAEpC,MAAM,2BAA2B,OAAO,eAA2B;AAEjE,QAAM,6BACJ,UAAM,4DAA0B,UAAU;AAG5C,QAAM,EAAE,UAAU,SAAS,GAAG,sBAAsB,IAClD;AAEF,QAAM,8BAA8B;AAAA,IAClC,SAAS;AAAA,IACT,GAAG;AAAA,EACL;AAEA,SAAO;AACT;AAEO,MAAM,0BAA0B,OACrC,YACA,SAAyB,aAAAA,SACzB,wBACwD;AACxD,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,EAAE,QAAQ,IAAI;AAEpB,QAAM,oCACJ,uBAAuB;AACzB,QAAM,4BAA4B,GAAG,OAAO,IAAI,iCAAiC;AAEjF,QAAM,qBACJ,mCAAAC,QAAmB,WAAW,GAAG,EACjC,OAAO,CAAC,OAAO,GAAG,aAAa,WAAW,QAAQ;AAEpD,QAAM,WAAW,WAAW;AAC5B,QAAM,8BACJ,MAAM,yBAAyB,UAAU;AAE3C,MAAI,oBAAoB;AAEtB,YAAI,kBAAAC,SAAU,oBAAoB,UAAU,GAAG;AAE7C,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,MACR;AAAA,IACF,OAAO;AACL,UAAI,UAAU;AACZ,cAAM,yBAAyB,UAAU,2BAA2B;AAEpE,eAAO,EAAE,QAAQ,WAAW,MAAM,SAAS;AAAA,MAC7C,OAAO;AAEL,cAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAE7E,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,QACF;AAEA,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAE7E,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,IACF;AAEA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,OAC/B,UACA,SACkB;AAClB,MAAI;AAEF,UAAM,UAAM,qBAAQ,QAAQ;AAG5B,UAAM,sBAAkB,sBAAW,GAAG;AAEtC,QAAI,CAAC,iBAAiB;AAEpB,gBAAM,uBAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACtC;AAEA,UAAM,gBAAY,qBAAQ,QAAQ;AAClC,UAAM,qBAAqB,aAAAF,QAAc,QAAQ,eAAe;AAAA,MAC9D,CAACG,mBAAc,qBAAQA,UAAS;AAAA,IAClC;AAEA,QAAI,CAAC,mBAAmB,SAAS,SAAS,GAAG;AAC3C,YAAM,IAAI;AAAA,QACR,2BAA2B,SAAS,WAAW,QAAQ;AAAA,MACzD;AAAA,IACF;AAEA,QAAI,cAAc,SAAS;AACzB,YAAM,iBAAiB,KAAK,UAAU,MAAM,MAAM,CAAC;AAGnD,gBAAM,2BAAU,UAAU,cAAc;AAAA,IAC1C,OAAO;AACL,gBAAM,gCAAY,UAAU,IAA6B;AAAA,IAC3D;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,IAAI;AAElB,UAAM,IAAI;AAAA,MACR,GAAG,eAAC,8BAA0B,4BAAa,QAAQ,CAAC,KAAK,KAAK;AAAA,IAChE;AAAA,EACF;AACF;","names":["configuration","dictionariesRecord","deepEqual","extention"]}
@@ -31,9 +31,9 @@ __export(writeJSFile_exports, {
31
31
  writeJSFile: () => writeJSFile
32
32
  });
33
33
  module.exports = __toCommonJS(writeJSFile_exports);
34
- var import_generator = __toESM(require("@babel/generator"));
34
+ var generate = __toESM(require("@babel/generator"));
35
35
  var babelParser = __toESM(require("@babel/parser"));
36
- var import_traverse = __toESM(require("@babel/traverse"));
36
+ var babelTraverse = __toESM(require("@babel/traverse"));
37
37
  var t = __toESM(require("@babel/types"));
38
38
  var import_config = require("@intlayer/config");
39
39
  var import_built = __toESM(require("@intlayer/config/built"));
@@ -44,6 +44,20 @@ var import_path = require("path");
44
44
  var import_getContentDeclarationFileTemplate = require('../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs');
45
45
  var import_formatCode = require('./formatCode.cjs');
46
46
  const writeJSFile = async (filePath, dictionary) => {
47
+ const normalizeTraverse = (mod) => {
48
+ const candidate = mod;
49
+ if (typeof candidate === "function") return candidate;
50
+ if (candidate?.default) {
51
+ if (typeof candidate.default === "function") return candidate.default;
52
+ if (typeof candidate.default?.default === "function")
53
+ return candidate.default.default;
54
+ if (typeof candidate.default?.traverse === "function")
55
+ return candidate.default.traverse;
56
+ }
57
+ if (typeof candidate?.traverse === "function") return candidate.traverse;
58
+ return candidate;
59
+ };
60
+ const traverse = normalizeTraverse(babelTraverse);
47
61
  const appLogger = (0, import_config.getAppLogger)(import_built.default);
48
62
  const {
49
63
  key: dictionaryIdentifierKey,
@@ -89,18 +103,20 @@ const writeJSFile = async (filePath, dictionary) => {
89
103
  });
90
104
  let dictionaryObjectPath = null;
91
105
  let dictionaryIdentifier = null;
92
- (0, import_traverse.default)(ast, {
106
+ traverse(ast, {
93
107
  ObjectExpression(path) {
94
108
  if (dictionaryObjectPath) return;
95
- const keyProp = path.node.properties.find((prop) => {
96
- if (!t.isObjectProperty(prop)) return false;
97
- if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))
98
- return false;
99
- const keyName = t.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
100
- if (keyName !== "key" || !t.isStringLiteral(prop.value)) return false;
101
- const propValue = prop.value.value;
102
- return propValue === dictionaryIdentifierKey;
103
- });
109
+ const keyProp = path.node.properties.find(
110
+ (prop) => {
111
+ if (!t.isObjectProperty(prop)) return false;
112
+ if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))
113
+ return false;
114
+ const keyName = t.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
115
+ if (keyName !== "key" || !t.isStringLiteral(prop.value)) return false;
116
+ const propValue = prop.value.value;
117
+ return propValue === dictionaryIdentifierKey;
118
+ }
119
+ );
104
120
  if (keyProp) {
105
121
  dictionaryObjectPath = path;
106
122
  path.stop();
@@ -112,7 +128,7 @@ const writeJSFile = async (filePath, dictionary) => {
112
128
  isVerbose: true
113
129
  });
114
130
  const candidateVars = [];
115
- (0, import_traverse.default)(ast, {
131
+ traverse(ast, {
116
132
  VariableDeclarator(path) {
117
133
  const { node } = path;
118
134
  if (!t.isIdentifier(node.id)) return;
@@ -149,19 +165,21 @@ const writeJSFile = async (filePath, dictionary) => {
149
165
  appLogger("Could not find dictionary object. Dumping all objects:", {
150
166
  isVerbose: true
151
167
  });
152
- (0, import_traverse.default)(ast, {
168
+ traverse(ast, {
153
169
  ObjectExpression(path) {
154
- const props = path.node.properties.map((prop) => {
155
- if (!t.isObjectProperty(prop)) return "non-object-property";
156
- if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))
157
- return "complex-key";
158
- const keyName = t.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
159
- let valueDesc = "unknown-value";
160
- if (t.isStringLiteral(prop.value)) {
161
- valueDesc = `"${prop.value.value}"`;
170
+ const props = path.node.properties.map(
171
+ (prop) => {
172
+ if (!t.isObjectProperty(prop)) return "non-object-property";
173
+ if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))
174
+ return "complex-key";
175
+ const keyName = t.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
176
+ let valueDesc = "unknown-value";
177
+ if (t.isStringLiteral(prop.value)) {
178
+ valueDesc = `"${prop.value.value}"`;
179
+ }
180
+ return `${keyName}: ${valueDesc}`;
162
181
  }
163
- return `${keyName}: ${valueDesc}`;
164
- }).join(", ");
182
+ ).join(", ");
165
183
  appLogger(`Object: { ${props} }`);
166
184
  }
167
185
  });
@@ -301,7 +319,7 @@ const writeJSFile = async (filePath, dictionary) => {
301
319
  }
302
320
  mergeValueIntoProperty(targetPropertyPath, newEntryData, entryKeyToUpdate);
303
321
  }
304
- const generatedCode = (0, import_generator.default)(ast, {
322
+ const generatedCode = generate.generate(ast, {
305
323
  retainLines: true,
306
324
  comments: true,
307
325
  jsescOption: {