@intlayer/chokidar 2.0.13 → 3.0.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 (182) hide show
  1. package/dist/cjs/chokidar/watcher.cjs +18 -26
  2. package/dist/cjs/chokidar/watcher.cjs.map +1 -1
  3. package/dist/cjs/fetchDistantDictionaries.cjs +101 -0
  4. package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -0
  5. package/dist/cjs/fetchDistantDictionaryKeys.cjs +50 -0
  6. package/dist/cjs/fetchDistantDictionaryKeys.cjs.map +1 -0
  7. package/dist/cjs/index.cjs +10 -0
  8. package/dist/cjs/index.cjs.map +1 -1
  9. package/dist/cjs/loadDictionaries/index.cjs +29 -0
  10. package/dist/cjs/loadDictionaries/index.cjs.map +1 -0
  11. package/dist/cjs/{transpiler/declaration_file_to_dictionary/intlayer_dictionary → loadDictionaries}/loadContentDeclaration.cjs +23 -7
  12. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -0
  13. package/dist/cjs/loadDictionaries/loadDictionaries.cjs +86 -0
  14. package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -0
  15. package/dist/cjs/{transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.cjs → loadDictionaries/loadDistantDictionaries.cjs} +15 -22
  16. package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs.map +1 -0
  17. package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs +51 -0
  18. package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs.map +1 -0
  19. package/dist/cjs/log.cjs +255 -0
  20. package/dist/cjs/log.cjs.map +1 -0
  21. package/dist/cjs/mergeDictionaries.cjs +62 -0
  22. package/dist/cjs/mergeDictionaries.cjs.map +1 -0
  23. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.cjs +13 -49
  24. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.cjs.map +1 -1
  25. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.cjs.map +1 -1
  26. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.cjs +52 -0
  27. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.cjs.map +1 -0
  28. package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs +1 -1
  29. package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs.map +1 -1
  30. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs +4 -37
  31. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs.map +1 -1
  32. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.cjs +0 -2
  33. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.cjs.map +1 -1
  34. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs +8 -10
  35. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs.map +1 -1
  36. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs +46 -0
  37. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs.map +1 -0
  38. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +1 -1
  39. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
  40. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +8 -9
  41. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -1
  42. package/dist/esm/chokidar/watcher.mjs +18 -16
  43. package/dist/esm/chokidar/watcher.mjs.map +1 -1
  44. package/dist/esm/fetchDistantDictionaries.mjs +67 -0
  45. package/dist/esm/fetchDistantDictionaries.mjs.map +1 -0
  46. package/dist/esm/fetchDistantDictionaryKeys.mjs +26 -0
  47. package/dist/esm/fetchDistantDictionaryKeys.mjs.map +1 -0
  48. package/dist/esm/index.mjs +10 -0
  49. package/dist/esm/index.mjs.map +1 -1
  50. package/dist/esm/loadDictionaries/index.mjs +5 -0
  51. package/dist/esm/loadDictionaries/index.mjs.map +1 -0
  52. package/dist/esm/{transpiler/declaration_file_to_dictionary/intlayer_dictionary → loadDictionaries}/loadContentDeclaration.mjs +22 -5
  53. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -0
  54. package/dist/esm/loadDictionaries/loadDictionaries.mjs +52 -0
  55. package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -0
  56. package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs +14 -0
  57. package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs.map +1 -0
  58. package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs +27 -0
  59. package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs.map +1 -0
  60. package/dist/esm/log.mjs +221 -0
  61. package/dist/esm/log.mjs.map +1 -0
  62. package/dist/esm/mergeDictionaries.mjs +28 -0
  63. package/dist/esm/mergeDictionaries.mjs.map +1 -0
  64. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.mjs +15 -54
  65. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.mjs.map +1 -1
  66. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.mjs.map +1 -1
  67. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.mjs +28 -0
  68. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.mjs.map +1 -0
  69. package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs +1 -1
  70. package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs.map +1 -1
  71. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs +5 -38
  72. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -1
  73. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.mjs +0 -1
  74. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.mjs.map +1 -1
  75. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs +8 -10
  76. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs.map +1 -1
  77. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs +22 -0
  78. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs.map +1 -0
  79. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +1 -1
  80. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
  81. package/dist/esm/transpiler/dictionary_to_type/createType.mjs +9 -9
  82. package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
  83. package/dist/types/chokidar/index.d.ts +2 -0
  84. package/dist/types/chokidar/index.d.ts.map +1 -0
  85. package/dist/types/chokidar/watcher.d.ts +4 -0
  86. package/dist/types/chokidar/watcher.d.ts.map +1 -0
  87. package/dist/types/fetchDistantDictionaries.d.ts +12 -0
  88. package/dist/types/fetchDistantDictionaries.d.ts.map +1 -0
  89. package/dist/types/fetchDistantDictionaryKeys.d.ts +2 -0
  90. package/dist/types/fetchDistantDictionaryKeys.d.ts.map +1 -0
  91. package/dist/types/index.d.ts +6 -0
  92. package/dist/types/index.d.ts.map +1 -0
  93. package/dist/types/loadDictionaries/index.d.ts +5 -0
  94. package/dist/types/loadDictionaries/index.d.ts.map +1 -0
  95. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +3 -0
  96. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -0
  97. package/dist/types/loadDictionaries/loadDictionaries.d.ts +3 -0
  98. package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -0
  99. package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts +8 -0
  100. package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts.map +1 -0
  101. package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts +3 -0
  102. package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts.map +1 -0
  103. package/dist/types/log.d.ts +40 -0
  104. package/dist/types/log.d.ts.map +1 -0
  105. package/dist/types/mergeDictionaries.d.ts +5 -0
  106. package/dist/types/mergeDictionaries.d.ts.map +1 -0
  107. package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.ts +6 -0
  108. package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.ts.map +1 -0
  109. package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.ts +7 -0
  110. package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.ts.map +1 -0
  111. package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.ts +2 -0
  112. package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.ts.map +1 -0
  113. package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.ts +2 -0
  114. package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.ts.map +1 -0
  115. package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.d.ts +7 -0
  116. package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.d.ts.map +1 -0
  117. package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +3 -0
  118. package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts.map +1 -0
  119. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +6 -0
  120. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +1 -0
  121. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.ts +3 -0
  122. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.ts.map +1 -0
  123. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts +6 -0
  124. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts.map +1 -0
  125. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts +3 -0
  126. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts.map +1 -0
  127. package/dist/types/transpiler/dictionary_to_main/createDictionaryList.d.ts +5 -0
  128. package/dist/types/transpiler/dictionary_to_main/createDictionaryList.d.ts.map +1 -0
  129. package/dist/types/transpiler/dictionary_to_main/index.d.ts +2 -0
  130. package/dist/types/transpiler/dictionary_to_main/index.d.ts.map +1 -0
  131. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +6 -0
  132. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts.map +1 -0
  133. package/dist/types/transpiler/dictionary_to_type/createType.d.ts +6 -0
  134. package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +1 -0
  135. package/dist/types/transpiler/dictionary_to_type/index.d.ts +3 -0
  136. package/dist/types/transpiler/dictionary_to_type/index.d.ts.map +1 -0
  137. package/dist/types/utils.d.ts +3 -0
  138. package/dist/types/utils.d.ts.map +1 -0
  139. package/package.json +32 -16
  140. package/dist/cjs/chokidar/index.d.ts +0 -2
  141. package/dist/cjs/chokidar/watcher.d.ts +0 -5
  142. package/dist/cjs/index.d.ts +0 -4
  143. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.ts +0 -6
  144. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.ts +0 -8
  145. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.ts +0 -3
  146. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.ts +0 -1
  147. package/dist/cjs/transpiler/declaration_file_to_dictionary/index.d.ts +0 -3
  148. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +0 -6
  149. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.cjs.map +0 -1
  150. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.d.ts +0 -44
  151. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.ts +0 -4
  152. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.cjs.map +0 -1
  153. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.d.ts +0 -10
  154. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts +0 -8
  155. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.d.ts +0 -6
  156. package/dist/cjs/transpiler/dictionary_to_main/index.d.ts +0 -1
  157. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +0 -7
  158. package/dist/cjs/transpiler/dictionary_to_type/createType.d.ts +0 -7
  159. package/dist/cjs/transpiler/dictionary_to_type/index.d.ts +0 -2
  160. package/dist/cjs/utils.d.ts +0 -4
  161. package/dist/esm/chokidar/index.d.mts +0 -2
  162. package/dist/esm/chokidar/watcher.d.mts +0 -5
  163. package/dist/esm/index.d.mts +0 -4
  164. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.mts +0 -6
  165. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.mts +0 -8
  166. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.mts +0 -3
  167. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.mts +0 -1
  168. package/dist/esm/transpiler/declaration_file_to_dictionary/index.d.mts +0 -3
  169. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.mts +0 -6
  170. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.d.mts +0 -44
  171. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.mjs +0 -21
  172. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.mjs.map +0 -1
  173. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.mts +0 -4
  174. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.d.mts +0 -10
  175. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.mjs.map +0 -1
  176. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.mts +0 -8
  177. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.d.mts +0 -6
  178. package/dist/esm/transpiler/dictionary_to_main/index.d.mts +0 -1
  179. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.d.mts +0 -7
  180. package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +0 -7
  181. package/dist/esm/transpiler/dictionary_to_type/index.d.mts +0 -2
  182. package/dist/esm/utils.d.mts +0 -4
@@ -0,0 +1,51 @@
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 loadLocalDictionaries_exports = {};
20
+ __export(loadLocalDictionaries_exports, {
21
+ loadLocalDictionaries: () => loadLocalDictionaries
22
+ });
23
+ module.exports = __toCommonJS(loadLocalDictionaries_exports);
24
+ var import_promises = require("fs/promises");
25
+ var import_path = require("path");
26
+ var import_config = require("@intlayer/config");
27
+ var import_loadContentDeclaration = require('./loadContentDeclaration.cjs');
28
+ const loadLocalDictionaries = async (contentDeclarationsPaths) => {
29
+ const { content } = (0, import_config.getConfiguration)();
30
+ const { dictionariesDir, baseDir } = content;
31
+ if (typeof contentDeclarationsPaths === "string") {
32
+ contentDeclarationsPaths = [contentDeclarationsPaths];
33
+ }
34
+ await (0, import_promises.mkdir)((0, import_path.resolve)(dictionariesDir), { recursive: true });
35
+ const result = [];
36
+ for await (const contentDeclarationPath of contentDeclarationsPaths) {
37
+ const dictionary = await (0, import_loadContentDeclaration.loadContentDeclarations)([contentDeclarationPath]);
38
+ const relativeFilePath = (0, import_path.relative)(baseDir, contentDeclarationPath);
39
+ const dictionaryWithPath = {
40
+ ...dictionary[0],
41
+ filePath: relativeFilePath
42
+ };
43
+ result.push(dictionaryWithPath);
44
+ }
45
+ return result;
46
+ };
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ loadLocalDictionaries
50
+ });
51
+ //# sourceMappingURL=loadLocalDictionaries.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/loadDictionaries/loadLocalDictionaries.ts"],"sourcesContent":["import { mkdir } from 'fs/promises';\nimport { resolve, relative } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { loadContentDeclarations } from './loadContentDeclaration';\n\nexport const loadLocalDictionaries = async (\n contentDeclarationsPaths: string[] | string\n): Promise<Dictionary[]> => {\n const { content } = getConfiguration();\n const { dictionariesDir, baseDir } = content;\n\n if (typeof contentDeclarationsPaths === 'string') {\n contentDeclarationsPaths = [contentDeclarationsPaths];\n }\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n const result: Dictionary[] = [];\n\n for await (const contentDeclarationPath of contentDeclarationsPaths) {\n const dictionary = await loadContentDeclarations([contentDeclarationPath]);\n\n const relativeFilePath = relative(baseDir, contentDeclarationPath);\n\n const dictionaryWithPath: Dictionary = {\n ...dictionary[0],\n filePath: relativeFilePath,\n };\n\n result.push(dictionaryWithPath);\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAsB;AACtB,kBAAkC;AAClC,oBAAiC;AAEjC,oCAAwC;AAEjC,MAAM,wBAAwB,OACnC,6BAC0B;AAC1B,QAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,QAAM,EAAE,iBAAiB,QAAQ,IAAI;AAErC,MAAI,OAAO,6BAA6B,UAAU;AAChD,+BAA2B,CAAC,wBAAwB;AAAA,EACtD;AAGA,YAAM,2BAAM,qBAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,QAAM,SAAuB,CAAC;AAE9B,mBAAiB,0BAA0B,0BAA0B;AACnE,UAAM,aAAa,UAAM,uDAAwB,CAAC,sBAAsB,CAAC;AAEzE,UAAM,uBAAmB,sBAAS,SAAS,sBAAsB;AAEjE,UAAM,qBAAiC;AAAA,MACrC,GAAG,WAAW,CAAC;AAAA,MACf,UAAU;AAAA,IACZ;AAEA,WAAO,KAAK,kBAAkB;AAAA,EAChC;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,255 @@
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 log_exports = {};
30
+ __export(log_exports, {
31
+ logger: () => logger
32
+ });
33
+ module.exports = __toCommonJS(log_exports);
34
+ var readline = __toESM(require("readline"));
35
+ class Logger {
36
+ dictionariesStatuses = [];
37
+ spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
38
+ spinnerTimer = null;
39
+ maxDictionaryKeyLength = 0;
40
+ // ANSI color codes
41
+ RESET = "\x1B[0m";
42
+ GREEN = "\x1B[32m";
43
+ RED = "\x1B[31m";
44
+ BLUE = "\x1B[34m";
45
+ GREY = "\x1B[90m";
46
+ GREY_DARK = "\x1B[90m";
47
+ // Singleton instance
48
+ static instance;
49
+ constructor() {
50
+ }
51
+ static getInstance() {
52
+ if (!Logger.instance) {
53
+ Logger.instance = new Logger();
54
+ }
55
+ return Logger.instance;
56
+ }
57
+ init(localDictionariesKeys, distantDictionariesKeys) {
58
+ const allKeys = Array.from(
59
+ /* @__PURE__ */ new Set([...localDictionariesKeys, ...distantDictionariesKeys])
60
+ );
61
+ this.maxDictionaryKeyLength = allKeys.reduce(
62
+ (max, key) => key.length > max ? key.length : max,
63
+ 0
64
+ );
65
+ this.dictionariesStatuses = allKeys.map((dictionaryKey) => {
66
+ const states = [];
67
+ if (localDictionariesKeys.includes(dictionaryKey)) {
68
+ states.push({
69
+ type: "local",
70
+ status: "pending",
71
+ spinnerFrameIndex: 0
72
+ });
73
+ }
74
+ if (distantDictionariesKeys.includes(dictionaryKey)) {
75
+ states.push({
76
+ type: "distant",
77
+ status: "pending",
78
+ spinnerFrameIndex: 0
79
+ });
80
+ }
81
+ return {
82
+ dictionaryKey,
83
+ state: states
84
+ };
85
+ });
86
+ for (const statusObj of this.dictionariesStatuses) {
87
+ process.stdout.write(this.getStatusLine(statusObj) + "\n");
88
+ }
89
+ this.startSpinner();
90
+ }
91
+ // New method to add dictionary keys after initialization
92
+ addDictionaryKeys(type, dictionaryKeys) {
93
+ for (const dictionaryKey of dictionaryKeys) {
94
+ if (dictionaryKey.length > this.maxDictionaryKeyLength) {
95
+ this.maxDictionaryKeyLength = dictionaryKey.length;
96
+ }
97
+ let statusObj = this.dictionariesStatuses.find(
98
+ (ds) => ds.dictionaryKey === dictionaryKey
99
+ );
100
+ if (!statusObj) {
101
+ statusObj = {
102
+ dictionaryKey,
103
+ state: []
104
+ };
105
+ this.dictionariesStatuses.push(statusObj);
106
+ const newState = {
107
+ type,
108
+ status: "pending",
109
+ spinnerFrameIndex: 0
110
+ };
111
+ statusObj.state.push(newState);
112
+ process.stdout.write(this.getStatusLine(statusObj) + "\n");
113
+ } else {
114
+ const existingState = statusObj.state.find((s) => s.type === type);
115
+ if (!existingState) {
116
+ const newState = {
117
+ type,
118
+ status: "pending",
119
+ spinnerFrameIndex: 0
120
+ };
121
+ statusObj.state.push(newState);
122
+ const lineIndex = this.dictionariesStatuses.indexOf(statusObj);
123
+ readline.moveCursor(
124
+ process.stdout,
125
+ 0,
126
+ -(this.dictionariesStatuses.length - lineIndex)
127
+ );
128
+ readline.clearLine(process.stdout, 0);
129
+ process.stdout.write(this.getStatusLine(statusObj) + "\n");
130
+ readline.moveCursor(
131
+ process.stdout,
132
+ 0,
133
+ this.dictionariesStatuses.length - lineIndex - 1
134
+ );
135
+ }
136
+ }
137
+ }
138
+ }
139
+ startSpinner() {
140
+ if (!this.spinnerTimer) {
141
+ this.spinnerTimer = setInterval(() => {
142
+ this.updateAllStatusLines();
143
+ }, 100);
144
+ }
145
+ }
146
+ stopSpinner() {
147
+ if (this.spinnerTimer) {
148
+ clearInterval(this.spinnerTimer);
149
+ this.spinnerTimer = null;
150
+ }
151
+ }
152
+ stop() {
153
+ this.stopSpinner();
154
+ this.updateAllStatusLines();
155
+ }
156
+ updateStatus(dictionaryKey, type, status) {
157
+ const statusObj = this.dictionariesStatuses.find(
158
+ (ds) => ds.dictionaryKey === dictionaryKey
159
+ );
160
+ if (statusObj) {
161
+ const state = statusObj.state.find((s) => s.type === type);
162
+ if (state) {
163
+ Object.assign(state, status);
164
+ } else {
165
+ if (status.status === void 0) {
166
+ status.status = "pending";
167
+ }
168
+ const newState = {
169
+ type,
170
+ status: status.status,
171
+ icon: status.icon ?? "",
172
+ error: status.error,
173
+ errorMessage: status.errorMessage,
174
+ spinnerFrameIndex: status.spinnerFrameIndex ?? 0
175
+ };
176
+ statusObj.state.push(newState);
177
+ }
178
+ } else {
179
+ const newState = {
180
+ type,
181
+ status: status.status ?? "pending",
182
+ icon: status.icon ?? "",
183
+ error: status.error,
184
+ errorMessage: status.errorMessage,
185
+ spinnerFrameIndex: status.spinnerFrameIndex ?? 0
186
+ };
187
+ this.dictionariesStatuses.push({
188
+ dictionaryKey,
189
+ state: [newState]
190
+ });
191
+ }
192
+ }
193
+ // Rest of the Logger class remains the same...
194
+ getStatusIcon(status) {
195
+ const statusIcons = {
196
+ pending: "\u23F2",
197
+ fetching: "",
198
+ // Spinner handled separately
199
+ built: "\u2714",
200
+ imported: "\u2714",
201
+ error: "\u2716"
202
+ };
203
+ return statusIcons[status] ?? "";
204
+ }
205
+ getStatusLine(statusObj) {
206
+ const keyPadding = this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;
207
+ const paddedKey = statusObj.dictionaryKey + " ".repeat(keyPadding);
208
+ const states = statusObj.state.map((state) => {
209
+ let colorStart = "";
210
+ let colorEnd = "";
211
+ let icon = this.getStatusIcon(state.status);
212
+ if (state.status === "fetching") {
213
+ icon = this.spinnerFrames[state.spinnerFrameIndex % this.spinnerFrames.length];
214
+ colorStart = this.BLUE;
215
+ colorEnd = this.RESET;
216
+ } else if (state.status === "error") {
217
+ colorStart = this.RED;
218
+ colorEnd = this.RESET;
219
+ } else if (state.status === "imported" || state.status === "built") {
220
+ colorStart = this.GREEN;
221
+ colorEnd = this.RESET;
222
+ } else {
223
+ colorStart = this.GREY;
224
+ colorEnd = this.RESET;
225
+ }
226
+ const statusBlock = `${this.GREY_DARK}[${state.type}: ${colorStart}${icon} ${state.status}${this.GREY_DARK}]${colorEnd}`;
227
+ return `${colorStart}${statusBlock}${colorEnd}`;
228
+ });
229
+ return `- ${paddedKey} ${states.join(" ")}`;
230
+ }
231
+ updateAllStatusLines() {
232
+ readline.moveCursor(process.stdout, 0, -this.dictionariesStatuses.length);
233
+ for (const statusObj of this.dictionariesStatuses) {
234
+ readline.clearLine(process.stdout, 0);
235
+ if (typeof statusObj?.state === "undefined") {
236
+ return;
237
+ }
238
+ statusObj.state.forEach((state) => {
239
+ if (state.status === "fetching") {
240
+ state.spinnerFrameIndex = (state.spinnerFrameIndex + 1) % this.spinnerFrames.length;
241
+ }
242
+ });
243
+ process.stdout.write(this.getStatusLine(statusObj) + "\n");
244
+ }
245
+ }
246
+ getStatuses() {
247
+ return this.dictionariesStatuses;
248
+ }
249
+ }
250
+ const logger = Logger.getInstance();
251
+ // Annotate the CommonJS export names for ESM import in node:
252
+ 0 && (module.exports = {
253
+ logger
254
+ });
255
+ //# sourceMappingURL=log.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/log.ts"],"sourcesContent":["import * as readline from 'readline';\n\nexport type State = {\n type: 'local' | 'distant';\n status: 'pending' | 'fetching' | 'fetched' | 'error' | 'imported' | 'built';\n icon?: string;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nexport type DictionariesStatus = {\n dictionaryKey: string;\n state: State[];\n};\n\nclass Logger {\n private dictionariesStatuses: DictionariesStatus[] = [];\n private spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private maxDictionaryKeyLength: number = 0;\n\n // ANSI color codes\n private RESET = '\\x1b[0m';\n private GREEN = '\\x1b[32m';\n private RED = '\\x1b[31m';\n private BLUE = '\\x1b[34m';\n private GREY = '\\x1b[90m';\n private GREY_DARK = '\\x1b[90m';\n\n // Singleton instance\n private static instance: Logger;\n\n private constructor() {}\n\n public static getInstance(): Logger {\n if (!Logger.instance) {\n Logger.instance = new Logger();\n }\n return Logger.instance;\n }\n\n public init(\n localDictionariesKeys: string[],\n distantDictionariesKeys: string[]\n ) {\n const allKeys = Array.from(\n new Set([...localDictionariesKeys, ...distantDictionariesKeys])\n );\n\n this.maxDictionaryKeyLength = allKeys.reduce(\n (max, key) => (key.length > max ? key.length : max),\n 0\n );\n\n this.dictionariesStatuses = allKeys.map((dictionaryKey) => {\n const states: State[] = [];\n if (localDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'local',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n if (distantDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'distant',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n return {\n dictionaryKey,\n state: states,\n };\n });\n\n // Output initial statuses\n for (const statusObj of this.dictionariesStatuses) {\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n }\n\n // Start spinner timer\n this.startSpinner();\n }\n\n // New method to add dictionary keys after initialization\n public addDictionaryKeys(\n type: 'local' | 'distant',\n dictionaryKeys: string[]\n ) {\n for (const dictionaryKey of dictionaryKeys) {\n // Update maxDictionaryKeyLength if the new key is longer\n if (dictionaryKey.length > this.maxDictionaryKeyLength) {\n this.maxDictionaryKeyLength = dictionaryKey.length;\n }\n\n let statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n\n if (!statusObj) {\n // If the dictionaryKey doesn't exist yet, create a new DictionariesStatus\n statusObj = {\n dictionaryKey,\n state: [],\n };\n this.dictionariesStatuses.push(statusObj);\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n\n // Output the new status line\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n } else {\n const existingState = statusObj.state.find((s) => s.type === type);\n if (!existingState) {\n // Add new state for the type\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n\n // Update the existing line\n const lineIndex = this.dictionariesStatuses.indexOf(statusObj);\n // Move cursor up to the lineIndex from the bottom\n readline.moveCursor(\n process.stdout,\n 0,\n -(this.dictionariesStatuses.length - lineIndex)\n );\n readline.clearLine(process.stdout, 0);\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n // Move cursor back to the bottom\n readline.moveCursor(\n process.stdout,\n 0,\n this.dictionariesStatuses.length - lineIndex - 1\n );\n }\n }\n }\n // No need to redraw all status lines\n }\n\n private startSpinner() {\n if (!this.spinnerTimer) {\n this.spinnerTimer = setInterval(() => {\n this.updateAllStatusLines();\n }, 100); // Update every 100ms\n }\n }\n\n private stopSpinner() {\n if (this.spinnerTimer) {\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n }\n\n public stop() {\n this.stopSpinner();\n // Update statuses one last time\n this.updateAllStatusLines();\n }\n\n public updateStatus(\n dictionaryKey: string,\n type: 'local' | 'distant',\n status: Partial<State>\n ) {\n const statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n if (statusObj) {\n const state = statusObj.state.find((s) => s.type === type);\n if (state) {\n // Update existing state\n Object.assign(state, status);\n } else {\n // If the state for this type doesn't exist yet, add it\n if (status.status === undefined) {\n status.status = 'pending'; // Provide default status\n }\n const newState: State = {\n type,\n status: status.status,\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n statusObj.state.push(newState);\n }\n } else {\n // If the status object doesn't exist, create it\n const newState: State = {\n type,\n status: status.status ?? 'pending',\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n this.dictionariesStatuses.push({\n dictionaryKey,\n state: [newState],\n });\n }\n }\n\n // Rest of the Logger class remains the same...\n\n private getStatusIcon(status: string): string {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n fetching: '', // Spinner handled separately\n built: '✔',\n imported: '✔',\n error: '✖',\n };\n return statusIcons[status] ?? '';\n }\n\n private getStatusLine(statusObj: DictionariesStatus): string {\n const keyPadding =\n this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;\n const paddedKey = statusObj.dictionaryKey + ' '.repeat(keyPadding);\n\n const states = statusObj.state.map((state) => {\n let colorStart = '';\n let colorEnd = '';\n let icon = this.getStatusIcon(state.status);\n if (state.status === 'fetching') {\n // Use spinner frame\n icon =\n this.spinnerFrames[\n state.spinnerFrameIndex! % this.spinnerFrames.length\n ];\n colorStart = this.BLUE;\n colorEnd = this.RESET;\n } else if (state.status === 'error') {\n colorStart = this.RED;\n colorEnd = this.RESET;\n } else if (state.status === 'imported' || state.status === 'built') {\n colorStart = this.GREEN;\n colorEnd = this.RESET;\n } else {\n colorStart = this.GREY;\n colorEnd = this.RESET;\n }\n\n // Format the status block\n const statusBlock = `${this.GREY_DARK}[${state.type}: ${colorStart}${icon} ${state.status}${this.GREY_DARK}]${colorEnd}`;\n\n return `${colorStart}${statusBlock}${colorEnd}`;\n });\n\n return `- ${paddedKey} ${states.join(' ')}`;\n }\n\n private updateAllStatusLines() {\n // Move cursor up to the first status line\n readline.moveCursor(process.stdout, 0, -this.dictionariesStatuses.length);\n\n for (const statusObj of this.dictionariesStatuses) {\n // Clear the line\n readline.clearLine(process.stdout, 0);\n\n if (typeof statusObj?.state === 'undefined') {\n return;\n }\n\n statusObj.state.forEach((state) => {\n if (state.status === 'fetching') {\n // Update spinner frame\n state.spinnerFrameIndex =\n (state.spinnerFrameIndex! + 1) % this.spinnerFrames.length;\n }\n });\n\n // Write the status line\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n }\n }\n\n public getStatuses() {\n return this.dictionariesStatuses;\n }\n}\n\nexport const logger = Logger.getInstance();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAA0B;AAgB1B,MAAM,OAAO;AAAA,EACH,uBAA6C,CAAC;AAAA,EAC9C,gBAAgB,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAAA,EACjE,eAAsC;AAAA,EACtC,yBAAiC;AAAA;AAAA,EAGjC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,YAAY;AAAA;AAAA,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ineProperty;
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 mergeDictionaries_exports = {};
30
+ __export(mergeDictionaries_exports, {
31
+ mergeByKey: () => mergeByKey
32
+ });
33
+ module.exports = __toCommonJS(mergeDictionaries_exports);
34
+ var import_deepmerge = __toESM(require("deepmerge"));
35
+ const mergeByKey = (key) => {
36
+ return (target, source, options) => {
37
+ const destination = [];
38
+ const sourceMap = /* @__PURE__ */ new Map();
39
+ source.forEach((item) => {
40
+ sourceMap.set(item[key], item);
41
+ });
42
+ target.forEach((targetItem) => {
43
+ const sourceItem = sourceMap.get(targetItem[key]);
44
+ if (sourceItem) {
45
+ const mergedItem = (0, import_deepmerge.default)(targetItem, sourceItem, options);
46
+ destination.push(mergedItem);
47
+ sourceMap.delete(targetItem[key]);
48
+ } else {
49
+ destination.push(targetItem);
50
+ }
51
+ });
52
+ sourceMap.forEach((item) => {
53
+ destination.push(item);
54
+ });
55
+ return destination;
56
+ };
57
+ };
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ mergeByKey
61
+ });
62
+ //# sourceMappingURL=mergeDictionaries.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mergeDictionaries.ts"],"sourcesContent":["import merge, { Options } from 'deepmerge';\n\n// Custom array merge function that merges objects by 'key'\nexport const mergeByKey = <T extends { key: string }>(key: keyof T) => {\n return (target: T[], source: T[], options?: Options): T[] => {\n const destination: T[] = [];\n\n // Create a map for quick lookup\n const sourceMap = new Map<string, T>();\n source.forEach((item) => {\n sourceMap.set(item[key] as string, item);\n });\n\n target.forEach((targetItem) => {\n const sourceItem = sourceMap.get(targetItem[key] as string);\n if (sourceItem) {\n // Merge the two items and assert the type\n const mergedItem = merge(targetItem, sourceItem, options) as T;\n destination.push(mergedItem);\n // Remove the item from the source map to avoid duplicates\n sourceMap.delete(targetItem[key] as string);\n } else {\n destination.push(targetItem);\n }\n });\n\n // Add remaining items from source\n sourceMap.forEach((item) => {\n destination.push(item);\n });\n\n return destination;\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA+B;AAGxB,MAAM,aAAa,CAA4B,QAAiB;AACrE,SAAO,CAAC,QAAa,QAAa,YAA2B;AAC3D,UAAM,cAAmB,CAAC;AAG1B,UAAM,YAAY,oBAAI,IAAe;AACrC,WAAO,QAAQ,CAAC,SAAS;AACvB,gBAAU,IAAI,KAAK,GAAG,GAAa,IAAI;AAAA,IACzC,CAAC;AAED,WAAO,QAAQ,CAAC,eAAe;AAC7B,YAAM,aAAa,UAAU,IAAI,WAAW,GAAG,CAAW;AAC1D,UAAI,YAAY;AAEd,cAAM,iBAAa,iBAAAA,SAAM,YAAY,YAAY,OAAO;AACxD,oBAAY,KAAK,UAAU;AAE3B,kBAAU,OAAO,WAAW,GAAG,CAAW;AAAA,MAC5C,OAAO;AACL,oBAAY,KAAK,UAAU;AAAA,MAC7B;AAAA,IACF,CAAC;AAGD,cAAU,QAAQ,CAAC,SAAS;AAC1B,kBAAY,KAAK,IAAI;AAAA,IACvB,CAAC;AAED,WAAO;AAAA,EACT;AACF;","names":["merge"]}
@@ -21,57 +21,21 @@ __export(buildI18nDictionary_exports, {
21
21
  buildI18nDictionary: () => buildI18nDictionary
22
22
  });
23
23
  module.exports = __toCommonJS(buildI18nDictionary_exports);
24
- var import_promises = require("fs/promises");
25
- var import_path = require("path");
26
- var import_config = require("@intlayer/config");
27
- var import_intlayer_dictionary = require('../intlayer_dictionary/index.cjs');
28
24
  var import_convertContentDeclarationInto18nDictionaries = require('./convertContentDeclarationInto18nDictionaries.cjs');
29
- const { content } = (0, import_config.getConfiguration)();
30
- const { i18nDictionariesDir } = content;
31
- const writeDictionary = async (dictionariesDeclaration) => {
32
- const resultDictionariesPaths = [];
33
- for (const [nameSpace, localContent] of Object.entries(
25
+ var import_writeDictionary = require('./writeDictionary.cjs');
26
+ const buildI18nDictionary = async (contentDeclarations) => {
27
+ const dictionariesDeclaration = contentDeclarations.reduce((acc, dictionary) => {
28
+ const { key, content } = dictionary;
29
+ const i18Content = (0, import_convertContentDeclarationInto18nDictionaries.createI18nDictionaries)(content);
30
+ return {
31
+ ...acc,
32
+ [key]: i18Content
33
+ };
34
+ }, {});
35
+ const dictionariesPaths = await (0, import_writeDictionary.writeDictionary)(
34
36
  dictionariesDeclaration
35
- )) {
36
- for await (const [locale, content2] of Object.entries(localContent)) {
37
- const contentString = JSON.stringify(content2);
38
- const outputFileName = `${nameSpace}.json`;
39
- const resultDirPath = (0, import_path.resolve)(i18nDictionariesDir, locale);
40
- const resultFilePath = (0, import_path.resolve)(resultDirPath, outputFileName);
41
- await (0, import_promises.mkdir)(resultDirPath, { recursive: true });
42
- await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
43
- console.error(`Error creating ${outputFileName}:`, err);
44
- });
45
- resultDictionariesPaths.push(resultFilePath);
46
- }
47
- }
48
- return resultDictionariesPaths;
49
- };
50
- const buildI18nDictionary = async (contentDeclarationsPaths) => {
51
- const resultDictionariesPaths = [];
52
- if (typeof contentDeclarationsPaths === "string") {
53
- contentDeclarationsPaths = [contentDeclarationsPaths];
54
- }
55
- for await (const contentDeclarationPath of contentDeclarationsPaths) {
56
- const result = await (0, import_intlayer_dictionary.processContentDeclaration)(contentDeclarationPath);
57
- if (!result) {
58
- continue;
59
- }
60
- const nestedContent = (0, import_intlayer_dictionary.extractObjectsWithId)(result);
61
- const dictionariesDeclaration = nestedContent.reduce((acc, content2) => {
62
- const id = content2.id;
63
- const i18Content = (0, import_convertContentDeclarationInto18nDictionaries.createI18nDictionaries)(content2);
64
- return {
65
- ...acc,
66
- [id]: i18Content
67
- };
68
- }, {});
69
- const dictionariesPaths = await writeDictionary(
70
- dictionariesDeclaration
71
- );
72
- resultDictionariesPaths.push(...dictionariesPaths);
73
- }
74
- return resultDictionariesPaths;
37
+ );
38
+ return dictionariesPaths;
75
39
  };
76
40
  // Annotate the CommonJS export names for ESM import in node:
77
41
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.ts"],"sourcesContent":["import { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { DeclarationContent } from '@intlayer/core';\nimport {\n processContentDeclaration,\n extractObjectsWithId,\n} from '../intlayer_dictionary/index';\nimport {\n type I18nDictionariesOutput,\n createI18nDictionaries,\n} from './convertContentDeclarationInto18nDictionaries';\n\nconst { content } = getConfiguration();\nconst { i18nDictionariesDir } = content;\n\ntype DictionariesDeclaration = Record<string, I18nDictionariesOutput>;\n\n/**\n * This function writes the dictionaries to the file system\n */\nconst writeDictionary = async (\n dictionariesDeclaration: DictionariesDeclaration\n) => {\n const resultDictionariesPaths: string[] = [];\n\n for (const [nameSpace, localContent] of Object.entries(\n dictionariesDeclaration\n )) {\n for await (const [locale, content] of Object.entries(localContent)) {\n const contentString = JSON.stringify(content);\n\n const outputFileName = `${nameSpace}.json`;\n const resultDirPath = resolve(i18nDictionariesDir, locale);\n const resultFilePath = resolve(resultDirPath, outputFileName);\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resultDirPath, { recursive: true });\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n }\n\n return resultDictionariesPaths;\n};\n\n/**\n * This function transpile content declaration to i18n dictionaries\n */\nexport const buildI18nDictionary = async (\n contentDeclarationsPaths: string[] | string\n) => {\n const resultDictionariesPaths: string[] = [];\n\n if (typeof contentDeclarationsPaths === 'string') {\n contentDeclarationsPaths = [contentDeclarationsPaths];\n }\n\n for await (const contentDeclarationPath of contentDeclarationsPaths) {\n const result = await processContentDeclaration(contentDeclarationPath);\n\n if (!result) {\n continue;\n }\n\n const nestedContent: DeclarationContent[] = extractObjectsWithId(result);\n\n // Create dictionaries for each nested content and format them\n const dictionariesDeclaration: DictionariesDeclaration =\n nestedContent.reduce((acc, content) => {\n const id: string = content.id;\n const i18Content = createI18nDictionaries(content);\n\n return {\n ...acc,\n [id]: i18Content,\n };\n }, {});\n\n // Write the dictionaries to the file system\n const dictionariesPaths: string[] = await writeDictionary(\n dictionariesDeclaration\n );\n\n // Add the paths to the result\n resultDictionariesPaths.push(...dictionariesPaths);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAiC;AACjC,kBAAwB;AACxB,oBAAiC;AAEjC,iCAGO;AACP,0DAGO;AAEP,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MA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T;","names":["content"]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/core';\nimport { createI18nDictionaries } from './convertContentDeclarationInto18nDictionaries';\nimport {\n writeDictionary,\n type DictionariesDeclaration,\n} from './writeDictionary';\n\n/**\n * This function transpile content declaration to i18n dictionaries\n */\nexport const buildI18nDictionary = async (\n contentDeclarations: Dictionary[]\n) => {\n // Create dictionaries for each nested content and format them\n const dictionariesDeclaration: DictionariesDeclaration =\n contentDeclarations.reduce((acc, dictionary) => {\n const { key, content } = dictionary;\n const i18Content = createI18nDictionaries(content);\n\n return {\n ...acc,\n [key]: i18Content,\n };\n }, {});\n\n // Write the dictionaries to the file system\n const dictionariesPaths: string[] = await writeDictionary(\n dictionariesDeclaration\n );\n\n return dictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0DAAuC;AACvC,6BAGO;AAKA,MAAM,sBAAsB,OACjC,wBACG;AAEH,QAAM,0BACJ,oBAAoB,OAAO,CAAC,KAAK,eAAe;AAC9C,UAAM,EAAE,KAAK,QAAQ,IAAI;AACzB,UAAM,iBAAa,4EAAuB,OAAO;AAEjD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,GAAG,GAAG;AAAA,IACT;AAAA,EACF,GAAG,CAAC,CAAC;AAGP,QAAM,oBAA8B,UAAM;AAAA,IACxC;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config';\nimport {\n NodeType,\n type TranslationContent,\n type Content,\n type TypedNode,\n type EnumerationContent,\n} from '@intlayer/core';\nimport { convertPluralsValues } from './convertPluralsValues';\n\ntype Dictionary = Record<string, unknown>;\nexport type I18nDictionariesOutput = Partial<Record<Locales, Dictionary>>;\n\nconst {\n internationalization: { locales },\n} = getConfiguration();\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' &&\n typeof node?.props !== 'undefined' &&\n typeof node?.type !== 'undefined';\n\n// Build dictionary for a specific locale\nconst buildDictionary = (content: Dictionary, locale: Locales): unknown => {\n if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Translation\n ) {\n const result = (content as TranslationContent<unknown>)[\n NodeType.Translation\n ][locale];\n\n return buildDictionary(result as Dictionary, locale);\n } else if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Enumeration\n ) {\n const plurals: Record<string, unknown> = {};\n\n Object.keys(\n (content as EnumerationContent<unknown>)[NodeType.Enumeration]\n ).forEach((quantity) => {\n const letterNumber = convertPluralsValues(quantity);\n\n const value = (content as EnumerationContent<unknown>)[\n quantity as keyof EnumerationContent<unknown>\n ];\n\n plurals[`${letterNumber}_${letterNumber}`] = buildDictionary(\n value as Dictionary,\n locale\n );\n });\n\n return plurals;\n } else if (\n // React element node\n isReactNode(content as Record<string, unknown>)\n ) {\n return JSON.stringify(content);\n } else if (\n // Nested object\n typeof content === 'object'\n ) {\n const result: Record<string, unknown> = {};\n\n Object.keys(content).forEach((dictionaryValue) => {\n result[dictionaryValue] = buildDictionary(\n content[dictionaryValue] as Dictionary,\n locale\n );\n });\n\n return result;\n }\n\n return content;\n};\n\nexport const createI18nDictionaries = (\n content: Content\n): I18nDictionariesOutput => {\n // Map dictionaries for each locale\n const result: I18nDictionariesOutput = locales.reduce(\n (acc, locale) => ({\n ...acc,\n [locale]: buildDictionary(content, locale),\n }),\n {}\n );\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,kBAMO;AACP,kCAAqC;AAKrC,MAAM;AAAA,EACJ,sBAAsB,EAAE,QAAQ;AAClC,QA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../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config';\nimport {\n NodeType,\n type TranslationContent,\n type TypedNode,\n type EnumerationContent,\n DictionaryValue,\n} from '@intlayer/core';\nimport { convertPluralsValues } from './convertPluralsValues';\n\ntype Dictionary = Record<string, unknown>;\nexport type I18nDictionariesOutput = Partial<Record<Locales, Dictionary>>;\n\nconst {\n internationalization: { locales },\n} = getConfiguration();\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' &&\n typeof node?.props !== 'undefined' &&\n typeof node?.type !== 'undefined';\n\n// Build dictionary for a specific locale\nconst buildDictionary = (\n content: DictionaryValue,\n locale: Locales\n): unknown => {\n if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Translation\n ) {\n const result = (content as TranslationContent<unknown>)[\n NodeType.Translation\n ][locale];\n\n return buildDictionary(result as DictionaryValue, locale);\n } else if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Enumeration\n ) {\n const plurals: Record<string, unknown> = {};\n\n Object.keys(\n (content as EnumerationContent<unknown>)[NodeType.Enumeration]\n ).forEach((quantity) => {\n const letterNumber = convertPluralsValues(quantity);\n\n const value = (content as EnumerationContent<unknown>)[\n quantity as keyof EnumerationContent<unknown>\n ];\n\n plurals[`${letterNumber}_${letterNumber}`] = buildDictionary(\n value as DictionaryValue,\n locale\n );\n });\n\n return plurals;\n } else if (\n // React element node\n isReactNode(content as Record<string, unknown>)\n ) {\n return JSON.stringify(content);\n } else if (\n // Nested object\n typeof content === 'object'\n ) {\n const result: Record<string, unknown> = {};\n\n Object.keys(content).forEach((dictionaryValue) => {\n result[dictionaryValue] = buildDictionary(\n content[dictionaryValue as keyof typeof content] as DictionaryValue,\n locale\n );\n });\n\n return result;\n }\n\n return content;\n};\n\nexport const createI18nDictionaries = (\n content: DictionaryValue\n): I18nDictionariesOutput => {\n // Map dictionaries for each locale\n const result: I18nDictionariesOutput = locales.reduce(\n (acc, locale) => ({\n ...acc,\n [locale]: buildDictionary(content, locale),\n }),\n {}\n );\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,kBAMO;AACP,kCAAqC;AAKrC,MAAM;AAAA,EACJ,sBAAsB,EAAE,QAAQ;AAClC,QAAI,gCAAiB;AAErB,MAAM,cAAc,CAAC,SACnB,OAAO,MAAM,QAAQ,eACrB,OAAO,MAAM,UAAU,eACvB,OAAO,MAAM,SAAS;AAGxB,MAAM,kBAAkB,CACtB,SACA,WACY;AACZ;AAAA;AAAA,IAEE,WACC,QAAsB,aAAa,qBAAS;AAAA,IAC7C;AACA,UAAM,SAAU,QACd,qBAAS,WACX,EAAE,MAAM;AAER,WAAO,gBAAgB,QAA2B,MAAM;AAAA,EAC1D;AAAA;AAAA,IAEE,WACC,QAAsB,aAAa,qBAAS;AAAA,IAC7C;AACA,UAAM,UAAmC,CAAC;AAE1C,WAAO;AAAA,MACJ,QAAwC,qBAAS,WAAW;AAAA,IAC/D,EAAE,QAAQ,CAAC,aAAa;AACtB,YAAM,mBAAe,kDAAqB,QAAQ;AAElD,YAAM,QAAS,QACb,QACF;AAEA,cAAQ,GAAG,YAAY,IAAI,YAAY,EAAE,IAAI;AAAA,QAC3C;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAAA;AAAA,IAEE,YAAY,OAAkC;AAAA,IAC9C;AACA,WAAO,KAAK,UAAU,OAAO;AAAA,EAC/B;AAAA;AAAA,IAEE,OAAO,YAAY;AAAA,IACnB;AACA,UAAM,SAAkC,CAAC;AAEzC,WAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,oBAAoB;AAChD,aAAO,eAAe,IAAI;AAAA,QACxB,QAAQ,eAAuC;AAAA,QAC/C;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,yBAAyB,CACpC,YAC2B;AAE3B,QAAM,SAAiC,QAAQ;AAAA,IAC7C,CAAC,KAAK,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,CAAC,MAAM,GAAG,gBAAgB,SAAS,MAAM;AAAA,IAC3C;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,52 @@
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 writeDictionary_exports = {};
20
+ __export(writeDictionary_exports, {
21
+ writeDictionary: () => writeDictionary
22
+ });
23
+ module.exports = __toCommonJS(writeDictionary_exports);
24
+ var import_promises = require("fs/promises");
25
+ var import_path = require("path");
26
+ var import_config = require("@intlayer/config");
27
+ const { content } = (0, import_config.getConfiguration)();
28
+ const { i18nDictionariesDir } = content;
29
+ const writeDictionary = async (dictionariesDeclaration) => {
30
+ const resultDictionariesPaths = [];
31
+ for (const [nameSpace, localContent] of Object.entries(
32
+ dictionariesDeclaration
33
+ )) {
34
+ for await (const [locale, content2] of Object.entries(localContent)) {
35
+ const contentString = JSON.stringify(content2);
36
+ const outputFileName = `${nameSpace}.json`;
37
+ const resultDirPath = (0, import_path.resolve)(i18nDictionariesDir, locale);
38
+ const resultFilePath = (0, import_path.resolve)(resultDirPath, outputFileName);
39
+ await (0, import_promises.mkdir)(resultDirPath, { recursive: true });
40
+ await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
41
+ console.error(`Error creating ${outputFileName}:`, err);
42
+ });
43
+ resultDictionariesPaths.push(resultFilePath);
44
+ }
45
+ }
46
+ return resultDictionariesPaths;
47
+ };
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ writeDictionary
51
+ });
52
+ //# sourceMappingURL=writeDictionary.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.ts"],"sourcesContent":["import { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport { I18nDictionariesOutput } from './convertContentDeclarationInto18nDictionaries';\n\nconst { content } = getConfiguration();\nconst { i18nDictionariesDir } = content;\n\nexport type DictionariesDeclaration = Record<string, I18nDictionariesOutput>;\n\n/**\n * This function writes the dictionaries to the file system\n */\nexport const writeDictionary = async (\n dictionariesDeclaration: DictionariesDeclaration\n) => {\n const resultDictionariesPaths: string[] = [];\n\n for (const [nameSpace, localContent] of Object.entries(\n dictionariesDeclaration\n )) {\n for await (const [locale, content] of Object.entries(localContent)) {\n const contentString = JSON.stringify(content);\n\n const outputFileName = `${nameSpace}.json`;\n const resultDirPath = resolve(i18nDictionariesDir, locale);\n const resultFilePath = resolve(resultDirPath, outputFileName);\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resultDirPath, { recursive: true });\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAiC;AACjC,kBAAwB;AACxB,oBAAiC;AAGjC,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,oBAAoB,IAAI;AAOzB,MAAM,kBAAkB,OAC7B,4BACG;AACH,QAAM,0BAAoC,CAAC;AAE3C,aAAW,CAAC,WAAW,YAAY,KAAK,OAAO;AAAA,IAC7C;AAAA,EACF,GAAG;AACD,qBAAiB,CAAC,QAAQA,QAAO,KAAK,OAAO,QAAQ,YAAY,GAAG;AAClE,YAAM,gBAAgB,KAAK,UAAUA,QAAO;AAE5C,YAAM,iBAAiB,GAAG,SAAS;AACnC,YAAM,oBAAgB,qBAAQ,qBAAqB,MAAM;AACzD,YAAM,qBAAiB,qBAAQ,eAAe,cAAc;AAG5D,gBAAM,uBAAM,eAAe,EAAE,WAAW,KAAK,CAAC;AAG9C,gBAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,gBAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,MACxD,CAAC;AAED,8BAAwB,KAAK,cAAc;AAAA,IAC7C;AAAA,EACF;AAEA,SAAO;AACT;","names":["content"]}
@@ -29,7 +29,7 @@ const {
29
29
  } = (0, import_config.getConfiguration)();
30
30
  const buildDictionary = async (contentDeclarationsPaths) => {
31
31
  if (dictionaryOutput.includes("i18next")) {
32
- return await (0, import_i18n_dictionary.buildI18nDictionary)(contentDeclarationsPaths);
32
+ await (0, import_i18n_dictionary.buildI18nDictionary)(contentDeclarationsPaths);
33
33
  }
34
34
  if (dictionaryOutput.includes("intlayer")) {
35
35
  return await (0, import_intlayer_dictionary.buildIntlayerDictionary)(contentDeclarationsPaths);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/declaration_file_to_dictionary/index.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { buildI18nDictionary } from './i18n_dictionary/index';\nimport { buildIntlayerDictionary } from './intlayer_dictionary/index';\n\nconst {\n content: { dictionaryOutput },\n} = getConfiguration();\n\nexport const buildDictionary = async (\n contentDeclarationsPaths: string | string[]\n): Promise<string[]> => {\n if (dictionaryOutput.includes('i18next')) {\n return await buildI18nDictionary(contentDeclarationsPaths);\n }\n\n if (dictionaryOutput.includes('intlayer')) {\n return await buildIntlayerDictionary(contentDeclarationsPaths);\n }\n\n return [];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AACjC,6BAAoC;AACpC,iCAAwC;AAExC,MAAM;AAAA,EACJ,SAAS,EAAE,iBAAiB;AAC9B,QAAI,gCAAiB;AAEd,MAAM,kBAAkB,OAC7B,6BACsB;AACtB,MAAI,iBAAiB,SAAS,SAAS,GAAG;AACxC,WAAO,UAAM,4CAAoB,wBAAwB;AAAA,EAC3D;AAEA,MAAI,iBAAiB,SAAS,UAAU,GAAG;AACzC,WAAO,UAAM,oDAAwB,wBAAwB;AAAA,EAC/D;AAEA,SAAO,CAAC;AACV;","names":[]}
1
+ {"version":3,"sources":["../../../../src/transpiler/declaration_file_to_dictionary/index.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport { buildI18nDictionary } from './i18n_dictionary/index';\nimport { buildIntlayerDictionary } from './intlayer_dictionary/index';\n\nconst {\n content: { dictionaryOutput },\n} = getConfiguration();\n\nexport const buildDictionary = async (\n contentDeclarationsPaths: Dictionary[]\n): Promise<string[]> => {\n if (dictionaryOutput.includes('i18next')) {\n await buildI18nDictionary(contentDeclarationsPaths);\n }\n\n if (dictionaryOutput.includes('intlayer')) {\n return await buildIntlayerDictionary(contentDeclarationsPaths);\n }\n\n return [];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,6BAAoC;AACpC,iCAAwC;AAExC,MAAM;AAAA,EACJ,SAAS,EAAE,iBAAiB;AAC9B,QAAI,gCAAiB;AAEd,MAAM,kBAAkB,OAC7B,6BACsB;AACtB,MAAI,iBAAiB,SAAS,SAAS,GAAG;AACxC,cAAM,4CAAoB,wBAAwB;AAAA,EACpD;AAEA,MAAI,iBAAiB,SAAS,UAAU,GAAG;AACzC,WAAO,UAAM,oDAAwB,wBAAwB;AAAA,EAC/D;AAEA,SAAO,CAAC;AACV;","names":[]}