@intlayer/chokidar 5.4.2 → 5.5.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/dist/cjs/chokidar/watcher.cjs +3 -3
  2. package/dist/cjs/chokidar/watcher.cjs.map +1 -1
  3. package/dist/cjs/cleanOutputDir.cjs +7 -9
  4. package/dist/cjs/cleanOutputDir.cjs.map +1 -1
  5. package/dist/cjs/fetchDistantDictionaries.cjs +4 -3
  6. package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
  7. package/dist/cjs/filterDictionaryLocales.cjs +58 -0
  8. package/dist/cjs/filterDictionaryLocales.cjs.map +1 -0
  9. package/dist/cjs/getBuiltUnmergedDictionariesPath.cjs +51 -0
  10. package/dist/cjs/getBuiltUnmergedDictionariesPath.cjs.map +1 -0
  11. package/dist/cjs/getContentDeclarationFileTemplate/cjsTemplate.md +9 -0
  12. package/dist/cjs/getContentDeclarationFileTemplate/esmTemplate.md +9 -0
  13. package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs +62 -0
  14. package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs.map +1 -0
  15. package/dist/cjs/getContentDeclarationFileTemplate/tsTemplate.md +8 -0
  16. package/dist/cjs/index.cjs +21 -6
  17. package/dist/cjs/index.cjs.map +1 -1
  18. package/dist/cjs/listGitFiles.cjs +98 -0
  19. package/dist/cjs/listGitFiles.cjs.map +1 -0
  20. package/dist/cjs/loadDictionaries/loadDictionaries.cjs +1 -23
  21. package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
  22. package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs +7 -1
  23. package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs.map +1 -1
  24. package/dist/cjs/mergeDictionaries.cjs +43 -23
  25. package/dist/cjs/mergeDictionaries.cjs.map +1 -1
  26. package/dist/cjs/prepareIntlayer.cjs +1 -1
  27. package/dist/cjs/prepareIntlayer.cjs.map +1 -1
  28. package/dist/cjs/processPerLocaleDictionary.cjs +49 -0
  29. package/dist/cjs/processPerLocaleDictionary.cjs.map +1 -0
  30. package/dist/cjs/reduceDictionaryContent/applyMask.cjs +50 -0
  31. package/dist/cjs/reduceDictionaryContent/applyMask.cjs.map +1 -0
  32. package/dist/cjs/reduceDictionaryContent/buildMask.cjs +49 -0
  33. package/dist/cjs/reduceDictionaryContent/buildMask.cjs.map +1 -0
  34. package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs +35 -0
  35. package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs.map +1 -0
  36. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.cjs +4 -4
  37. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.cjs.map +1 -1
  38. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs +56 -8
  39. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs.map +1 -1
  40. package/dist/cjs/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.cjs +4 -4
  41. package/dist/cjs/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.cjs.map +1 -1
  42. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs +21 -1
  43. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +1 -1
  44. package/dist/cjs/writeContentDeclaration/formatCode.cjs +61 -0
  45. package/dist/cjs/writeContentDeclaration/formatCode.cjs.map +1 -0
  46. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +36 -37
  47. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
  48. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +377 -0
  49. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -0
  50. package/dist/esm/chokidar/watcher.mjs +5 -5
  51. package/dist/esm/chokidar/watcher.mjs.map +1 -1
  52. package/dist/esm/cleanOutputDir.mjs +7 -9
  53. package/dist/esm/cleanOutputDir.mjs.map +1 -1
  54. package/dist/esm/fetchDistantDictionaries.mjs +5 -4
  55. package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
  56. package/dist/esm/filterDictionaryLocales.mjs +37 -0
  57. package/dist/esm/filterDictionaryLocales.mjs.map +1 -0
  58. package/dist/esm/getBuiltUnmergedDictionariesPath.mjs +17 -0
  59. package/dist/esm/getBuiltUnmergedDictionariesPath.mjs.map +1 -0
  60. package/dist/esm/getContentDeclarationFileTemplate/cjsTemplate.md +9 -0
  61. package/dist/esm/getContentDeclarationFileTemplate/esmTemplate.md +9 -0
  62. package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs +37 -0
  63. package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs.map +1 -0
  64. package/dist/esm/getContentDeclarationFileTemplate/tsTemplate.md +8 -0
  65. package/dist/esm/index.mjs +21 -9
  66. package/dist/esm/index.mjs.map +1 -1
  67. package/dist/esm/listGitFiles.mjs +64 -0
  68. package/dist/esm/listGitFiles.mjs.map +1 -0
  69. package/dist/esm/loadDictionaries/loadDictionaries.mjs +1 -13
  70. package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
  71. package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs +7 -1
  72. package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs.map +1 -1
  73. package/dist/esm/mergeDictionaries.mjs +42 -22
  74. package/dist/esm/mergeDictionaries.mjs.map +1 -1
  75. package/dist/esm/prepareIntlayer.mjs +3 -3
  76. package/dist/esm/prepareIntlayer.mjs.map +1 -1
  77. package/dist/esm/processPerLocaleDictionary.mjs +25 -0
  78. package/dist/esm/processPerLocaleDictionary.mjs.map +1 -0
  79. package/dist/esm/reduceDictionaryContent/applyMask.mjs +26 -0
  80. package/dist/esm/reduceDictionaryContent/applyMask.mjs.map +1 -0
  81. package/dist/esm/reduceDictionaryContent/buildMask.mjs +24 -0
  82. package/dist/esm/reduceDictionaryContent/buildMask.mjs.map +1 -0
  83. package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs +11 -0
  84. package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs.map +1 -0
  85. package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.mjs +4 -4
  86. package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.mjs.map +1 -1
  87. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs +54 -8
  88. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs.map +1 -1
  89. package/dist/esm/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.mjs +4 -4
  90. package/dist/esm/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.mjs.map +1 -1
  91. package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +21 -1
  92. package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
  93. package/dist/esm/writeContentDeclaration/formatCode.mjs +37 -0
  94. package/dist/esm/writeContentDeclaration/formatCode.mjs.map +1 -0
  95. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +35 -36
  96. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
  97. package/dist/esm/writeContentDeclaration/writeJSFile.mjs +345 -0
  98. package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -0
  99. package/dist/types/chokidar/watcher.d.ts.map +1 -1
  100. package/dist/types/cleanOutputDir.d.ts.map +1 -1
  101. package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
  102. package/dist/types/filterDictionaryLocales.d.ts +4 -0
  103. package/dist/types/filterDictionaryLocales.d.ts.map +1 -0
  104. package/dist/types/getBuiltUnmergedDictionariesPath.d.ts +5 -0
  105. package/dist/types/getBuiltUnmergedDictionariesPath.d.ts.map +1 -0
  106. package/dist/types/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.d.ts +2 -0
  107. package/dist/types/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.d.ts.map +1 -0
  108. package/dist/types/index.d.ts +12 -7
  109. package/dist/types/index.d.ts.map +1 -1
  110. package/dist/types/listGitFiles.d.ts +9 -0
  111. package/dist/types/listGitFiles.d.ts.map +1 -0
  112. package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
  113. package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts.map +1 -1
  114. package/dist/types/mergeDictionaries.d.ts +2 -4
  115. package/dist/types/mergeDictionaries.d.ts.map +1 -1
  116. package/dist/types/processPerLocaleDictionary.d.ts +32 -0
  117. package/dist/types/processPerLocaleDictionary.d.ts.map +1 -0
  118. package/dist/types/reduceDictionaryContent/applyMask.d.ts +3 -0
  119. package/dist/types/reduceDictionaryContent/applyMask.d.ts.map +1 -0
  120. package/dist/types/reduceDictionaryContent/buildMask.d.ts +5 -0
  121. package/dist/types/reduceDictionaryContent/buildMask.d.ts.map +1 -0
  122. package/dist/types/reduceDictionaryContent/reduceDictionaryContent.d.ts +3 -0
  123. package/dist/types/reduceDictionaryContent/reduceDictionaryContent.d.ts.map +1 -0
  124. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts +38 -0
  125. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts.map +1 -1
  126. package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts.map +1 -1
  127. package/dist/types/writeContentDeclaration/formatCode.d.ts +2 -0
  128. package/dist/types/writeContentDeclaration/formatCode.d.ts.map +1 -0
  129. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
  130. package/dist/types/writeContentDeclaration/writeJSFile.d.ts +9 -0
  131. package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -0
  132. package/package.json +21 -13
@@ -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 loadDictionaries_exports = {};
30
20
  __export(loadDictionaries_exports, {
@@ -32,10 +22,8 @@ __export(loadDictionaries_exports, {
32
22
  });
33
23
  module.exports = __toCommonJS(loadDictionaries_exports);
34
24
  var import_config = require("@intlayer/config");
35
- var import_deepmerge = __toESM(require("deepmerge"));
36
25
  var import_fetchDistantDictionaryKeys = require('../fetchDistantDictionaryKeys.cjs');
37
26
  var import_log = require('../log.cjs');
38
- var import_mergeDictionaries = require('../mergeDictionaries.cjs');
39
27
  var import_utils = require('../utils.cjs');
40
28
  var import_loadContentDeclaration = require('./loadContentDeclaration.cjs');
41
29
  var import_loadDistantDictionaries = require('./loadDistantDictionaries.cjs');
@@ -59,7 +47,6 @@ const loadDictionaries = async (contentDeclarationsPaths, configuration = (0, im
59
47
  );
60
48
  let distantDictionaries = [];
61
49
  let distantDictionaryKeys = [];
62
- let mergedDictionaries = localDictionaries;
63
50
  if (editor.clientId && editor.clientSecret) {
64
51
  try {
65
52
  distantDictionaryKeys = await (0, import_fetchDistantDictionaryKeys.fetchDistantDictionaryKeys)();
@@ -68,15 +55,6 @@ const loadDictionaries = async (contentDeclarationsPaths, configuration = (0, im
68
55
  distantDictionaries = await (0, import_loadDistantDictionaries.loadDistantDictionaries)({
69
56
  dictionaryKeys: orderedDistantDictionaryKeys
70
57
  });
71
- if (editor.dictionaryPriorityStrategy === "distant_first") {
72
- mergedDictionaries = (0, import_deepmerge.default)(localDictionaries, distantDictionaries, {
73
- arrayMerge: (0, import_mergeDictionaries.mergeByKey)("key")
74
- });
75
- } else {
76
- mergedDictionaries = (0, import_deepmerge.default)(distantDictionaries, localDictionaries, {
77
- arrayMerge: (0, import_mergeDictionaries.mergeByKey)("key")
78
- });
79
- }
80
58
  } catch (_error) {
81
59
  (0, import_config.appLogger)("Error during fetching distant dictionaries", {
82
60
  level: "error"
@@ -84,7 +62,7 @@ const loadDictionaries = async (contentDeclarationsPaths, configuration = (0, im
84
62
  }
85
63
  }
86
64
  import_log.logger.stop();
87
- return mergedDictionaries;
65
+ return [...localDictionaries, ...distantDictionaries];
88
66
  } catch (error) {
89
67
  import_log.logger.stop();
90
68
  throw error;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { appLogger, ESMxCJSRequire, getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport merge from 'deepmerge';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { mergeByKey } from '../mergeDictionaries';\nimport { sortAlphabetically } from '../utils';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string,\n configuration = getConfiguration(),\n projectRequire = ESMxCJSRequire\n): Promise<Dictionary[]> => {\n try {\n const { editor } = configuration;\n\n appLogger('Dictionaries:', { isVerbose: true });\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] = await loadContentDeclarations(\n files,\n projectRequire\n );\n const localDictionaryKeys = localDictionaries\n .map((dict) => dict.key)\n .filter(Boolean); // Remove empty or undefined keys\n\n // Initialize the logger with both local and distant dictionaries\n logger.init(localDictionaryKeys, []);\n\n // Update logger statuses for local dictionaries\n logger.updateStatus(\n localDictionaries.map((dict) => ({\n dictionaryKey: dict.key,\n type: 'local',\n status: { status: 'built' },\n }))\n );\n\n let distantDictionaries: DictionaryAPI[] = [];\n let distantDictionaryKeys: string[] = [];\n let mergedDictionaries = localDictionaries;\n\n if (editor.clientId && editor.clientSecret) {\n try {\n // Fetch distant dictionary keys\n distantDictionaryKeys = await fetchDistantDictionaryKeys();\n\n const orderedDistantDictionaryKeys =\n distantDictionaryKeys.sort(sortAlphabetically);\n\n // Add distant dictionaries to the logger\n logger.addDictionaryKeys('distant', orderedDistantDictionaryKeys);\n\n // Fetch distant dictionaries\n distantDictionaries = await loadDistantDictionaries({\n dictionaryKeys: orderedDistantDictionaryKeys,\n });\n 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 } catch (_error) {\n appLogger('Error during fetching distant dictionaries', {\n level: 'error',\n });\n }\n }\n\n // Ensure the logger is stopped\n logger.stop();\n\n return mergedDictionaries;\n } catch (error) {\n // Ensure the logger is stopped\n logger.stop();\n\n throw error; // Re-throw the error after logging\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA4D;AAE5D,uBAAkB;AAClB,wCAA2C;AAC3C,iBAAuB;AACvB,+BAA2B;AAC3B,mBAAmC;AACnC,oCAAwC;AACxC,qCAAwC;AAEjC,MAAM,mBAAmB,OAC9B,0BACA,oBAAgB,gCAAiB,GACjC,iBAAiB,iCACS;AAC1B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI;AAEnB,iCAAU,iBAAiB,EAAE,WAAW,KAAK,CAAC;AAE9C,UAAM,QAAQ,MAAM,QAAQ,wBAAwB,IAChD,2BACA,CAAC,wBAAwB;AAE7B,UAAM,oBAAkC,UAAM;AAAA,MAC5C;AAAA,MACA;AAAA,IACF;AACA,UAAM,sBAAsB,kBACzB,IAAI,CAAC,SAAS,KAAK,GAAG,EACtB,OAAO,OAAO;AAGjB,sBAAO,KAAK,qBAAqB,CAAC,CAAC;AAGnC,sBAAO;AAAA,MACL,kBAAkB,IAAI,CAAC,UAAU;AAAA,QAC/B,eAAe,KAAK;AAAA,QACpB,MAAM;AAAA,QACN,QAAQ,EAAE,QAAQ,QAAQ;AAAA,MAC5B,EAAE;AAAA,IACJ;AAEA,QAAI,sBAAuC,CAAC;AAC5C,QAAI,wBAAkC,CAAC;AACvC,QAAI,qBAAqB;AAEzB,QAAI,OAAO,YAAY,OAAO,cAAc;AAC1C,UAAI;AAEF,gCAAwB,UAAM,8DAA2B;AAEzD,cAAM,+BACJ,sBAAsB,KAAK,+BAAkB;AAG/C,0BAAO,kBAAkB,WAAW,4BAA4B;AAGhE,8BAAsB,UAAM,wDAAwB;AAAA,UAClD,gBAAgB;AAAA,QAClB,CAAC;AACD,YAAI,OAAO,+BAA+B,iBAAiB;AAEzD,mCAAqB,iBAAAA,SAAM,mBAAmB,qBAAqB;AAAA,YACjE,gBAAY,qCAAW,KAAK;AAAA,UAC9B,CAAC;AAAA,QACH,OAAO;AAEL,mCAAqB,iBAAAA,SAAM,qBAAqB,mBAAmB;AAAA,YACjE,gBAAY,qCAAW,KAAK;AAAA,UAC9B,CAAC;AAAA,QACH;AAAA,MACF,SAAS,QAAQ;AACf,qCAAU,8CAA8C;AAAA,UACtD,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAGA,sBAAO,KAAK;AAEZ,WAAO;AAAA,EACT,SAAS,OAAO;AAEd,sBAAO,KAAK;AAEZ,UAAM;AAAA,EACR;AACF;","names":["merge"]}
1
+ {"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { appLogger, ESMxCJSRequire, getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { sortAlphabetically } from '../utils';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string,\n configuration = getConfiguration(),\n projectRequire = ESMxCJSRequire\n): Promise<Dictionary[]> => {\n try {\n const { editor } = configuration;\n\n appLogger('Dictionaries:', { isVerbose: true });\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] = await loadContentDeclarations(\n files,\n projectRequire\n );\n const localDictionaryKeys = localDictionaries\n .map((dict) => dict.key)\n .filter(Boolean); // Remove empty or undefined keys\n\n // Initialize the logger with both local and distant dictionaries\n logger.init(localDictionaryKeys, []);\n\n // Update logger statuses for local dictionaries\n logger.updateStatus(\n localDictionaries.map((dict) => ({\n dictionaryKey: dict.key,\n type: 'local',\n status: { status: 'built' },\n }))\n );\n\n let distantDictionaries: DictionaryAPI[] = [];\n let distantDictionaryKeys: string[] = [];\n\n if (editor.clientId && editor.clientSecret) {\n try {\n // Fetch distant dictionary keys\n distantDictionaryKeys = await fetchDistantDictionaryKeys();\n\n const orderedDistantDictionaryKeys =\n distantDictionaryKeys.sort(sortAlphabetically);\n\n // Add distant dictionaries to the logger\n logger.addDictionaryKeys('distant', orderedDistantDictionaryKeys);\n\n // Fetch distant dictionaries\n distantDictionaries = await loadDistantDictionaries({\n dictionaryKeys: orderedDistantDictionaryKeys,\n });\n } catch (_error) {\n appLogger('Error during fetching distant dictionaries', {\n level: 'error',\n });\n }\n }\n\n // Ensure the logger is stopped\n logger.stop();\n\n return [...localDictionaries, ...distantDictionaries];\n } catch (error) {\n // Ensure the logger is stopped\n logger.stop();\n\n throw error; // Re-throw the error after logging\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA4D;AAE5D,wCAA2C;AAC3C,iBAAuB;AACvB,mBAAmC;AACnC,oCAAwC;AACxC,qCAAwC;AAEjC,MAAM,mBAAmB,OAC9B,0BACA,oBAAgB,gCAAiB,GACjC,iBAAiB,iCACS;AAC1B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI;AAEnB,iCAAU,iBAAiB,EAAE,WAAW,KAAK,CAAC;AAE9C,UAAM,QAAQ,MAAM,QAAQ,wBAAwB,IAChD,2BACA,CAAC,wBAAwB;AAE7B,UAAM,oBAAkC,UAAM;AAAA,MAC5C;AAAA,MACA;AAAA,IACF;AACA,UAAM,sBAAsB,kBACzB,IAAI,CAAC,SAAS,KAAK,GAAG,EACtB,OAAO,OAAO;AAGjB,sBAAO,KAAK,qBAAqB,CAAC,CAAC;AAGnC,sBAAO;AAAA,MACL,kBAAkB,IAAI,CAAC,UAAU;AAAA,QAC/B,eAAe,KAAK;AAAA,QACpB,MAAM;AAAA,QACN,QAAQ,EAAE,QAAQ,QAAQ;AAAA,MAC5B,EAAE;AAAA,IACJ;AAEA,QAAI,sBAAuC,CAAC;AAC5C,QAAI,wBAAkC,CAAC;AAEvC,QAAI,OAAO,YAAY,OAAO,cAAc;AAC1C,UAAI;AAEF,gCAAwB,UAAM,8DAA2B;AAEzD,cAAM,+BACJ,sBAAsB,KAAK,+BAAkB;AAG/C,0BAAO,kBAAkB,WAAW,4BAA4B;AAGhE,8BAAsB,UAAM,wDAAwB;AAAA,UAClD,gBAAgB;AAAA,QAClB,CAAC;AAAA,MACH,SAAS,QAAQ;AACf,qCAAU,8CAA8C;AAAA,UACtD,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAGA,sBAAO,KAAK;AAEZ,WAAO,CAAC,GAAG,mBAAmB,GAAG,mBAAmB;AAAA,EACtD,SAAS,OAAO;AAEd,sBAAO,KAAK;AAEZ,UAAM;AAAA,EACR;AACF;","names":[]}
@@ -22,10 +22,16 @@ __export(loadDistantDictionaries_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(loadDistantDictionaries_exports);
24
24
  var import_fetchDistantDictionaries = require('../fetchDistantDictionaries.cjs');
25
+ const formatDistantDictionaries = (dictionaries) => {
26
+ return dictionaries.map((dict) => ({
27
+ ...dict,
28
+ location: "distant"
29
+ }));
30
+ };
25
31
  const loadDistantDictionaries = async (options) => {
26
32
  try {
27
33
  const distantDictionaries = await (0, import_fetchDistantDictionaries.fetchDistantDictionaries)(options);
28
- return distantDictionaries;
34
+ return formatDistantDictionaries(distantDictionaries);
29
35
  } catch (error) {
30
36
  console.error(error);
31
37
  return [];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/loadDictionaries/loadDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is 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":[]}
1
+ {"version":3,"sources":["../../../src/loadDictionaries/loadDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { fetchDistantDictionaries } from '../fetchDistantDictionaries';\n\ntype LoadDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n};\n\nconst formatDistantDictionaries = (dictionaries: DictionaryAPI[]) => {\n return dictionaries.map((dict) => ({\n ...dict,\n location: 'distant' as const,\n }));\n};\n\nexport const loadDistantDictionaries = async (\n options: LoadDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n try {\n const distantDictionaries = await fetchDistantDictionaries(options);\n\n return formatDistantDictionaries(distantDictionaries);\n } catch (error) {\n console.error(error);\n return [];\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sCAAyC;AAOzC,MAAM,4BAA4B,CAAC,iBAAkC;AACnE,SAAO,aAAa,IAAI,CAAC,UAAU;AAAA,IACjC,GAAG;AAAA,IACH,UAAU;AAAA,EACZ,EAAE;AACJ;AAEO,MAAM,0BAA0B,OACrC,YAC6B;AAC7B,MAAI;AACF,UAAM,sBAAsB,UAAM,0DAAyB,OAAO;AAElE,WAAO,0BAA0B,mBAAmB;AAAA,EACtD,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
@@ -28,35 +28,55 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var mergeDictionaries_exports = {};
30
30
  __export(mergeDictionaries_exports, {
31
- mergeByKey: () => mergeByKey
31
+ mergeDictionaries: () => mergeDictionaries
32
32
  });
33
33
  module.exports = __toCommonJS(mergeDictionaries_exports);
34
+ var import_config = require("@intlayer/config");
35
+ var import_built = __toESM(require("@intlayer/config/built"));
36
+ var import_core = require("@intlayer/core");
34
37
  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);
38
+ const checkTypesMatch = (obj1, obj2, dictionaryKey, path = []) => {
39
+ const type1 = (0, import_core.getNodeType)(obj1);
40
+ const type2 = (0, import_core.getNodeType)(obj2);
41
+ if (type1 !== type2) {
42
+ (0, import_config.appLogger)(
43
+ `Error: Dictionary ${dictionaryKey} has a multiple content files with type mismatch at path "${path.join(".")}": Cannot merge ${type1} with ${type2}`,
44
+ {
45
+ level: "error"
50
46
  }
51
- });
52
- sourceMap.forEach((item) => {
53
- destination.push(item);
54
- });
55
- return destination;
56
- };
47
+ );
48
+ }
49
+ if (type1 === "object" && obj1 && obj2) {
50
+ const allKeys = /* @__PURE__ */ new Set([...Object.keys(obj1), ...Object.keys(obj2)]);
51
+ for (const key of allKeys) {
52
+ if (key in obj1 && key in obj2) {
53
+ checkTypesMatch(obj1[key], obj2[key], dictionaryKey, [...path, key]);
54
+ }
55
+ }
56
+ }
57
+ };
58
+ const mergeDictionaries = (dictionaries) => {
59
+ const { editor } = import_built.default;
60
+ let mergedDictionaries = dictionaries[0];
61
+ for (let i = 1; i < dictionaries.length; i++) {
62
+ const currentDictionary = dictionaries[i];
63
+ checkTypesMatch(
64
+ mergedDictionaries,
65
+ currentDictionary,
66
+ currentDictionary.key,
67
+ []
68
+ );
69
+ const isDistant = currentDictionary.location === "distant";
70
+ if (editor.dictionaryPriorityStrategy === "distant_first" && isDistant) {
71
+ mergedDictionaries = (0, import_deepmerge.default)(mergedDictionaries, currentDictionary);
72
+ } else {
73
+ mergedDictionaries = (0, import_deepmerge.default)(currentDictionary, mergedDictionaries);
74
+ }
75
+ }
76
+ return { ...mergedDictionaries, filePath: void 0 };
57
77
  };
58
78
  // Annotate the CommonJS export names for ESM import in node:
59
79
  0 && (module.exports = {
60
- mergeByKey
80
+ mergeDictionaries
61
81
  });
62
82
  //# sourceMappingURL=mergeDictionaries.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mergeDictionaries.ts"],"sourcesContent":["import merge, { type 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,uBAAoC;AAG7B,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"]}
1
+ {"version":3,"sources":["../../src/mergeDictionaries.ts"],"sourcesContent":["import { appLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/core';\nimport { getNodeType } from '@intlayer/core';\nimport merge from 'deepmerge';\n\nconst checkTypesMatch = (\n obj1: any,\n obj2: any,\n dictionaryKey: string,\n path: string[] = []\n): void => {\n const type1 = getNodeType(obj1);\n const type2 = getNodeType(obj2);\n\n if (type1 !== type2) {\n appLogger(\n `Error: Dictionary ${dictionaryKey} has a multiple content files with type mismatch at path \"${path.join('.')}\": Cannot merge ${type1} with ${type2}`,\n {\n level: 'error',\n }\n );\n }\n\n if (type1 === 'object' && obj1 && obj2) {\n const allKeys = new Set([...Object.keys(obj1), ...Object.keys(obj2)]);\n for (const key of allKeys) {\n if (key in obj1 && key in obj2) {\n checkTypesMatch(obj1[key], obj2[key], dictionaryKey, [...path, key]);\n }\n }\n }\n};\n\nexport const mergeDictionaries = (dictionaries: Dictionary[]): Dictionary => {\n const { editor } = configuration;\n\n let mergedDictionaries: Dictionary = dictionaries[0];\n\n for (let i = 1; i < dictionaries.length; i++) {\n const currentDictionary = dictionaries[i];\n\n // Check types before merging\n checkTypesMatch(\n mergedDictionaries,\n currentDictionary,\n currentDictionary.key,\n []\n );\n\n const isDistant = currentDictionary.location === 'distant';\n\n if (editor.dictionaryPriorityStrategy === 'distant_first' && isDistant) {\n mergedDictionaries = merge(mergedDictionaries, currentDictionary);\n } else {\n mergedDictionaries = merge(currentDictionary, mergedDictionaries);\n }\n }\n\n return { ...mergedDictionaries, filePath: undefined };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0B;AAC1B,mBAA0B;AAE1B,kBAA4B;AAC5B,uBAAkB;AAElB,MAAM,kBAAkB,CACtB,MACA,MACA,eACA,OAAiB,CAAC,MACT;AACT,QAAM,YAAQ,yBAAY,IAAI;AAC9B,QAAM,YAAQ,yBAAY,IAAI;AAE9B,MAAI,UAAU,OAAO;AACnB;AAAA,MACE,qBAAqB,aAAa,6DAA6D,KAAK,KAAK,GAAG,CAAC,mBAAmB,KAAK,SAAS,KAAK;AAAA,MACnJ;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,MAAI,UAAU,YAAY,QAAQ,MAAM;AACtC,UAAM,UAAU,oBAAI,IAAI,CAAC,GAAG,OAAO,KAAK,IAAI,GAAG,GAAG,OAAO,KAAK,IAAI,CAAC,CAAC;AACpE,eAAW,OAAO,SAAS;AACzB,UAAI,OAAO,QAAQ,OAAO,MAAM;AAC9B,wBAAgB,KAAK,GAAG,GAAG,KAAK,GAAG,GAAG,eAAe,CAAC,GAAG,MAAM,GAAG,CAAC;AAAA,MACrE;AAAA,IACF;AAAA,EACF;AACF;AAEO,MAAM,oBAAoB,CAAC,iBAA2C;AAC3E,QAAM,EAAE,OAAO,IAAI,aAAAA;AAEnB,MAAI,qBAAiC,aAAa,CAAC;AAEnD,WAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAC5C,UAAM,oBAAoB,aAAa,CAAC;AAGxC;AAAA,MACE;AAAA,MACA;AAAA,MACA,kBAAkB;AAAA,MAClB,CAAC;AAAA,IACH;AAEA,UAAM,YAAY,kBAAkB,aAAa;AAEjD,QAAI,OAAO,+BAA+B,mBAAmB,WAAW;AACtE,+BAAqB,iBAAAC,SAAM,oBAAoB,iBAAiB;AAAA,IAClE,OAAO;AACL,+BAAqB,iBAAAA,SAAM,mBAAmB,kBAAkB;AAAA,IAClE;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,oBAAoB,UAAU,OAAU;AACtD;","names":["configuration","merge"]}
@@ -23,12 +23,12 @@ __export(prepareIntlayer_exports, {
23
23
  module.exports = __toCommonJS(prepareIntlayer_exports);
24
24
  var import_config = require("@intlayer/config");
25
25
  var import_cleanOutputDir = require('./cleanOutputDir.cjs');
26
+ var import_listDictionariesPath = require('./listDictionariesPath.cjs');
26
27
  var import_loadDictionaries = require('./loadDictionaries/loadDictionaries.cjs');
27
28
  var import_declaration_file_to_dictionary = require('./transpiler/declaration_file_to_dictionary/index.cjs');
28
29
  var import_createDictionaryEntryPoint = require('./transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs');
29
30
  var import_dictionary_to_type = require('./transpiler/dictionary_to_type/index.cjs');
30
31
  var import_writeConfiguration = require('./writeConfiguration/index.cjs');
31
- var import_listDictionariesPath = require('./listDictionariesPath.cjs');
32
32
  const prepareIntlayer = async (configuration = (0, import_config.getConfiguration)(), projectRequire = import_config.ESMxCJSRequire) => {
33
33
  (0, import_cleanOutputDir.cleanOutputDir)(configuration);
34
34
  (0, import_config.appLogger)("Output directory cleaned", {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n type IntlayerConfig,\n appLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createTypes,\n createModuleAugmentation,\n} from './transpiler/dictionary_to_type/index';\nimport { writeConfiguration } from './writeConfiguration';\nimport { listDictionaries } from './listDictionariesPath';\n\nexport const prepareIntlayer = async (\n configuration: IntlayerConfig = getConfiguration(),\n projectRequire = ESMxCJSRequire\n) => {\n cleanOutputDir(configuration);\n\n appLogger('Output directory cleaned', {\n isVerbose: true,\n });\n\n const files: string[] = listDictionaries(configuration);\n\n const dictionaries = await loadDictionaries(\n files,\n configuration,\n projectRequire\n );\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries, configuration);\n\n createTypes(dictionariesPaths, configuration);\n\n createDictionaryEntryPoint(configuration);\n\n appLogger('Dictionaries built');\n\n createModuleAugmentation(configuration);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n writeConfiguration(configuration);\n\n appLogger('Configuration written', {\n isVerbose: true,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKO;AACP,4BAA+B;AAC/B,8BAAiC;AACjC,4CAAgC;AAChC,wCAA2C;AAC3C,gCAGO;AACP,gCAAmC;AACnC,kCAAiC;AAE1B,MAAM,kBAAkB,OAC7B,oBAAgC,gCAAiB,GACjD,iBAAiB,iCACd;AACH,4CAAe,aAAa;AAE5B,+BAAU,4BAA4B;AAAA,IACpC,WAAW;AAAA,EACb,CAAC;AAED,QAAM,YAAkB,8CAAiB,aAAa;AAEtD,QAAM,eAAe,UAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGA,QAAM,oBAAoB,UAAM,uDAAgB,cAAc,aAAa;AAE3E,6CAAY,mBAAmB,aAAa;AAE5C,oEAA2B,aAAa;AAExC,+BAAU,oBAAoB;AAE9B,0DAAyB,aAAa;AAEtC,+BAAU,6BAA6B;AAAA,IACrC,WAAW;AAAA,EACb,CAAC;AAED,oDAAmB,aAAa;AAEhC,+BAAU,yBAAyB;AAAA,IACjC,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n type IntlayerConfig,\n appLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { listDictionaries } from './listDictionariesPath';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createModuleAugmentation,\n createTypes,\n} from './transpiler/dictionary_to_type/index';\nimport { writeConfiguration } from './writeConfiguration';\n\nexport const prepareIntlayer = async (\n configuration: IntlayerConfig = getConfiguration(),\n projectRequire = ESMxCJSRequire\n) => {\n cleanOutputDir(configuration);\n\n appLogger('Output directory cleaned', {\n isVerbose: true,\n });\n\n const files: string[] = listDictionaries(configuration);\n\n const dictionaries = await loadDictionaries(\n files,\n configuration,\n projectRequire\n );\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries, configuration);\n\n createTypes(dictionariesPaths, configuration);\n\n createDictionaryEntryPoint(configuration);\n\n appLogger('Dictionaries built');\n\n createModuleAugmentation(configuration);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n writeConfiguration(configuration);\n\n appLogger('Configuration written', {\n isVerbose: true,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKO;AACP,4BAA+B;AAC/B,kCAAiC;AACjC,8BAAiC;AACjC,4CAAgC;AAChC,wCAA2C;AAC3C,gCAGO;AACP,gCAAmC;AAE5B,MAAM,kBAAkB,OAC7B,oBAAgC,gCAAiB,GACjD,iBAAiB,iCACd;AACH,4CAAe,aAAa;AAE5B,+BAAU,4BAA4B;AAAA,IACpC,WAAW;AAAA,EACb,CAAC;AAED,QAAM,YAAkB,8CAAiB,aAAa;AAEtD,QAAM,eAAe,UAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGA,QAAM,oBAAoB,UAAM,uDAAgB,cAAc,aAAa;AAE3E,6CAAY,mBAAmB,aAAa;AAE5C,oEAA2B,aAAa;AAExC,+BAAU,oBAAoB;AAE9B,0DAAyB,aAAa;AAEtC,+BAAU,6BAA6B;AAAA,IACrC,WAAW;AAAA,EACb,CAAC;AAED,oDAAmB,aAAa;AAEhC,+BAAU,yBAAyB;AAAA,IACjC,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
@@ -0,0 +1,49 @@
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 processPerLocaleDictionary_exports = {};
20
+ __export(processPerLocaleDictionary_exports, {
21
+ processPerLocaleDictionary: () => processPerLocaleDictionary
22
+ });
23
+ module.exports = __toCommonJS(processPerLocaleDictionary_exports);
24
+ var import_core = require("@intlayer/core");
25
+ const processPerLocaleDictionary = (dictionary) => {
26
+ const isPerLocaleDictionary = typeof dictionary.locale === "string";
27
+ if (!isPerLocaleDictionary) {
28
+ return dictionary;
29
+ }
30
+ const transformStringToTranslationPlugin = {
31
+ id: "transform-string-to-translation-plugin",
32
+ canHandle: (node) => typeof node === "string" || typeof node === "number",
33
+ transform: (node) => (0, import_core.t)({ [dictionary.locale]: node })
34
+ };
35
+ return {
36
+ ...dictionary,
37
+ locale: void 0,
38
+ content: (0, import_core.deepTransformNode)(dictionary.content, {
39
+ dictionaryKey: dictionary.key,
40
+ keyPath: [],
41
+ plugins: [transformStringToTranslationPlugin]
42
+ })
43
+ };
44
+ };
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ processPerLocaleDictionary
48
+ });
49
+ //# sourceMappingURL=processPerLocaleDictionary.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/processPerLocaleDictionary.ts"],"sourcesContent":["import { deepTransformNode, Plugins, t, type Dictionary } from '@intlayer/core';\n\n/**\n *\n * Should transform per locale dictionaries to multi-locale dictionaries\n *\n * Example:\n *\n * ```json5\n * // .intlayer/dictionaries/home.fr.json\n * { 'key': 'home', 'locale': 'fr', 'content': { 'example': \"value\", ... } },\n * ```\n *\n * Result:\n *\n * ```json5\n * // .intlayer/dictionaries/home.json\n * {\n * 'key': 'home',\n * 'content': {\n * 'example': {\n * 'nodeType': 'translation',\n * 'translation': {\n * 'fr': 'valeur',\n * }\n * }, ... } },\n * ```\n *\n * @param dictionary\n * @returns\n */\nexport const processPerLocaleDictionary = (dictionary: Dictionary) => {\n const isPerLocaleDictionary = typeof dictionary.locale === 'string';\n\n if (!isPerLocaleDictionary) {\n return dictionary;\n }\n\n const transformStringToTranslationPlugin: Plugins = {\n id: 'transform-string-to-translation-plugin',\n canHandle: (node) => typeof node === 'string' || typeof node === 'number',\n transform: (node: string | number) =>\n t({ [dictionary.locale as string]: node }),\n };\n\n return {\n ...dictionary,\n locale: undefined,\n content: deepTransformNode(dictionary.content, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [transformStringToTranslationPlugin],\n }),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA+D;AA+BxD,MAAM,6BAA6B,CAAC,eAA2B;AACpE,QAAM,wBAAwB,OAAO,WAAW,WAAW;AAE3D,MAAI,CAAC,uBAAuB;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,qCAA8C;AAAA,IAClD,IAAI;AAAA,IACJ,WAAW,CAAC,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS;AAAA,IACjE,WAAW,CAAC,aACV,eAAE,EAAE,CAAC,WAAW,MAAgB,GAAG,KAAK,CAAC;AAAA,EAC7C;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ;AAAA,IACR,aAAS,+BAAkB,WAAW,SAAS;AAAA,MAC7C,eAAe,WAAW;AAAA,MAC1B,SAAS,CAAC;AAAA,MACV,SAAS,CAAC,kCAAkC;AAAA,IAC9C,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -0,0 +1,50 @@
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 applyMask_exports = {};
20
+ __export(applyMask_exports, {
21
+ applyMask: () => applyMask
22
+ });
23
+ module.exports = __toCommonJS(applyMask_exports);
24
+ const applyMask = (full, mask) => {
25
+ if (mask === true) {
26
+ return full;
27
+ }
28
+ if (Array.isArray(mask) && Array.isArray(full)) {
29
+ return mask.map((m, i) => applyMask(full[i], m));
30
+ }
31
+ if (full && typeof full === "object" && "nodeType" in full) {
32
+ if (mask && typeof mask === "object") {
33
+ return full;
34
+ }
35
+ return full;
36
+ }
37
+ if (mask && typeof mask === "object" && full && typeof full === "object") {
38
+ const out = {};
39
+ for (const [k, m] of Object.entries(mask)) {
40
+ out[k] = applyMask(full[k], m);
41
+ }
42
+ return out;
43
+ }
44
+ return full;
45
+ };
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ applyMask
49
+ });
50
+ //# sourceMappingURL=applyMask.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/reduceDictionaryContent/applyMask.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/core';\n\nexport const applyMask = (full: Dictionary, mask: any): Dictionary => {\n // the mask \"true\" → we don't filter\n if (mask === true) {\n return full;\n }\n\n // arrays\n if (Array.isArray(mask) && Array.isArray(full)) {\n return mask.map((m, i) => applyMask(full[i], m)) as any;\n }\n\n // handle node with nodeType property\n if (full && typeof full === 'object' && 'nodeType' in full) {\n if (mask && typeof mask === 'object') {\n return full; // Keep the full object with nodeType intact\n }\n return full;\n }\n\n // generic object\n if (mask && typeof mask === 'object' && full && typeof full === 'object') {\n const out: any = {};\n for (const [k, m] of Object.entries(mask)) {\n out[k] = applyMask((full as any)[k], m);\n }\n return out;\n }\n\n // unexpected case: we return the original value\n return full;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,YAAY,CAAC,MAAkB,SAA0B;AAEpE,MAAI,SAAS,MAAM;AACjB,WAAO;AAAA,EACT;AAGA,MAAI,MAAM,QAAQ,IAAI,KAAK,MAAM,QAAQ,IAAI,GAAG;AAC9C,WAAO,KAAK,IAAI,CAAC,GAAG,MAAM,UAAU,KAAK,CAAC,GAAG,CAAC,CAAC;AAAA,EACjD;AAGA,MAAI,QAAQ,OAAO,SAAS,YAAY,cAAc,MAAM;AAC1D,QAAI,QAAQ,OAAO,SAAS,UAAU;AACpC,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAGA,MAAI,QAAQ,OAAO,SAAS,YAAY,QAAQ,OAAO,SAAS,UAAU;AACxE,UAAM,MAAW,CAAC;AAClB,eAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,IAAI,GAAG;AACzC,UAAI,CAAC,IAAI,UAAW,KAAa,CAAC,GAAG,CAAC;AAAA,IACxC;AACA,WAAO;AAAA,EACT;AAGA,SAAO;AACT;","names":[]}
@@ -0,0 +1,49 @@
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 buildMask_exports = {};
20
+ __export(buildMask_exports, {
21
+ buildMask: () => buildMask,
22
+ buildMaskPlugin: () => buildMaskPlugin
23
+ });
24
+ module.exports = __toCommonJS(buildMask_exports);
25
+ var import_core = require("@intlayer/core");
26
+ const passTypedNodePlugin = {
27
+ id: "pass-typed-node-plugin",
28
+ canHandle: (node) => typeof node === "object" && typeof node?.nodeType === "string",
29
+ transform: (node, props, deepTransformNode2) => deepTransformNode2(node[node.nodeType], props)
30
+ };
31
+ const buildMaskPlugin = {
32
+ id: "build-mask-plugin",
33
+ canHandle: (node) => typeof node === "string" || typeof node === "number",
34
+ transform: () => true
35
+ };
36
+ const buildMask = (source) => ({
37
+ ...source,
38
+ content: (0, import_core.deepTransformNode)(source.content, {
39
+ dictionaryKey: source.key,
40
+ keyPath: [],
41
+ plugins: [passTypedNodePlugin, buildMaskPlugin]
42
+ })
43
+ });
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ buildMask,
47
+ buildMaskPlugin
48
+ });
49
+ //# sourceMappingURL=buildMask.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/reduceDictionaryContent/buildMask.ts"],"sourcesContent":["import { deepTransformNode, Dictionary, type Plugins } from '@intlayer/core';\n\nconst passTypedNodePlugin: Plugins = {\n id: 'pass-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node, props, deepTransformNode) =>\n deepTransformNode(node[node.nodeType], props),\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const buildMaskPlugin: Plugins = {\n id: 'build-mask-plugin',\n canHandle: (node) => typeof node === 'string' || typeof node === 'number',\n transform: () => true,\n};\n\nexport const buildMask = (source: Dictionary): any => ({\n ...source,\n content: deepTransformNode(source.content, {\n dictionaryKey: source.key,\n keyPath: [],\n plugins: [passTypedNodePlugin, buildMaskPlugin],\n }),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA4D;AAE5D,MAAM,sBAA+B;AAAA,EACnC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,OAAO,MAAM,aAAa;AAAA,EACxD,WAAW,CAAC,MAAM,OAAOA,uBACvBA,mBAAkB,KAAK,KAAK,QAAQ,GAAG,KAAK;AAChD;AAGO,MAAM,kBAA2B;AAAA,EACtC,IAAI;AAAA,EACJ,WAAW,CAAC,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS;AAAA,EACjE,WAAW,MAAM;AACnB;AAEO,MAAM,YAAY,CAAC,YAA6B;AAAA,EACrD,GAAG;AAAA,EACH,aAAS,+BAAkB,OAAO,SAAS;AAAA,IACzC,eAAe,OAAO;AAAA,IACtB,SAAS,CAAC;AAAA,IACV,SAAS,CAAC,qBAAqB,eAAe;AAAA,EAChD,CAAC;AACH;","names":["deepTransformNode"]}
@@ -0,0 +1,35 @@
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 reduceDictionaryContent_exports = {};
20
+ __export(reduceDictionaryContent_exports, {
21
+ reduceDictionaryContent: () => reduceDictionaryContent
22
+ });
23
+ module.exports = __toCommonJS(reduceDictionaryContent_exports);
24
+ var import_applyMask = require('./applyMask.cjs');
25
+ var import_buildMask = require('./buildMask.cjs');
26
+ const reduceDictionaryContent = (fullDictionary, partialDictionary) => {
27
+ const mask = (0, import_buildMask.buildMask)(partialDictionary);
28
+ const result = (0, import_applyMask.applyMask)(fullDictionary, mask);
29
+ return result;
30
+ };
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ reduceDictionaryContent
34
+ });
35
+ //# sourceMappingURL=reduceDictionaryContent.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/reduceDictionaryContent/reduceDictionaryContent.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/core';\nimport { applyMask } from './applyMask';\nimport { buildMask } from './buildMask';\n\nexport const reduceDictionaryContent = (\n fullDictionary: Dictionary,\n partialDictionary: Dictionary\n) => {\n const mask = buildMask(partialDictionary);\n const result = applyMask(fullDictionary, mask);\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA0B;AAC1B,uBAA0B;AAEnB,MAAM,0BAA0B,CACrC,gBACA,sBACG;AACH,QAAM,WAAO,4BAAU,iBAAiB;AACxC,QAAM,aAAS,4BAAU,gBAAgB,IAAI;AAE7C,SAAO;AACT;","names":[]}
@@ -21,9 +21,9 @@ __export(writeDictionary_exports, {
21
21
  writeDictionary: () => writeDictionary
22
22
  });
23
23
  module.exports = __toCommonJS(writeDictionary_exports);
24
+ var import_config = require("@intlayer/config");
24
25
  var import_promises = require("fs/promises");
25
26
  var import_path = require("path");
26
- var import_config = require("@intlayer/config");
27
27
  const writeDictionary = async (dictionariesDeclaration, configuration = (0, import_config.getConfiguration)()) => {
28
28
  const { i18nextResourcesDir } = configuration.content;
29
29
  const resultDictionariesPaths = [];
@@ -33,9 +33,9 @@ const writeDictionary = async (dictionariesDeclaration, configuration = (0, impo
33
33
  for await (const [locale, content] of Object.entries(localContent)) {
34
34
  const contentString = JSON.stringify(content);
35
35
  const outputFileName = `${nameSpace}.json`;
36
- const resultDirPath = (0, import_path.resolve)(i18nextResourcesDir, locale);
37
- const resultFilePath = (0, import_path.resolve)(resultDirPath, outputFileName);
38
- await (0, import_promises.mkdir)(resultDirPath, { recursive: true });
36
+ const dictionariesDirPath = (0, import_path.resolve)(i18nextResourcesDir, locale);
37
+ const resultFilePath = (0, import_path.resolve)(dictionariesDirPath, outputFileName);
38
+ await (0, import_promises.mkdir)(dictionariesDirPath, { recursive: true });
39
39
  await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
40
40
  console.error(`Error creating ${outputFileName}:`, err);
41
41
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.ts"],"sourcesContent":["import { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { I18nextDictionariesOutput } from './convertContentDeclarationInto18nDictionaries';\n\nexport type DictionariesDeclaration = Record<string, I18nextDictionariesOutput>;\n\n/**\n * This function writes the dictionaries to the file system\n */\nexport const writeDictionary = async (\n dictionariesDeclaration: DictionariesDeclaration,\n configuration = getConfiguration()\n) => {\n const { i18nextResourcesDir } = configuration.content;\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(i18nextResourcesDir, 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;AAQ1B,MAAM,kBAAkB,OAC7B,yBACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,oBAAoB,IAAI,cAAc;AAE9C,QAAM,0BAAoC,CAAC;AAE3C,aAAW,CAAC,WAAW,YAAY,KAAK,OAAO;AAAA,IAC7C;AAAA,EACF,GAAG;AACD,qBAAiB,CAAC,QAAQ,OAAO,KAAK,OAAO,QAAQ,YAAY,GAAG;AAClE,YAAM,gBAAgB,KAAK,UAAU,OAAO;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":[]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport type { I18nextDictionariesOutput } from './convertContentDeclarationInto18nDictionaries';\n\nexport type DictionariesDeclaration = Record<string, I18nextDictionariesOutput>;\n\n/**\n * This function writes the dictionaries to the file system\n */\nexport const writeDictionary = async (\n dictionariesDeclaration: DictionariesDeclaration,\n configuration = getConfiguration()\n) => {\n const { i18nextResourcesDir } = configuration.content;\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 dictionariesDirPath = resolve(i18nextResourcesDir, locale);\n const resultFilePath = resolve(dictionariesDirPath, outputFileName);\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(dictionariesDirPath, { 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,oBAAiC;AACjC,sBAAiC;AACjC,kBAAwB;AAQjB,MAAM,kBAAkB,OAC7B,yBACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,oBAAoB,IAAI,cAAc;AAE9C,QAAM,0BAAoC,CAAC;AAE3C,aAAW,CAAC,WAAW,YAAY,KAAK,OAAO;AAAA,IAC7C;AAAA,EACF,GAAG;AACD,qBAAiB,CAAC,QAAQ,OAAO,KAAK,OAAO,QAAQ,YAAY,GAAG;AAClE,YAAM,gBAAgB,KAAK,UAAU,OAAO;AAE5C,YAAM,iBAAiB,GAAG,SAAS;AACnC,YAAM,0BAAsB,qBAAQ,qBAAqB,MAAM;AAC/D,YAAM,qBAAiB,qBAAQ,qBAAqB,cAAc;AAGlE,gBAAM,uBAAM,qBAAqB,EAAE,WAAW,KAAK,CAAC;AAGpD,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":[]}
@@ -18,30 +18,78 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var writeDictionary_exports = {};
20
20
  __export(writeDictionary_exports, {
21
- writeDictionary: () => writeDictionary
21
+ writeDictionary: () => writeDictionary,
22
+ writeFinalDictionaries: () => writeFinalDictionaries,
23
+ writeUnmergedDictionaries: () => writeUnmergedDictionaries
22
24
  });
23
25
  module.exports = __toCommonJS(writeDictionary_exports);
26
+ var import_config = require("@intlayer/config");
24
27
  var import_promises = require("fs/promises");
25
28
  var import_path = require("path");
26
- var import_config = require("@intlayer/config");
27
- const writeDictionary = async (dictionaries, configuration = (0, import_config.getConfiguration)()) => {
29
+ var import_mergeDictionaries = require('../../../mergeDictionaries.cjs');
30
+ var import_processPerLocaleDictionary = require('../../../processPerLocaleDictionary.cjs');
31
+ const groupDictionariesByKey = (dictionaries) => {
32
+ return dictionaries.reduce(
33
+ (acc, dictionary) => {
34
+ const key = dictionary.key;
35
+ if (!acc[key]) {
36
+ acc[key] = [];
37
+ }
38
+ acc[key].push(dictionary);
39
+ return acc;
40
+ },
41
+ {}
42
+ );
43
+ };
44
+ const writeUnmergedDictionaries = async (dictionaries, configuration = (0, import_config.getConfiguration)()) => {
45
+ const { unmergedDictionariesDir } = configuration.content;
46
+ await (0, import_promises.mkdir)(unmergedDictionariesDir, { recursive: true });
47
+ const groupedDictionaries = groupDictionariesByKey(dictionaries);
48
+ for (const [key, dictionaries2] of Object.entries(groupedDictionaries)) {
49
+ const isDevelopment = process.env.NODE_ENV === "development";
50
+ const contentString = isDevelopment ? JSON.stringify(dictionaries2, null, 2) : JSON.stringify(dictionaries2);
51
+ const outputFileName = `${key}.json`;
52
+ const unmergedFilePath = (0, import_path.resolve)(unmergedDictionariesDir, outputFileName);
53
+ await (0, import_promises.writeFile)(unmergedFilePath, contentString, "utf8").catch((err) => {
54
+ console.error(`Error creating unmerged ${outputFileName}:`, err);
55
+ });
56
+ }
57
+ return groupedDictionaries;
58
+ };
59
+ const writeFinalDictionaries = async (groupedDictionaries, configuration = (0, import_config.getConfiguration)()) => {
28
60
  const { dictionariesDir } = configuration.content;
29
61
  const resultDictionariesPaths = [];
30
- for await (const dictionaryContent of dictionaries) {
62
+ for (const [key, dictionaries] of Object.entries(groupedDictionaries)) {
63
+ const multiLocaleDictionaries = dictionaries.map(
64
+ (dictionary) => (0, import_processPerLocaleDictionary.processPerLocaleDictionary)(dictionary)
65
+ );
66
+ const mergedDictionary = (0, import_mergeDictionaries.mergeDictionaries)(multiLocaleDictionaries);
31
67
  const isDevelopment = process.env.NODE_ENV === "development";
32
- const contentString = isDevelopment ? JSON.stringify(dictionaryContent, null, 2) : JSON.stringify(dictionaryContent);
33
- const key = dictionaryContent.key;
68
+ const contentString = isDevelopment ? JSON.stringify(mergedDictionary, null, 2) : JSON.stringify(mergedDictionary);
34
69
  const outputFileName = `${key}.json`;
35
70
  const resultFilePath = (0, import_path.resolve)(dictionariesDir, outputFileName);
36
71
  await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
37
- console.error(`Error creating ${outputFileName}:`, err);
72
+ console.error(`Error creating merged ${outputFileName}:`, err);
38
73
  });
39
74
  resultDictionariesPaths.push(resultFilePath);
40
75
  }
41
76
  return resultDictionariesPaths;
42
77
  };
78
+ const writeDictionary = async (dictionaries, configuration = (0, import_config.getConfiguration)()) => {
79
+ const unmergedDictionaries = await writeUnmergedDictionaries(
80
+ dictionaries,
81
+ configuration
82
+ );
83
+ const finalDictionaries = await writeFinalDictionaries(
84
+ unmergedDictionaries,
85
+ configuration
86
+ );
87
+ return finalDictionaries;
88
+ };
43
89
  // Annotate the CommonJS export names for ESM import in node:
44
90
  0 && (module.exports = {
45
- writeDictionary
91
+ writeDictionary,
92
+ writeFinalDictionaries,
93
+ writeUnmergedDictionaries
46
94
  });
47
95
  //# sourceMappingURL=writeDictionary.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"sourcesContent":["import { writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n\nexport const writeDictionary = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n) => {\n const { dictionariesDir } = configuration.content;\n const resultDictionariesPaths: string[] = [];\n\n for await (const dictionaryContent of dictionaries) {\n const isDevelopment = process.env.NODE_ENV === 'development';\n const contentString = isDevelopment\n ? JSON.stringify(dictionaryContent, null, 2)\n : JSON.stringify(dictionaryContent);\n\n const key = dictionaryContent.key;\n const outputFileName = `${key}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\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 return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0B;AAC1B,kBAAwB;AACxB,oBAAiC;AAG1B,MAAM,kBAAkB,OAC7B,cACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,gBAAgB,IAAI,cAAc;AAC1C,QAAM,0BAAoC,CAAC;AAE3C,mBAAiB,qBAAqB,cAAc;AAClD,UAAM,gBAAgB,QAAQ,IAAI,aAAa;AAC/C,UAAM,gBAAgB,gBAClB,KAAK,UAAU,mBAAmB,MAAM,CAAC,IACzC,KAAK,UAAU,iBAAiB;AAEpC,UAAM,MAAM,kBAAkB;AAC9B,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,qBAAiB,qBAAQ,iBAAiB,cAAc;AAG9D,cAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,IACxD,CAAC;AAED,4BAAwB,KAAK,cAAc;AAAA,EAC7C;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { mergeDictionaries } from '../../../mergeDictionaries';\nimport { processPerLocaleDictionary } from '../../../processPerLocaleDictionary';\n\nconst groupDictionariesByKey = (\n dictionaries: Dictionary[]\n): Record<string, Dictionary[]> => {\n return dictionaries.reduce(\n (acc, dictionary) => {\n const key = dictionary.key;\n if (!acc[key]) {\n acc[key] = [];\n }\n acc[key].push(dictionary);\n return acc;\n },\n {} as Record<string, Dictionary[]>\n );\n};\n\n/**\n * Write the unmerged dictionaries to the unmergedDictionariesDir\n * @param dictionaries - The dictionaries to write\n * @param configuration - The configuration\n * @returns The grouped dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * console.log(unmergedDictionaries);\n *\n * // .intlayer/unmerged_dictionaries/home.json\n * // {\n * // [\n * // { key: 'home', content: { ... } },\n * // { key: 'home', content: { ... } },\n * // ],\n * // }\n * ```\n */\nexport const writeUnmergedDictionaries = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n): Promise<Record<string, Dictionary[]>> => {\n const { unmergedDictionariesDir } = configuration.content;\n\n // Create the merged dictionaries directory\n await mkdir(unmergedDictionariesDir, { recursive: true });\n\n // Group dictionaries by key and write to unmergedDictionariesDir\n const groupedDictionaries = groupDictionariesByKey(dictionaries);\n\n for (const [key, dictionaries] of Object.entries(groupedDictionaries)) {\n const isDevelopment = process.env.NODE_ENV === 'development';\n const contentString = isDevelopment\n ? JSON.stringify(dictionaries, null, 2)\n : JSON.stringify(dictionaries);\n\n const outputFileName = `${key}.json`;\n const unmergedFilePath = resolve(unmergedDictionariesDir, outputFileName);\n\n // Write the grouped dictionaries\n await writeFile(unmergedFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating unmerged ${outputFileName}:`, err);\n });\n }\n\n return groupedDictionaries;\n};\n\n/**\n * Write the final dictionaries to the dictionariesDir\n * @param groupedDictionaries - The grouped dictionaries\n * @param configuration - The configuration\n * @returns The final dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeFinalDictionaries = async (\n groupedDictionaries: Record<string, Dictionary[]>,\n configuration = getConfiguration()\n) => {\n const { dictionariesDir } = configuration.content;\n const resultDictionariesPaths: string[] = [];\n\n // Merge dictionaries with the same key and write to dictionariesDir\n for (const [key, dictionaries] of Object.entries(groupedDictionaries)) {\n const multiLocaleDictionaries = dictionaries.map((dictionary) =>\n processPerLocaleDictionary(dictionary)\n );\n const mergedDictionary = mergeDictionaries(multiLocaleDictionaries);\n\n const isDevelopment = process.env.NODE_ENV === 'development';\n const contentString = isDevelopment\n ? JSON.stringify(mergedDictionary, null, 2)\n : JSON.stringify(mergedDictionary);\n\n const outputFileName = `${key}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Write the merged dictionary\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating merged ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n\n return resultDictionariesPaths;\n};\n\nexport const writeDictionary = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n) => {\n const unmergedDictionaries = await writeUnmergedDictionaries(\n dictionaries,\n configuration\n );\n\n const finalDictionaries = await writeFinalDictionaries(\n unmergedDictionaries,\n configuration\n );\n\n return finalDictionaries;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,sBAAiC;AACjC,kBAAwB;AACxB,+BAAkC;AAClC,wCAA2C;AAE3C,MAAM,yBAAyB,CAC7B,iBACiC;AACjC,SAAO,aAAa;AAAA,IAClB,CAAC,KAAK,eAAe;AACnB,YAAM,MAAM,WAAW;AACvB,UAAI,CAAC,IAAI,GAAG,GAAG;AACb,YAAI,GAAG,IAAI,CAAC;AAAA,MACd;AACA,UAAI,GAAG,EAAE,KAAK,UAAU;AACxB,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;AAsBO,MAAM,4BAA4B,OACvC,cACA,oBAAgB,gCAAiB,MACS;AAC1C,QAAM,EAAE,wBAAwB,IAAI,cAAc;AAGlD,YAAM,uBAAM,yBAAyB,EAAE,WAAW,KAAK,CAAC;AAGxD,QAAM,sBAAsB,uBAAuB,YAAY;AAE/D,aAAW,CAAC,KAAKA,aAAY,KAAK,OAAO,QAAQ,mBAAmB,GAAG;AACrE,UAAM,gBAAgB,QAAQ,IAAI,aAAa;AAC/C,UAAM,gBAAgB,gBAClB,KAAK,UAAUA,eAAc,MAAM,CAAC,IACpC,KAAK,UAAUA,aAAY;AAE/B,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,uBAAmB,qBAAQ,yBAAyB,cAAc;AAGxE,cAAM,2BAAU,kBAAkB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACtE,cAAQ,MAAM,2BAA2B,cAAc,KAAK,GAAG;AAAA,IACjE,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAkBO,MAAM,yBAAyB,OACpC,qBACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,gBAAgB,IAAI,cAAc;AAC1C,QAAM,0BAAoC,CAAC;AAG3C,aAAW,CAAC,KAAK,YAAY,KAAK,OAAO,QAAQ,mBAAmB,GAAG;AACrE,UAAM,0BAA0B,aAAa;AAAA,MAAI,CAAC,mBAChD,8DAA2B,UAAU;AAAA,IACvC;AACA,UAAM,uBAAmB,4CAAkB,uBAAuB;AAElE,UAAM,gBAAgB,QAAQ,IAAI,aAAa;AAC/C,UAAM,gBAAgB,gBAClB,KAAK,UAAU,kBAAkB,MAAM,CAAC,IACxC,KAAK,UAAU,gBAAgB;AAEnC,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,qBAAiB,qBAAQ,iBAAiB,cAAc;AAG9D,cAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,yBAAyB,cAAc,KAAK,GAAG;AAAA,IAC/D,CAAC;AAED,4BAAwB,KAAK,cAAc;AAAA,EAC7C;AAEA,SAAO;AACT;AAEO,MAAM,kBAAkB,OAC7B,cACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,uBAAuB,MAAM;AAAA,IACjC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,oBAAoB,MAAM;AAAA,IAC9B;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;","names":["dictionaries"]}