@intlayer/chokidar 5.3.4 → 5.3.6

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 (99) hide show
  1. package/dist/cjs/cleanOutputDir.cjs +3 -4
  2. package/dist/cjs/cleanOutputDir.cjs.map +1 -1
  3. package/dist/cjs/getBuiltDictionariesPath.cjs +2 -3
  4. package/dist/cjs/getBuiltDictionariesPath.cjs.map +1 -1
  5. package/dist/cjs/index.cjs +3 -0
  6. package/dist/cjs/index.cjs.map +1 -1
  7. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +2 -2
  8. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
  9. package/dist/cjs/loadDictionaries/loadDictionaries.cjs +7 -4
  10. package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
  11. package/dist/cjs/log.cjs +5 -5
  12. package/dist/cjs/log.cjs.map +1 -1
  13. package/dist/cjs/prepareContentDeclaration.cjs.map +1 -1
  14. package/dist/cjs/prepareIntlayer.cjs +11 -7
  15. package/dist/cjs/prepareIntlayer.cjs.map +1 -1
  16. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.cjs +5 -3
  17. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.cjs.map +1 -1
  18. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.cjs +2 -4
  19. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.cjs.map +1 -1
  20. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.cjs +4 -5
  21. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.cjs.map +1 -1
  22. package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs +4 -6
  23. package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs.map +1 -1
  24. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs +4 -4
  25. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs.map +1 -1
  26. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs +4 -4
  27. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs.map +1 -1
  28. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs +22 -14
  29. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +1 -1
  30. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +19 -18
  31. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
  32. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +2 -3
  33. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -1
  34. package/dist/esm/cleanOutputDir.mjs +3 -4
  35. package/dist/esm/cleanOutputDir.mjs.map +1 -1
  36. package/dist/esm/getBuiltDictionariesPath.mjs +2 -3
  37. package/dist/esm/getBuiltDictionariesPath.mjs.map +1 -1
  38. package/dist/esm/index.mjs +2 -0
  39. package/dist/esm/index.mjs.map +1 -1
  40. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +3 -3
  41. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
  42. package/dist/esm/loadDictionaries/loadDictionaries.mjs +8 -5
  43. package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
  44. package/dist/esm/log.mjs +5 -5
  45. package/dist/esm/log.mjs.map +1 -1
  46. package/dist/esm/prepareContentDeclaration.mjs.map +1 -1
  47. package/dist/esm/prepareIntlayer.mjs +12 -7
  48. package/dist/esm/prepareIntlayer.mjs.map +1 -1
  49. package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.mjs +5 -3
  50. package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.mjs.map +1 -1
  51. package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.mjs +2 -4
  52. package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.mjs.map +1 -1
  53. package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.mjs +4 -5
  54. package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.mjs.map +1 -1
  55. package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs +4 -6
  56. package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs.map +1 -1
  57. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs +4 -4
  58. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -1
  59. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs +4 -4
  60. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs.map +1 -1
  61. package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +22 -14
  62. package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
  63. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +19 -18
  64. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
  65. package/dist/esm/transpiler/dictionary_to_type/createType.mjs +6 -4
  66. package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
  67. package/dist/types/cleanOutputDir.d.ts +1 -1
  68. package/dist/types/cleanOutputDir.d.ts.map +1 -1
  69. package/dist/types/getBuiltDictionariesPath.d.ts +1 -1
  70. package/dist/types/getBuiltDictionariesPath.d.ts.map +1 -1
  71. package/dist/types/index.d.ts +1 -0
  72. package/dist/types/index.d.ts.map +1 -1
  73. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +1 -1
  74. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
  75. package/dist/types/loadDictionaries/loadDictionaries.d.ts +1 -1
  76. package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
  77. package/dist/types/log.d.ts +3 -2
  78. package/dist/types/log.d.ts.map +1 -1
  79. package/dist/types/prepareIntlayer.d.ts +1 -1
  80. package/dist/types/prepareIntlayer.d.ts.map +1 -1
  81. package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.d.ts +1 -1
  82. package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.d.ts.map +1 -1
  83. package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.d.ts +1 -1
  84. package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.d.ts.map +1 -1
  85. package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.d.ts +1 -1
  86. package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.d.ts.map +1 -1
  87. package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +1 -1
  88. package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts.map +1 -1
  89. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +1 -1
  90. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +1 -1
  91. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts +1 -1
  92. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts.map +1 -1
  93. package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts +1 -1
  94. package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts.map +1 -1
  95. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +1 -1
  96. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts.map +1 -1
  97. package/dist/types/transpiler/dictionary_to_type/createType.d.ts +2 -1
  98. package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +1 -1
  99. package/package.json +13 -13
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\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) => {\n cleanOutputDir();\n\n appLogger('Output directory cleaned', {\n isVerbose: true,\n });\n\n const files: string[] = listDictionaries(configuration);\n\n const dictionaries = await loadDictionaries(files);\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint();\n\n appLogger('Dictionaries built');\n\n createModuleAugmentation();\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,EAEE;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,wBAAwB;AAE1B,MAAM,kBAAkB,OAC7B,gBAAgC,iBAAiB,MAC9C;AACH,iBAAe;AAEf,YAAU,4BAA4B;AAAA,IACpC,WAAW;AAAA,EACb,CAAC;AAED,QAAM,QAAkB,iBAAiB,aAAa;AAEtD,QAAM,eAAe,MAAM,iBAAiB,KAAK;AAGjD,QAAM,oBAAoB,MAAM,gBAAgB,YAAY;AAE5D,cAAY,iBAAiB;AAE7B,6BAA2B;AAE3B,YAAU,oBAAoB;AAE9B,2BAAyB;AAEzB,YAAU,6BAA6B;AAAA,IACrC,WAAW;AAAA,EACb,CAAC;AAED,qBAAmB,aAAa;AAEhC,YAAU,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 { 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,EACE;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,wBAAwB;AAE1B,MAAM,kBAAkB,OAC7B,gBAAgC,iBAAiB,GACjD,iBAAiB,mBACd;AACH,iBAAe,aAAa;AAE5B,YAAU,4BAA4B;AAAA,IACpC,WAAW;AAAA,EACb,CAAC;AAED,QAAM,QAAkB,iBAAiB,aAAa;AAEtD,QAAM,eAAe,MAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGA,QAAM,oBAAoB,MAAM,gBAAgB,cAAc,aAAa;AAE3E,cAAY,mBAAmB,aAAa;AAE5C,6BAA2B,aAAa;AAExC,YAAU,oBAAoB;AAE9B,2BAAyB,aAAa;AAEtC,YAAU,6BAA6B;AAAA,IACrC,WAAW;AAAA,EACb,CAAC;AAED,qBAAmB,aAAa;AAEhC,YAAU,yBAAyB;AAAA,IACjC,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
@@ -2,17 +2,19 @@ import { createI18nextDictionaries } from "./convertContentDeclarationInto18nDic
2
2
  import {
3
3
  writeDictionary
4
4
  } from "./writeDictionary.mjs";
5
- const buildI18nDictionary = async (contentDeclarations) => {
5
+ import { getConfiguration } from "@intlayer/config";
6
+ const buildI18nDictionary = async (contentDeclarations, configuration = getConfiguration()) => {
6
7
  const dictionariesDeclaration = contentDeclarations.reduce((acc, dictionary) => {
7
8
  const { key, content } = dictionary;
8
- const i18Content = createI18nextDictionaries(content);
9
+ const i18Content = createI18nextDictionaries(content, configuration);
9
10
  return {
10
11
  ...acc,
11
12
  [key]: i18Content
12
13
  };
13
14
  }, {});
14
15
  const dictionariesPaths = await writeDictionary(
15
- dictionariesDeclaration
16
+ dictionariesDeclaration,
17
+ configuration
16
18
  );
17
19
  return dictionariesPaths;
18
20
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/core';\nimport { createI18nextDictionaries } from './convertContentDeclarationInto18nDictionaries';\nimport {\n writeDictionary,\n type DictionariesDeclaration,\n} from './writeDictionary';\n\n/**\n * This function transpile content declaration to i18n dictionaries\n */\nexport const buildI18nDictionary = async (\n contentDeclarations: Dictionary[]\n) => {\n // Create dictionaries for each nested content and format them\n const dictionariesDeclaration: DictionariesDeclaration =\n contentDeclarations.reduce((acc, dictionary) => {\n const { key, content } = dictionary;\n const i18Content = createI18nextDictionaries(content);\n\n return {\n ...acc,\n [key]: i18Content,\n };\n }, {});\n\n // Write the dictionaries to the file system\n const dictionariesPaths: string[] = await writeDictionary(\n dictionariesDeclaration\n );\n\n return dictionariesPaths;\n};\n"],"mappings":"AACA,SAAS,iCAAiC;AAC1C;AAAA,EACE;AAAA,OAEK;AAKA,MAAM,sBAAsB,OACjC,wBACG;AAEH,QAAM,0BACJ,oBAAoB,OAAO,CAAC,KAAK,eAAe;AAC9C,UAAM,EAAE,KAAK,QAAQ,IAAI;AACzB,UAAM,aAAa,0BAA0B,OAAO;AAEpD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,GAAG,GAAG;AAAA,IACT;AAAA,EACF,GAAG,CAAC,CAAC;AAGP,QAAM,oBAA8B,MAAM;AAAA,IACxC;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/core';\nimport { createI18nextDictionaries } from './convertContentDeclarationInto18nDictionaries';\nimport {\n writeDictionary,\n type DictionariesDeclaration,\n} from './writeDictionary';\nimport { getConfiguration } from '@intlayer/config';\n\n/**\n * This function transpile content declaration to i18n dictionaries\n */\nexport const buildI18nDictionary = async (\n contentDeclarations: Dictionary[],\n configuration = getConfiguration()\n) => {\n // Create dictionaries for each nested content and format them\n const dictionariesDeclaration: DictionariesDeclaration =\n contentDeclarations.reduce((acc, dictionary) => {\n const { key, content } = dictionary;\n const i18Content = createI18nextDictionaries(content, configuration);\n\n return {\n ...acc,\n [key]: i18Content,\n };\n }, {});\n\n // Write the dictionaries to the file system\n const dictionariesPaths: string[] = await writeDictionary(\n dictionariesDeclaration,\n configuration\n );\n\n return dictionariesPaths;\n};\n"],"mappings":"AACA,SAAS,iCAAiC;AAC1C;AAAA,EACE;AAAA,OAEK;AACP,SAAS,wBAAwB;AAK1B,MAAM,sBAAsB,OACjC,qBACA,gBAAgB,iBAAiB,MAC9B;AAEH,QAAM,0BACJ,oBAAoB,OAAO,CAAC,KAAK,eAAe;AAC9C,UAAM,EAAE,KAAK,QAAQ,IAAI;AACzB,UAAM,aAAa,0BAA0B,SAAS,aAAa;AAEnE,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,GAAG,GAAG;AAAA,IACT;AAAA,EACF,GAAG,CAAC,CAAC;AAGP,QAAM,oBAA8B,MAAM;AAAA,IACxC;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -3,9 +3,6 @@ import {
3
3
  NodeType
4
4
  } from "@intlayer/core";
5
5
  import { convertPluralsValues } from "./convertPluralsValues.mjs";
6
- const {
7
- internationalization: { locales }
8
- } = getConfiguration();
9
6
  const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined" && typeof node?.type !== "undefined";
10
7
  const buildDictionary = (content, locale) => {
11
8
  if (
@@ -67,7 +64,8 @@ const buildDictionary = (content, locale) => {
67
64
  }
68
65
  return content;
69
66
  };
70
- const createI18nextDictionaries = (content) => {
67
+ const createI18nextDictionaries = (content, configuration = getConfiguration()) => {
68
+ const { locales } = configuration.internationalization;
71
69
  const result = locales.reduce(
72
70
  (acc, locale) => ({
73
71
  ...acc,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config';\nimport {\n NodeType,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n type ContentNode,\n} from '@intlayer/core';\nimport { convertPluralsValues } from './convertPluralsValues';\n\ntype Dictionary = Record<string, unknown>;\nexport type I18nextDictionariesOutput = Partial<Record<Locales, Dictionary>>;\n\nconst {\n internationalization: { locales },\n} = getConfiguration();\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' &&\n typeof node?.props !== 'undefined' &&\n typeof node?.type !== 'undefined';\n\n// Build dictionary for a specific locale\nconst buildDictionary = (content: ContentNode, locale: Locales): unknown => {\n if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Translation\n ) {\n const contentState = (content as TranslationContent)[NodeType.Translation];\n const result = contentState[locale as keyof typeof contentState];\n\n return buildDictionary(result as ContentNode, locale);\n } else if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Enumeration\n ) {\n const plurals: Record<string, unknown> = {};\n\n Object.keys(\n (content as EnumerationContent<unknown>)[NodeType.Enumeration]\n ).forEach((quantity) => {\n const letterNumber = convertPluralsValues(quantity);\n\n const value = (content as EnumerationContent<unknown>)[\n quantity as keyof EnumerationContent<unknown>\n ];\n\n plurals[`${letterNumber}_${letterNumber}`] = buildDictionary(\n value as ContentNode,\n locale\n );\n });\n\n return plurals;\n } else if (\n // React element node\n isReactNode(content as Record<string, unknown>)\n ) {\n return JSON.stringify(content);\n } else if (\n // Nested object\n typeof content === 'object' &&\n Array.isArray(content)\n ) {\n const result: unknown[] = [];\n\n Object.keys(content).forEach((dictionaryValue) => {\n result.push(\n buildDictionary(\n content[dictionaryValue as keyof typeof content] as ContentNode,\n locale\n )\n );\n });\n\n return result;\n } else if (\n // Nested object\n typeof content === 'object'\n ) {\n const result: Record<string, unknown> = {};\n\n Object.keys(content as Record<string, unknown>).forEach(\n (dictionaryValue) => {\n result[dictionaryValue] = buildDictionary(\n content?.[\n dictionaryValue as keyof typeof content\n ] as unknown as ContentNode,\n locale\n );\n }\n );\n\n return result;\n }\n\n return content;\n};\n\nexport const createI18nextDictionaries = (\n content: ContentNode\n): I18nextDictionariesOutput => {\n // Map dictionaries for each locale\n const result: I18nextDictionariesOutput = locales.reduce(\n (acc, locale) => ({\n ...acc,\n [locale]: buildDictionary(content, locale),\n }),\n {}\n );\n\n return result;\n};\n"],"mappings":"AAAA,SAAS,wBAAsC;AAC/C;AAAA,EACE;AAAA,OAKK;AACP,SAAS,4BAA4B;AAKrC,MAAM;AAAA,EACJ,sBAAsB,EAAE,QAAQ;AAClC,IAAI,iBAAiB;AAErB,MAAM,cAAc,CAAC,SACnB,OAAO,MAAM,QAAQ,eACrB,OAAO,MAAM,UAAU,eACvB,OAAO,MAAM,SAAS;AAGxB,MAAM,kBAAkB,CAAC,SAAsB,WAA6B;AAC1E;AAAA;AAAA,IAEE,WACC,QAAsB,aAAa,SAAS;AAAA,IAC7C;AACA,UAAM,eAAgB,QAA+B,SAAS,WAAW;AACzE,UAAM,SAAS,aAAa,MAAmC;AAE/D,WAAO,gBAAgB,QAAuB,MAAM;AAAA,EACtD;AAAA;AAAA,IAEE,WACC,QAAsB,aAAa,SAAS;AAAA,IAC7C;AACA,UAAM,UAAmC,CAAC;AAE1C,WAAO;AAAA,MACJ,QAAwC,SAAS,WAAW;AAAA,IAC/D,EAAE,QAAQ,CAAC,aAAa;AACtB,YAAM,eAAe,qBAAqB,QAAQ;AAElD,YAAM,QAAS,QACb,QACF;AAEA,cAAQ,GAAG,YAAY,IAAI,YAAY,EAAE,IAAI;AAAA,QAC3C;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAAA;AAAA,IAEE,YAAY,OAAkC;AAAA,IAC9C;AACA,WAAO,KAAK,UAAU,OAAO;AAAA,EAC/B;AAAA;AAAA,IAEE,OAAO,YAAY,YACnB,MAAM,QAAQ,OAAO;AAAA,IACrB;AACA,UAAM,SAAoB,CAAC;AAE3B,WAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,oBAAoB;AAChD,aAAO;AAAA,QACL;AAAA,UACE,QAAQ,eAAuC;AAAA,UAC/C;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAAA;AAAA,IAEE,OAAO,YAAY;AAAA,IACnB;AACA,UAAM,SAAkC,CAAC;AAEzC,WAAO,KAAK,OAAkC,EAAE;AAAA,MAC9C,CAAC,oBAAoB;AACnB,eAAO,eAAe,IAAI;AAAA,UACxB,UACE,eACF;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,4BAA4B,CACvC,YAC8B;AAE9B,QAAM,SAAoC,QAAQ;AAAA,IAChD,CAAC,KAAK,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,CAAC,MAAM,GAAG,gBAAgB,SAAS,MAAM;AAAA,IAC3C;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config';\nimport {\n NodeType,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n type ContentNode,\n} from '@intlayer/core';\nimport { convertPluralsValues } from './convertPluralsValues';\n\ntype Dictionary = Record<string, unknown>;\nexport type I18nextDictionariesOutput = Partial<Record<Locales, Dictionary>>;\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' &&\n typeof node?.props !== 'undefined' &&\n typeof node?.type !== 'undefined';\n\n// Build dictionary for a specific locale\nconst buildDictionary = (content: ContentNode, locale: Locales): unknown => {\n if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Translation\n ) {\n const contentState = (content as TranslationContent)[NodeType.Translation];\n const result = contentState[locale as keyof typeof contentState];\n\n return buildDictionary(result as ContentNode, locale);\n } else if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Enumeration\n ) {\n const plurals: Record<string, unknown> = {};\n\n Object.keys(\n (content as EnumerationContent<unknown>)[NodeType.Enumeration]\n ).forEach((quantity) => {\n const letterNumber = convertPluralsValues(quantity);\n\n const value = (content as EnumerationContent<unknown>)[\n quantity as keyof EnumerationContent<unknown>\n ];\n\n plurals[`${letterNumber}_${letterNumber}`] = buildDictionary(\n value as ContentNode,\n locale\n );\n });\n\n return plurals;\n } else if (\n // React element node\n isReactNode(content as Record<string, unknown>)\n ) {\n return JSON.stringify(content);\n } else if (\n // Nested object\n typeof content === 'object' &&\n Array.isArray(content)\n ) {\n const result: unknown[] = [];\n\n Object.keys(content).forEach((dictionaryValue) => {\n result.push(\n buildDictionary(\n content[dictionaryValue as keyof typeof content] as ContentNode,\n locale\n )\n );\n });\n\n return result;\n } else if (\n // Nested object\n typeof content === 'object'\n ) {\n const result: Record<string, unknown> = {};\n\n Object.keys(content as Record<string, unknown>).forEach(\n (dictionaryValue) => {\n result[dictionaryValue] = buildDictionary(\n content?.[\n dictionaryValue as keyof typeof content\n ] as unknown as ContentNode,\n locale\n );\n }\n );\n\n return result;\n }\n\n return content;\n};\n\nexport const createI18nextDictionaries = (\n content: ContentNode,\n configuration = getConfiguration()\n): I18nextDictionariesOutput => {\n const { locales } = configuration.internationalization;\n\n // Map dictionaries for each locale\n const result: I18nextDictionariesOutput = locales.reduce(\n (acc, locale) => ({\n ...acc,\n [locale]: buildDictionary(content, locale),\n }),\n {}\n );\n\n return result;\n};\n"],"mappings":"AAAA,SAAS,w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ACxB,UACE,eACF;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,4BAA4B,CACvC,SACA,gBAAgB,iBAAiB,MACH;AAC9B,QAAM,EAAE,QAAQ,IAAI,cAAc;AAGlC,QAAM,SAAoC,QAAQ;AAAA,IAChD,CAAC,KAAK,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,CAAC,MAAM,GAAG,gBAAgB,SAAS,MAAM;AAAA,IAC3C;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
@@ -1,15 +1,14 @@
1
1
  import { mkdir, writeFile } from "fs/promises";
2
2
  import { resolve } from "path";
3
3
  import { getConfiguration } from "@intlayer/config";
4
- const { content } = getConfiguration();
5
- const { i18nextResourcesDir } = content;
6
- const writeDictionary = async (dictionariesDeclaration) => {
4
+ const writeDictionary = async (dictionariesDeclaration, configuration = getConfiguration()) => {
5
+ const { i18nextResourcesDir } = configuration.content;
7
6
  const resultDictionariesPaths = [];
8
7
  for (const [nameSpace, localContent] of Object.entries(
9
8
  dictionariesDeclaration
10
9
  )) {
11
- for await (const [locale, content2] of Object.entries(localContent)) {
12
- const contentString = JSON.stringify(content2);
10
+ for await (const [locale, content] of Object.entries(localContent)) {
11
+ const contentString = JSON.stringify(content);
13
12
  const outputFileName = `${nameSpace}.json`;
14
13
  const resultDirPath = resolve(i18nextResourcesDir, locale);
15
14
  const resultFilePath = resolve(resultDirPath, outputFileName);
@@ -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\nconst { content } = getConfiguration();\nconst { i18nextResourcesDir } = content;\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) => {\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,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,wBAAwB;AAGjC,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,oBAAoB,IAAI;AAOzB,MAAM,kBAAkB,OAC7B,4BACG;AACH,QAAM,0BAAoC,CAAC;AAE3C,aAAW,CAAC,WAAW,YAAY,KAAK,OAAO;AAAA,IAC7C;AAAA,EACF,GAAG;AACD,qBAAiB,CAAC,QAAQA,QAAO,KAAK,OAAO,QAAQ,YAAY,GAAG;AAClE,YAAM,gBAAgB,KAAK,UAAUA,QAAO;AAE5C,YAAM,iBAAiB,GAAG,SAAS;AACnC,YAAM,gBAAgB,QAAQ,qBAAqB,MAAM;AACzD,YAAM,iBAAiB,QAAQ,eAAe,cAAc;AAG5D,YAAM,MAAM,eAAe,EAAE,WAAW,KAAK,CAAC;AAG9C,YAAM,UAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,gBAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,MACxD,CAAC;AAED,8BAAwB,KAAK,cAAc;AAAA,IAC7C;AAAA,EACF;AAEA,SAAO;AACT;","names":["content"]}
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,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,wBAAwB;AAQ1B,MAAM,kBAAkB,OAC7B,yBACA,gBAAgB,iBAAiB,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,gBAAgB,QAAQ,qBAAqB,MAAM;AACzD,YAAM,iBAAiB,QAAQ,eAAe,cAAc;AAG5D,YAAM,MAAM,eAAe,EAAE,WAAW,KAAK,CAAC;AAG9C,YAAM,UAAU,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,15 +1,13 @@
1
1
  import { getConfiguration } from "@intlayer/config";
2
2
  import { buildI18nDictionary } from "./i18next_dictionary/index.mjs";
3
3
  import { buildIntlayerDictionary } from "./intlayer_dictionary/index.mjs";
4
- const {
5
- content: { dictionaryOutput }
6
- } = getConfiguration();
7
- const buildDictionary = async (dictionaries) => {
4
+ const buildDictionary = async (dictionaries, configuration = getConfiguration()) => {
5
+ const { dictionaryOutput } = configuration.content;
8
6
  if (dictionaryOutput.includes("i18next")) {
9
- await buildI18nDictionary(dictionaries);
7
+ await buildI18nDictionary(dictionaries, configuration);
10
8
  }
11
9
  if (dictionaryOutput.includes("intlayer")) {
12
- return await buildIntlayerDictionary(dictionaries);
10
+ return await buildIntlayerDictionary(dictionaries, configuration);
13
11
  }
14
12
  return [];
15
13
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/declaration_file_to_dictionary/index.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { buildI18nDictionary } from './i18next_dictionary/index';\nimport { buildIntlayerDictionary } from './intlayer_dictionary/index';\n\nconst {\n content: { dictionaryOutput },\n} = getConfiguration();\n\nexport const buildDictionary = async (\n dictionaries: Dictionary[]\n): Promise<string[]> => {\n if (dictionaryOutput.includes('i18next')) {\n await buildI18nDictionary(dictionaries);\n }\n\n if (dictionaryOutput.includes('intlayer')) {\n return await buildIntlayerDictionary(dictionaries);\n }\n\n return [];\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AAEjC,SAAS,2BAA2B;AACpC,SAAS,+BAA+B;AAExC,MAAM;AAAA,EACJ,SAAS,EAAE,iBAAiB;AAC9B,IAAI,iBAAiB;AAEd,MAAM,kBAAkB,OAC7B,iBACsB;AACtB,MAAI,iBAAiB,SAAS,SAAS,GAAG;AACxC,UAAM,oBAAoB,YAAY;AAAA,EACxC;AAEA,MAAI,iBAAiB,SAAS,UAAU,GAAG;AACzC,WAAO,MAAM,wBAAwB,YAAY;AAAA,EACnD;AAEA,SAAO,CAAC;AACV;","names":[]}
1
+ {"version":3,"sources":["../../../../src/transpiler/declaration_file_to_dictionary/index.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { buildI18nDictionary } from './i18next_dictionary/index';\nimport { buildIntlayerDictionary } from './intlayer_dictionary/index';\n\nexport const buildDictionary = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n): Promise<string[]> => {\n const { dictionaryOutput } = configuration.content;\n\n if (dictionaryOutput.includes('i18next')) {\n await buildI18nDictionary(dictionaries, configuration);\n }\n\n if (dictionaryOutput.includes('intlayer')) {\n return await buildIntlayerDictionary(dictionaries, configuration);\n }\n\n return [];\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AAEjC,SAAS,2BAA2B;AACpC,SAAS,+BAA+B;AAEjC,MAAM,kBAAkB,OAC7B,cACA,gBAAgB,iBAAiB,MACX;AACtB,QAAM,EAAE,iBAAiB,IAAI,cAAc;AAE3C,MAAI,iBAAiB,SAAS,SAAS,GAAG;AACxC,UAAM,oBAAoB,cAAc,aAAa;AAAA,EACvD;AAEA,MAAI,iBAAiB,SAAS,UAAU,GAAG;AACzC,WAAO,MAAM,wBAAwB,cAAc,aAAa;AAAA,EAClE;AAEA,SAAO,CAAC;AACV;","names":[]}
@@ -2,12 +2,12 @@ import { mkdir } from "fs/promises";
2
2
  import { resolve } from "path";
3
3
  import { getConfiguration } from "@intlayer/config";
4
4
  import { writeDictionary } from "./writeDictionary.mjs";
5
- const { content } = getConfiguration();
6
- const { dictionariesDir } = content;
7
- const buildIntlayerDictionary = async (contentDeclarations) => {
5
+ const buildIntlayerDictionary = async (contentDeclarations, configuration = getConfiguration()) => {
6
+ const { dictionariesDir } = configuration.content;
8
7
  await mkdir(resolve(dictionariesDir), { recursive: true });
9
8
  const dictionariesPaths = await writeDictionary(
10
- contentDeclarations
9
+ contentDeclarations,
10
+ configuration
11
11
  );
12
12
  return dictionariesPaths;
13
13
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts"],"sourcesContent":["import { mkdir } from 'fs/promises';\nimport { resolve } from 'path';\n// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { writeDictionary } from './writeDictionary';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir } = content;\n\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const buildIntlayerDictionary = async (\n contentDeclarations: (DictionaryAPI | Dictionary)[]\n) => {\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n const dictionariesPaths: string[] = await writeDictionary(\n contentDeclarations as Dictionary[]\n );\n\n return dictionariesPaths;\n};\n"],"mappings":"AAAA,SAAS,aAAa;AACtB,SAAS,eAAe;AAGxB,SAAS,wBAAwB;AAEjC,SAAS,uBAAuB;AAEhC,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,gBAAgB,IAAI;AAKrB,MAAM,0BAA0B,OACrC,wBACG;AAEH,QAAM,MAAM,QAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,QAAM,oBAA8B,MAAM;AAAA,IACxC;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts"],"sourcesContent":["import { mkdir } from 'fs/promises';\nimport { resolve } from 'path';\n// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { writeDictionary } from './writeDictionary';\n\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const buildIntlayerDictionary = async (\n contentDeclarations: (DictionaryAPI | Dictionary)[],\n configuration = getConfiguration()\n) => {\n const { dictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n const dictionariesPaths: string[] = await writeDictionary(\n contentDeclarations as Dictionary[],\n configuration\n );\n\n return dictionariesPaths;\n};\n"],"mappings":"AAAA,SAAS,aAAa;AACtB,SAAS,eAAe;AAGxB,SAAS,wBAAwB;AAEjC,SAAS,uBAAuB;AAKzB,MAAM,0BAA0B,OACrC,qBACA,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,EAAE,gBAAgB,IAAI,cAAc;AAG1C,QAAM,MAAM,QAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,QAAM,oBAA8B,MAAM;AAAA,IACxC;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,12 +1,12 @@
1
1
  import { writeFile } from "fs/promises";
2
2
  import { resolve } from "path";
3
3
  import { getConfiguration } from "@intlayer/config";
4
- const { dictionariesDir } = getConfiguration().content;
5
- const writeDictionary = async (dictionaries) => {
4
+ const writeDictionary = async (dictionaries, configuration = getConfiguration()) => {
5
+ const { dictionariesDir } = configuration.content;
6
6
  const resultDictionariesPaths = [];
7
7
  for await (const dictionaryContent of dictionaries) {
8
- const isDevelopement = process.env.NODE_ENV === "development";
9
- const contentString = isDevelopement ? JSON.stringify(dictionaryContent, null, 2) : JSON.stringify(dictionaryContent);
8
+ const isDevelopment = process.env.NODE_ENV === "development";
9
+ const contentString = isDevelopment ? JSON.stringify(dictionaryContent, null, 2) : JSON.stringify(dictionaryContent);
10
10
  const key = dictionaryContent.key;
11
11
  const outputFileName = `${key}.json`;
12
12
  const resultFilePath = resolve(dictionariesDir, outputFileName);
@@ -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\nconst { dictionariesDir } = getConfiguration().content;\n\nexport const writeDictionary = async (dictionaries: Dictionary[]) => {\n const resultDictionariesPaths: string[] = [];\n\n for await (const dictionaryContent of dictionaries) {\n const isDevelopement = process.env.NODE_ENV === 'development';\n const contentString = isDevelopement\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,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,SAAS,wBAAwB;AAGjC,MAAM,EAAE,gBAAgB,IAAI,iBAAiB,EAAE;AAExC,MAAM,kBAAkB,OAAO,iBAA+B;AACnE,QAAM,0BAAoC,CAAC;AAE3C,mBAAiB,qBAAqB,cAAc;AAClD,UAAM,iBAAiB,QAAQ,IAAI,aAAa;AAChD,UAAM,gBAAgB,iBAClB,KAAK,UAAU,mBAAmB,MAAM,CAAC,IACzC,KAAK,UAAU,iBAAiB;AAEpC,UAAM,MAAM,kBAAkB;AAC9B,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,iBAAiB,QAAQ,iBAAiB,cAAc;AAG9D,UAAM,UAAU,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 { 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,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,SAAS,wBAAwB;AAG1B,MAAM,kBAAkB,OAC7B,cACA,gBAAgB,iBAAiB,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,iBAAiB,QAAQ,iBAAiB,cAAc;AAG9D,UAAM,UAAU,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":[]}
@@ -3,10 +3,9 @@ import { basename, extname, relative, resolve } from "path";
3
3
  import { getConfiguration } from "@intlayer/config";
4
4
  import { getBuiltDictionariesPath } from "../../getBuiltDictionariesPath.mjs";
5
5
  import { getFileHash } from "../../utils.mjs";
6
- const { content } = getConfiguration();
7
- const { mainDir } = content;
8
- const generateDictionaryListContent = (dictionaries, format = "esm") => {
9
- let content2 = "";
6
+ const generateDictionaryListContent = (dictionaries, format = "esm", configuration = getConfiguration()) => {
7
+ const { mainDir } = configuration.content;
8
+ let content = "";
10
9
  const dictionariesRef = dictionaries.map((dictionaryPath) => ({
11
10
  relativePath: relative(mainDir, dictionaryPath),
12
11
  id: basename(dictionaryPath, extname(dictionaryPath)),
@@ -16,34 +15,43 @@ const generateDictionaryListContent = (dictionaries, format = "esm") => {
16
15
  }));
17
16
  dictionariesRef.forEach((dictionary) => {
18
17
  if (format === "esm")
19
- content2 += `import ${dictionary.hash} from '${dictionary.relativePath}';
18
+ content += `import ${dictionary.hash} from '${dictionary.relativePath}';
20
19
  `;
21
20
  if (format === "cjs")
22
- content2 += `const ${dictionary.hash} = require('${dictionary.relativePath}');
21
+ content += `const ${dictionary.hash} = require('${dictionary.relativePath}');
23
22
  `;
24
23
  });
25
- content2 += "\n";
24
+ content += "\n";
26
25
  const formattedDictionaryMap = dictionariesRef.map((dictionary) => ` "${dictionary.id}": ${dictionary.hash}`).join(",\n");
27
26
  if (format === "esm")
28
- content2 += `export default {
27
+ content += `export default {
29
28
  ${formattedDictionaryMap}
30
29
  };
31
30
  `;
32
31
  if (format === "cjs")
33
- content2 += `module.exports = {
32
+ content += `module.exports = {
34
33
  ${formattedDictionaryMap}
35
34
  };
36
35
  `;
37
- return content2;
36
+ return content;
38
37
  };
39
- const createDictionaryEntryPoint = () => {
38
+ const createDictionaryEntryPoint = (configuration = getConfiguration()) => {
39
+ const { mainDir } = configuration.content;
40
40
  if (!existsSync(mainDir)) {
41
41
  mkdirSync(mainDir, { recursive: true });
42
42
  }
43
- const dictionariesPath = getBuiltDictionariesPath();
44
- const cjsContent = generateDictionaryListContent(dictionariesPath, "cjs");
43
+ const dictionariesPath = getBuiltDictionariesPath(configuration);
44
+ const cjsContent = generateDictionaryListContent(
45
+ dictionariesPath,
46
+ "cjs",
47
+ configuration
48
+ );
45
49
  writeFileSync(resolve(mainDir, "dictionaries.cjs"), cjsContent);
46
- const esmContent = generateDictionaryListContent(dictionariesPath, "esm");
50
+ const esmContent = generateDictionaryListContent(
51
+ dictionariesPath,
52
+ "esm",
53
+ configuration
54
+ );
47
55
  writeFileSync(resolve(mainDir, "dictionaries.mjs"), esmContent);
48
56
  };
49
57
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, relative, resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport { getBuiltDictionariesPath } from '../../getBuiltDictionariesPath';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { mainDir } = content;\n\n/**\n * This function generates the content of the dictionary list file\n */\nconst generateDictionaryListContent = (\n dictionaries: string[],\n format: 'cjs' | 'esm' = 'esm'\n): string => {\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: relative(mainDir, dictionaryPath),\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash}`)\n .join(',\\n');\n\n if (format === 'esm')\n content += `export default {\\n${formattedDictionaryMap}\\n};\\n`;\n if (format === 'cjs')\n content += `module.exports = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n return content;\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryEntryPoint = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = getBuiltDictionariesPath();\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionariesPath, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionariesPath, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,SAAS,UAAU,eAAe;AACrD,SAAS,wBAAwB;AACjC,SAAS,gCAAgC;AACzC,SAAS,mBAAmB;AAE5B,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,QAAQ,IAAI;AAKpB,MAAM,gCAAgC,CACpC,cACA,SAAwB,UACb;AACX,MAAIA,WAAU;AAEd,QAAM,kBAAkB,aAAa,IAAI,CAAC,oBAAoB;AAAA,IAC5D,cAAc,SAAS,SAAS,cAAc;AAAA,IAC9C,IAAI,SAAS,gBAAgB,QAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,IAAI,YAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,QAAI,WAAW;AACb,MAAAA,YAAW,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AACvE,QAAI,WAAW;AACb,MAAAA,YAAW,SAAS,WAAW,IAAI,eAAe,WAAW,YAAY;AAAA;AAAA,EAC7E,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,MAAM,WAAW,EAAE,MAAM,WAAW,IAAI,EAAE,EAC9D,KAAK,KAAK;AAEb,MAAI,WAAW;AACb,IAAAA,YAAW;AAAA,EAAqB,sBAAsB;AAAA;AAAA;AACxD,MAAI,WAAW;AACb,IAAAA,YAAW;AAAA,EAAuB,sBAAsB;AAAA;AAAA;AAE1D,SAAOA;AACT;AAKO,MAAM,6BAA6B,MAAM;AAE9C,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,yBAAyB;AAG5D,QAAM,aAAa,8BAA8B,kBAAkB,KAAK;AACxE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa,8BAA8B,kBAAkB,KAAK;AACxE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, relative, resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport { getBuiltDictionariesPath } from '../../getBuiltDictionariesPath';\nimport { getFileHash } from '../../utils';\n\n/**\n * This function generates the content of the dictionary list file\n */\nconst generateDictionaryListContent = (\n dictionaries: string[],\n format: 'cjs' | 'esm' = 'esm',\n configuration = getConfiguration()\n): string => {\n const { mainDir } = configuration.content;\n\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: relative(mainDir, dictionaryPath),\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash}`)\n .join(',\\n');\n\n if (format === 'esm')\n content += `export default {\\n${formattedDictionaryMap}\\n};\\n`;\n if (format === 'cjs')\n content += `module.exports = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n return content;\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryEntryPoint = (\n configuration = getConfiguration()\n) => {\n const { mainDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = getBuiltDictionariesPath(configuration);\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(\n dictionariesPath,\n 'cjs',\n configuration\n );\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(\n dictionariesPath,\n 'esm',\n configuration\n );\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,SAAS,UAAU,eAAe;AACrD,SAAS,wBAAwB;AACjC,SAAS,gCAAgC;AACzC,SAAS,mBAAmB;AAK5B,MAAM,gCAAgC,CACpC,cACA,SAAwB,OACxB,gBAAgB,iBAAiB,MACtB;AACX,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,MAAI,UAAU;AAEd,QAAM,kBAAkB,aAAa,IAAI,CAAC,oBAAoB;AAAA,IAC5D,cAAc,SAAS,SAAS,cAAc;AAAA,IAC9C,IAAI,SAAS,gBAAgB,QAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,IAAI,YAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,QAAI,WAAW;AACb,iBAAW,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AACvE,QAAI,WAAW;AACb,iBAAW,SAAS,WAAW,IAAI,eAAe,WAAW,YAAY;AAAA;AAAA,EAC7E,CAAC;AAED,aAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,MAAM,WAAW,EAAE,MAAM,WAAW,IAAI,EAAE,EAC9D,KAAK,KAAK;AAEb,MAAI,WAAW;AACb,eAAW;AAAA,EAAqB,sBAAsB;AAAA;AAAA;AACxD,MAAI,WAAW;AACb,eAAW;AAAA,EAAuB,sBAAsB;AAAA;AAAA;AAE1D,SAAO;AACT;AAKO,MAAM,6BAA6B,CACxC,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,EAAE,QAAQ,IAAI,cAAc;AAGlC,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,yBAAyB,aAAa;AAGzE,QAAM,aAAa;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":[]}
@@ -3,19 +3,19 @@ import { basename, extname, join, relative } from "path";
3
3
  import { Locales, getConfiguration } from "@intlayer/config";
4
4
  import fg from "fast-glob";
5
5
  import { getFileHash, kebabCaseToCamelCase } from "../../utils.mjs";
6
- const { content, internationalization } = getConfiguration();
7
- const { moduleAugmentationDir, typesDir } = content;
8
- const { locales, requiredLocales, strictMode } = internationalization;
9
6
  const getTypeName = (key) => `${kebabCaseToCamelCase(key)}Content`;
10
- const formatLocales = (locales2) => locales2.map((locale) => {
7
+ const formatLocales = (locales) => locales.map((locale) => {
11
8
  for (const key in Locales) {
12
9
  if (Locales[key] === locale) {
13
10
  return `Locales.${key}`;
14
11
  }
15
12
  }
16
13
  }).join(" | ");
17
- const generateTypeIndexContent = (typeFiles) => {
18
- let content2 = "/* eslint-disable */\nimport { Locales } from 'intlayer';\n";
14
+ const generateTypeIndexContent = (typeFiles, configuration = getConfiguration()) => {
15
+ const { content, internationalization } = configuration;
16
+ const { moduleAugmentationDir } = content;
17
+ const { locales, requiredLocales, strictMode } = internationalization;
18
+ let fileContent = "/* eslint-disable */\nimport { Locales } from 'intlayer';\n";
19
19
  const dictionariesRef = typeFiles.map((dictionaryPath) => ({
20
20
  relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,
21
21
  id: basename(dictionaryPath, extname(dictionaryPath)),
@@ -24,10 +24,10 @@ const generateTypeIndexContent = (typeFiles) => {
24
24
  // Get the hash of the dictionary to avoid conflicts
25
25
  }));
26
26
  dictionariesRef.forEach((dictionary) => {
27
- content2 += `import ${dictionary.hash} from '${dictionary.relativePath}';
27
+ fileContent += `import ${dictionary.hash} from '${dictionary.relativePath}';
28
28
  `;
29
29
  });
30
- content2 += "\n";
30
+ fileContent += "\n";
31
31
  const formattedDictionaryMap = dictionariesRef.map((dictionary) => ` "${dictionary.id}": typeof ${dictionary.hash};`).join("\n");
32
32
  const requiredLocalesValues = requiredLocales.length > 0 ? requiredLocales.filter(
33
33
  (locale) => locales.map((locale2) => String(locale2)).includes(String(locale))
@@ -35,27 +35,28 @@ const generateTypeIndexContent = (typeFiles) => {
35
35
  const formattedLocales = formatLocales(locales);
36
36
  const formattedRequiredLocales = formatLocales(requiredLocalesValues);
37
37
  const strictModeRecord = strictMode === "strict" ? `interface IConfigLocales<Content> extends Record<DeclaredLocales, Content> {}` : strictMode === "inclusive" ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}` : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;
38
- content2 += `declare module 'intlayer' {
38
+ fileContent += `declare module 'intlayer' {
39
39
  `;
40
- content2 += ` interface IntlayerDictionaryTypesConnector {
40
+ fileContent += ` interface IntlayerDictionaryTypesConnector {
41
41
  ${formattedDictionaryMap}
42
42
  }
43
43
 
44
44
  `;
45
- content2 += ` type DeclaredLocales = ${formattedLocales};
45
+ fileContent += ` type DeclaredLocales = ${formattedLocales};
46
46
  `;
47
- content2 += ` type RequiredLocales = ${formattedRequiredLocales};
47
+ fileContent += ` type RequiredLocales = ${formattedRequiredLocales};
48
48
  `;
49
- content2 += ` type ExtractedLocales = Extract<Locales, RequiredLocales>;
49
+ fileContent += ` type ExtractedLocales = Extract<Locales, RequiredLocales>;
50
50
  `;
51
- content2 += ` type ExcludedLocales = Exclude<Locales, RequiredLocales>;
51
+ fileContent += ` type ExcludedLocales = Exclude<Locales, RequiredLocales>;
52
52
  `;
53
- content2 += ` ${strictModeRecord}
53
+ fileContent += ` ${strictModeRecord}
54
54
  `;
55
- content2 += `}`;
56
- return content2;
55
+ fileContent += `}`;
56
+ return fileContent;
57
57
  };
58
- const createModuleAugmentation = () => {
58
+ const createModuleAugmentation = (configuration = getConfiguration()) => {
59
+ const { moduleAugmentationDir, typesDir } = configuration.content;
59
60
  if (!existsSync(moduleAugmentationDir)) {
60
61
  mkdirSync(moduleAugmentationDir, { recursive: true });
61
62
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash, kebabCaseToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { moduleAugmentationDir, typesDir } = content;\nconst { locales, requiredLocales, strictMode } = internationalization;\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\nconst formatLocales = (locales: Locales[]): string =>\n locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id (without the extension)\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": typeof ${dictionary.hash};`)\n .join('\\n');\n\n const requiredLocalesValues =\n requiredLocales.length > 0\n ? requiredLocales.filter((locale) =>\n locales.map((locale) => String(locale)).includes(String(locale))\n )\n : locales;\n\n const formattedLocales = formatLocales(locales);\n const formattedRequiredLocales = formatLocales(requiredLocalesValues);\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<DeclaredLocales, Content> {}`\n : strictMode === 'inclusive'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type DeclaredLocales = ${formattedLocales};\\n`;\n content += ` type RequiredLocales = ${formattedRequiredLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, RequiredLocales>;\\n`;\n content += ` type ExcludedLocales = Exclude<Locales, RequiredLocales>;\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionariesTypesDefinitions: string[] = fg.sync(`${typesDir}/*.ts`, {\n ignore: ['**/*.d.ts'],\n });\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,SAAS,MAAM,gBAAgB;AAClD,SAAS,SAAS,wBAAwB;AAC1C,OAAO,QAAQ;AACf,SAAS,aAAa,4BAA4B;AAElD,MAAM,EAAE,SAAS,qBAAqB,IAAI,iBAAiB;AAC3D,MAAM,EAAE,uBAAuB,SAAS,IAAI;AAC5C,MAAM,EAA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A4B,wBAAwB;AAAA;AAC/D,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW,KAAK,gBAAgB;AAAA;AAChC,EAAAA,YAAW;AAEX,SAAOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,CAAC,WAAW,qBAAqB,GAAG;AACtC,cAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,+BAAyC,GAAG,KAAK,GAAG,QAAQ,SAAS;AAAA,IACzE,QAAQ,CAAC,WAAW;AAAA,EACtB,CAAC;AAGD,QAAM,YAAY,yBAAyB,4BAA4B;AACvE,gBAAc,KAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["locales","content","locale"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash, kebabCaseToCamelCase } from '../../utils';\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\nconst formatLocales = (locales: Locales[]): string =>\n locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (\n typeFiles: string[],\n configuration = getConfiguration()\n): string => {\n const { content, internationalization } = configuration;\n const { moduleAugmentationDir } = content;\n const { locales, requiredLocales, strictMode } = internationalization;\n\n let fileContent =\n \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id (without the extension)\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n fileContent += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n });\n\n fileContent += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": typeof ${dictionary.hash};`)\n .join('\\n');\n\n const requiredLocalesValues =\n requiredLocales.length > 0\n ? requiredLocales.filter((locale) =>\n locales.map((locale) => String(locale)).includes(String(locale))\n )\n : locales;\n\n const formattedLocales = formatLocales(locales);\n const formattedRequiredLocales = formatLocales(requiredLocalesValues);\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<DeclaredLocales, Content> {}`\n : strictMode === 'inclusive'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n fileContent += `declare module 'intlayer' {\\n`;\n fileContent += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n fileContent += ` type DeclaredLocales = ${formattedLocales};\\n`;\n fileContent += ` type RequiredLocales = ${formattedRequiredLocales};\\n`;\n fileContent += ` type ExtractedLocales = Extract<Locales, RequiredLocales>;\\n`;\n fileContent += ` type ExcludedLocales = Exclude<Locales, RequiredLocales>;\\n`;\n fileContent += ` ${strictModeRecord}\\n`;\n fileContent += `}`;\n\n return fileContent;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = (\n configuration = getConfiguration()\n) => {\n const { moduleAugmentationDir, typesDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionariesTypesDefinitions: string[] = fg.sync(`${typesDir}/*.ts`, {\n ignore: ['**/*.d.ts'],\n });\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,SAAS,MAAM,gBAAgB;AAClD,SAAS,SAAS,wBAAwB;AAC1C,OAAO,QAAQ;AACf,SAAS,aAAa,4BAA4B;AAE3C,MAAM,cAAc,CAAC,QAC1B,GAAG,qBAAqB,GAAG,CAAC;AAE9B,MAAM,gBAAgB,CAAC,YACrB,QACG,IAAI,CAAC,WAAW;AACf,aAAW,OAAO,SAAS;AACzB,QAAI,QAAQ,GAA2B,MAAM,QAAQ;AACnD,aAAO,WAAW,GAAG;AAAA,IACvB;AAAA,EACF;AACF,CAAC,EACA,KAAK,KAAK;AAKf,MAAM,2BAA2B,CAC/B,WACA,gBAAgB,iBAAiB,MACtB;AACX,QAAM,EAAE,SAAS,qBAAqB,IAAI;AAC1C,QAAM,EAAE,sBAAsB,IAAI;AAClC,QAAM,EAAE,SAAS,iBAAiB,WAAW,IAAI;AAEjD,MAAI,cACF;AAEF,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,KAAK,SAAS,uBAAuB,cAAc,CAAC;AAAA,IAClE,IAAI,SAAS,gBAAgB,QAAQ,cAAc,CAAC;AAAA;A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@
1
1
  import { existsSync, mkdirSync, writeFileSync } from "fs";
2
2
  import { resolve } from "path";
3
- import { getConfiguration, ESMxCJSRequire } from "@intlayer/config";
4
- const { content } = getConfiguration();
5
- const { typesDir } = content;
3
+ import {
4
+ getConfiguration,
5
+ ESMxCJSRequire
6
+ } from "@intlayer/config";
6
7
  const requireUncached = (module) => {
7
8
  delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];
8
9
  return ESMxCJSRequire(module);
@@ -18,7 +19,8 @@ const generateTypeScriptType = (dictionary) => {
18
19
  export default ${jsonString} as const;
19
20
  `;
20
21
  };
21
- const createTypes = (dictionariesPaths) => {
22
+ const createTypes = (dictionariesPaths, configuration = getConfiguration()) => {
23
+ const { typesDir } = configuration.content;
22
24
  const resultTypesPaths = [];
23
25
  if (!existsSync(typesDir)) {
24
26
  mkdirSync(typesDir, { recursive: true });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { getConfiguration, ESMxCJSRequire } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n\nconst { content } = getConfiguration();\nconst { typesDir } = content;\n\nconst requireUncached = (module: string) => {\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];\n return ESMxCJSRequire(module);\n};\n\nexport const generateTypeScriptType = (dictionary: Dictionary) => {\n const jsonString = JSON.stringify(dictionary, null, 2)\n // Remove quotes from keys only if they are valid identifiers.\n .replace(/\"([^\"]+)\":/g, (_, key) => {\n // Valid identifier: must start with a letter, underscore, or dollar sign,\n // followed by letters, digits, underscores, or dollar signs.\n if (/^[$A-Za-z_][0-9A-Za-z_$]*$/.test(key)) {\n return `${key}:`;\n }\n // Otherwise, keep the quotes\n return `\"${key}\":`;\n });\n\n return `/* eslint-disable */\\nexport default ${jsonString} as const;\\n`;\n};\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = (dictionariesPaths: string[]): string[] => {\n const resultTypesPaths: string[] = [];\n\n // Create type folders if they don't exist\n if (!existsSync(typesDir)) {\n mkdirSync(typesDir, { recursive: true });\n }\n\n for (const dictionaryPath of dictionariesPaths) {\n const dictionary: Dictionary = requireUncached(dictionaryPath);\n\n if (!dictionary.key) {\n // Skip dictionary if it doesn't have a key, if not exported as default etc\n continue;\n }\n\n const typeDefinition: string = generateTypeScriptType(dictionary);\n\n const outputPath: string = resolve(typesDir, `${dictionary.key}.ts`);\n\n writeFileSync(outputPath, typeDefinition);\n\n resultTypesPaths.push(outputPath);\n }\n\n return resultTypesPaths;\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,eAAe;AACxB,SAAS,kBAAkB,sBAAsB;AAGjD,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,SAAS,IAAI;AAErB,MAAM,kBAAkB,CAAC,WAAmB;AAC1C,SAAO,eAAe,MAAM,eAAe,QAAQ,MAAM,CAAC;AAC1D,SAAO,eAAe,MAAM;AAC9B;AAEO,MAAM,yBAAyB,CAAC,eAA2B;AAChE,QAAM,aAAa,KAAK,UAAU,YAAY,MAAM,CAAC,EAElD,QAAQ,eAAe,CAAC,GAAG,QAAQ;AAGlC,QAAI,6BAA6B,KAAK,GAAG,GAAG;AAC1C,aAAO,GAAG,GAAG;AAAA,IACf;AAEA,WAAO,IAAI,GAAG;AAAA,EAChB,CAAC;AAEH,SAAO;AAAA,iBAAwC,UAAU;AAAA;AAC3D;AAIO,MAAM,cAAc,CAAC,sBAA0C;AACpE,QAAM,mBAA6B,CAAC;AAGpC,MAAI,CAAC,WAAW,QAAQ,GAAG;AACzB,cAAU,UAAU,EAAE,WAAW,KAAK,CAAC;AAAA,EACzC;AAEA,aAAW,kBAAkB,mBAAmB;AAC9C,UAAM,aAAyB,gBAAgB,cAAc;AAE7D,QAAI,CAAC,WAAW,KAAK;AAEnB;AAAA,IACF;AAEA,UAAM,iBAAyB,uBAAuB,UAAU;AAEhE,UAAM,aAAqB,QAAQ,UAAU,GAAG,WAAW,GAAG,KAAK;AAEnE,kBAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport {\n getConfiguration,\n ESMxCJSRequire,\n IntlayerConfig,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n\nconst requireUncached = (module: string) => {\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];\n return ESMxCJSRequire(module);\n};\n\nexport const generateTypeScriptType = (dictionary: Dictionary) => {\n const jsonString = JSON.stringify(dictionary, null, 2)\n // Remove quotes from keys only if they are valid identifiers.\n .replace(/\"([^\"]+)\":/g, (_, key) => {\n // Valid identifier: must start with a letter, underscore, or dollar sign,\n // followed by letters, digits, underscores, or dollar signs.\n if (/^[$A-Za-z_][0-9A-Za-z_$]*$/.test(key)) {\n return `${key}:`;\n }\n // Otherwise, keep the quotes\n return `\"${key}\":`;\n });\n\n return `/* eslint-disable */\\nexport default ${jsonString} as const;\\n`;\n};\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = (\n dictionariesPaths: string[],\n configuration: IntlayerConfig = getConfiguration()\n): string[] => {\n const { typesDir } = configuration.content;\n const resultTypesPaths: string[] = [];\n\n // Create type folders if they don't exist\n if (!existsSync(typesDir)) {\n mkdirSync(typesDir, { recursive: true });\n }\n\n for (const dictionaryPath of dictionariesPaths) {\n const dictionary: Dictionary = requireUncached(dictionaryPath);\n\n if (!dictionary.key) {\n // Skip dictionary if it doesn't have a key, if not exported as default etc\n continue;\n }\n\n const typeDefinition: string = generateTypeScriptType(dictionary);\n\n const outputPath: string = resolve(typesDir, `${dictionary.key}.ts`);\n\n writeFileSync(outputPath, typeDefinition);\n\n resultTypesPaths.push(outputPath);\n }\n\n return resultTypesPaths;\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAGP,MAAM,kBAAkB,CAAC,WAAmB;AAC1C,SAAO,eAAe,MAAM,eAAe,QAAQ,MAAM,CAAC;AAC1D,SAAO,eAAe,MAAM;AAC9B;AAEO,MAAM,yBAAyB,CAAC,eAA2B;AAChE,QAAM,aAAa,KAAK,UAAU,YAAY,MAAM,CAAC,EAElD,QAAQ,eAAe,CAAC,GAAG,QAAQ;AAGlC,QAAI,6BAA6B,KAAK,GAAG,GAAG;AAC1C,aAAO,GAAG,GAAG;AAAA,IACf;AAEA,WAAO,IAAI,GAAG;AAAA,EAChB,CAAC;AAEH,SAAO;AAAA,iBAAwC,UAAU;AAAA;AAC3D;AAIO,MAAM,cAAc,CACzB,mBACA,gBAAgC,iBAAiB,MACpC;AACb,QAAM,EAAE,SAAS,IAAI,cAAc;AACnC,QAAM,mBAA6B,CAAC;AAGpC,MAAI,CAAC,WAAW,QAAQ,GAAG;AACzB,cAAU,UAAU,EAAE,WAAW,KAAK,CAAC;AAAA,EACzC;AAEA,aAAW,kBAAkB,mBAAmB;AAC9C,UAAM,aAAyB,gBAAgB,cAAc;AAE7D,QAAI,CAAC,WAAW,KAAK;AAEnB;AAAA,IACF;AAEA,UAAM,iBAAyB,uBAAuB,UAAU;AAEhE,UAAM,aAAqB,QAAQ,UAAU,GAAG,WAAW,GAAG,KAAK;AAEnE,kBAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
@@ -1,2 +1,2 @@
1
- export declare const cleanOutputDir: () => void;
1
+ export declare const cleanOutputDir: (configuration?: import("@intlayer/config").IntlayerConfig) => void;
2
2
  //# sourceMappingURL=cleanOutputDir.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cleanOutputDir.d.ts","sourceRoot":"","sources":["../../src/cleanOutputDir.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,YAkB1B,CAAC"}
1
+ {"version":3,"file":"cleanOutputDir.d.ts","sourceRoot":"","sources":["../../src/cleanOutputDir.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,GAAI,yDAAkC,SAgBhE,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * This function generates a list of dictionaries in the main directory
3
3
  */
4
- export declare const getBuiltDictionariesPath: () => string[];
4
+ export declare const getBuiltDictionariesPath: (configuration?: import("@intlayer/config").IntlayerConfig) => string[];
5
5
  //# sourceMappingURL=getBuiltDictionariesPath.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getBuiltDictionariesPath.d.ts","sourceRoot":"","sources":["../../src/getBuiltDictionariesPath.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,eAAO,MAAM,wBAAwB,gBASpC,CAAC"}
1
+ {"version":3,"file":"getBuiltDictionariesPath.d.ts","sourceRoot":"","sources":["../../src/getBuiltDictionariesPath.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,eAAO,MAAM,wBAAwB,GACnC,yDAAkC,aAYnC,CAAC"}
@@ -4,6 +4,7 @@ export { buildDictionary } from './transpiler/declaration_file_to_dictionary/ind
4
4
  export { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';
5
5
  export { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';
6
6
  export { fetchDistantDictionaries } from './fetchDistantDictionaries';
7
+ export { fetchDistantDictionaryKeys } from './fetchDistantDictionaryKeys';
7
8
  export { loadDistantDictionaries, loadDictionaries, loadLocalDictionaries, } from './loadDictionaries/index';
8
9
  export { checkDictionaryChanges } from './checkDictionaryChanges';
9
10
  export { listDictionaries } from './listDictionariesPath';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[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ClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EACL,uBAAuB,EACvB,KAAK,gBAAgB,GACtB,MAAM,2BAA2B,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import type { Dictionary } from '@intlayer/core';
2
- export declare const loadContentDeclarations: (contentDeclarationFilePath: string[]) => Promise<Dictionary[]>;
2
+ export declare const loadContentDeclarations: (contentDeclarationFilePath: string[], projectRequire?: NodeJS.Require) => Promise<Dictionary[]>;
3
3
  //# sourceMappingURL=loadContentDeclaration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loadContentDeclaration.d.ts","sourceRoot":"","sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,eAAO,MAAM,uBAAuB,GAClC,4BAA4B,MAAM,EAAE,KACnC,OAAO,CAAC,UAAU,EAAE,CAwBtB,CAAC"}
1
+ {"version":3,"file":"loadContentDeclaration.d.ts","sourceRoot":"","sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,eAAO,MAAM,uBAAuB,GAClC,4BAA4B,MAAM,EAAE,EACpC,+BAA+B,KAC9B,OAAO,CAAC,UAAU,EAAE,CAwBtB,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import type { Dictionary } from '@intlayer/core';
2
- export declare const loadDictionaries: (contentDeclarationsPaths: string[] | string) => Promise<Dictionary[]>;
2
+ export declare const loadDictionaries: (contentDeclarationsPaths: string[] | string, configuration?: import("@intlayer/config").IntlayerConfig, projectRequire?: NodeJS.Require) => Promise<Dictionary[]>;
3
3
  //# sourceMappingURL=loadDictionaries.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loadDictionaries.d.ts","sourceRoot":"","sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AASjD,eAAO,MAAM,gBAAgB,GAC3B,0BAA0B,MAAM,EAAE,GAAG,MAAM,KAC1C,OAAO,CAAC,UAAU,EAAE,CAwEtB,CAAC"}
1
+ {"version":3,"file":"loadDictionaries.d.ts","sourceRoot":"","sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AASjD,eAAO,MAAM,gBAAgB,GAC3B,0BAA0B,MAAM,EAAE,GAAG,MAAM,EAC3C,yDAAkC,EAClC,+BAA+B,KAC9B,OAAO,CAAC,UAAU,EAAE,CA6EtB,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { type IntlayerConfig } from '@intlayer/config';
1
2
  export type State = {
2
3
  type: 'local' | 'distant';
3
4
  status: 'pending' | 'fetching' | 'fetched' | 'error' | 'imported' | 'built';
@@ -19,11 +20,11 @@ declare class Logger {
19
20
  private originalStdoutWrite;
20
21
  private extraLines;
21
22
  private isUpdating;
22
- private config;
23
+ private config?;
23
24
  private static instance;
24
25
  private constructor();
25
26
  static getInstance(): Logger;
26
- init(localDictionariesKeys: string[], distantDictionariesKeys: string[]): void;
27
+ init(localDictionariesKeys: string[], distantDictionariesKeys: string[], configuration?: IntlayerConfig): void;
27
28
  addDictionaryKeys(type: 'local' | 'distant', dictionaryKeys: string[]): void;
28
29
  private startSpinner;
29
30
  private stopSpinner;
@@ -1 +1 @@
1
- {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,MAAM,EAAE,SAAS,G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W;IAQnB,OAAO,CAAC,YAAY;IAgEb,IAAI;IAIJ,YAAY,CACjB,YAAY,EAAE;QACZ,aAAa,EAAE,MAAM,CAAC;QACtB,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;QAC1B,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;KACxB,EAAE;IA+CL,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,aAAa;IAmCrB,OAAO,CAAC,oBAAoB;IA4BrB,WAAW;CAGnB;AAED,eAAO,MAAM,MAAM,QAAuB,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import { type IntlayerConfig } from '@intlayer/config';
2
- export declare const prepareIntlayer: (configuration?: IntlayerConfig) => Promise<void>;
2
+ export declare const prepareIntlayer: (configuration?: IntlayerConfig, projectRequire?: NodeJS.Require) => Promise<void>;
3
3
  //# sourceMappingURL=prepareIntlayer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prepareIntlayer.d.ts","sourceRoot":"","sources":["../../src/prepareIntlayer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAGpB,MAAM,kBAAkB,CAAC;AAY1B,eAAO,MAAM,eAAe,GAC1B,gBAAe,cAAmC,kBAgCnD,CAAC"}
1
+ {"version":3,"file":"prepareIntlayer.d.ts","sourceRoot":"","sources":["../../src/prepareIntlayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,kBAAkB,CAAC;AAY1B,eAAO,MAAM,eAAe,GAC1B,gBAAe,cAAmC,EAClD,+BAA+B,kBAoChC,CAAC"}
@@ -2,5 +2,5 @@ import type { Dictionary } from '@intlayer/core';
2
2
  /**
3
3
  * This function transpile content declaration to i18n dictionaries
4
4
  */
5
- export declare const buildI18nDictionary: (contentDeclarations: Dictionary[]) => Promise<string[]>;
5
+ export declare const buildI18nDictionary: (contentDeclarations: Dictionary[], configuration?: import("@intlayer/config").IntlayerConfig) => Promise<string[]>;
6
6
  //# sourceMappingURL=buildI18nextDictionary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildI18nextDictionary.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAOjD;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC9B,qBAAqB,UAAU,EAAE,sBAoBlC,CAAC"}
1
+ {"version":3,"file":"buildI18nextDictionary.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAQjD;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC9B,qBAAqB,UAAU,EAAE,EACjC,yDAAkC,sBAqBnC,CAAC"}