@intlayer/chokidar 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/cjs/chokidar/watcher.cjs +4 -4
  2. package/dist/cjs/chokidar/watcher.cjs.map +1 -1
  3. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.cjs +80 -0
  4. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.cjs.map +1 -0
  5. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.ts +6 -0
  6. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.cjs +86 -0
  7. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.cjs.map +1 -0
  8. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.ts +8 -0
  9. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.cjs +50 -0
  10. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.cjs.map +1 -0
  11. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.ts +3 -0
  12. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.cjs +23 -0
  13. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.cjs.map +1 -0
  14. package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.ts +1 -0
  15. package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs +43 -0
  16. package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs.map +1 -0
  17. package/dist/cjs/transpiler/declaration_file_to_dictionary/index.d.ts +3 -0
  18. package/dist/cjs/transpiler/{intlater_module_to_dictionary/transpileContentDeclaration.cjs → declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs} +17 -11
  19. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs.map +1 -0
  20. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +6 -0
  21. package/dist/cjs/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/extractNestedJSON.cjs +1 -1
  22. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.cjs.map +1 -0
  23. package/dist/cjs/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/index.cjs +7 -7
  24. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.cjs.map +1 -0
  25. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.ts +4 -0
  26. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.cjs.map +1 -0
  27. package/dist/cjs/transpiler/{intlater_module_to_dictionary/processModule.cjs → declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs} +5 -6
  28. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs.map +1 -0
  29. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +12 -9
  30. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
  31. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +24 -12
  32. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -1
  33. package/dist/esm/chokidar/watcher.mjs +4 -4
  34. package/dist/esm/chokidar/watcher.mjs.map +1 -1
  35. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.mts +6 -0
  36. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.mjs +61 -0
  37. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.mjs.map +1 -0
  38. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.mts +8 -0
  39. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.mjs +64 -0
  40. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.mjs.map +1 -0
  41. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.mts +3 -0
  42. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.mjs +26 -0
  43. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.mjs.map +1 -0
  44. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.mts +1 -0
  45. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.mjs +2 -0
  46. package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.mjs.map +1 -0
  47. package/dist/esm/transpiler/declaration_file_to_dictionary/index.d.mts +3 -0
  48. package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs +19 -0
  49. package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs.map +1 -0
  50. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.mts +6 -0
  51. package/dist/esm/transpiler/{intlater_module_to_dictionary/transpileContentDeclaration.mjs → declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs} +12 -6
  52. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -0
  53. package/dist/esm/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/extractNestedJSON.mjs +1 -1
  54. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.mjs.map +1 -0
  55. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.mts +4 -0
  56. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.mjs +4 -0
  57. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.mjs.map +1 -0
  58. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.mjs.map +1 -0
  59. package/dist/esm/transpiler/{intlater_module_to_dictionary/processModule.mjs → declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs} +2 -3
  60. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs.map +1 -0
  61. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +12 -9
  62. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
  63. package/dist/esm/transpiler/dictionary_to_type/createType.mjs +24 -12
  64. package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
  65. package/package.json +4 -4
  66. package/src/chokidar/watcher.ts +5 -14
  67. package/src/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.ts +95 -0
  68. package/src/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.ts +91 -0
  69. package/src/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.ts +22 -0
  70. package/src/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.ts +1 -0
  71. package/src/transpiler/declaration_file_to_dictionary/index.ts +21 -0
  72. package/src/transpiler/{intlater_module_to_dictionary/transpileContentDeclaration.ts → declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts} +12 -4
  73. package/src/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/extractNestedJSON.ts +1 -1
  74. package/src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.ts +3 -0
  75. package/src/transpiler/{intlater_module_to_dictionary/processModule.ts → declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.ts} +2 -3
  76. package/src/transpiler/dictionary_to_type/createModuleAugmentation.ts +21 -14
  77. package/src/transpiler/dictionary_to_type/createType.ts +36 -19
  78. package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs.map +0 -1
  79. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs.map +0 -1
  80. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.d.ts +0 -4
  81. package/dist/cjs/transpiler/intlater_module_to_dictionary/loadContentDeclaration.cjs.map +0 -1
  82. package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs.map +0 -1
  83. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.cjs.map +0 -1
  84. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.d.ts +0 -6
  85. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs.map +0 -1
  86. package/dist/esm/transpiler/intlater_module_to_dictionary/index.d.mts +0 -4
  87. package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs +0 -4
  88. package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs.map +0 -1
  89. package/dist/esm/transpiler/intlater_module_to_dictionary/loadContentDeclaration.mjs.map +0 -1
  90. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs.map +0 -1
  91. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.d.mts +0 -6
  92. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.mjs.map +0 -1
  93. package/src/transpiler/intlater_module_to_dictionary/index.ts +0 -3
  94. /package/dist/cjs/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/extractNestedJSON.d.ts +0 -0
  95. /package/dist/cjs/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/loadContentDeclaration.cjs +0 -0
  96. /package/dist/cjs/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/loadContentDeclaration.d.ts +0 -0
  97. /package/dist/cjs/transpiler/{intlater_module_to_dictionary/processModule.d.ts → declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts} +0 -0
  98. /package/dist/esm/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/extractNestedJSON.d.mts +0 -0
  99. /package/dist/esm/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/loadContentDeclaration.d.mts +0 -0
  100. /package/dist/esm/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/loadContentDeclaration.mjs +0 -0
  101. /package/dist/esm/transpiler/{intlater_module_to_dictionary/processModule.d.mts → declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.mts} +0 -0
  102. /package/src/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/loadContentDeclaration.ts +0 -0
@@ -60,12 +60,25 @@ export const generateTypeScriptType = (obj: ContentModule): string => {
60
60
  return typeDefinition;
61
61
  };
62
62
 
63
+ const isReactNode = (node: Record<string, unknown>): boolean =>
64
+ typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';
65
+
66
+ // eslint-disable-next-line sonarjs/cognitive-complexity
63
67
  export const generateTypeScriptTypeContent = (obj: Content): string => {
64
- let typeDefinition = ``;
68
+ if (typeof obj !== 'object' || obj === null) {
69
+ return `${typeof obj}`;
70
+ }
71
+
72
+ const isReactNodeValue = isReactNode(obj as Record<string, unknown>);
65
73
 
74
+ if (isReactNodeValue) {
75
+ // ReactNode handling
76
+ return `JSX.Element`;
77
+ }
78
+
79
+ let typeDefinition = ``;
66
80
  for (const [key, value] of Object.entries(obj)) {
67
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
- const nodeType: NodeType | undefined = (value as TypedNode).nodeType;
81
+ const nodeType: NodeType | undefined = (value as TypedNode)?.nodeType;
69
82
  type ValueKey = keyof typeof value;
70
83
 
71
84
  if (
@@ -73,33 +86,37 @@ export const generateTypeScriptTypeContent = (obj: Content): string => {
73
86
  typeof value === 'object' &&
74
87
  nodeType === NodeType.Translation
75
88
  ) {
76
- const tsType =
77
- typeof value?.[internationalization.defaultLocale as ValueKey];
89
+ const tsType = generateTypeScriptTypeContent(
90
+ value?.[internationalization.defaultLocale as ValueKey]
91
+ );
78
92
  typeDefinition += ` ${key}: ${tsType},\n`;
79
93
  } else if (
80
94
  // Check if the value is a typed node
81
95
  typeof value === 'object' &&
82
96
  nodeType === NodeType.Enumeration
83
97
  ) {
84
- const tsType =
85
- typeof value?.[internationalization.defaultLocale as ValueKey];
98
+ const tsType = generateTypeScriptTypeContent(
99
+ value?.[internationalization.defaultLocale as ValueKey] as Content
100
+ );
86
101
 
87
102
  typeDefinition += ` ${key}: (quantity: number) => ${tsType},\n`;
88
103
  } else if (
89
104
  // Check if the value is a nested object
90
- typeof value === 'object' &&
91
- !Array.isArray(value)
92
- ) {
93
- // Nested object, recurse
94
- const nestedType = generateTypeScriptTypeContent(value as Content);
95
- typeDefinition += ` ${key}: {${nestedType}},\n`;
96
- } else if (
97
- // Check if the value is an array
98
- Array.isArray(value)
105
+ typeof value === 'object'
99
106
  ) {
100
- // Array handling (simplified, assumes non-empty arrays with uniform type)
101
- const arrayType = typeof value[0];
102
- typeDefinition += ` ${key}: ${arrayType}[],\n`;
107
+ const isArray = Array.isArray(value);
108
+
109
+ if (isArray) {
110
+ // Array handling (simplified, assumes non-empty arrays with uniform type)
111
+ const arrayType = generateTypeScriptTypeContent(value as Content);
112
+
113
+ typeDefinition += ` ${key}: ${arrayType}[],\n`;
114
+ } else {
115
+ // Nested object, recurse
116
+ const nestedType = generateTypeScriptTypeContent(value as Content);
117
+
118
+ typeDefinition += ` ${key}: {${nestedType}},\n`;
119
+ }
103
120
  } else if (
104
121
  // Check if the value is an 'id'
105
122
  typeof value === 'string' &&
@@ -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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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 +0,0 @@
1
- {"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/index.ts"],"sourcesContent":["export * from './extractNestedJSON';\nexport * from './processModule';\nexport * from './transpileContentDeclaration';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,kDAAc,gCAAd;AACA,kDAAc,4BADd;AAEA,kDAAc,0CAFd;","names":[]}
@@ -1,4 +0,0 @@
1
- export { extractObjectsWithId } from './extractNestedJSON.js';
2
- export { processContentDeclaration } from './processModule.js';
3
- export { transpileContentDeclaration } from './transpileContentDeclaration.js';
4
- import '@intlayer/core';
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/loadContentDeclaration.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { createRequire } from 'module';\nimport { type Context, runInNewContext } from 'vm';\nimport type { ContentModule } from '@intlayer/core';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n console,\n require: isESModule ? createRequire(import.meta.url) : require,\n};\n\nconst transformationOption: BuildOptions = {\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n },\n format: 'cjs', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n};\n\nconst filterValidContentDeclaration = (\n contentDeclaration: ContentModule\n): ContentModule => {\n // @TODO Implement filtering of valid content declaration\n return contentDeclaration;\n};\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadContentDeclaration = (\n contentDeclarationFilePath: string\n): ContentModule | undefined => {\n let contentDeclaration: ContentModule | undefined = undefined;\n\n const fileExtension = contentDeclarationFilePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Assume JSON\n return require(contentDeclarationFilePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [contentDeclarationFilePath],\n\n ...transformationOption,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n runInNewContext(moduleResultString, sandboxContext);\n\n if (\n sandboxContext.exports.default &&\n Object.keys(sandboxContext.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports.default &&\n Object.keys(sandboxContext.module.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n contentDeclaration = sandboxContext.module.exports;\n }\n\n if (typeof contentDeclaration === 'undefined') {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n return filterValidContentDeclaration(contentDeclaration);\n } catch (error) {\n console.error('Error:', error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA8B;AAC9B,gBAA8C;AAE9C,qBAA+D;AAJ/D;AAMA,MAAM,aAAa,OAAO,YAAY,QAAQ;AAE9C,MAAM,iBAA0B;AAAA,EAC9B,SAAS;AAAA,IACP,SAAS,CAAC;AAAA,EACZ;AAAA,EACA,QAAQ;AAAA,IACN,SAAS,CAAC;AAAA,EACZ;AAAA,EACA;AAAA,EACA,SAAS,iBAAa,6BAAc,YAAY,GAAG,IAAI;AACzD;AAEA,MAAM,uBAAqC;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AAAA,EACA,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AACV;AAEA,MAAM,gCAAgC,CACpC,uBACkB;AAElB,SAAO;AACT;AAOO,MAAM,yBAAyB,CACpC,+BAC8B;AAC9B,MAAI,qBAAgD;AAEpD,QAAM,gBAAgB,2BAA2B,MAAM,GAAG,EAAE,IAAI,KAAK;AAErE,MAAI;AACF,QAAI,kBAAkB,QAAQ;AAE5B,aAAO,QAAQ,0BAA0B;AAAA,IAC3C;AAIA,UAAM,mBAA4B,0BAAU;AAAA,MAC1C,aAAa,CAAC,0BAA0B;AAAA,MAExC,GAAG;AAAA,IACL,CAAC;AAED,UAAM,qBAAqB,aAAa,cAAc,CAAC,EAAE;AAEzD,QAAI,CAAC,oBAAoB;AACvB,cAAQ,MAAM,yCAAyC;AACvD,aAAO;AAAA,IACT;AAEA,mCAAgB,oBAAoB,cAAc;AAElD,QACE,eAAe,QAAQ,WACvB,OAAO,KAAK,eAAe,QAAQ,OAAO,EAAE,SAAS,GACrD;AAEA,2BAAqB,eAAe,QAAQ;AAAA,IAC9C,WACE,eAAe,OAAO,QAAQ,YAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,QAAQ,EAAE,SAAS,GAC7D;AAEA,2BAAqB,eAAe,OAAO,QAAQ;AAAA,IACrD,WACE,eAAe,OAAO,QAAQ,WAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,OAAO,EAAE,SAAS,GAC5D;AAEA,2BAAqB,eAAe,OAAO,QAAQ;AAAA,IACrD,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,2BAAqB,eAAe,OAAO;AAAA,IAC7C;AAEA,QAAI,OAAO,uBAAuB,aAAa;AAC7C,cAAQ,MAAM,yCAAyC;AACvD,aAAO;AAAA,IACT;AAEA,WAAO,8BAA8B,kBAAkB;AAAA,EACzD,SAAS,OAAO;AACd,YAAQ,MAAM,UAAU,KAAK;AAAA,EAC/B;AACF;","names":[]}
@@ -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';\nimport { loadContentDeclaration } from './loadContentDeclaration';\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 processContentDeclaration = async (file: string) => {\n try {\n const functionPath = resolve(file);\n const entry = loadContentDeclaration(functionPath);\n\n if (!entry) {\n console.error('No entry found in module:', functionPath);\n return;\n }\n\n return (await processFunctionResults(entry)) as ContentModule;\n } catch (error) {\n console.error('Error processing module:', error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwB;AAOxB,oCAAuC;AAKvC,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,4BAA4B,OAAO,SAAiB;AAC/D,MAAI;AACF,UAAM,mBAAe,qBAAQ,IAAI;AACjC,UAAM,YAAQ,sDAAuB,YAAY;AAEjD,QAAI,CAAC,OAAO;AACV,cAAQ,MAAM,6BAA6B,YAAY;AACvD;AAAA,IACF;AAEA,WAAQ,MAAM,uBAAuB,KAAK;AAAA,EAC5C,SAAS,OAAO;AACd,YAAQ,MAAM,4BAA4B,KAAK;AAAA,EACjD;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.ts"],"sourcesContent":["import { 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 { processContentDeclaration } from './processModule';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir } = content;\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 transpileContentDeclaration = async (\n contentDeclarationsPaths: string[] | string\n) => {\n const resultDictionariesPaths: string[] = [];\n\n if (typeof contentDeclarationsPaths === 'string') {\n contentDeclarationsPaths = [contentDeclarationsPaths];\n }\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n for await (const contentDeclarationPath of contentDeclarationsPaths) {\n const result = await processContentDeclaration(contentDeclarationPath);\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;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAiC;AACjC,kBAAwB;AACxB,oBAAiC;AAEjC,+BAAqC;AACrC,2BAA0C;AAE1C,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,gBAAgB,IAAI;AAE5B,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,qBAAiB,qBAAQ,iBAAiB,cAAc;AAG9D,cAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,IACxD,CAAC;AAED,4BAAwB,KAAK,cAAc;AAAA,EAC7C;AAEA,SAAO;AACT;AAKO,MAAM,8BAA8B,OACzC,6BACG;AACH,QAAM,0BAAoC,CAAC;AAE3C,MAAI,OAAO,6BAA6B,UAAU;AAChD,+BAA2B,CAAC,wBAAwB;AAAA,EACtD;AAGA,YAAM,2BAAM,qBAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,mBAAiB,0BAA0B,0BAA0B;AACnE,UAAM,SAAS,UAAM,gDAA0B,sBAAsB;AAErE,QAAI,CAAC,QAAQ;AACX;AAAA,IACF;AAEA,UAAM,oBAAiC,+CAAqB,MAAM;AAElE,UAAM,oBAA8B,MAAM,gBAAgB,aAAa;AAEvE,4BAAwB,KAAK,GAAG,iBAAiB;AAAA,EACnD;AAEA,SAAO;AACT;","names":["content"]}
@@ -1,6 +0,0 @@
1
- /**
2
- * This function transpile the bundled code to to make dictionaries as JSON files
3
- */
4
- declare const transpileContentDeclaration: (contentDeclarationsPaths: string[] | string) => Promise<string[]>;
5
-
6
- export { transpileContentDeclaration };
@@ -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 { processContentDeclaration } from './processModule.mjs';
3
- export { transpileContentDeclaration } from './transpileContentDeclaration.mjs';
4
- import '@intlayer/core';
@@ -1,4 +0,0 @@
1
- export * from './extractNestedJSON.mjs';
2
- export * from './processModule.mjs';
3
- export * from './transpileContentDeclaration.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 './transpileContentDeclaration';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/loadContentDeclaration.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { createRequire } from 'module';\nimport { type Context, runInNewContext } from 'vm';\nimport type { ContentModule } from '@intlayer/core';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n console,\n require: isESModule ? createRequire(import.meta.url) : require,\n};\n\nconst transformationOption: BuildOptions = {\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n },\n format: 'cjs', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n};\n\nconst filterValidContentDeclaration = (\n contentDeclaration: ContentModule\n): ContentModule => {\n // @TODO Implement filtering of valid content declaration\n return contentDeclaration;\n};\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadContentDeclaration = (\n contentDeclarationFilePath: string\n): ContentModule | undefined => {\n let contentDeclaration: ContentModule | undefined = undefined;\n\n const fileExtension = contentDeclarationFilePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Assume JSON\n return require(contentDeclarationFilePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [contentDeclarationFilePath],\n\n ...transformationOption,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n runInNewContext(moduleResultString, sandboxContext);\n\n if (\n sandboxContext.exports.default &&\n Object.keys(sandboxContext.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports.default &&\n Object.keys(sandboxContext.module.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n contentDeclaration = sandboxContext.module.exports;\n }\n\n if (typeof contentDeclaration === 'undefined') {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n return filterValidContentDeclaration(contentDeclaration);\n } catch (error) {\n console.error('Error:', error);\n }\n};\n"],"mappings":"AACA,SAAS,qBAAqB;AAC9B,SAAuB,uBAAuB;AAE9C,SAA4B,iBAAmC;AAE/D,MAAM,aAAa,OAAO,YAAY,QAAQ;AAE9C,MAAM,iBAA0B;AAAA,EAC9B,SAAS;AAAA,IACP,SAAS,CAAC;AAAA,EACZ;AAAA,EACA,QAAQ;AAAA,IACN,SAAS,CAAC;AAAA,EACZ;AAAA,EACA;AAAA,EACA,SAAS,aAAa,cAAc,YAAY,GAAG,IAAI;AACzD;AAEA,MAAM,uBAAqC;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AAAA,EACA,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AACV;AAEA,MAAM,gCAAgC,CACpC,uBACkB;AAElB,SAAO;AACT;AAOO,MAAM,yBAAyB,CACpC,+BAC8B;AAC9B,MAAI,qBAAgD;AAEpD,QAAM,gBAAgB,2BAA2B,MAAM,GAAG,EAAE,IAAI,KAAK;AAErE,MAAI;AACF,QAAI,kBAAkB,QAAQ;AAE5B,aAAO,QAAQ,0BAA0B;AAAA,IAC3C;AAIA,UAAM,eAA4B,UAAU;AAAA,MAC1C,aAAa,CAAC,0BAA0B;AAAA,MAExC,GAAG;AAAA,IACL,CAAC;AAED,UAAM,qBAAqB,aAAa,cAAc,CAAC,EAAE;AAEzD,QAAI,CAAC,oBAAoB;AACvB,cAAQ,MAAM,yCAAyC;AACvD,aAAO;AAAA,IACT;AAEA,oBAAgB,oBAAoB,cAAc;AAElD,QACE,eAAe,QAAQ,WACvB,OAAO,KAAK,eAAe,QAAQ,OAAO,EAAE,SAAS,GACrD;AAEA,2BAAqB,eAAe,QAAQ;AAAA,IAC9C,WACE,eAAe,OAAO,QAAQ,YAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,QAAQ,EAAE,SAAS,GAC7D;AAEA,2BAAqB,eAAe,OAAO,QAAQ;AAAA,IACrD,WACE,eAAe,OAAO,QAAQ,WAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,OAAO,EAAE,SAAS,GAC5D;AAEA,2BAAqB,eAAe,OAAO,QAAQ;AAAA,IACrD,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,2BAAqB,eAAe,OAAO;AAAA,IAC7C;AAEA,QAAI,OAAO,uBAAuB,aAAa;AAC7C,cAAQ,MAAM,yCAAyC;AACvD,aAAO;AAAA,IACT;AAEA,WAAO,8BAA8B,kBAAkB;AAAA,EACzD,SAAS,OAAO;AACd,YAAQ,MAAM,UAAU,KAAK;AAAA,EAC/B;AACF;","names":[]}
@@ -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';\nimport { loadContentDeclaration } from './loadContentDeclaration';\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 processContentDeclaration = async (file: string) => {\n try {\n const functionPath = resolve(file);\n const entry = loadContentDeclaration(functionPath);\n\n if (!entry) {\n console.error('No entry found in module:', functionPath);\n return;\n }\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;AAOxB,SAAS,8BAA8B;AAKvC,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,4BAA4B,OAAO,SAAiB;AAC/D,MAAI;AACF,UAAM,eAAe,QAAQ,IAAI;AACjC,UAAM,QAAQ,uBAAuB,YAAY;AAEjD,QAAI,CAAC,OAAO;AACV,cAAQ,MAAM,6BAA6B,YAAY;AACvD;AAAA,IACF;AAEA,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 transpileContentDeclaration: (contentDeclarationsPaths: string[] | string) => Promise<string[]>;
5
-
6
- export { transpileContentDeclaration };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.ts"],"sourcesContent":["import { 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 { processContentDeclaration } from './processModule';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir } = content;\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 transpileContentDeclaration = async (\n contentDeclarationsPaths: string[] | string\n) => {\n const resultDictionariesPaths: string[] = [];\n\n if (typeof contentDeclarationsPaths === 'string') {\n contentDeclarationsPaths = [contentDeclarationsPaths];\n }\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n for await (const contentDeclarationPath of contentDeclarationsPaths) {\n const result = await processContentDeclaration(contentDeclarationPath);\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,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,wBAAwB;AAEjC,SAAS,4BAA4B;AACrC,SAAS,iCAAiC;AAE1C,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,gBAAgB,IAAI;AAE5B,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,8BAA8B,OACzC,6BACG;AACH,QAAM,0BAAoC,CAAC;AAE3C,MAAI,OAAO,6BAA6B,UAAU;AAChD,+BAA2B,CAAC,wBAAwB;AAAA,EACtD;AAGA,QAAM,MAAM,QAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,mBAAiB,0BAA0B,0BAA0B;AACnE,UAAM,SAAS,MAAM,0BAA0B,sBAAsB;AAErE,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,3 +0,0 @@
1
- export * from './extractNestedJSON';
2
- export * from './processModule';
3
- export * from './transpileContentDeclaration';