@intlayer/chokidar 5.8.1-canary.0 → 6.0.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) 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} +10 -10
  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 +10 -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 +101 -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/formatCode.cjs +7 -4
  59. package/dist/cjs/writeContentDeclaration/formatCode.cjs.map +1 -1
  60. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +5 -1
  61. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
  62. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +43 -25
  63. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
  64. package/dist/esm/chokidar/watcher.mjs +16 -21
  65. package/dist/esm/chokidar/watcher.mjs.map +1 -1
  66. package/dist/esm/fetchDistantDictionaries.mjs +24 -28
  67. package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
  68. package/dist/esm/{fetchDistantDictionaryKeys.mjs → fetchDistantDictionaryKeysAndUpdateTimestamp.mjs} +6 -6
  69. package/dist/esm/fetchDistantDictionaryKeysAndUpdateTimestamp.mjs.map +1 -0
  70. package/dist/esm/filterInvalidDictionaries.mjs +40 -0
  71. package/dist/esm/filterInvalidDictionaries.mjs.map +1 -0
  72. package/dist/esm/getBuiltFetchDictionariesPath.mjs +18 -0
  73. package/dist/esm/getBuiltFetchDictionariesPath.mjs.map +1 -0
  74. package/dist/esm/getBuiltRemoteDictionariesPath.mjs +17 -0
  75. package/dist/esm/getBuiltRemoteDictionariesPath.mjs.map +1 -0
  76. package/dist/esm/index.mjs +8 -9
  77. package/dist/esm/index.mjs.map +1 -1
  78. package/dist/esm/loadDictionaries/index.mjs +2 -2
  79. package/dist/esm/loadDictionaries/index.mjs.map +1 -1
  80. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +61 -18
  81. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
  82. package/dist/esm/loadDictionaries/loadDictionaries.mjs +132 -53
  83. package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
  84. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +66 -0
  85. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -0
  86. package/dist/esm/loadDictionaries/log.mjs +125 -0
  87. package/dist/esm/loadDictionaries/log.mjs.map +1 -0
  88. package/dist/esm/mergeDictionaries.mjs +19 -23
  89. package/dist/esm/mergeDictionaries.mjs.map +1 -1
  90. package/dist/esm/orderDictionaries.mjs +37 -0
  91. package/dist/esm/orderDictionaries.mjs.map +1 -0
  92. package/dist/esm/prepareContentDeclaration.mjs +4 -1
  93. package/dist/esm/prepareContentDeclaration.mjs.map +1 -1
  94. package/dist/esm/prepareIntlayer.mjs +9 -4
  95. package/dist/esm/prepareIntlayer.mjs.map +1 -1
  96. package/dist/esm/processPerLocaleDictionary.mjs.map +1 -1
  97. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs +25 -9
  98. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -1
  99. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs +45 -43
  100. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs.map +1 -1
  101. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs +58 -0
  102. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs.map +1 -0
  103. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs +29 -21
  104. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs.map +1 -1
  105. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs +28 -0
  106. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs.map +1 -0
  107. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs +45 -30
  108. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs.map +1 -1
  109. package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +39 -34
  110. package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
  111. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +4 -6
  112. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
  113. package/dist/esm/transpiler/dictionary_to_type/createType.mjs +17 -16
  114. package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
  115. package/dist/esm/utils/formatter.mjs +15 -0
  116. package/dist/esm/utils/formatter.mjs.map +1 -0
  117. package/dist/esm/utils/parallelize.mjs +9 -0
  118. package/dist/esm/utils/parallelize.mjs.map +1 -0
  119. package/dist/esm/utils/runOnce.mjs +2 -1
  120. package/dist/esm/utils/runOnce.mjs.map +1 -1
  121. package/dist/esm/writeContentDeclaration/formatCode.mjs +8 -5
  122. package/dist/esm/writeContentDeclaration/formatCode.mjs.map +1 -1
  123. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +5 -1
  124. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
  125. package/dist/esm/writeContentDeclaration/writeJSFile.mjs +40 -22
  126. package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
  127. package/dist/types/chokidar/watcher.d.ts.map +1 -1
  128. package/dist/types/fetchDistantDictionaries.d.ts +2 -1
  129. package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
  130. package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts +3 -0
  131. package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts.map +1 -0
  132. package/dist/types/filterInvalidDictionaries.d.ts +3 -0
  133. package/dist/types/filterInvalidDictionaries.d.ts.map +1 -0
  134. package/dist/types/getBuiltFetchDictionariesPath.d.ts +5 -0
  135. package/dist/types/getBuiltFetchDictionariesPath.d.ts.map +1 -0
  136. package/dist/types/getBuiltRemoteDictionariesPath.d.ts +5 -0
  137. package/dist/types/getBuiltRemoteDictionariesPath.d.ts.map +1 -0
  138. package/dist/types/index.d.ts +3 -4
  139. package/dist/types/index.d.ts.map +1 -1
  140. package/dist/types/loadDictionaries/index.d.ts +2 -2
  141. package/dist/types/loadDictionaries/index.d.ts.map +1 -1
  142. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +4 -1
  143. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
  144. package/dist/types/loadDictionaries/loadDictionaries.d.ts +11 -1
  145. package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
  146. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +6 -0
  147. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -0
  148. package/dist/types/loadDictionaries/log.d.ts +19 -0
  149. package/dist/types/loadDictionaries/log.d.ts.map +1 -0
  150. package/dist/types/mergeDictionaries.d.ts +1 -1
  151. package/dist/types/mergeDictionaries.d.ts.map +1 -1
  152. package/dist/types/orderDictionaries.d.ts +10 -0
  153. package/dist/types/orderDictionaries.d.ts.map +1 -0
  154. package/dist/types/prepareContentDeclaration.d.ts.map +1 -1
  155. package/dist/types/prepareIntlayer.d.ts.map +1 -1
  156. package/dist/types/processPerLocaleDictionary.d.ts +1 -1
  157. package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +1 -0
  158. package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts.map +1 -1
  159. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +4 -3
  160. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +1 -1
  161. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts +1 -1
  162. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts.map +1 -1
  163. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts +23 -0
  164. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts.map +1 -0
  165. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts +1 -1
  166. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts.map +1 -1
  167. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts +19 -0
  168. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts.map +1 -0
  169. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.d.ts.map +1 -1
  170. package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts +1 -1
  171. package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts.map +1 -1
  172. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +1 -1
  173. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts.map +1 -1
  174. package/dist/types/transpiler/dictionary_to_type/createType.d.ts +1 -1
  175. package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +1 -1
  176. package/dist/types/utils/formatter.d.ts +4 -0
  177. package/dist/types/utils/formatter.d.ts.map +1 -0
  178. package/dist/types/utils/parallelize.d.ts +2 -0
  179. package/dist/types/utils/parallelize.d.ts.map +1 -0
  180. package/dist/types/utils/runOnce.d.ts +1 -1
  181. package/dist/types/utils/runOnce.d.ts.map +1 -1
  182. package/dist/types/writeContentDeclaration/formatCode.d.ts.map +1 -1
  183. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +1 -1
  184. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
  185. package/dist/types/writeContentDeclaration/writeJSFile.d.ts +1 -1
  186. package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -1
  187. package/package.json +19 -17
  188. package/dist/cjs/checkDictionaryChanges.cjs +0 -58
  189. package/dist/cjs/checkDictionaryChanges.cjs.map +0 -1
  190. package/dist/cjs/fetchDistantDictionaryKeys.cjs.map +0 -1
  191. package/dist/cjs/getFilteredLocalesContent.cjs +0 -70
  192. package/dist/cjs/getFilteredLocalesContent.cjs.map +0 -1
  193. package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs +0 -44
  194. package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs.map +0 -1
  195. package/dist/cjs/log.cjs +0 -296
  196. package/dist/cjs/log.cjs.map +0 -1
  197. package/dist/esm/checkDictionaryChanges.mjs +0 -37
  198. package/dist/esm/checkDictionaryChanges.mjs.map +0 -1
  199. package/dist/esm/fetchDistantDictionaryKeys.mjs.map +0 -1
  200. package/dist/esm/getFilteredLocalesContent.mjs +0 -49
  201. package/dist/esm/getFilteredLocalesContent.mjs.map +0 -1
  202. package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs +0 -20
  203. package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs.map +0 -1
  204. package/dist/esm/log.mjs +0 -262
  205. package/dist/esm/log.mjs.map +0 -1
  206. package/dist/types/checkDictionaryChanges.d.ts +0 -3
  207. package/dist/types/checkDictionaryChanges.d.ts.map +0 -1
  208. package/dist/types/fetchDistantDictionaryKeys.d.ts +0 -3
  209. package/dist/types/fetchDistantDictionaryKeys.d.ts.map +0 -1
  210. package/dist/types/getFilteredLocalesContent.d.ts +0 -4
  211. package/dist/types/getFilteredLocalesContent.d.ts.map +0 -1
  212. package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts +0 -8
  213. package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts.map +0 -1
  214. package/dist/types/log.d.ts +0 -45
  215. package/dist/types/log.d.ts.map +0 -1
@@ -15,15 +15,15 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
16
  var loadDictionaries_exports = {};
17
17
  module.exports = __toCommonJS(loadDictionaries_exports);
18
+ __reExport(loadDictionaries_exports, require('./loadContentDeclaration.cjs'), module.exports);
18
19
  __reExport(loadDictionaries_exports, require('./loadDictionaries.cjs'), module.exports);
19
- __reExport(loadDictionaries_exports, require('./loadDistantDictionaries.cjs'), module.exports);
20
20
  __reExport(loadDictionaries_exports, require('./loadLocalDictionaries.cjs'), module.exports);
21
- __reExport(loadDictionaries_exports, require('./loadContentDeclaration.cjs'), module.exports);
21
+ __reExport(loadDictionaries_exports, require('./loadRemoteDictionaries.cjs'), module.exports);
22
22
  // Annotate the CommonJS export names for ESM import in node:
23
23
  0 && (module.exports = {
24
+ ...require('./loadContentDeclaration.cjs'),
24
25
  ...require('./loadDictionaries.cjs'),
25
- ...require('./loadDistantDictionaries.cjs'),
26
26
  ...require('./loadLocalDictionaries.cjs'),
27
- ...require('./loadContentDeclaration.cjs')
27
+ ...require('./loadRemoteDictionaries.cjs')
28
28
  });
29
29
  //# sourceMappingURL=index.cjs.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;AAAA;AAAA,qCAAc,+BAAd;AACA,qCAAc,sCADd;AAEA,qCAAc,oCAFd;AAGA,qCAAc,qCAHd;","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;AAAA;AAAA,qCAAc,qCAAd;AACA,qCAAc,+BADd;AAEA,qCAAc,oCAFd;AAGA,qCAAc,qCAHd;","names":[]}
@@ -18,33 +18,73 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var loadContentDeclaration_exports = {};
20
20
  __export(loadContentDeclaration_exports, {
21
+ formatLocalDictionaries: () => formatLocalDictionaries,
21
22
  loadContentDeclarations: () => loadContentDeclarations
22
23
  });
23
24
  module.exports = __toCommonJS(loadContentDeclaration_exports);
24
25
  var import_config = require("@intlayer/config");
26
+ var import_path = require("path");
27
+ var import_filterInvalidDictionaries = require('../filterInvalidDictionaries.cjs');
25
28
  var import_processContentDeclaration = require('../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs');
26
- const loadContentDeclarations = async (contentDeclarationFilePath, projectRequire = import_config.ESMxCJSRequire) => {
27
- const contentDeclarations = contentDeclarationFilePath.map((path) => ({
28
- ...(0, import_config.loadExternalFile)(path, void 0, projectRequire),
29
- filePath: path
29
+ var import_parallelize = require('../utils/parallelize.cjs');
30
+ const formatLocalDictionaries = (dictionariesRecord) => Object.entries(dictionariesRecord).map(([relativePath, dict]) => ({
31
+ ...dict,
32
+ localId: `${dict.key}::local::${relativePath}`,
33
+ location: "locale",
34
+ filePath: relativePath
35
+ }));
36
+ const loadContentDeclarations = async (contentDeclarationFilePath, configuration = (0, import_config.getConfiguration)(), projectRequire = import_config.ESMxCJSRequire, onStatusUpdate) => {
37
+ const dictionariesRecord = contentDeclarationFilePath.reduce(
38
+ (acc, path) => {
39
+ const relativePath = (0, import_path.relative)(configuration.content.baseDir, path);
40
+ return {
41
+ ...acc,
42
+ [relativePath]: (0, import_config.loadExternalFile)(path, void 0, projectRequire)
43
+ };
44
+ },
45
+ {}
46
+ );
47
+ const contentDeclarations = formatLocalDictionaries(dictionariesRecord);
48
+ const listFoundDictionaries = contentDeclarations.map((declaration) => ({
49
+ dictionaryKey: declaration.key,
50
+ type: "local",
51
+ status: "found"
30
52
  }));
31
- const resultDictionariesPaths = [];
32
- for await (const contentDeclaration of contentDeclarations) {
33
- if (!contentDeclaration) {
34
- continue;
53
+ onStatusUpdate?.(listFoundDictionaries);
54
+ const processedDictionaries = await (0, import_parallelize.parallelize)(
55
+ contentDeclarations,
56
+ async (contentDeclaration) => {
57
+ if (!contentDeclaration) {
58
+ return void 0;
59
+ }
60
+ onStatusUpdate?.([
61
+ {
62
+ dictionaryKey: contentDeclaration.key,
63
+ type: "local",
64
+ status: "building"
65
+ }
66
+ ]);
67
+ const processedContentDeclaration = await (0, import_processContentDeclaration.processContentDeclaration)(
68
+ contentDeclaration
69
+ );
70
+ if (!processedContentDeclaration) {
71
+ return void 0;
72
+ }
73
+ onStatusUpdate?.([
74
+ {
75
+ dictionaryKey: processedContentDeclaration.key,
76
+ type: "local",
77
+ status: "built"
78
+ }
79
+ ]);
80
+ return processedContentDeclaration;
35
81
  }
36
- const processedContentDeclaration = await (0, import_processContentDeclaration.processContentDeclaration)(
37
- contentDeclaration
38
- );
39
- if (!processedContentDeclaration) {
40
- continue;
41
- }
42
- resultDictionariesPaths.push(processedContentDeclaration);
43
- }
44
- return resultDictionariesPaths;
82
+ );
83
+ return (0, import_filterInvalidDictionaries.filterInvalidDictionaries)(processedDictionaries);
45
84
  };
46
85
  // Annotate the CommonJS export names for ESM import in node:
47
86
  0 && (module.exports = {
87
+ formatLocalDictionaries,
48
88
  loadContentDeclarations
49
89
  });
50
90
  //# sourceMappingURL=loadContentDeclaration.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"sourcesContent":["import { ESMxCJSRequire, loadExternalFile } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { processContentDeclaration } from '../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration';\n\nexport const loadContentDeclarations = async (\n contentDeclarationFilePath: string[],\n projectRequire = ESMxCJSRequire\n): Promise<Dictionary[]> => {\n const contentDeclarations = contentDeclarationFilePath.map((path) => ({\n ...loadExternalFile(path, undefined, projectRequire),\n filePath: path,\n }));\n const resultDictionariesPaths: Dictionary[] = [];\n\n for await (const contentDeclaration of contentDeclarations) {\n if (!contentDeclaration) {\n continue;\n }\n\n const processedContentDeclaration = await processContentDeclaration(\n contentDeclaration as Dictionary\n );\n\n if (!processedContentDeclaration) {\n continue;\n }\n\n resultDictionariesPaths.push(processedContentDeclaration);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiD;AAEjD,uCAA0C;AAEnC,MAAM,0BAA0B,OACrC,4BACA,iBAAiB,iCACS;AAC1B,QAAM,sBAAsB,2BAA2B,IAAI,CAAC,UAAU;AAAA,IACpE,OAAG,gCAAiB,MAAM,QAAW,cAAc;AAAA,IACnD,UAAU;AAAA,EACZ,EAAE;AACF,QAAM,0BAAwC,CAAC;AAE/C,mBAAiB,sBAAsB,qBAAqB;AAC1D,QAAI,CAAC,oBAAoB;AACvB;AAAA,IACF;AAEA,UAAM,8BAA8B,UAAM;AAAA,MACxC;AAAA,IACF;AAEA,QAAI,CAAC,6BAA6B;AAChC;AAAA,IACF;AAEA,4BAAwB,KAAK,2BAA2B;AAAA,EAC1D;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n getConfiguration,\n IntlayerConfig,\n loadExternalFile,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { relative } from 'path';\nimport { filterInvalidDictionaries } from '../filterInvalidDictionaries';\nimport { processContentDeclaration } from '../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration';\nimport { parallelize } from '../utils/parallelize';\nimport { DictionariesStatus } from './loadDictionaries';\n\nexport const formatLocalDictionaries = (\n dictionariesRecord: Record<string, Dictionary>\n): Dictionary[] =>\n Object.entries(dictionariesRecord).map(([relativePath, dict]) => ({\n ...dict,\n localId: `${dict.key}::local::${relativePath}`,\n location: 'locale' as const,\n filePath: relativePath,\n }));\n\nexport const loadContentDeclarations = async (\n contentDeclarationFilePath: string[],\n configuration: IntlayerConfig = getConfiguration(),\n projectRequire = ESMxCJSRequire,\n onStatusUpdate?: (status: DictionariesStatus[]) => void\n): Promise<Dictionary[]> => {\n const dictionariesRecord = contentDeclarationFilePath.reduce(\n (acc, path) => {\n const relativePath = relative(configuration.content.baseDir, path);\n return {\n ...acc,\n [relativePath]: loadExternalFile(path, undefined, projectRequire),\n };\n },\n {} as Record<string, Dictionary>\n );\n const contentDeclarations: Dictionary[] =\n formatLocalDictionaries(dictionariesRecord);\n\n const listFoundDictionaries = contentDeclarations.map((declaration) => ({\n dictionaryKey: declaration.key,\n type: 'local' as const,\n status: 'found' as const,\n }));\n\n onStatusUpdate?.(listFoundDictionaries);\n\n const processedDictionaries = await parallelize(\n contentDeclarations,\n async (contentDeclaration): Promise<Dictionary | undefined> => {\n if (!contentDeclaration) {\n return undefined;\n }\n\n onStatusUpdate?.([\n {\n dictionaryKey: contentDeclaration.key,\n type: 'local',\n status: 'building',\n },\n ]);\n\n const processedContentDeclaration = await processContentDeclaration(\n contentDeclaration as Dictionary\n );\n\n if (!processedContentDeclaration) {\n return undefined;\n }\n\n onStatusUpdate?.([\n {\n dictionaryKey: processedContentDeclaration.key,\n type: 'local',\n status: 'built',\n },\n ]);\n\n return processedContentDeclaration;\n }\n );\n\n return filterInvalidDictionaries(processedDictionaries);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKO;AAEP,kBAAyB;AACzB,uCAA0C;AAC1C,uCAA0C;AAC1C,yBAA4B;AAGrB,MAAM,0BAA0B,CACrC,uBAEA,OAAO,QAAQ,kBAAkB,EAAE,IAAI,CAAC,CAAC,cAAc,IAAI,OAAO;AAAA,EAChE,GAAG;AAAA,EACH,SAAS,GAAG,KAAK,GAAG,YAAY,YAAY;AAAA,EAC5C,UAAU;AAAA,EACV,UAAU;AACZ,EAAE;AAEG,MAAM,0BAA0B,OACrC,4BACA,oBAAgC,gCAAiB,GACjD,iBAAiB,8BACjB,mBAC0B;AAC1B,QAAM,qBAAqB,2BAA2B;AAAA,IACpD,CAAC,KAAK,SAAS;AACb,YAAM,mBAAe,sBAAS,cAAc,QAAQ,SAAS,IAAI;AACjE,aAAO;AAAA,QACL,GAAG;AAAA,QACH,CAAC,YAAY,OAAG,gCAAiB,MAAM,QAAW,cAAc;AAAA,MAClE;AAAA,IACF;AAAA,IACA,CAAC;AAAA,EACH;AACA,QAAM,sBACJ,wBAAwB,kBAAkB;AAE5C,QAAM,wBAAwB,oBAAoB,IAAI,CAAC,iBAAiB;AAAA,IACtE,eAAe,YAAY;AAAA,IAC3B,MAAM;AAAA,IACN,QAAQ;AAAA,EACV,EAAE;AAEF,mBAAiB,qBAAqB;AAEtC,QAAM,wBAAwB,UAAM;AAAA,IAClC;AAAA,IACA,OAAO,uBAAwD;AAC7D,UAAI,CAAC,oBAAoB;AACvB,eAAO;AAAA,MACT;AAEA,uBAAiB;AAAA,QACf;AAAA,UACE,eAAe,mBAAmB;AAAA,UAClC,MAAM;AAAA,UACN,QAAQ;AAAA,QACV;AAAA,MACF,CAAC;AAED,YAAM,8BAA8B,UAAM;AAAA,QACxC;AAAA,MACF;AAEA,UAAI,CAAC,6BAA6B;AAChC,eAAO;AAAA,MACT;AAEA,uBAAiB;AAAA,QACf;AAAA,UACE,eAAe,4BAA4B;AAAA,UAC3C,MAAM;AAAA,UACN,QAAQ;AAAA,QACV;AAAA,MACF,CAAC;AAED,aAAO;AAAA,IACT;AAAA,EACF;AAEA,aAAO,4DAA0B,qBAAqB;AACxD;","names":[]}
@@ -23,65 +23,140 @@ __export(loadDictionaries_exports, {
23
23
  module.exports = __toCommonJS(loadDictionaries_exports);
24
24
  var import_config = require("@intlayer/config");
25
25
  var import_node_path = require("node:path");
26
- var import_fetchDistantDictionaryKeys = require('../fetchDistantDictionaryKeys.cjs');
27
- var import_log = require('../log.cjs');
28
- var import_sortAlphabetically = require('../utils/sortAlphabetically.cjs');
29
26
  var import_loadContentDeclaration = require('./loadContentDeclaration.cjs');
30
- var import_loadDistantDictionaries = require('./loadDistantDictionaries.cjs');
31
- const loadDictionaries = async (contentDeclarationsPaths, configuration = (0, import_config.getConfiguration)(), projectRequire = import_config.ESMxCJSRequire) => {
32
- try {
33
- const appLogger = (0, import_config.getAppLogger)(configuration);
34
- const { editor } = configuration;
35
- appLogger("Dictionaries:", { isVerbose: true });
36
- const files = Array.isArray(contentDeclarationsPaths) ? contentDeclarationsPaths : [contentDeclarationsPaths];
37
- const localDictionaries = await (0, import_loadContentDeclaration.loadContentDeclarations)(
38
- files,
39
- projectRequire
27
+ var import_loadRemoteDictionaries = require('./loadRemoteDictionaries.cjs');
28
+ var import_log = require('./log.cjs');
29
+ let loadDictionariesStatus = [];
30
+ const logger = new import_log.DictionariesLogger();
31
+ const setLoadDictionariesStatus = (statuses) => {
32
+ let updated = [...loadDictionariesStatus];
33
+ for (const incoming of statuses) {
34
+ const idx = updated.findIndex(
35
+ (s) => s.dictionaryKey === incoming.dictionaryKey && s.type === incoming.type
40
36
  );
41
- const filteredLocalDictionaries = localDictionaries.filter((dict) => {
42
- const hasKey = Boolean(dict.key);
43
- const hasContent = Boolean(dict.content);
44
- if (!hasContent) {
45
- console.error(
37
+ if (idx >= 0) {
38
+ updated[idx] = incoming;
39
+ } else {
40
+ updated.push(incoming);
41
+ }
42
+ }
43
+ loadDictionariesStatus = updated;
44
+ logger.update(statuses);
45
+ return updated;
46
+ };
47
+ const iconFor = (status) => {
48
+ switch (status) {
49
+ case "built":
50
+ case "imported":
51
+ case "fetched":
52
+ return "\u2714";
53
+ case "error":
54
+ return "\u2716";
55
+ default:
56
+ return "\u23F2";
57
+ }
58
+ };
59
+ const colorFor = (status) => {
60
+ switch (status) {
61
+ case "built":
62
+ case "imported":
63
+ case "fetched":
64
+ return import_config.ANSIColors.GREEN;
65
+ case "error":
66
+ return import_config.ANSIColors.RED;
67
+ default:
68
+ return import_config.ANSIColors.BLUE;
69
+ }
70
+ };
71
+ const printSummary = (configuration = (0, import_config.getConfiguration)()) => {
72
+ if (configuration.log.mode !== "verbose") return;
73
+ const appLogger = (0, import_config.getAppLogger)(configuration);
74
+ const byKey = /* @__PURE__ */ new Map();
75
+ for (const s of loadDictionariesStatus) {
76
+ const rec = byKey.get(s.dictionaryKey) ?? {};
77
+ if (s.type === "local") rec.local = s.status;
78
+ if (s.type === "remote") rec.remote = s.status;
79
+ byKey.set(s.dictionaryKey, rec);
80
+ }
81
+ const keys = Array.from(byKey.keys()).sort((a, b) => a.localeCompare(b));
82
+ for (const key of keys) {
83
+ const rec = byKey.get(key);
84
+ const labels = [];
85
+ if (rec.local) {
86
+ const inner = (0, import_config.colorize)(
87
+ `${iconFor(rec.local)} ${rec.local}`,
88
+ colorFor(rec.local)
89
+ );
90
+ labels.push(
91
+ `${import_config.ANSIColors.GREY}[` + (0, import_config.colorize)("local: ", import_config.ANSIColors.GREY) + inner + `${import_config.ANSIColors.GREY}]${import_config.ANSIColors.RESET}`
92
+ );
93
+ }
94
+ if (rec.remote) {
95
+ const inner = (0, import_config.colorize)(
96
+ `${iconFor(rec.remote)} ${rec.remote}`,
97
+ colorFor(rec.remote)
98
+ );
99
+ labels.push(
100
+ `${import_config.ANSIColors.GREY}[` + (0, import_config.colorize)("distant: ", import_config.ANSIColors.GREY) + inner + `${import_config.ANSIColors.GREY}]${import_config.ANSIColors.RESET}`
101
+ );
102
+ }
103
+ appLogger(
104
+ ` - ${(0, import_config.colon)((0, import_config.colorizeKey)(key), { colSize: keys })} ${labels.join(" ")}`
105
+ );
106
+ }
107
+ };
108
+ const loadDictionaries = async (contentDeclarationsPaths, configuration = (0, import_config.getConfiguration)(), projectRequire = import_config.ESMxCJSRequire) => {
109
+ const appLogger = (0, import_config.getAppLogger)(configuration);
110
+ appLogger("Dictionaries:", { isVerbose: true });
111
+ const files = Array.isArray(contentDeclarationsPaths) ? contentDeclarationsPaths : [contentDeclarationsPaths];
112
+ const localDictionaries = await (0, import_loadContentDeclaration.loadContentDeclarations)(
113
+ files,
114
+ configuration,
115
+ projectRequire,
116
+ setLoadDictionariesStatus
117
+ );
118
+ const filteredLocalDictionaries = localDictionaries.filter((dict) => {
119
+ const hasKey = Boolean(dict.key);
120
+ const hasContent = Boolean(dict.content);
121
+ if (!hasContent) {
122
+ appLogger(
123
+ [
46
124
  "Content declaration has no exported content",
47
125
  dict.filePath ? (0, import_node_path.relative)(configuration.content.baseDir, dict.filePath) : ""
48
- );
49
- } else if (!hasKey) {
50
- console.error("Content declaration has no key", dict.filePath);
51
- }
52
- return hasKey && hasContent;
53
- });
54
- const localDictionaryKeys = filteredLocalDictionaries.map((dict) => dict.key).filter(Boolean);
55
- import_log.logger.init(localDictionaryKeys, []);
56
- import_log.logger.updateStatus(
57
- filteredLocalDictionaries.map((dict) => ({
58
- dictionaryKey: dict.key,
59
- type: "local",
60
- status: { status: "built" }
61
- }))
62
- );
63
- let distantDictionaries = [];
64
- let distantDictionaryKeys = [];
65
- if (editor.clientId && editor.clientSecret) {
66
- try {
67
- distantDictionaryKeys = await (0, import_fetchDistantDictionaryKeys.fetchDistantDictionaryKeys)();
68
- const orderedDistantDictionaryKeys = distantDictionaryKeys.sort(import_sortAlphabetically.sortAlphabetically);
69
- import_log.logger.addDictionaryKeys("distant", orderedDistantDictionaryKeys);
70
- distantDictionaries = await (0, import_loadDistantDictionaries.loadDistantDictionaries)({
71
- dictionaryKeys: orderedDistantDictionaryKeys
72
- });
73
- } catch (_error) {
74
- appLogger("Error during fetching distant dictionaries", {
75
- level: "error"
76
- });
77
- }
126
+ ],
127
+ { level: "error" }
128
+ );
129
+ } else if (!hasKey) {
130
+ appLogger(["Content declaration has no key", dict.filePath], {
131
+ level: "error"
132
+ });
78
133
  }
79
- import_log.logger.stop();
80
- return [...filteredLocalDictionaries, ...distantDictionaries];
81
- } catch (error) {
82
- import_log.logger.stop();
83
- throw error;
134
+ return hasKey && hasContent;
135
+ });
136
+ const localDictionariesStatus = filteredLocalDictionaries.map(
137
+ (dict) => ({
138
+ dictionaryKey: dict.key,
139
+ type: "local",
140
+ status: "built"
141
+ })
142
+ );
143
+ setLoadDictionariesStatus(localDictionariesStatus);
144
+ const hasRemoteDictionaries = Boolean(
145
+ configuration.editor.clientId && configuration.editor.clientSecret
146
+ );
147
+ let remoteDictionaries = [];
148
+ if (hasRemoteDictionaries) {
149
+ remoteDictionaries = await (0, import_loadRemoteDictionaries.loadRemoteDictionaries)(
150
+ configuration,
151
+ setLoadDictionariesStatus
152
+ );
84
153
  }
154
+ logger.finish();
155
+ printSummary(configuration);
156
+ return {
157
+ localDictionaries: filteredLocalDictionaries,
158
+ remoteDictionaries
159
+ };
85
160
  };
86
161
  // Annotate the CommonJS export names for ESM import in node:
87
162
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport {\n ESMxCJSRequire,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { relative } from 'node:path';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { sortAlphabetically } from '../utils/sortAlphabetically';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string,\n configuration = getConfiguration(),\n projectRequire = ESMxCJSRequire\n): Promise<Dictionary[]> => {\n try {\n const appLogger = getAppLogger(configuration);\n const { editor } = configuration;\n\n appLogger('Dictionaries:', { isVerbose: true });\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] = await loadContentDeclarations(\n files,\n projectRequire\n );\n\n const filteredLocalDictionaries = localDictionaries.filter((dict) => {\n const hasKey = Boolean(dict.key);\n const hasContent = Boolean(dict.content);\n\n if (!hasContent) {\n console.error(\n 'Content declaration has no exported content',\n dict.filePath\n ? relative(configuration.content.baseDir, dict.filePath)\n : ''\n );\n } else if (!hasKey) {\n console.error('Content declaration has no key', dict.filePath);\n }\n\n return hasKey && hasContent;\n });\n\n const localDictionaryKeys = filteredLocalDictionaries\n .map((dict) => dict.key)\n .filter(Boolean); // Remove empty or undefined keys\n\n // Initialize the logger with both local and distant dictionaries\n logger.init(localDictionaryKeys, []);\n\n // Update logger statuses for local dictionaries\n logger.updateStatus(\n filteredLocalDictionaries.map((dict) => ({\n dictionaryKey: dict.key,\n type: 'local',\n status: { status: 'built' },\n }))\n );\n\n let distantDictionaries: DictionaryAPI[] = [];\n let distantDictionaryKeys: string[] = [];\n\n if (editor.clientId && editor.clientSecret) {\n try {\n // Fetch distant dictionary keys\n distantDictionaryKeys = await fetchDistantDictionaryKeys();\n\n const orderedDistantDictionaryKeys =\n distantDictionaryKeys.sort(sortAlphabetically);\n\n // Add distant dictionaries to the logger\n logger.addDictionaryKeys('distant', orderedDistantDictionaryKeys);\n\n // Fetch distant dictionaries\n distantDictionaries = await loadDistantDictionaries({\n dictionaryKeys: orderedDistantDictionaryKeys,\n });\n } catch (_error) {\n appLogger('Error during fetching distant dictionaries', {\n level: 'error',\n });\n }\n }\n\n // Ensure the logger is stopped\n logger.stop();\n\n return [...filteredLocalDictionaries, ...distantDictionaries];\n } catch (error) {\n // Ensure the logger is stopped\n logger.stop();\n\n throw error; // Re-throw the error after logging\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAIO;AAEP,uBAAyB;AACzB,wCAA2C;AAC3C,iBAAuB;AACvB,gCAAmC;AACnC,oCAAwC;AACxC,qCAAwC;AAEjC,MAAM,mBAAmB,OAC9B,0BACA,oBAAgB,gCAAiB,GACjC,iBAAiB,iCACS;AAC1B,MAAI;AACF,UAAM,gBAAY,4BAAa,aAAa;AAC5C,UAAM,EAAE,OAAO,IAAI;AAEnB,cAAU,iBAAiB,EAAE,WAAW,KAAK,CAAC;AAE9C,UAAM,QAAQ,MAAM,QAAQ,wBAAwB,IAChD,2BACA,CAAC,wBAAwB;AAE7B,UAAM,oBAAkC,UAAM;AAAA,MAC5C;AAAA,MACA;AAAA,IACF;AAEA,UAAM,4BAA4B,kBAAkB,OAAO,CAAC,SAAS;AACnE,YAAM,SAAS,QAAQ,KAAK,GAAG;AAC/B,YAAM,aAAa,QAAQ,KAAK,OAAO;AAEvC,UAAI,CAAC,YAAY;AACf,gBAAQ;AAAA,UACN;AAAA,UACA,KAAK,eACD,2BAAS,cAAc,QAAQ,SAAS,KAAK,QAAQ,IACrD;AAAA,QACN;AAAA,MACF,WAAW,CAAC,QAAQ;AAClB,gBAAQ,MAAM,kCAAkC,KAAK,QAAQ;AAAA,MAC/D;AAEA,aAAO,UAAU;AAAA,IACnB,CAAC;AAED,UAAM,sBAAsB,0BACzB,IAAI,CAAC,SAAS,KAAK,GAAG,EACtB,OAAO,OAAO;AAGjB,sBAAO,KAAK,qBAAqB,CAAC,CAAC;AAGnC,sBAAO;AAAA,MACL,0BAA0B,IAAI,CAAC,UAAU;AAAA,QACvC,eAAe,KAAK;AAAA,QACpB,MAAM;AAAA,QACN,QAAQ,EAAE,QAAQ,QAAQ;AAAA,MAC5B,EAAE;AAAA,IACJ;AAEA,QAAI,sBAAuC,CAAC;AAC5C,QAAI,wBAAkC,CAAC;AAEvC,QAAI,OAAO,YAAY,OAAO,cAAc;AAC1C,UAAI;AAEF,gCAAwB,UAAM,8DAA2B;AAEzD,cAAM,+BACJ,sBAAsB,KAAK,4CAAkB;AAG/C,0BAAO,kBAAkB,WAAW,4BAA4B;AAGhE,8BAAsB,UAAM,wDAAwB;AAAA,UAClD,gBAAgB;AAAA,QAClB,CAAC;AAAA,MACH,SAAS,QAAQ;AACf,kBAAU,8CAA8C;AAAA,UACtD,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAGA,sBAAO,KAAK;AAEZ,WAAO,CAAC,GAAG,2BAA2B,GAAG,mBAAmB;AAAA,EAC9D,SAAS,OAAO;AAEd,sBAAO,KAAK;AAEZ,UAAM;AAAA,EACR;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n ESMxCJSRequire,\n getAppLogger,\n getConfiguration,\n type IntlayerConfig,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { relative } from 'node:path';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadRemoteDictionaries } from './loadRemoteDictionaries';\nimport { DictionariesLogger } from './log';\n\nexport type DictionariesStatus = {\n dictionaryKey: string;\n type: 'local' | 'remote';\n status:\n | 'pending' // Key found but not fetched yet\n | 'fetching' // If dictionary fetch is in progress\n | 'fetched' // If dictionary fetch succeeded\n | 'error' // If dictionary fetch failed\n | 'imported' // If dictionary already fetched and still up to date\n | 'found' // If dictionary key is found but promise is not resolved yet (ex: fetching distant content)\n | 'building' // If dictionary is being built\n | 'built'; // If dictionary is built;\n error?: string;\n};\n\nlet loadDictionariesStatus: DictionariesStatus[] = [];\nconst logger = new DictionariesLogger();\n\nconst setLoadDictionariesStatus = (statuses: DictionariesStatus[]) => {\n let updated: DictionariesStatus[] = [...loadDictionariesStatus];\n\n for (const incoming of statuses) {\n const idx = updated.findIndex(\n (s) =>\n s.dictionaryKey === incoming.dictionaryKey && s.type === incoming.type\n );\n if (idx >= 0) {\n updated[idx] = incoming;\n } else {\n updated.push(incoming);\n }\n }\n\n loadDictionariesStatus = updated;\n logger.update(statuses);\n\n return updated;\n};\n\ntype StatusRecord = {\n local?: DictionariesStatus['status'];\n remote?: DictionariesStatus['status'];\n};\n\nconst iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'built':\n case 'imported':\n case 'fetched':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n};\n\nconst colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'built':\n case 'imported':\n case 'fetched':\n return ANSIColors.GREEN;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n};\n\nconst printSummary = (configuration: IntlayerConfig = getConfiguration()) => {\n if (configuration.log.mode !== 'verbose') return;\n\n const appLogger = getAppLogger(configuration);\n\n // Aggregate by dictionary key\n const byKey = new Map<string, StatusRecord>();\n for (const s of loadDictionariesStatus) {\n const rec = byKey.get(s.dictionaryKey) ?? {};\n if (s.type === 'local') rec.local = s.status;\n if (s.type === 'remote') rec.remote = s.status;\n byKey.set(s.dictionaryKey, rec);\n }\n\n const keys = Array.from(byKey.keys()).sort((a, b) => a.localeCompare(b));\n\n for (const key of keys) {\n const rec = byKey.get(key)!;\n const labels: string[] = [];\n\n if (rec.local) {\n const inner = colorize(\n `${iconFor(rec.local)} ${rec.local}`,\n colorFor(rec.local)\n );\n labels.push(\n `${ANSIColors.GREY}[` +\n colorize('local: ', ANSIColors.GREY) +\n inner +\n `${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n if (rec.remote) {\n const inner = colorize(\n `${iconFor(rec.remote)} ${rec.remote}`,\n colorFor(rec.remote)\n );\n labels.push(\n `${ANSIColors.GREY}[` +\n colorize('distant: ', ANSIColors.GREY) +\n inner +\n `${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n appLogger(\n ` - ${colon(colorizeKey(key), { colSize: keys })} ${labels.join(' ')}`\n );\n }\n};\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string,\n configuration: IntlayerConfig = getConfiguration(),\n projectRequire = ESMxCJSRequire\n): Promise<{\n localDictionaries: Dictionary[];\n remoteDictionaries: Dictionary[];\n}> => {\n const appLogger = getAppLogger(configuration);\n\n appLogger('Dictionaries:', { isVerbose: true });\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] = await loadContentDeclarations(\n files,\n configuration,\n projectRequire,\n setLoadDictionariesStatus\n );\n\n const filteredLocalDictionaries = localDictionaries.filter((dict) => {\n const hasKey = Boolean(dict.key);\n const hasContent = Boolean(dict.content);\n\n if (!hasContent) {\n appLogger(\n [\n 'Content declaration has no exported content',\n dict.filePath\n ? relative(configuration.content.baseDir, dict.filePath)\n : '',\n ],\n { level: 'error' }\n );\n } else if (!hasKey) {\n appLogger(['Content declaration has no key', dict.filePath], {\n level: 'error',\n });\n }\n\n return hasKey && hasContent;\n });\n\n const localDictionariesStatus = filteredLocalDictionaries.map(\n (dict) =>\n ({\n dictionaryKey: dict.key,\n type: 'local',\n status: 'built',\n }) as const\n );\n\n setLoadDictionariesStatus(localDictionariesStatus);\n\n const hasRemoteDictionaries = Boolean(\n configuration.editor.clientId && configuration.editor.clientSecret\n );\n\n let remoteDictionaries: Dictionary[] = [];\n if (hasRemoteDictionaries) {\n remoteDictionaries = await loadRemoteDictionaries(\n configuration,\n setLoadDictionariesStatus\n );\n }\n\n // Stop spinner and show final progress line(s)\n logger.finish();\n\n printSummary(configuration);\n\n return {\n localDictionaries: filteredLocalDictionaries,\n remoteDictionaries,\n };\n};\n"],"mappings":"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","names":[]}
@@ -0,0 +1,101 @@
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 loadRemoteDictionaries_exports = {};
30
+ __export(loadRemoteDictionaries_exports, {
31
+ formatDistantDictionaries: () => formatDistantDictionaries,
32
+ loadRemoteDictionaries: () => loadRemoteDictionaries
33
+ });
34
+ module.exports = __toCommonJS(loadRemoteDictionaries_exports);
35
+ var import_config = require("@intlayer/config");
36
+ var import_remote_dictionaries_entry = __toESM(require("@intlayer/remote-dictionaries-entry"));
37
+ var import_fetchDistantDictionaries = require('../fetchDistantDictionaries.cjs');
38
+ var import_fetchDistantDictionaryKeysAndUpdateTimestamp = require('../fetchDistantDictionaryKeysAndUpdateTimestamp.cjs');
39
+ var import_sortAlphabetically = require('../utils/sortAlphabetically.cjs');
40
+ const formatDistantDictionaries = (dictionaries) => dictionaries.map((dict) => ({
41
+ ...dict,
42
+ localId: `${dict.key}::remote::${dict.id}`,
43
+ location: "distant"
44
+ }));
45
+ const loadRemoteDictionaries = async (configuration = (0, import_config.getConfiguration)(), onStatusUpdate) => {
46
+ const appLogger = (0, import_config.getAppLogger)(configuration);
47
+ const { editor } = configuration;
48
+ const hasRemoteDictionaries = Boolean(editor.clientId && editor.clientSecret);
49
+ if (!hasRemoteDictionaries) return [];
50
+ try {
51
+ const distantDictionaryUpdateTimeStamp = await (0, import_fetchDistantDictionaryKeysAndUpdateTimestamp.fetchDistantDictionaryKeysAndUpdateTimestamp)(configuration);
52
+ const dictionariesKeysToFetch = Object.entries(
53
+ distantDictionaryUpdateTimeStamp
54
+ ).filter(([dictionaryKey, updatedAt]) => {
55
+ if (!updatedAt) return true;
56
+ if (!import_remote_dictionaries_entry.default[dictionaryKey]) return true;
57
+ return import_remote_dictionaries_entry.default[dictionaryKey] > updatedAt;
58
+ }).map(([dictionaryKey]) => dictionaryKey);
59
+ const cachedDictionaries = Object.values(import_remote_dictionaries_entry.default).filter(
60
+ (dictionary) => dictionary?.updatedAt && !dictionariesKeysToFetch.includes(dictionary.key)
61
+ );
62
+ if (cachedDictionaries.length > 0) {
63
+ onStatusUpdate?.(
64
+ cachedDictionaries.map((d) => ({
65
+ dictionaryKey: d.key,
66
+ type: "remote",
67
+ status: "imported"
68
+ }))
69
+ );
70
+ }
71
+ const orderedDistantDictionaryKeys = dictionariesKeysToFetch.sort(import_sortAlphabetically.sortAlphabetically);
72
+ if (orderedDistantDictionaryKeys.length > 0) {
73
+ onStatusUpdate?.(
74
+ orderedDistantDictionaryKeys.map((key) => ({
75
+ dictionaryKey: key,
76
+ type: "remote",
77
+ status: "pending"
78
+ }))
79
+ );
80
+ }
81
+ const distantDictionariesData = await (0, import_fetchDistantDictionaries.fetchDistantDictionaries)(
82
+ {
83
+ dictionaryKeys: orderedDistantDictionaryKeys
84
+ },
85
+ onStatusUpdate
86
+ );
87
+ const distantDictionaries = formatDistantDictionaries(
88
+ distantDictionariesData
89
+ );
90
+ return [...cachedDictionaries, ...distantDictionaries];
91
+ } catch (error) {
92
+ appLogger(`${import_config.x} Failed to fetch distant dictionaries`, { level: "error" });
93
+ return [];
94
+ }
95
+ };
96
+ // Annotate the CommonJS export names for ESM import in node:
97
+ 0 && (module.exports = {
98
+ formatDistantDictionaries,
99
+ loadRemoteDictionaries
100
+ });
101
+ //# sourceMappingURL=loadRemoteDictionaries.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/loadDictionaries/loadRemoteDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { getAppLogger, getConfiguration, x } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport remoteDictionariesRecord from '@intlayer/remote-dictionaries-entry';\nimport { fetchDistantDictionaries } from '../fetchDistantDictionaries';\nimport { fetchDistantDictionaryKeysAndUpdateTimestamp } from '../fetchDistantDictionaryKeysAndUpdateTimestamp';\nimport { DictionariesStatus } from '../loadDictionaries/loadDictionaries';\nimport { sortAlphabetically } from '../utils/sortAlphabetically';\n\nexport const formatDistantDictionaries = (\n dictionaries: DictionaryAPI[]\n): Dictionary[] =>\n dictionaries.map((dict) => ({\n ...dict,\n localId: `${dict.key}::remote::${dict.id}`,\n location: 'distant' as const,\n }));\n\nexport const loadRemoteDictionaries = async (\n configuration = getConfiguration(),\n onStatusUpdate?: (status: DictionariesStatus[]) => void\n): Promise<DictionaryAPI[]> => {\n const appLogger = getAppLogger(configuration);\n const { editor } = configuration;\n\n const hasRemoteDictionaries = Boolean(editor.clientId && editor.clientSecret);\n\n if (!hasRemoteDictionaries) return [];\n\n try {\n const distantDictionaryUpdateTimeStamp: Record<string, number> =\n await fetchDistantDictionaryKeysAndUpdateTimestamp(configuration);\n\n const dictionariesKeysToFetch = Object.entries(\n distantDictionaryUpdateTimeStamp\n )\n .filter(([dictionaryKey, updatedAt]) => {\n // If dictionary doesn't have updatedAt, always fetch it\n if (!updatedAt) return true;\n\n // If remote timestamp doesn't exist, fetch it\n if (!remoteDictionariesRecord[dictionaryKey]) return true;\n\n // If remote timestamp is newer than local, fetch it\n return remoteDictionariesRecord[dictionaryKey] > updatedAt;\n })\n .map(([dictionaryKey]) => dictionaryKey);\n\n const cachedDictionaries = Object.values(remoteDictionariesRecord).filter(\n (dictionary) =>\n dictionary?.updatedAt &&\n !dictionariesKeysToFetch.includes(dictionary.key)\n );\n\n // Report cached as already imported\n if (cachedDictionaries.length > 0) {\n onStatusUpdate?.(\n cachedDictionaries.map((d) => ({\n dictionaryKey: d.key,\n type: 'remote',\n status: 'imported',\n }))\n );\n }\n\n const orderedDistantDictionaryKeys =\n dictionariesKeysToFetch.sort(sortAlphabetically);\n\n // Report pending for keys to be fetched so totals are visible immediately\n if (orderedDistantDictionaryKeys.length > 0) {\n onStatusUpdate?.(\n orderedDistantDictionaryKeys.map((key) => ({\n dictionaryKey: key,\n type: 'remote',\n status: 'pending',\n }))\n );\n }\n\n const distantDictionariesData = await fetchDistantDictionaries(\n {\n dictionaryKeys: orderedDistantDictionaryKeys,\n },\n onStatusUpdate\n );\n\n const distantDictionaries: DictionaryAPI[] = formatDistantDictionaries(\n distantDictionariesData\n );\n\n return [...cachedDictionaries, ...distantDictionaries];\n } catch (error) {\n appLogger(`${x} Failed to fetch distant dictionaries`, { level: 'error' });\n return [];\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAkD;AAElD,uCAAqC;AACrC,sCAAyC;AACzC,0DAA6D;AAE7D,gCAAmC;AAE5B,MAAM,4BAA4B,CACvC,iBAEA,aAAa,IAAI,CAAC,UAAU;AAAA,EAC1B,GAAG;AAAA,EACH,SAAS,GAAG,KAAK,GAAG,aAAa,KAAK,EAAE;AAAA,EACxC,UAAU;AACZ,EAAE;AAEG,MAAM,yBAAyB,OACpC,oBAAgB,gCAAiB,GACjC,mBAC6B;AAC7B,QAAM,gBAAY,4BAAa,aAAa;AAC5C,QAAM,EAAE,OAAO,IAAI;AAEnB,QAAM,wBAAwB,QAAQ,OAAO,YAAY,OAAO,YAAY;AAE5E,MAAI,CAAC,sBAAuB,QAAO,CAAC;AAEpC,MAAI;AACF,UAAM,mCACJ,UAAM,kGAA6C,aAAa;AAElE,UAAM,0BAA0B,OAAO;AAAA,MACrC;AAAA,IACF,EACG,OAAO,CAAC,CAAC,eAAe,SAAS,MAAM;AAEtC,UAAI,CAAC,UAAW,QAAO;AAGvB,UAAI,CAAC,iCAAAA,QAAyB,aAAa,EAAG,QAAO;AAGrD,aAAO,iCAAAA,QAAyB,aAAa,IAAI;AAAA,IACnD,CAAC,EACA,IAAI,CAAC,CAAC,aAAa,MAAM,aAAa;AAEzC,UAAM,qBAAqB,OAAO,OAAO,iCAAAA,OAAwB,EAAE;AAAA,MACjE,CAAC,eACC,YAAY,aACZ,CAAC,wBAAwB,SAAS,WAAW,GAAG;AAAA,IACpD;AAGA,QAAI,mBAAmB,SAAS,GAAG;AACjC;AAAA,QACE,mBAAmB,IAAI,CAAC,OAAO;AAAA,UAC7B,eAAe,EAAE;AAAA,UACjB,MAAM;AAAA,UACN,QAAQ;AAAA,QACV,EAAE;AAAA,MACJ;AAAA,IACF;AAEA,UAAM,+BACJ,wBAAwB,KAAK,4CAAkB;AAGjD,QAAI,6BAA6B,SAAS,GAAG;AAC3C;AAAA,QACE,6BAA6B,IAAI,CAAC,SAAS;AAAA,UACzC,eAAe;AAAA,UACf,MAAM;AAAA,UACN,QAAQ;AAAA,QACV,EAAE;AAAA,MACJ;AAAA,IACF;AAEA,UAAM,0BAA0B,UAAM;AAAA,MACpC;AAAA,QACE,gBAAgB;AAAA,MAClB;AAAA,MACA;AAAA,IACF;AAEA,UAAM,sBAAuC;AAAA,MAC3C;AAAA,IACF;AAEA,WAAO,CAAC,GAAG,oBAAoB,GAAG,mBAAmB;AAAA,EACvD,SAAS,OAAO;AACd,cAAU,GAAG,eAAC,yCAAyC,EAAE,OAAO,QAAQ,CAAC;AACzE,WAAO,CAAC;AAAA,EACV;AACF;","names":["remoteDictionariesRecord"]}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var log_exports = {};
20
+ __export(log_exports, {
21
+ DictionariesLogger: () => DictionariesLogger
22
+ });
23
+ module.exports = __toCommonJS(log_exports);
24
+ var import_config = require("@intlayer/config");
25
+ class DictionariesLogger {
26
+ statuses = [];
27
+ spinnerTimer = null;
28
+ spinnerIndex = 0;
29
+ renderedLines = 0;
30
+ spinnerFrames = import_config.spinnerFrames;
31
+ isFinished = false;
32
+ prefix;
33
+ lastRenderedState = "";
34
+ constructor() {
35
+ const configuration = (0, import_config.getConfiguration)();
36
+ this.prefix = configuration.log.prefix;
37
+ }
38
+ update(newStatuses) {
39
+ if (this.isFinished) return;
40
+ for (const status of newStatuses) {
41
+ const index = this.statuses.findIndex(
42
+ (s) => s.dictionaryKey === status.dictionaryKey && s.type === status.type
43
+ );
44
+ if (index >= 0) {
45
+ this.statuses[index] = status;
46
+ } else {
47
+ this.statuses.push(status);
48
+ }
49
+ }
50
+ this.startSpinner();
51
+ this.render();
52
+ }
53
+ finish() {
54
+ this.isFinished = true;
55
+ this.stopSpinner();
56
+ this.render();
57
+ }
58
+ startSpinner() {
59
+ if (this.spinnerTimer || this.isFinished) return;
60
+ this.spinnerTimer = setInterval(() => {
61
+ this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;
62
+ this.render();
63
+ }, 100);
64
+ }
65
+ stopSpinner() {
66
+ if (!this.spinnerTimer) return;
67
+ clearInterval(this.spinnerTimer);
68
+ this.spinnerTimer = null;
69
+ }
70
+ render() {
71
+ const { localTotal, localDone, remoteTotal, remoteDone } = this.computeProgress();
72
+ const frame = this.spinnerFrames[this.spinnerIndex];
73
+ const lines = [];
74
+ const isLocalDone = localDone === localTotal;
75
+ const isRemoteDone = remoteDone === remoteTotal;
76
+ if (isLocalDone) {
77
+ lines.push(
78
+ `${this.prefix} ${(0, import_config.colorize)("\u2714", import_config.ANSIColors.GREEN)} local dictionaries: ${localDone}/${localTotal}`
79
+ );
80
+ } else {
81
+ lines.push(
82
+ `${this.prefix} ${(0, import_config.colorize)(frame, import_config.ANSIColors.BLUE)} local dictionaries: ${localDone}/${localTotal}`
83
+ );
84
+ }
85
+ if (remoteTotal > 0) {
86
+ if (isRemoteDone) {
87
+ lines.push(
88
+ `${this.prefix} ${(0, import_config.colorize)("\u2714", import_config.ANSIColors.GREEN)} remote dictionaries: ${remoteDone}/${remoteTotal}`
89
+ );
90
+ } else {
91
+ lines.push(
92
+ `${this.prefix} ${(0, import_config.colorize)(frame, import_config.ANSIColors.BLUE)} remote dictionaries: ${remoteDone}/${remoteTotal}`
93
+ );
94
+ }
95
+ }
96
+ const currentState = lines.join("\n");
97
+ if (currentState === this.lastRenderedState) {
98
+ return;
99
+ }
100
+ this.lastRenderedState = currentState;
101
+ if (this.renderedLines > 0) {
102
+ process.stdout.write(`\x1B[${this.renderedLines}F`);
103
+ }
104
+ const totalLinesToClear = Math.max(this.renderedLines, lines.length);
105
+ for (let i = 0; i < totalLinesToClear; i++) {
106
+ process.stdout.write("\x1B[2K");
107
+ const line = lines[i];
108
+ if (line !== void 0) {
109
+ process.stdout.write(line);
110
+ }
111
+ process.stdout.write("\n");
112
+ }
113
+ this.renderedLines = lines.length;
114
+ }
115
+ computeProgress() {
116
+ const localKeys = new Set(
117
+ this.statuses.filter((s) => s.type === "local").map((s) => s.dictionaryKey)
118
+ );
119
+ const localDoneKeys = new Set(
120
+ this.statuses.filter(
121
+ (s) => s.type === "local" && (s.status === "built" || s.status === "error")
122
+ ).map((s) => s.dictionaryKey)
123
+ );
124
+ const remoteKeys = new Set(
125
+ this.statuses.filter((s) => s.type === "remote").map((s) => s.dictionaryKey)
126
+ );
127
+ const remoteDoneKeys = new Set(
128
+ this.statuses.filter(
129
+ (s) => s.type === "remote" && (s.status === "fetched" || s.status === "imported" || s.status === "error")
130
+ ).map((s) => s.dictionaryKey)
131
+ );
132
+ return {
133
+ localTotal: localKeys.size,
134
+ localDone: localDoneKeys.size,
135
+ remoteTotal: remoteKeys.size,
136
+ remoteDone: remoteDoneKeys.size
137
+ };
138
+ }
139
+ }
140
+ // Annotate the CommonJS export names for ESM import in node:
141
+ 0 && (module.exports = {
142
+ DictionariesLogger
143
+ });
144
+ //# sourceMappingURL=log.cjs.map