@intlayer/chokidar 2.0.13 → 3.0.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 (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
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
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
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var watcher_exports = {};
30
20
  __export(watcher_exports, {
@@ -33,53 +23,55 @@ __export(watcher_exports, {
33
23
  module.exports = __toCommonJS(watcher_exports);
34
24
  var import_path = require("path");
35
25
  var import_config = require("@intlayer/config");
36
- var import_chokidar = __toESM(require("chokidar"));
26
+ var import_chokidar = require("chokidar");
37
27
  var import_glob = require("glob");
28
+ var import_loadDictionaries = require('../loadDictionaries/loadDictionaries.cjs');
29
+ var import_loadLocalDictionaries = require('../loadDictionaries/loadLocalDictionaries.cjs');
38
30
  var import_declaration_file_to_dictionary = require('../transpiler/declaration_file_to_dictionary/index.cjs');
39
31
  var import_createDictionaryList = require('../transpiler/dictionary_to_main/createDictionaryList.cjs');
40
32
  var import_dictionary_to_type = require('../transpiler/dictionary_to_type/index.cjs');
33
+ const LOG_PREFIX = "[intlayer] ";
41
34
  const watch = (options) => {
42
35
  const { content } = (0, import_config.getConfiguration)({
43
36
  verbose: true
44
37
  });
45
38
  const { watchedFilesPatternWithPath, baseDir } = content;
46
39
  const files = (0, import_glob.sync)(watchedFilesPatternWithPath);
47
- return import_chokidar.default.watch(watchedFilesPatternWithPath, {
40
+ return (0, import_chokidar.watch)(watchedFilesPatternWithPath, {
48
41
  persistent: true,
49
42
  // Make the watcher persistent
50
43
  ignoreInitial: true,
51
44
  // Process existing files
52
45
  ...options
53
46
  }).on("ready", async () => {
54
- const dictionariesPaths = await (0, import_declaration_file_to_dictionary.buildDictionary)(files);
47
+ const dictionaries = await (0, import_loadDictionaries.loadDictionaries)(files);
48
+ const dictionariesPaths = await (0, import_declaration_file_to_dictionary.buildDictionary)(dictionaries);
55
49
  await (0, import_dictionary_to_type.createTypes)(dictionariesPaths);
56
- console.info("[intlayer] TypeScript types built");
50
+ console.info(`${LOG_PREFIX}TypeScript types built`);
57
51
  (0, import_dictionary_to_type.createModuleAugmentation)();
58
- console.info("[intlayer] Intlayer module augmentation built");
52
+ console.info(`${LOG_PREFIX}Intlayer module augmentation built`);
59
53
  (0, import_createDictionaryList.createDictionaryList)();
60
- console.info("[intlayer] Intlayer dictionary list built");
61
- const relativeDictionariesPath = dictionariesPaths.map(
62
- (dictionary) => (0, import_path.relative)(baseDir, dictionary)
63
- );
64
- console.info("[intlayer] Dictionaries:", relativeDictionariesPath);
54
+ console.info(`${LOG_PREFIX}Intlayer dictionary list built`);
65
55
  }).on("unlink", (filePath) => {
66
56
  console.info("Removed file detected: ", (0, import_path.relative)(baseDir, filePath));
67
57
  }).on("add", async (filePath) => {
68
58
  console.info(
69
- "[intlayer] Additional file detected: ",
59
+ `${LOG_PREFIX}Additional file detected: `,
70
60
  (0, import_path.relative)(baseDir, filePath)
71
61
  );
72
- const dictionaries = await (0, import_declaration_file_to_dictionary.buildDictionary)(filePath);
62
+ const localeDictionaries = await (0, import_loadLocalDictionaries.loadLocalDictionaries)(filePath);
63
+ const dictionaries = await (0, import_declaration_file_to_dictionary.buildDictionary)(localeDictionaries);
73
64
  await (0, import_dictionary_to_type.createTypes)(dictionaries);
74
- console.info("[intlayer] TypeScript types built");
65
+ console.info(`${LOG_PREFIX}TypeScript types built`);
75
66
  (0, import_dictionary_to_type.createModuleAugmentation)();
76
- console.info("[intlayer] Intlayer module augmentation built");
67
+ console.info(`${LOG_PREFIX}Intlayer module augmentation built`);
77
68
  (0, import_createDictionaryList.createDictionaryList)();
78
69
  }).on("change", async (filePath) => {
79
70
  console.info("Change detected: ", (0, import_path.relative)(baseDir, filePath));
80
- const dictionaries = await (0, import_declaration_file_to_dictionary.buildDictionary)(filePath);
71
+ const localeDictionaries = await (0, import_loadLocalDictionaries.loadLocalDictionaries)(filePath);
72
+ const dictionaries = await (0, import_declaration_file_to_dictionary.buildDictionary)(localeDictionaries);
81
73
  await (0, import_dictionary_to_type.createTypes)(dictionaries);
82
- console.info("[intlayer] TypeScript types built");
74
+ console.info(`${LOG_PREFIX}TypeScript types built`);
83
75
  }).on("error", (error) => {
84
76
  console.error("Watcher error:", error);
85
77
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport chokidar, { type WatchOptions } from 'chokidar';\nimport { sync } from 'glob';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const { content } = getConfiguration({\n verbose: true,\n });\n\n const { watchedFilesPatternWithPath, baseDir } = content;\n\n const files: string[] = sync(watchedFilesPatternWithPath);\n\n return chokidar\n .watch(watchedFilesPatternWithPath, {\n persistent: true, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n const dictionariesPaths = await buildDictionary(files);\n\n await createTypes(dictionariesPaths);\n console.info('[intlayer] TypeScript types built');\n\n createModuleAugmentation();\n console.info('[intlayer] Intlayer module augmentation built');\n\n createDictionaryList();\n console.info('[intlayer] Intlayer dictionary list built');\n\n const relativeDictionariesPath = dictionariesPaths.map((dictionary) =>\n relative(baseDir, dictionary)\n );\n\n console.info('[intlayer] Dictionaries:', relativeDictionariesPath);\n })\n .on('unlink', (filePath) => {\n // Process the file with the functionToRun\n console.info('Removed file detected: ', relative(baseDir, filePath));\n })\n .on('add', async (filePath) => {\n // Process the file with the functionToRun\n console.info(\n '[intlayer] Additional file detected: ',\n relative(baseDir, filePath)\n );\n const dictionaries = await buildDictionary(filePath);\n\n await createTypes(dictionaries);\n console.info('[intlayer] TypeScript types built');\n\n createModuleAugmentation();\n console.info('[intlayer] Intlayer module augmentation built');\n\n createDictionaryList();\n })\n .on('change', async (filePath) => {\n // Process the file with the functionToRun\n console.info('Change detected: ', relative(baseDir, filePath));\n const dictionaries = await buildDictionary(filePath);\n\n await createTypes(dictionaries);\n console.info('[intlayer] TypeScript types built');\n })\n .on('error', (error) => {\n console.error('Watcher error:', error);\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyB;AACzB,oBAAiC;AACjC,sBAA4C;AAC5C,kBAAqB;AACrB,4CAAgC;AAChC,kCAAqC;AACrC,gCAGO;AAGA,MAAM,QAAQ,CAAC,YAA2B;AAC/C,QAAM,EAAE,QAAQ,QAAI,gCAAiB;AAAA,IACnC,SAAS;AAAA,EACX,CAAC;AAED,QAAM,EAAE,6BAA6B,QAAQ,IAAI;AAEjD,QAAM,YAAkB,kBAAK,2BAA2B;AAExD,SAAO,gBAAAA,QACJ,MAAM,6BAA6B;AAAA,IAClC,YAAY;AAAA;AAAA,IACZ,eAAe;AAAA;AAAA,IACf,GAAG;AAAA,EACL,CAAC,EACA,GAAG,SAAS,YAAY;AACvB,UAAM,oBAAoB,UAAM,uDAAgB,KAAK;AAErD,cAAM,uCAAY,iBAAiB;AACnC,YAAQ,KAAK,mCAAmC;AAEhD,4DAAyB;AACzB,YAAQ,KAAK,+CAA+C;AAE5D,0DAAqB;AACrB,YAAQ,KAAK,2CAA2C;AAExD,UAAM,2BAA2B,kBAAkB;AAAA,MAAI,CAAC,mBACtD,sBAAS,SAAS,UAAU;AAAA,IAC9B;AAEA,YAAQ,KAAK,4BAA4B,wBAAwB;AAAA,EACnE,CAAC,EACA,GAAG,UAAU,CAAC,aAAa;AAE1B,YAAQ,KAAK,+BAA2B,sBAAS,SAAS,QAAQ,CAAC;AAAA,EACrE,CAAC,EACA,GAAG,OAAO,OAAO,aAAa;AAE7B,YAAQ;AAAA,MACN;AAAA,UACA,sBAAS,SAAS,QAAQ;AAAA,IAC5B;AACA,UAAM,eAAe,UAAM,uDAAgB,QAAQ;AAEnD,cAAM,uCAAY,YAAY;AAC9B,YAAQ,KAAK,mCAAmC;AAEhD,4DAAyB;AACzB,YAAQ,KAAK,+CAA+C;AAE5D,0DAAqB;AAAA,EACvB,CAAC,EACA,GAAG,UAAU,OAAO,aAAa;AAEhC,YAAQ,KAAK,yBAAqB,sBAAS,SAAS,QAAQ,CAAC;AAC7D,UAAM,eAAe,UAAM,uDAAgB,QAAQ;AAEnD,cAAM,uCAAY,YAAY;AAC9B,YAAQ,KAAK,mCAAmC;AAAA,EAClD,CAAC,EACA,GAAG,SAAS,CAAC,UAAU;AACtB,YAAQ,MAAM,kBAAkB,KAAK;AAAA,EACvC,CAAC;AACL;","names":["chokidar"]}
1
+ {"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { getConfiguration } from '@intlayer/config';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { sync } from 'glob';\nimport { loadDictionaries } from '../loadDictionaries/loadDictionaries';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\n\nconst LOG_PREFIX = '[intlayer] ';\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: ChokidarOptions) => {\n const { content } = getConfiguration({\n verbose: true,\n });\n\n const { watchedFilesPatternWithPath, baseDir } = content;\n\n const files: string[] = sync(watchedFilesPatternWithPath);\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: true, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n const dictionaries = await loadDictionaries(files);\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries);\n\n await createTypes(dictionariesPaths);\n console.info(`${LOG_PREFIX}TypeScript types built`);\n\n createModuleAugmentation();\n console.info(`${LOG_PREFIX}Intlayer module augmentation built`);\n\n createDictionaryList();\n console.info(`${LOG_PREFIX}Intlayer dictionary list built`);\n })\n .on('unlink', (filePath) => {\n // Process the file with the functionToRun\n console.info('Removed file detected: ', relative(baseDir, filePath));\n })\n .on('add', async (filePath) => {\n // Process the file with the functionToRun\n console.info(\n `${LOG_PREFIX}Additional file detected: `,\n relative(baseDir, filePath)\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const dictionaries = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionaries);\n console.info(`${LOG_PREFIX}TypeScript types built`);\n\n createModuleAugmentation();\n console.info(`${LOG_PREFIX}Intlayer module augmentation built`);\n\n createDictionaryList();\n })\n .on('change', async (filePath) => {\n // Process the file with the functionToRun\n console.info('Change detected: ', relative(baseDir, filePath));\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const dictionaries = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionaries);\n console.info(`${LOG_PREFIX}TypeScript types built`);\n })\n .on('error', (error) => {\n console.error('Watcher error:', error);\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyB;AACzB,o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BAAqB,sBAAS,SAAS,QAAQ,CAAC;AAE7D,UAAM,qBAAqB,UAAM,oDAAsB,QAAQ;AAC/D,UAAM,eAAe,UAAM,uDAAgB,kBAAkB;AAE7D,cAAM,uCAAY,YAAY;AAC9B,YAAQ,KAAK,GAAG,UAAU,wBAAwB;AAAA,EACpD,CAAC,EACA,GAAG,SAAS,CAAC,UAAU;AACtB,YAAQ,MAAM,kBAAkB,KAAK;AAAA,EACvC,CAAC;AACL;","names":["chokidarWatch"]}
@@ -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 fetchDistantDictionaries_exports = {};
30
+ __export(fetchDistantDictionaries_exports, {
31
+ fetchDistantDictionaries: () => fetchDistantDictionaries
32
+ });
33
+ module.exports = __toCommonJS(fetchDistantDictionaries_exports);
34
+ var import_config = require("@intlayer/config");
35
+ var import_libs = require("@intlayer/design-system/libs");
36
+ var import_p_limit = __toESM(require("p-limit"));
37
+ var import_log = require('./log.cjs');
38
+ const fetchDistantDictionaries = async (options) => {
39
+ try {
40
+ const {
41
+ editor: { clientId, clientSecret }
42
+ } = (0, import_config.getConfiguration)();
43
+ if (!clientId || !clientSecret) {
44
+ throw new Error(
45
+ "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
46
+ );
47
+ }
48
+ const oAuth2TokenResult = await import_libs.intlayerAPI.auth.getOAuth2AccessToken();
49
+ const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
50
+ const distantDictionariesKeys = options.dictionaryKeys;
51
+ const limit = (0, import_p_limit.default)(5);
52
+ const processDictionary = async (dictionaryKey) => {
53
+ import_log.logger.updateStatus(dictionaryKey, "distant", { status: "fetching" });
54
+ try {
55
+ const getDictionaryResult = await import_libs.intlayerAPI.dictionary.getDictionary(
56
+ dictionaryKey,
57
+ void 0,
58
+ {
59
+ headers: { Authorization: `Bearer ${oAuth2AccessToken}` }
60
+ }
61
+ );
62
+ const distantDictionary = getDictionaryResult.data;
63
+ if (!distantDictionary) {
64
+ throw new Error(`Dictionary ${dictionaryKey} not found on remote`);
65
+ }
66
+ import_log.logger.updateStatus(dictionaryKey, "distant", { status: "imported" });
67
+ return distantDictionary;
68
+ } catch (error) {
69
+ import_log.logger.updateStatus(dictionaryKey, "distant", {
70
+ status: "error",
71
+ error,
72
+ errorMessage: `${options?.logPrefix ?? ""}Error fetching dictionary ${dictionaryKey}: ${error}`
73
+ });
74
+ return void 0;
75
+ }
76
+ };
77
+ const fetchPromises = distantDictionariesKeys.map(
78
+ (dictionaryKey) => limit(() => processDictionary(dictionaryKey))
79
+ );
80
+ const result = await Promise.all(fetchPromises);
81
+ const statuses = import_log.logger.getStatuses();
82
+ for (const statusObj of statuses) {
83
+ const currentState = statusObj.state.find((s) => s.type === "distant");
84
+ if (currentState && currentState.errorMessage) {
85
+ console.error(currentState.errorMessage);
86
+ }
87
+ }
88
+ const filteredResult = result.filter(
89
+ (dict) => dict !== void 0
90
+ );
91
+ return filteredResult;
92
+ } catch (error) {
93
+ console.error(error);
94
+ return [];
95
+ }
96
+ };
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ fetchDistantDictionaries
100
+ });
101
+ //# sourceMappingURL=fetchDistantDictionaries.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/fetchDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\n// @ts-ignore @intlayer/design-system not build yet\nimport { intlayerAPI } from '@intlayer/design-system/libs';\nimport pLimit from 'p-limit';\nimport { logger } from './log';\n\ntype FetchDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n logPrefix?: string;\n};\n\n/**\n * Fetch distant dictionaries and update the logger with their statuses.\n */\nexport const fetchDistantDictionaries = async (\n options: FetchDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n try {\n const {\n editor: { clientId, clientSecret },\n } = getConfiguration();\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n const distantDictionariesKeys = options.dictionaryKeys;\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Adjust the limit as needed\n\n const processDictionary = async (\n dictionaryKey: string\n ): Promise<DictionaryAPI | undefined> => {\n logger.updateStatus(dictionaryKey, 'distant', { status: 'fetching' });\n\n try {\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n logger.updateStatus(dictionaryKey, 'distant', { status: 'imported' });\n\n return distantDictionary;\n } catch (error) {\n logger.updateStatus(dictionaryKey, 'distant', {\n status: 'error',\n error: error as Error,\n errorMessage: `${options?.logPrefix ?? ''}Error fetching dictionary ${dictionaryKey}: ${error}`,\n });\n return undefined;\n }\n };\n\n const fetchPromises = distantDictionariesKeys.map((dictionaryKey) =>\n limit(() => processDictionary(dictionaryKey))\n );\n\n const result = await Promise.all(fetchPromises);\n\n // Output any error messages\n const statuses = logger.getStatuses();\n for (const statusObj of statuses) {\n const currentState = statusObj.state.find((s) => s.type === 'distant');\n if (currentState && currentState.errorMessage) {\n console.error(currentState.errorMessage);\n }\n }\n\n // Remove undefined values\n const filteredResult = result.filter(\n (dict): dict is DictionaryAPI => dict !== undefined\n );\n\n return filteredResult;\n } catch (error) {\n console.error(error);\n return [];\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAiC;AAEjC,kBAA4B;AAC5B,qBAAmB;AACnB,iBAAuB;AAWhB,MAAM,2BAA2B,OACtC,YAC6B;AAC7B,MAAI;AACF,UAAM;AAAA,MACJ,QAAQ,EAAE,UAAU,aAAa;AAAA,IACnC,QAAI,gCAAiB;AAErB,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,MAAM,wBAAY,KAAK,qBAAqB;AAEtE,UAAM,oBAAoB,kBAAkB,MAAM;AAElD,UAAM,0BAA0B,QAAQ;AAGxC,UAAM,YAAQ,eAAAA,SAAO,CAAC;AAEtB,UAAM,oBAAoB,OACxB,k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Descriptor;
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 fetchDistantDictionaryKeys_exports = {};
20
+ __export(fetchDistantDictionaryKeys_exports, {
21
+ fetchDistantDictionaryKeys: () => fetchDistantDictionaryKeys
22
+ });
23
+ module.exports = __toCommonJS(fetchDistantDictionaryKeys_exports);
24
+ var import_config = require("@intlayer/config");
25
+ var import_libs = require("@intlayer/design-system/libs");
26
+ const fetchDistantDictionaryKeys = async () => {
27
+ const {
28
+ editor: { clientId, clientSecret }
29
+ } = (0, import_config.getConfiguration)();
30
+ if (!clientId || !clientSecret) {
31
+ throw new Error(
32
+ "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
33
+ );
34
+ }
35
+ const oAuth2TokenResult = await import_libs.intlayerAPI.auth.getOAuth2AccessToken();
36
+ const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
37
+ const getDictionariesKeysResult = await import_libs.intlayerAPI.dictionary.getDictionariesKeys({
38
+ headers: { Authorization: `Bearer ${oAuth2AccessToken}` }
39
+ });
40
+ if (!getDictionariesKeysResult.data) {
41
+ throw new Error("No distant dictionaries found");
42
+ }
43
+ const distantDictionariesKeys = getDictionariesKeysResult.data;
44
+ return distantDictionariesKeys;
45
+ };
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ fetchDistantDictionaryKeys
49
+ });
50
+ //# sourceMappingURL=fetchDistantDictionaryKeys.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/fetchDistantDictionaryKeys.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\n// @ts-ignore @intlayer/design-system not build yet\nimport { intlayerAPI } from '@intlayer/design-system/libs';\n\nexport const fetchDistantDictionaryKeys = async (): Promise<string[]> => {\n const {\n editor: { clientId, clientSecret },\n } = getConfiguration();\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Get the list of dictionary keys\n const getDictionariesKeysResult =\n await intlayerAPI.dictionary.getDictionariesKeys({\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n });\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n const distantDictionariesKeys: string[] = getDictionariesKeysResult.data;\n\n // Apply any filtering if needed\n return distantDictionariesKeys;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,kBAA4B;AAErB,MAAM,6BAA6B,YAA+B;AACvE,QAAM;AAAA,IACJ,QAAQ,EAAE,UAAU,aAAa;AAAA,EACnC,QAAI,gCAAiB;AAErB,MAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,oBAAoB,MAAM,wBAAY,KAAK,qBAAqB;AAEtE,QAAM,oBAAoB,kBAAkB,MAAM;AAGlD,QAAM,4BACJ,MAAM,wBAAY,WAAW,oBAAoB;AAAA,IAC/C,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,EAC1D,CAAC;AAEH,MAAI,CAAC,0BAA0B,MAAM;AACnC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AAEA,QAAM,0BAAoC,0BAA0B;AAGpE,SAAO;AACT;","names":[]}
@@ -20,16 +20,26 @@ var src_exports = {};
20
20
  __export(src_exports, {
21
21
  createDictionaryList: () => import_createDictionaryList.createDictionaryList,
22
22
  createModuleAugmentation: () => import_createModuleAugmentation.createModuleAugmentation,
23
+ fetchDistantDictionaries: () => import_fetchDistantDictionaries.fetchDistantDictionaries,
24
+ loadDictionaries: () => import_loadDictionaries.loadDictionaries,
25
+ loadDistantDictionaries: () => import_loadDictionaries.loadDistantDictionaries,
26
+ loadLocalDictionaries: () => import_loadDictionaries.loadLocalDictionaries,
23
27
  watch: () => import_watcher.watch
24
28
  });
25
29
  module.exports = __toCommonJS(src_exports);
26
30
  var import_watcher = require('./chokidar/watcher.cjs');
27
31
  var import_createDictionaryList = require('./transpiler/dictionary_to_main/createDictionaryList.cjs');
28
32
  var import_createModuleAugmentation = require('./transpiler/dictionary_to_type/createModuleAugmentation.cjs');
33
+ var import_fetchDistantDictionaries = require('./fetchDistantDictionaries.cjs');
34
+ var import_loadDictionaries = require('./loadDictionaries/index.cjs');
29
35
  // Annotate the CommonJS export names for ESM import in node:
30
36
  0 && (module.exports = {
31
37
  createDictionaryList,
32
38
  createModuleAugmentation,
39
+ fetchDistantDictionaries,
40
+ loadDictionaries,
41
+ loadDistantDictionaries,
42
+ loadLocalDictionaries,
33
43
  watch
34
44
  });
35
45
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { watch } from './chokidar/watcher';\nexport { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsB;AACtB,kCAAqC;AACrC,sCAAyC;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { watch } from './chokidar/watcher';\nexport { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\nexport { fetchDistantDictionaries } from './fetchDistantDictionaries';\nexport {\n loadDistantDictionaries,\n loadDictionaries,\n loadLocalDictionaries,\n} from './loadDictionaries/index';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsB;AACtB,kCAAqC;AACrC,sCAAyC;AACzC,sCAAyC;AACzC,8BAIO;","names":[]}
@@ -0,0 +1,29 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var loadDictionaries_exports = {};
17
+ module.exports = __toCommonJS(loadDictionaries_exports);
18
+ __reExport(loadDictionaries_exports, require('./loadDictionaries.cjs'), module.exports);
19
+ __reExport(loadDictionaries_exports, require('./loadDistantDictionaries.cjs'), module.exports);
20
+ __reExport(loadDictionaries_exports, require('./loadLocalDictionaries.cjs'), module.exports);
21
+ __reExport(loadDictionaries_exports, require('./loadContentDeclaration.cjs'), module.exports);
22
+ // Annotate the CommonJS export names for ESM import in node:
23
+ 0 && (module.exports = {
24
+ ...require('./loadDictionaries.cjs'),
25
+ ...require('./loadDistantDictionaries.cjs'),
26
+ ...require('./loadLocalDictionaries.cjs'),
27
+ ...require('./loadContentDeclaration.cjs')
28
+ });
29
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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":[]}
@@ -18,14 +18,13 @@ 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
- loadContentDeclaration: () => loadContentDeclaration
21
+ loadContentDeclarations: () => loadContentDeclarations
22
22
  });
23
23
  module.exports = __toCommonJS(loadContentDeclaration_exports);
24
- var import_module = require("module");
25
24
  var import_vm = require("vm");
25
+ var import_config = require("@intlayer/config");
26
26
  var import_esbuild = require("esbuild");
27
- const import_meta = {};
28
- const isESModule = typeof import_meta.url === "string";
27
+ var import_intlayer_dictionary = require('../transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.cjs');
29
28
  const sandboxContext = {
30
29
  exports: {
31
30
  default: {}
@@ -34,7 +33,7 @@ const sandboxContext = {
34
33
  exports: {}
35
34
  },
36
35
  console,
37
- require: isESModule ? (0, import_module.createRequire)(import_meta.url) : require
36
+ require: import_config.ESMxCJSRequire
38
37
  };
39
38
  const transformationOption = {
40
39
  loader: {
@@ -61,7 +60,7 @@ const loadContentDeclaration = (contentDeclarationFilePath) => {
61
60
  const fileExtension = contentDeclarationFilePath.split(".").pop() ?? "";
62
61
  try {
63
62
  if (fileExtension === "json") {
64
- return require(contentDeclarationFilePath);
63
+ return (0, import_config.ESMxCJSRequire)(contentDeclarationFilePath);
65
64
  }
66
65
  const moduleResult = (0, import_esbuild.buildSync)({
67
66
  entryPoints: [contentDeclarationFilePath],
@@ -91,8 +90,25 @@ const loadContentDeclaration = (contentDeclarationFilePath) => {
91
90
  console.error("Error:", error);
92
91
  }
93
92
  };
93
+ const loadContentDeclarations = async (contentDeclarationFilePath) => {
94
+ const contentDeclarations = contentDeclarationFilePath.map(
95
+ loadContentDeclaration
96
+ );
97
+ const resultDictionariesPaths = [];
98
+ for await (const contentDeclaration of contentDeclarations) {
99
+ if (!contentDeclaration) {
100
+ continue;
101
+ }
102
+ const processedContentDeclaration = await (0, import_intlayer_dictionary.processContentDeclaration)(contentDeclaration);
103
+ if (!processedContentDeclaration) {
104
+ continue;
105
+ }
106
+ resultDictionariesPaths.push(processedContentDeclaration);
107
+ }
108
+ return resultDictionariesPaths;
109
+ };
94
110
  // Annotate the CommonJS export names for ESM import in node:
95
111
  0 && (module.exports = {
96
- loadContentDeclaration
112
+ loadContentDeclarations
97
113
  });
98
114
  //# sourceMappingURL=loadContentDeclaration.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"sourcesContent":["import { type Context, runInNewContext } from 'vm';\nimport { ESMxCJSRequire } from '@intlayer/config';\nimport type { DeclarationContent, Dictionary } from '@intlayer/core';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport { processContentDeclaration } from '../transpiler/declaration_file_to_dictionary/intlayer_dictionary';\n\nconst sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n console,\n require: ESMxCJSRequire,\n};\n\nconst transformationOption: BuildOptions = {\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n },\n format: 'cjs', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n};\n\nconst filterValidContentDeclaration = (\n contentDeclaration: DeclarationContent\n): DeclarationContent => {\n // @TODO Implement filtering of valid content declaration\n return contentDeclaration as unknown as DeclarationContent;\n};\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nconst loadContentDeclaration = (\n contentDeclarationFilePath: string\n): DeclarationContent | undefined => {\n let contentDeclaration: DeclarationContent | undefined = undefined;\n\n const fileExtension = contentDeclarationFilePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Assume JSON\n return ESMxCJSRequire(contentDeclarationFilePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [contentDeclarationFilePath],\n\n ...transformationOption,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n runInNewContext(moduleResultString, sandboxContext);\n\n if (\n sandboxContext.exports.default &&\n Object.keys(sandboxContext.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports.default &&\n Object.keys(sandboxContext.module.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n contentDeclaration = sandboxContext.module.exports;\n }\n\n if (typeof contentDeclaration === 'undefined') {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n return filterValidContentDeclaration(contentDeclaration);\n } catch (error) {\n console.error('Error:', error);\n }\n};\n\nexport const loadContentDeclarations = async (\n contentDeclarationFilePath: string[]\n): Promise<Dictionary[]> => {\n const contentDeclarations = contentDeclarationFilePath.map(\n loadContentDeclaration\n );\n const resultDictionariesPaths: Dictionary[] = [];\n\n for await (const contentDeclaration of contentDeclarations) {\n if (!contentDeclaration) {\n continue;\n }\n\n const processedContentDeclaration =\n await processContentDeclaration(contentDeclaration);\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,gBAA8C;AAC9C,oBAA+B;AAE/B,qBAA+D;AAC/D,iCAA0C;AAE1C,MAAM,iBAA0B;AAAA,EAC9B,SAAS;AAAA,IACP,SAAS,CAAC;AAAA,EACZ;AAAA,EACA,QAAQ;AAAA,IACN,SAAS,CAAC;AAAA,EACZ;AAAA,EACA;AAAA,EACA,SAAS;AACX;AAEA,MAAM,uBAAqC;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AAAA,EACA,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AACV;AAEA,MAAM,gCAAgC,CACpC,uBACuB;AAEvB,SAAO;AACT;AAOA,MAAM,yBAAyB,CAC7B,+BACmC;AACnC,MAAI,qBAAqD;AAEzD,QAAM,gBAAgB,2BAA2B,MAAM,GAAG,EAAE,IAAI,KAAK;AAErE,MAAI;AACF,QAAI,kBAAkB,QAAQ;AAE5B,iBAAO,8BAAe,0BAA0B;AAAA,IAClD;AAIA,UAAM,mBAA4B,0BAAU;AAAA,MAC1C,aAAa,CAAC,0BAA0B;AAAA,MAExC,GAAG;AAAA,IACL,CAAC;AAED,UAAM,qBAAqB,aAAa,cAAc,CAAC,EAAE;AAEzD,QAAI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ptor;
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 loadDictionaries_exports = {};
30
+ __export(loadDictionaries_exports, {
31
+ loadDictionaries: () => loadDictionaries
32
+ });
33
+ module.exports = __toCommonJS(loadDictionaries_exports);
34
+ var import_config = require("@intlayer/config");
35
+ var import_deepmerge = __toESM(require("deepmerge"));
36
+ var import_fetchDistantDictionaryKeys = require('../fetchDistantDictionaryKeys.cjs');
37
+ var import_log = require('../log.cjs');
38
+ var import_mergeDictionaries = require('../mergeDictionaries.cjs');
39
+ var import_loadContentDeclaration = require('./loadContentDeclaration.cjs');
40
+ var import_loadDistantDictionaries = require('./loadDistantDictionaries.cjs');
41
+ const LOG_PREFIX = "[intlayer] ";
42
+ const loadDictionaries = async (contentDeclarationsPaths) => {
43
+ try {
44
+ const { editor } = (0, import_config.getConfiguration)({
45
+ verbose: true
46
+ });
47
+ console.info(`${LOG_PREFIX}Dictionaries:`);
48
+ const files = Array.isArray(contentDeclarationsPaths) ? contentDeclarationsPaths : [contentDeclarationsPaths];
49
+ const localDictionaries = await (0, import_loadContentDeclaration.loadContentDeclarations)(files);
50
+ const localDictionaryKeys = localDictionaries.map((dict) => dict.key);
51
+ import_log.logger.init(localDictionaryKeys, []);
52
+ for (const dict of localDictionaries) {
53
+ import_log.logger.updateStatus(dict.key, "local", { status: "built" });
54
+ }
55
+ let distantDictionaries = [];
56
+ let distantDictionaryKeys = [];
57
+ let mergedDictionaries = localDictionaries;
58
+ if (editor.clientId && editor.clientSecret) {
59
+ distantDictionaryKeys = await (0, import_fetchDistantDictionaryKeys.fetchDistantDictionaryKeys)();
60
+ import_log.logger.addDictionaryKeys("distant", distantDictionaryKeys);
61
+ distantDictionaries = await (0, import_loadDistantDictionaries.loadDistantDictionaries)({
62
+ dictionaryKeys: distantDictionaryKeys
63
+ });
64
+ if (editor.dictionaryPriorityStrategy === "distant_first") {
65
+ mergedDictionaries = (0, import_deepmerge.default)(localDictionaries, distantDictionaries, {
66
+ arrayMerge: (0, import_mergeDictionaries.mergeByKey)("key")
67
+ });
68
+ } else {
69
+ mergedDictionaries = (0, import_deepmerge.default)(distantDictionaries, localDictionaries, {
70
+ arrayMerge: (0, import_mergeDictionaries.mergeByKey)("key")
71
+ });
72
+ }
73
+ }
74
+ import_log.logger.stop();
75
+ return mergedDictionaries;
76
+ } catch (error) {
77
+ console.error(error);
78
+ import_log.logger.stop();
79
+ throw error;
80
+ }
81
+ };
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ loadDictionaries
85
+ });
86
+ //# sourceMappingURL=loadDictionaries.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport merge from 'deepmerge';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { mergeByKey } from '../mergeDictionaries';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nconst LOG_PREFIX = '[intlayer] ';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string\n): Promise<Dictionary[]> => {\n try {\n const { editor } = getConfiguration({\n verbose: true,\n });\n\n console.info(`${LOG_PREFIX}Dictionaries:`);\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] =\n await loadContentDeclarations(files);\n const localDictionaryKeys = localDictionaries.map((dict) => dict.key);\n\n // Initialize the logger with both local and distant dictionaries\n logger.init(localDictionaryKeys, []);\n\n // Update logger statuses for local dictionaries\n for (const dict of localDictionaries) {\n logger.updateStatus(dict.key, 'local', { status: 'built' });\n }\n\n let distantDictionaries: DictionaryAPI[] = [];\n let distantDictionaryKeys: string[] = [];\n let mergedDictionaries = localDictionaries;\n\n if (editor.clientId && editor.clientSecret) {\n // Fetch distant dictionary keys\n distantDictionaryKeys = await fetchDistantDictionaryKeys();\n\n // Add distant dictionaries to the logger\n logger.addDictionaryKeys('distant', distantDictionaryKeys);\n\n // Fetch distant dictionaries\n distantDictionaries = await loadDistantDictionaries({\n dictionaryKeys: distantDictionaryKeys,\n });\n if (editor.dictionaryPriorityStrategy === 'distant_first') {\n // Merge the dictionaries\n mergedDictionaries = merge(localDictionaries, distantDictionaries, {\n arrayMerge: mergeByKey('key'),\n });\n } else {\n // Merge the dictionaries\n mergedDictionaries = merge(distantDictionaries, localDictionaries, {\n arrayMerge: mergeByKey('key'),\n });\n }\n }\n\n // Ensure the logger is stopped\n logger.stop();\n\n return mergedDictionaries;\n } catch (error) {\n console.error(error);\n // Ensure the logger is stopped\n logger.st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AAK;AAEZ,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAEnB,sBAAO,KAAK;AACZ,UAAM;AAAA,EACR;AACF;","names":["merge"]}
@@ -16,30 +16,23 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var extractNestedJSON_exports = {};
20
- __export(extractNestedJSON_exports, {
21
- extractObjectsWithId: () => extractObjectsWithId
19
+ var loadDistantDictionaries_exports = {};
20
+ __export(loadDistantDictionaries_exports, {
21
+ loadDistantDictionaries: () => loadDistantDictionaries
22
22
  });
23
- module.exports = __toCommonJS(extractNestedJSON_exports);
24
- const extractObjectsWithId = (input) => {
25
- const search = (obj, results2) => {
26
- if (obj && typeof obj === "object") {
27
- if (Object.hasOwn(obj, "id")) {
28
- results2.push(obj);
29
- }
30
- for (const key of Object.keys(obj)) {
31
- if (typeof obj[key] === "object") {
32
- search(obj[key], results2);
33
- }
34
- }
35
- }
36
- };
37
- const results = [];
38
- search(input, results);
39
- return results;
23
+ module.exports = __toCommonJS(loadDistantDictionaries_exports);
24
+ var import_fetchDistantDictionaries = require('../fetchDistantDictionaries.cjs');
25
+ const loadDistantDictionaries = async (options) => {
26
+ try {
27
+ const distantDictionaries = await (0, import_fetchDistantDictionaries.fetchDistantDictionaries)(options);
28
+ return distantDictionaries;
29
+ } catch (error) {
30
+ console.error(error);
31
+ return [];
32
+ }
40
33
  };
41
34
  // Annotate the CommonJS export names for ESM import in node:
42
35
  0 && (module.exports = {
43
- extractObjectsWithId
36
+ loadDistantDictionaries
44
37
  });
45
- //# sourceMappingURL=extractNestedJSON.cjs.map
38
+ //# sourceMappingURL=loadDistantDictionaries.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/loadDictionaries/loadDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { fetchDistantDictionaries } from '../fetchDistantDictionaries';\n\ntype LoadDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n};\n\nexport const loadDistantDictionaries = async (\n options: LoadDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n try {\n const distantDictionaries = await fetchDistantDictionaries(options);\n\n return distantDictionaries;\n } catch (error) {\n console.error(error);\n return [];\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sCAAyC;AAOlC,MAAM,0BAA0B,OACrC,YAC6B;AAC7B,MAAI;AACF,UAAM,sBAAsB,UAAM,0DAAyB,OAAO;AAElE,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}