@intlayer/webpack 1.0.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dist/cjs/{scripts/startServer.cjs → getEntries.cjs} +19 -14
  2. package/dist/cjs/getEntries.cjs.map +1 -0
  3. package/dist/cjs/getEntries.d.ts +5 -0
  4. package/dist/cjs/index.cjs +0 -7
  5. package/dist/cjs/index.cjs.map +1 -1
  6. package/dist/cjs/index.d.ts +0 -2
  7. package/dist/cjs/utils.cjs +26 -17
  8. package/dist/cjs/utils.cjs.map +1 -1
  9. package/dist/cjs/utils.d.ts +5 -2
  10. package/dist/cjs/webpack-plugin.cjs +4 -134
  11. package/dist/cjs/webpack-plugin.cjs.map +1 -1
  12. package/dist/cjs/webpack-plugin.d.ts +1 -11
  13. package/dist/cjs/webpack.config.cjs +28 -25
  14. package/dist/cjs/webpack.config.cjs.map +1 -1
  15. package/dist/esm/getEntries.d.mts +5 -0
  16. package/dist/esm/getEntries.mjs +17 -0
  17. package/dist/esm/getEntries.mjs.map +1 -0
  18. package/dist/esm/index.d.mts +0 -2
  19. package/dist/esm/index.mjs +0 -4
  20. package/dist/esm/index.mjs.map +1 -1
  21. package/dist/esm/utils.d.mts +5 -2
  22. package/dist/esm/utils.mjs +13 -15
  23. package/dist/esm/utils.mjs.map +1 -1
  24. package/dist/esm/webpack-plugin.d.mts +1 -11
  25. package/dist/esm/webpack-plugin.mjs +4 -134
  26. package/dist/esm/webpack-plugin.mjs.map +1 -1
  27. package/dist/esm/webpack.config.mjs +29 -26
  28. package/dist/esm/webpack.config.mjs.map +1 -1
  29. package/package.json +11 -15
  30. package/src/getEntries.ts +19 -0
  31. package/src/index.ts +2 -12
  32. package/src/utils.ts +19 -19
  33. package/src/webpack-plugin.ts +5 -180
  34. package/src/webpack.config.ts +32 -28
  35. package/dist/cjs/scripts/bundle.cjs +0 -65
  36. package/dist/cjs/scripts/bundle.cjs.map +0 -1
  37. package/dist/cjs/scripts/bundle.d.ts +0 -7
  38. package/dist/cjs/scripts/index.cjs +0 -25
  39. package/dist/cjs/scripts/index.cjs.map +0 -1
  40. package/dist/cjs/scripts/index.d.ts +0 -3
  41. package/dist/cjs/scripts/startServer.cjs.map +0 -1
  42. package/dist/cjs/scripts/startServer.d.ts +0 -5
  43. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +0 -76
  44. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +0 -1
  45. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.d.ts +0 -6
  46. package/dist/cjs/transpiler/dictionary_to_main/index.cjs +0 -23
  47. package/dist/cjs/transpiler/dictionary_to_main/index.cjs.map +0 -1
  48. package/dist/cjs/transpiler/dictionary_to_main/index.d.ts +0 -1
  49. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +0 -87
  50. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +0 -1
  51. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +0 -7
  52. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +0 -110
  53. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +0 -1
  54. package/dist/cjs/transpiler/dictionary_to_type/createType.d.ts +0 -42
  55. package/dist/cjs/transpiler/dictionary_to_type/index.cjs +0 -25
  56. package/dist/cjs/transpiler/dictionary_to_type/index.cjs.map +0 -1
  57. package/dist/cjs/transpiler/dictionary_to_type/index.d.ts +0 -3
  58. package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs +0 -45
  59. package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs.map +0 -1
  60. package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.ts +0 -44
  61. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs +0 -27
  62. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs.map +0 -1
  63. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.d.ts +0 -4
  64. package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs +0 -67
  65. package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs.map +0 -1
  66. package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.d.ts +0 -8
  67. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs +0 -96
  68. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs.map +0 -1
  69. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.ts +0 -6
  70. package/dist/esm/scripts/bundle.d.mts +0 -7
  71. package/dist/esm/scripts/bundle.mjs +0 -40
  72. package/dist/esm/scripts/bundle.mjs.map +0 -1
  73. package/dist/esm/scripts/index.d.mts +0 -3
  74. package/dist/esm/scripts/index.mjs +0 -3
  75. package/dist/esm/scripts/index.mjs.map +0 -1
  76. package/dist/esm/scripts/startServer.d.mts +0 -5
  77. package/dist/esm/scripts/startServer.mjs +0 -12
  78. package/dist/esm/scripts/startServer.mjs.map +0 -1
  79. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.d.mts +0 -6
  80. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +0 -52
  81. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs.map +0 -1
  82. package/dist/esm/transpiler/dictionary_to_main/index.d.mts +0 -1
  83. package/dist/esm/transpiler/dictionary_to_main/index.mjs +0 -2
  84. package/dist/esm/transpiler/dictionary_to_main/index.mjs.map +0 -1
  85. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.d.mts +0 -7
  86. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +0 -62
  87. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +0 -1
  88. package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +0 -42
  89. package/dist/esm/transpiler/dictionary_to_type/createType.mjs +0 -86
  90. package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +0 -1
  91. package/dist/esm/transpiler/dictionary_to_type/index.d.mts +0 -3
  92. package/dist/esm/transpiler/dictionary_to_type/index.mjs +0 -3
  93. package/dist/esm/transpiler/dictionary_to_type/index.mjs.map +0 -1
  94. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.mts +0 -44
  95. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs +0 -21
  96. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs.map +0 -1
  97. package/dist/esm/transpiler/intlater_module_to_dictionary/index.d.mts +0 -4
  98. package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs +0 -4
  99. package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs.map +0 -1
  100. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.d.mts +0 -8
  101. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs +0 -43
  102. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs.map +0 -1
  103. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.mts +0 -6
  104. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs +0 -72
  105. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs.map +0 -1
  106. package/src/scripts/bundle.ts +0 -44
  107. package/src/scripts/index.ts +0 -2
  108. package/src/scripts/startServer.ts +0 -14
  109. package/src/transpiler/dictionary_to_main/createDictionaryList.ts +0 -65
  110. package/src/transpiler/dictionary_to_main/index.ts +0 -1
  111. package/src/transpiler/dictionary_to_type/createModuleAugmentation.ts +0 -95
  112. package/src/transpiler/dictionary_to_type/createType.ts +0 -140
  113. package/src/transpiler/dictionary_to_type/index.ts +0 -2
  114. package/src/transpiler/intlater_module_to_dictionary/extractNestedJSON.ts +0 -60
  115. package/src/transpiler/intlater_module_to_dictionary/index.ts +0 -3
  116. package/src/transpiler/intlater_module_to_dictionary/processModule.ts +0 -69
  117. package/src/transpiler/intlater_module_to_dictionary/transpileBundledCode.ts +0 -107
@@ -1,42 +0,0 @@
1
- import { ContentModule, Content } from '@intlayer/core';
2
-
3
- /**
4
- *
5
- * This function generates a TypeScript type definition from a JSON object
6
- *
7
- * Example:
8
- *
9
- * const input = {
10
- * id: '1',
11
- * name: 'John Doe',
12
- * address: {
13
- * id: '2',
14
- * street: '123 Main St',
15
- * city: 'Springfield',
16
- * }
17
- * };
18
- *
19
- * const result = generateTypeScriptType(input, 'RootObject');
20
- * console.log(result);
21
- *
22
- * Output:
23
- *
24
- * type RootObject = {
25
- * id: '1',
26
- * name: string,
27
- * address: {
28
- * id: '2',
29
- * street: string,
30
- * city: string,
31
- * },
32
- * };
33
- *
34
- */
35
- declare const generateTypeScriptType: (obj: ContentModule) => string;
36
- declare const generateTypeScriptTypeContent: (obj: Content) => string;
37
- /**
38
- * This function generates a TypeScript type definition from a JSON object
39
- */
40
- declare const createTypes: (dictionariesPaths: string[]) => string[];
41
-
42
- export { createTypes, generateTypeScriptType, generateTypeScriptTypeContent };
@@ -1,86 +0,0 @@
1
- import { existsSync, mkdirSync, writeFileSync } from "fs";
2
- import { resolve } from "path";
3
- import { getConfiguration } from "@intlayer/config";
4
- import {
5
- NodeType
6
- } from "@intlayer/core";
7
- import { getTypeName } from './createModuleAugmentation.mjs';
8
- const { content, internationalization } = getConfiguration();
9
- const { typesDir } = content;
10
- const generateTypeScriptType = (obj) => {
11
- let typeDefinition = ``;
12
- const typeName = getTypeName(obj.id);
13
- typeDefinition += `export type ${typeName} = {
14
- `;
15
- typeDefinition += generateTypeScriptTypeContent(obj);
16
- typeDefinition += "};\n\n";
17
- return typeDefinition;
18
- };
19
- const generateTypeScriptTypeContent = (obj) => {
20
- let typeDefinition = ``;
21
- for (const [key, value] of Object.entries(obj)) {
22
- const nodeType = value.nodeType;
23
- if (
24
- // Check if the value is a typed node
25
- typeof value === "object" && nodeType === NodeType.Translation
26
- ) {
27
- const tsType = typeof value[internationalization.defaultLocale];
28
- typeDefinition += ` ${key}: ${tsType},
29
- `;
30
- } else if (
31
- // Check if the value is a typed node
32
- typeof value === "object" && nodeType === NodeType.Enumeration
33
- ) {
34
- const tsType = typeof value[internationalization.defaultLocale];
35
- typeDefinition += ` ${key}: (quantity: number) => ${tsType},
36
- `;
37
- } else if (
38
- // Check if the value is a nested object
39
- typeof value === "object" && !Array.isArray(value)
40
- ) {
41
- const nestedType = generateTypeScriptTypeContent(value);
42
- typeDefinition += ` ${key}: {${nestedType}},
43
- `;
44
- } else if (
45
- // Check if the value is an array
46
- Array.isArray(value)
47
- ) {
48
- const arrayType = typeof value[0];
49
- typeDefinition += ` ${key}: ${arrayType}[],
50
- `;
51
- } else if (
52
- // Check if the value is an 'id'
53
- typeof value === "string" && key === "id"
54
- ) {
55
- const tsType = `"${value}"`;
56
- typeDefinition += ` ${key}: ${tsType},
57
- `;
58
- } else {
59
- const tsType = typeof value;
60
- typeDefinition += ` ${key}: ${tsType},
61
- `;
62
- }
63
- }
64
- return typeDefinition;
65
- };
66
- const createTypes = (dictionariesPaths) => {
67
- const resultTypesPaths = [];
68
- if (!existsSync(typesDir)) {
69
- mkdirSync(typesDir, { recursive: true });
70
- }
71
- for (const dictionaryPath of dictionariesPaths) {
72
- const contentModule = require(dictionaryPath);
73
- const dictionaryName = contentModule.id;
74
- const typeDefinition = generateTypeScriptType(contentModule);
75
- const outputPath = resolve(typesDir, `${dictionaryName}.d.ts`);
76
- writeFileSync(outputPath, typeDefinition);
77
- resultTypesPaths.push(outputPath);
78
- }
79
- return resultTypesPaths;
80
- };
81
- export {
82
- createTypes,
83
- generateTypeScriptType,
84
- generateTypeScriptTypeContent
85
- };
86
- //# sourceMappingURL=createType.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport {\n NodeType,\n type Content,\n type ContentModule,\n type TypedNode,\n} from '@intlayer/core';\nimport { getTypeName } from './createModuleAugmentation';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir } = content;\n\n/**\n *\n * This function generates a TypeScript type definition from a JSON object\n *\n * Example:\n *\n * const input = {\n * id: '1',\n * name: 'John Doe',\n * address: {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * }\n * };\n *\n * const result = generateTypeScriptType(input, 'RootObject');\n * console.log(result);\n *\n * Output:\n *\n * type RootObject = {\n * id: '1',\n * name: string,\n * address: {\n * id: '2',\n * street: string,\n * city: string,\n * },\n * };\n *\n */\nexport const generateTypeScriptType = (obj: ContentModule): string => {\n let typeDefinition = ``;\n\n const typeName = getTypeName(obj.id);\n\n typeDefinition += `export type ${typeName} = {\\n`;\n typeDefinition += generateTypeScriptTypeContent(obj);\n typeDefinition += '};\\n\\n';\n\n return typeDefinition;\n};\n\nexport const generateTypeScriptTypeContent = (obj: Content): string => {\n let typeDefinition = ``;\n\n for (const [key, value] of Object.entries(obj)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nodeType: NodeType | undefined = (value as TypedNode).nodeType;\n\n if (\n // Check if the value is a typed node\n typeof value === 'object' &&\n nodeType === NodeType.Translation\n ) {\n const tsType =\n typeof value[internationalization.defaultLocale as keyof typeof value];\n typeDefinition += ` ${key}: ${tsType},\\n`;\n } else if (\n // Check if the value is a typed node\n typeof value === 'object' &&\n nodeType === NodeType.Enumeration\n ) {\n const tsType =\n typeof value[internationalization.defaultLocale as keyof typeof value];\n\n typeDefinition += ` ${key}: (quantity: number) => ${tsType},\\n`;\n } else if (\n // Check if the value is a nested object\n typeof value === 'object' &&\n !Array.isArray(value)\n ) {\n // Nested object, recurse\n const nestedType = generateTypeScriptTypeContent(value as Content);\n typeDefinition += ` ${key}: {${nestedType}},\\n`;\n } else if (\n // Check if the value is an array\n Array.isArray(value)\n ) {\n // Array handling (simplified, assumes non-empty arrays with uniform type)\n const arrayType = typeof value[0];\n typeDefinition += ` ${key}: ${arrayType}[],\\n`;\n } else if (\n // Check if the value is an 'id'\n typeof value === 'string' &&\n key === 'id'\n ) {\n // Special handling for 'id' field\n const tsType = `\"${value}\"`;\n typeDefinition += ` ${key}: ${tsType},\\n`;\n } else {\n // Primitive type\n const tsType = typeof value;\n typeDefinition += ` ${key}: ${tsType},\\n`;\n }\n }\n\n return typeDefinition;\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 contentModule: ContentModule = require(dictionaryPath);\n const dictionaryName: string = contentModule.id;\n const typeDefinition: string = generateTypeScriptType(contentModule);\n\n const outputPath = resolve(typesDir, `${dictionaryName}.d.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,wBAAwB;AACjC;AAAA,EACE;AAAA,OAIK;AACP,SAAS,mBAAmB;AAE5B,MAAM,EAAE,SAAS,qBAAqB,IAAI,iBAAiB;AAC3D,MAAM,EAAE,SAAS,IAAI;AAkCd,MAAM,yBAAyB,CAAC,QAA+B;AACpE,MAAI,iBAAiB;AAErB,QAAM,WAAW,YAAY,IAAI,EAAE;AAEnC,oBAAkB,eAAe,QAAQ;AAAA;AACzC,oBAAkB,8BAA8B,GAAG;AACnD,oBAAkB;AAElB,SAAO;AACT;AAEO,MAAM,gCAAgC,CAAC,QAAyB;AACrE,MAAI,iBAAiB;AAErB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAE9C,UAAM,WAAkC,MAAoB;AAE5D;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,aAAa,SAAS;AAAA,MACtB;AACA,YAAM,SACJ,OAAO,MAAM,qBAAqB,aAAmC;AACvE,wBAAkB,KAAK,GAAG,KAAK,MAAM;AAAA;AAAA,IACvC;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,aAAa,SAAS;AAAA,MACtB;AACA,YAAM,SACJ,OAAO,MAAM,qBAAqB,aAAmC;AAEvE,wBAAkB,KAAK,GAAG,2BAA2B,MAAM;AAAA;AAAA,IAC7D;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,CAAC,MAAM,QAAQ,KAAK;AAAA,MACpB;AAEA,YAAM,aAAa,8BAA8B,KAAgB;AACjE,wBAAkB,KAAK,GAAG,MAAM,UAAU;AAAA;AAAA,IAC5C;AAAA;AAAA,MAEE,MAAM,QAAQ,KAAK;AAAA,MACnB;AAEA,YAAM,YAAY,OAAO,MAAM,CAAC;AAChC,wBAAkB,KAAK,GAAG,KAAK,SAAS;AAAA;AAAA,IAC1C;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,QAAQ;AAAA,MACR;AAEA,YAAM,SAAS,IAAI,KAAK;AACxB,wBAAkB,KAAK,GAAG,KAAK,MAAM;AAAA;AAAA,IACvC,OAAO;AAEL,YAAM,SAAS,OAAO;AACtB,wBAAkB,KAAK,GAAG,KAAK,MAAM;AAAA;AAAA,IACvC;AAAA,EACF;AAEA,SAAO;AACT;AAKO,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,gBAA+B,QAAQ,cAAc;AAC3D,UAAM,iBAAyB,cAAc;AAC7C,UAAM,iBAAyB,uBAAuB,aAAa;AAEnE,UAAM,aAAa,QAAQ,UAAU,GAAG,cAAc,OAAO;AAE7D,kBAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
@@ -1,3 +0,0 @@
1
- export { createModuleAugmentation, getTypeName } from './createModuleAugmentation.mjs';
2
- export { createTypes, generateTypeScriptType, generateTypeScriptTypeContent } from './createType.mjs';
3
- import '@intlayer/core';
@@ -1,3 +0,0 @@
1
- export * from './createModuleAugmentation.mjs';
2
- export * from './createType.mjs';
3
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/index.ts"],"sourcesContent":["export * from './createModuleAugmentation';\nexport * from './createType';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
@@ -1,44 +0,0 @@
1
- import { ContentModule } from '@intlayer/core';
2
-
3
- /**
4
- *
5
- * This function extracts all nested objects with an 'id' field from the input object and returns them as an array
6
- *
7
- * Example:
8
- *
9
- * const input = {
10
- * id: '1',
11
- * name: 'John Doe',
12
- * address: {
13
- * id: '2',
14
- * street: '123 Main St',
15
- * city: 'Springfield',
16
- * state: 'IL'
17
- * },
18
- * };
19
- * const result = extractObjectsWithId(input);
20
- * console.log(result);
21
- *
22
- * Output:
23
- *
24
- * [{
25
- * id: '1',
26
- * name: 'John Doe',
27
- * address: {
28
- * id: '2',
29
- * street: '123 Main St',
30
- * city: 'Springfield',
31
- * state: 'IL'
32
- * }
33
- * },
34
- * {
35
- * id: '2',
36
- * street: '123 Main St',
37
- * city: 'Springfield',
38
- * state: 'IL'
39
- * }]
40
- *
41
- */
42
- declare const extractObjectsWithId: (input: ContentModule) => ContentModule[];
43
-
44
- export { extractObjectsWithId };
@@ -1,21 +0,0 @@
1
- const extractObjectsWithId = (input) => {
2
- const search = (obj, results2) => {
3
- if (obj && typeof obj === "object") {
4
- if (Object.prototype.hasOwnProperty.call(obj, "id")) {
5
- results2.push(obj);
6
- }
7
- for (const key of Object.keys(obj)) {
8
- if (typeof obj[key] === "object") {
9
- search(obj[key], results2);
10
- }
11
- }
12
- }
13
- };
14
- const results = [];
15
- search(input, results);
16
- return results;
17
- };
18
- export {
19
- extractObjectsWithId
20
- };
21
- //# sourceMappingURL=extractNestedJSON.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/extractNestedJSON.ts"],"sourcesContent":["import type { Content, ContentModule } from '@intlayer/core';\n\n/**\n *\n * This function extracts all nested objects with an 'id' field from the input object and returns them as an array\n *\n * Example:\n *\n * const input = {\n * id: '1',\n * name: 'John Doe',\n * address: {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * state: 'IL'\n * },\n * };\n * const result = extractObjectsWithId(input);\n * console.log(result);\n *\n * Output:\n *\n * [{\n * id: '1',\n * name: 'John Doe',\n * address: {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * state: 'IL'\n * }\n * },\n * {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * state: 'IL'\n * }]\n *\n */\nexport const extractObjectsWithId = (input: ContentModule): ContentModule[] => {\n // Function to recursively search and extract nested objects with an 'id'\n const search = (obj: Content, results: ContentModule[]): void => {\n if (obj && typeof obj === 'object') {\n if (Object.prototype.hasOwnProperty.call(obj, 'id')) {\n results.push(obj as ContentModule);\n }\n for (const key of Object.keys(obj)) {\n if (typeof obj[key] === 'object') {\n search(obj[key] as Content, results);\n }\n }\n }\n };\n\n const results: ContentModule[] = [];\n search(input, results);\n return results;\n};\n"],"mappings":"AAyCO,MAAM,uBAAuB,CAAC,UAA0C;AAE7E,QAAM,SAAS,CAAC,KAAcA,aAAmC;AAC/D,QAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,UAAI,OAAO,UAAU,eAAe,KAAK,KAAK,IAAI,GAAG;AACnD,QAAAA,SAAQ,KAAK,GAAoB;AAAA,MACnC;AACA,iBAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,YAAI,OAAO,IAAI,GAAG,MAAM,UAAU;AAChC,iBAAO,IAAI,GAAG,GAAcA,QAAO;AAAA,QACrC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAA2B,CAAC;AAClC,SAAO,OAAO,OAAO;AACrB,SAAO;AACT;","names":["results"]}
@@ -1,4 +0,0 @@
1
- export { extractObjectsWithId } from './extractNestedJSON.mjs';
2
- export { processModule } from './processModule.mjs';
3
- export { transpileBundledCode } from './transpileBundledCode.mjs';
4
- import '@intlayer/core';
@@ -1,4 +0,0 @@
1
- export * from './extractNestedJSON.mjs';
2
- export * from './processModule.mjs';
3
- export * from './transpileBundledCode.mjs';
4
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/index.ts"],"sourcesContent":["export * from './extractNestedJSON';\nexport * from './processModule';\nexport * from './transpileBundledCode';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -1,8 +0,0 @@
1
- import { ContentModule } from '@intlayer/core';
2
-
3
- /**
4
- * Function to load, process the module and return the Intlayer ContentModule from the module file
5
- */
6
- declare const processModule: (file: string) => Promise<ContentModule | undefined>;
7
-
8
- export { processModule };
@@ -1,43 +0,0 @@
1
- import { resolve } from "path";
2
- const loadModule = async (modulePath) => {
3
- return (await import(modulePath)).default;
4
- };
5
- const processFunctionResults = async (entry) => {
6
- if (entry && typeof entry === "object") {
7
- const promises = [];
8
- const result = {};
9
- for (const key of Object.keys(entry)) {
10
- const field = entry?.[key];
11
- if (typeof field === "object") {
12
- result[key] = await processFunctionResults(
13
- field
14
- );
15
- }
16
- if (typeof field === "function") {
17
- const promise = (async () => {
18
- const value = await field();
19
- result[key] = value;
20
- })();
21
- promises.push(promise);
22
- } else {
23
- result[key] = field;
24
- }
25
- }
26
- await Promise.all(promises);
27
- return result;
28
- }
29
- return entry;
30
- };
31
- const processModule = async (file) => {
32
- try {
33
- const functionPath = resolve(file);
34
- const entry = await loadModule(functionPath);
35
- return await processFunctionResults(entry);
36
- } catch (error) {
37
- console.error("Error processing module:", error);
38
- }
39
- };
40
- export {
41
- processModule
42
- };
43
- //# sourceMappingURL=processModule.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/processModule.ts"],"sourcesContent":["import { resolve } from 'path';\nimport type {\n Content,\n ContentModule,\n FlatContent,\n FlatContentValue,\n} from '@intlayer/core';\n\n/**\n * Function to load the module file in a sandboxed environment\n */\nconst loadModule = async (modulePath: string): Promise<ContentModule> => {\n // @TODO: Sandbox the module to prevent malicious code execution\n\n return (await import(modulePath)).default;\n};\n\n/**\n * Function to replace function and async function fields with their results in the object\n */\nconst processFunctionResults = async (entry: Content): Promise<FlatContent> => {\n if (entry && typeof entry === 'object') {\n const promises: Promise<void>[] = [];\n const result: FlatContent = {};\n\n for (const key of Object.keys(entry)) {\n const field = entry?.[key];\n\n if (typeof field === 'object') {\n result[key] = (await processFunctionResults(\n field as Content\n )) as FlatContentValue;\n }\n\n if (typeof field === 'function') {\n // Wait for the function to resolve if it's an async function\n const promise = (async () => {\n // Execute the function and await the result if it's a Promise\n const value = await field();\n result[key] = value as FlatContentValue;\n })();\n promises.push(promise);\n } else {\n result[key] = field as FlatContentValue;\n }\n }\n\n // Wait for all async operations to complete\n await Promise.all(promises);\n\n return result;\n }\n\n return entry;\n};\n\n/**\n * Function to load, process the module and return the Intlayer ContentModule from the module file\n */\nexport const processModule = async (file: string) => {\n try {\n const functionPath = resolve(file);\n const entry = await loadModule(functionPath);\n\n return (await processFunctionResults(entry)) as ContentModule;\n } catch (error) {\n console.error('Error processing module:', error);\n }\n};\n"],"mappings":"AAAA,SAAS,eAAe;AAWxB,MAAM,aAAa,OAAO,eAA+C;AAGvE,UAAQ,MAAM,OAAO,aAAa;AACpC;AAKA,MAAM,yBAAyB,OAAO,UAAyC;AAC7E,MAAI,SAAS,OAAO,UAAU,UAAU;AACtC,UAAM,WAA4B,CAAC;AACnC,UAAM,SAAsB,CAAC;AAE7B,eAAW,OAAO,OAAO,KAAK,KAAK,GAAG;AACpC,YAAM,QAAQ,QAAQ,GAAG;AAEzB,UAAI,OAAO,UAAU,UAAU;AAC7B,eAAO,GAAG,IAAK,MAAM;AAAA,UACnB;AAAA,QACF;AAAA,MACF;AAEA,UAAI,OAAO,UAAU,YAAY;AAE/B,cAAM,WAAW,YAAY;AAE3B,gBAAM,QAAQ,MAAM,MAAM;AAC1B,iBAAO,GAAG,IAAI;AAAA,QAChB,GAAG;AACH,iBAAS,KAAK,OAAO;AAAA,MACvB,OAAO;AACL,eAAO,GAAG,IAAI;AAAA,MAChB;AAAA,IACF;AAGA,UAAM,QAAQ,IAAI,QAAQ;AAE1B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAKO,MAAM,gBAAgB,OAAO,SAAiB;AACnD,MAAI;AACF,UAAM,eAAe,QAAQ,IAAI;AACjC,UAAM,QAAQ,MAAM,WAAW,YAAY;AAE3C,WAAQ,MAAM,uBAAuB,KAAK;AAAA,EAC5C,SAAS,OAAO;AACd,YAAQ,MAAM,4BAA4B,KAAK;AAAA,EACjD;AACF;","names":[]}
@@ -1,6 +0,0 @@
1
- /**
2
- * This function transpile the bundled code to to make dictionaries as JSON files
3
- */
4
- declare const transpileBundledCode: (bundledEntriesPaths: string[] | string) => Promise<string[]>;
5
-
6
- export { transpileBundledCode };
@@ -1,72 +0,0 @@
1
- import { existsSync } from "fs";
2
- import { mkdir, writeFile } from "fs/promises";
3
- import { resolve } from "path";
4
- import { getConfiguration } from "@intlayer/config";
5
- import { extractObjectsWithId } from './extractNestedJSON.mjs';
6
- import { processModule } from './processModule.mjs';
7
- const { content } = getConfiguration();
8
- const { dictionariesDir, bundleFileExtension } = content;
9
- const loadBundledModule = async (bundledEntryPath) => {
10
- const entryFilePath = resolve(bundledEntryPath);
11
- const isEntryFilePathExist = existsSync(entryFilePath);
12
- if (!isEntryFilePathExist) {
13
- console.error("Entry file not found. " + entryFilePath);
14
- return;
15
- }
16
- const isEntryPathValid = entryFilePath.endsWith(bundleFileExtension);
17
- if (!isEntryPathValid) {
18
- return;
19
- }
20
- try {
21
- delete require.cache[entryFilePath];
22
- const entry = await import(entryFilePath);
23
- let result;
24
- if (entry.default) {
25
- result = await processModule(entryFilePath);
26
- } else {
27
- result = entry;
28
- }
29
- return result;
30
- } catch (err) {
31
- console.error(`Error transpiling ${entryFilePath}:`, err);
32
- }
33
- };
34
- const buildDictionary = async (dictionaries) => {
35
- const resultDictionariesPaths = [];
36
- for await (const content2 of dictionaries) {
37
- const contentString = JSON.stringify(content2);
38
- const id = content2.id;
39
- const outputFileName = `${id}.json`;
40
- const resultFilePath = resolve(dictionariesDir, outputFileName);
41
- await writeFile(resultFilePath, contentString, "utf8").catch((err) => {
42
- console.error(`Error creating ${outputFileName}:`, err);
43
- });
44
- resultDictionariesPaths.push(resultFilePath);
45
- }
46
- return resultDictionariesPaths;
47
- };
48
- const transpileBundledCode = async (bundledEntriesPaths) => {
49
- const resultDictionariesPaths = [];
50
- if (typeof bundledEntriesPaths === "string") {
51
- bundledEntriesPaths = [bundledEntriesPaths];
52
- }
53
- const filteredBundledEntriesPaths = bundledEntriesPaths.filter(
54
- // Filter js files;
55
- (bundledEntryPath) => bundledEntryPath.endsWith(bundleFileExtension)
56
- );
57
- await mkdir(resolve(dictionariesDir), { recursive: true });
58
- for await (const bundledEntryPath of filteredBundledEntriesPaths) {
59
- const result = await loadBundledModule(bundledEntryPath);
60
- if (!result) {
61
- continue;
62
- }
63
- const nestedContent = extractObjectsWithId(result);
64
- const dictionariesPaths = await buildDictionary(nestedContent);
65
- resultDictionariesPaths.push(...dictionariesPaths);
66
- }
67
- return resultDictionariesPaths;
68
- };
69
- export {
70
- transpileBundledCode
71
- };
72
- //# sourceMappingURL=transpileBundledCode.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/transpileBundledCode.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { ContentModule } from '@intlayer/core';\nimport { extractObjectsWithId } from './extractNestedJSON';\nimport { processModule } from './processModule';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir, bundleFileExtension } = content;\n\nconst loadBundledModule = async (bundledEntryPath: string) => {\n const entryFilePath = resolve(bundledEntryPath);\n\n const isEntryFilePathExist = existsSync(entryFilePath);\n\n if (!isEntryFilePathExist) {\n console.error('Entry file not found. ' + entryFilePath);\n return;\n }\n\n const isEntryPathValid = entryFilePath.endsWith(bundleFileExtension);\n\n if (!isEntryPathValid) {\n return;\n }\n\n try {\n // Remove the module from the cache\n delete require.cache[entryFilePath];\n\n // Require the module anew\n const entry = await import(entryFilePath);\n\n let result: ContentModule | undefined;\n\n if (entry.default) {\n // JS or TS file\n result = await processModule(entryFilePath);\n } else {\n // JSON file\n result = entry;\n }\n\n return result;\n } catch (err) {\n console.error(`Error transpiling ${entryFilePath}:`, err);\n }\n};\n\nconst buildDictionary = async (dictionaries: ContentModule[]) => {\n const resultDictionariesPaths: string[] = [];\n\n for await (const content of dictionaries) {\n const contentString = JSON.stringify(content);\n\n const id = content.id;\n const outputFileName = `${id}.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\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const transpileBundledCode = async (\n bundledEntriesPaths: string[] | string\n) => {\n const resultDictionariesPaths: string[] = [];\n\n if (typeof bundledEntriesPaths === 'string') {\n bundledEntriesPaths = [bundledEntriesPaths];\n }\n\n const filteredBundledEntriesPaths: string[] = bundledEntriesPaths.filter(\n // Filter js files;\n (bundledEntryPath) => bundledEntryPath.endsWith(bundleFileExtension)\n );\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n for await (const bundledEntryPath of filteredBundledEntriesPaths) {\n const result = await loadBundledModule(bundledEntryPath);\n\n if (!result) {\n continue;\n }\n\n const nestedContent: ContentModule[] = extractObjectsWithId(result);\n\n const dictionariesPaths: string[] = await buildDictionary(nestedContent);\n\n resultDictionariesPaths.push(...dictionariesPaths);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,wBAAwB;AAEjC,SAAS,4BAA4B;AACrC,SAAS,qBAAqB;AAE9B,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,iBAAiB,oBAAoB,IAAI;AAEjD,MAAM,oBAAoB,OAAO,qBAA6B;AAC5D,QAAM,gBAAgB,QAAQ,gBAAgB;AAE9C,QAAM,uBAAuB,WAAW,aAAa;AAErD,MAAI,CAAC,sBAAsB;AACzB,YAAQ,MAAM,2BAA2B,aAAa;AACtD;AAAA,EACF;AAEA,QAAM,mBAAmB,cAAc,SAAS,mBAAmB;AAEnE,MAAI,CAAC,kBAAkB;AACrB;AAAA,EACF;AAEA,MAAI;AAEF,WAAO,QAAQ,MAAM,aAAa;AAGlC,UAAM,QAAQ,MAAM,OAAO;AAE3B,QAAI;AAEJ,QAAI,MAAM,SAAS;AAEjB,eAAS,MAAM,cAAc,aAAa;AAAA,IAC5C,OAAO;AAEL,eAAS;AAAA,IACX;AAEA,WAAO;AAAA,EACT,SAAS,KAAK;AACZ,YAAQ,MAAM,qBAAqB,aAAa,KAAK,GAAG;AAAA,EAC1D;AACF;AAEA,MAAM,kBAAkB,OAAO,iBAAkC;AAC/D,QAAM,0BAAoC,CAAC;AAE3C,mBAAiBA,YAAW,cAAc;AACxC,UAAM,gBAAgB,KAAK,UAAUA,QAAO;AAE5C,UAAM,KAAKA,SAAQ;AACnB,UAAM,iBAAiB,GAAG,EAAE;AAC5B,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;AAKO,MAAM,uBAAuB,OAClC,wBACG;AACH,QAAM,0BAAoC,CAAC;AAE3C,MAAI,OAAO,wBAAwB,UAAU;AAC3C,0BAAsB,CAAC,mBAAmB;AAAA,EAC5C;AAEA,QAAM,8BAAwC,oBAAoB;AAAA;AAAA,IAEhE,CAAC,qBAAqB,iBAAiB,SAAS,mBAAmB;AAAA,EACrE;AAGA,QAAM,MAAM,QAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,mBAAiB,oBAAoB,6BAA6B;AAChE,UAAM,SAAS,MAAM,kBAAkB,gBAAgB;AAEvD,QAAI,CAAC,QAAQ;AACX;AAAA,IACF;AAEA,UAAM,gBAAiC,qBAAqB,MAAM;AAElE,UAAM,oBAA8B,MAAM,gBAAgB,aAAa;AAEvE,4BAAwB,KAAK,GAAG,iBAAiB;AAAA,EACnD;AAEA,SAAO;AACT;","names":["content"]}
@@ -1,44 +0,0 @@
1
- import type { Compiler } from 'webpack';
2
-
3
- export const bundle = (compiler: Compiler) =>
4
- // Run the compiler
5
- compiler.run((err, stats) => {
6
- // Handle errors and webpack compilation stats
7
- if (err) {
8
- console.error('Webpack compilation error:', err);
9
- return;
10
- }
11
-
12
- console.info('Webpack compilation successful.');
13
-
14
- if (stats)
15
- console.info(
16
- stats.toString({
17
- // Add options here to customize the stats output
18
- colors: true,
19
- })
20
- );
21
- });
22
-
23
- export const watch = (compiler: Compiler) =>
24
- // Run the compiler
25
- compiler.watch({}, (err, stats) => {
26
- // Handle errors and webpack compilation stats
27
- if (err) {
28
- console.error('Webpack compilation error:', err);
29
- return;
30
- }
31
-
32
- console.info('Webpack compilation successful.');
33
-
34
- if (stats)
35
- console.info(
36
- stats.toString({
37
- // Add options here to customize the stats output
38
- colors: true,
39
- })
40
- );
41
-
42
- // After successful compilation, start the server
43
- console.info('Watch IntLayer content...');
44
- });
@@ -1,2 +0,0 @@
1
- export * from './startServer';
2
- export * from './bundle';
@@ -1,14 +0,0 @@
1
- import type { Compiler } from 'webpack';
2
- import { devServerConfig } from '../webpack.config';
3
-
4
- const WebpackDevServer = require('webpack-dev-server');
5
-
6
- export const startServer = (compiler: Compiler) => {
7
- // Create a new instance of webpack-dev-server
8
- const devServer = new WebpackDevServer(devServerConfig, compiler);
9
-
10
- // Start the server
11
- devServer.startCallback(() => {
12
- console.info('Webpack Dev Server is running...');
13
- });
14
- };
@@ -1,65 +0,0 @@
1
- import { existsSync, mkdirSync, writeFileSync } from 'fs';
2
- import { basename, extname, relative, resolve } from 'path';
3
- import { getConfiguration } from '@intlayer/config';
4
- import { sync } from 'glob';
5
- import { getFileHash } from '../../utils';
6
-
7
- const { content } = getConfiguration();
8
- const { dictionariesDir, mainDir } = content;
9
-
10
- /**
11
- * This function generates the content of the dictionary list file
12
- */
13
- const generateDictionaryListContent = (
14
- dictionaries: string[],
15
- format: 'cjs' | 'esm' = 'esm'
16
- ): string => {
17
- let content = '';
18
-
19
- const dictionariesRef = dictionaries.map((dictionaryPath) => ({
20
- relativePath: relative(mainDir, dictionaryPath),
21
- id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id
22
- hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts
23
- }));
24
-
25
- // Import all dictionaries
26
- dictionariesRef.forEach((dictionary) => {
27
- if (format === 'esm')
28
- content += `import ${dictionary.hash} from '${dictionary.relativePath}';\n`;
29
- if (format === 'cjs')
30
- content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\n`;
31
- });
32
-
33
- content += '\n';
34
-
35
- // Format Dictionary Map
36
- const formattedDictionaryMap: string = dictionariesRef
37
- .map((dictionary) => `"${dictionary.id}": ${dictionary.hash}`)
38
- .join(',\n');
39
-
40
- if (format === 'esm')
41
- content += `export default {\n${formattedDictionaryMap}\n};\n`;
42
- if (format === 'cjs')
43
- content += `module.exports = {\n${formattedDictionaryMap}\n};\n`;
44
-
45
- return content;
46
- };
47
-
48
- /**
49
- * This function generates a list of dictionaries in the main directory
50
- */
51
- export const createDictionaryList = () => {
52
- // Create main directory if it doesn't exist
53
- if (!existsSync(mainDir)) {
54
- mkdirSync(mainDir, { recursive: true });
55
- }
56
-
57
- const dictionaries: string[] = sync(`${dictionariesDir}/**/*.json`);
58
-
59
- // Create the dictionary list file
60
- const cjsContent = generateDictionaryListContent(dictionaries, 'cjs');
61
- writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);
62
-
63
- const esmContent = generateDictionaryListContent(dictionaries, 'esm');
64
- writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);
65
- };
@@ -1 +0,0 @@
1
- export * from './createDictionaryList';
@@ -1,95 +0,0 @@
1
- import { existsSync, mkdirSync, writeFileSync } from 'fs';
2
- import { basename, join, relative } from 'path';
3
- import { Locales, getConfiguration } from '@intlayer/config';
4
- import { sync } from 'glob';
5
- import { getFileHash, transformToCamelCase } from '../../utils';
6
-
7
- const { content, internationalization } = getConfiguration();
8
- const { typesDir, moduleAugmentationDir } = content;
9
- const { locales } = internationalization;
10
-
11
- export const getTypeName = (id: string): string =>
12
- transformToCamelCase(`${id}Content`);
13
-
14
- /**
15
- * This function generates the content of the module augmentation file
16
- */
17
- const generateTypeIndexContent = (typeFiles: string[]): string => {
18
- let content =
19
- "/* eslint-disable */\nimport 'intlayer';\nimport { Locales } from '@intlayer/config'\n";
20
-
21
- const dictionariesRef = typeFiles.map((dictionaryPath) => ({
22
- relativePath: relative(moduleAugmentationDir, dictionaryPath),
23
- id: basename(dictionaryPath, '.d.ts'), // Get the base name as the dictionary id
24
- hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts
25
- }));
26
-
27
- // Import all dictionaries
28
- dictionariesRef.forEach((dictionary) => {
29
- const typeName = getTypeName(dictionary.id);
30
- content += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';\n`;
31
- });
32
-
33
- content += '\n';
34
-
35
- // Format Dictionary Map
36
- const formattedDictionaryMap: string = dictionariesRef
37
- .map((dictionary) => ` "${dictionary.id}": ${dictionary.hash};`)
38
- .join('\n');
39
-
40
- const formatLocales = locales
41
- .map((locale) => {
42
- for (const key in Locales) {
43
- if (Locales[key as keyof typeof Locales] === locale) {
44
- return ` ${key} = '${locale}'`;
45
- }
46
- }
47
- })
48
- .join(',\n');
49
-
50
- /**
51
- * Write the module augmentation to extend the intlayer module with the dictionaries types
52
- * Will suggest the type resulting of the dictionaries
53
- *
54
- * declare module 'intlayer' {
55
- * interface IntlayerDictionaryTypesConnector = {
56
- * dictionaries: {
57
- * id: DictionaryType;
58
- * }
59
- * }
60
- *
61
- * enum ConfigLocales {
62
- * ENGLISH = 'en',
63
- * FRENCH = 'fr',
64
- * SPANISH = 'es',
65
- * }
66
- *
67
- * interface IConfigLocales<Content> extends Record<ConfigLocales, Content> {}
68
- *
69
- * }
70
- * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
71
- */
72
- content += `declare module 'intlayer' {\n`;
73
- content += ` interface IntlayerDictionaryTypesConnector {\n${formattedDictionaryMap}\n }\n\n`;
74
- content += ` enum ConfigLocales {\n${formatLocales}\n };\n\n`;
75
- content += ` interface IConfigLocales<Content> extends Record<ConfigLocales, Content> {}\n`;
76
- content += `};`;
77
-
78
- return content;
79
- };
80
-
81
- /**
82
- * This function generates a index file merging all the types
83
- */
84
- export const createModuleAugmentation = () => {
85
- // Create main directory if it doesn't exist
86
- if (!existsSync(moduleAugmentationDir)) {
87
- mkdirSync(moduleAugmentationDir, { recursive: true });
88
- }
89
-
90
- const dictionaries: string[] = sync(`${typesDir}/**/*.d.ts`);
91
- // Create the dictionary list file
92
-
93
- const tsContent = generateTypeIndexContent(dictionaries);
94
- writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);
95
- };