@intlayer/config 1.0.2 → 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 (152) hide show
  1. package/dist/cjs/client.cjs +2 -10
  2. package/dist/cjs/client.cjs.map +1 -1
  3. package/dist/cjs/client.d.ts +1 -1
  4. package/dist/cjs/configFile/buildConfigurationFields.cjs +295 -39
  5. package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
  6. package/dist/cjs/configFile/buildConfigurationFields.d.ts +3 -0
  7. package/dist/cjs/configFile/getConfiguration.cjs.map +1 -1
  8. package/dist/cjs/configFile/getConfiguration.d.ts +3 -0
  9. package/dist/cjs/configFile/index.cjs +3 -1
  10. package/dist/cjs/configFile/index.cjs.map +1 -1
  11. package/dist/cjs/configFile/index.d.ts +1 -0
  12. package/dist/cjs/configFile/loadConfigurationFile.cjs +8 -1
  13. package/dist/cjs/configFile/loadConfigurationFile.cjs.map +1 -1
  14. package/dist/cjs/configFile/loadConfigurationFile.d.ts +6 -0
  15. package/dist/cjs/configFile/searchConfigurationFile.cjs.map +1 -1
  16. package/dist/cjs/configFile/searchConfigurationFile.d.ts +11 -0
  17. package/dist/cjs/defaultValues/internationalization.cjs +1 -5
  18. package/dist/cjs/defaultValues/internationalization.cjs.map +1 -1
  19. package/dist/cjs/defaultValues/internationalization.d.ts +1 -1
  20. package/dist/cjs/defaultValues/server.cjs +15 -7
  21. package/dist/cjs/defaultValues/server.cjs.map +1 -1
  22. package/dist/cjs/defaultValues/server.d.ts +6 -3
  23. package/dist/cjs/envVariables/detectPlatform.cjs +56 -0
  24. package/dist/cjs/envVariables/detectPlatform.cjs.map +1 -0
  25. package/dist/cjs/envVariables/detectPlatform.d.ts +8 -0
  26. package/dist/cjs/envVariables/extractEnvVariable/index.cjs +44 -0
  27. package/dist/cjs/envVariables/extractEnvVariable/index.cjs.map +1 -0
  28. package/dist/cjs/envVariables/extractEnvVariable/index.d.ts +7 -0
  29. package/dist/cjs/envVariables/extractEnvVariable/next.cjs +70 -0
  30. package/dist/cjs/envVariables/extractEnvVariable/next.cjs.map +1 -0
  31. package/dist/cjs/envVariables/extractEnvVariable/next.d.ts +7 -0
  32. package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs +70 -0
  33. package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs.map +1 -0
  34. package/dist/cjs/envVariables/extractEnvVariable/react_app.d.ts +7 -0
  35. package/dist/cjs/envVariables/extractEnvVariable/types.cjs +17 -0
  36. package/dist/cjs/envVariables/extractEnvVariable/types.cjs.map +1 -0
  37. package/dist/cjs/envVariables/extractEnvVariable/types.d.ts +11 -0
  38. package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs +70 -0
  39. package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs.map +1 -0
  40. package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.d.ts +7 -0
  41. package/dist/cjs/envVariables/extractEnvVariable/vite.cjs +78 -0
  42. package/dist/cjs/envVariables/extractEnvVariable/vite.cjs.map +1 -0
  43. package/dist/cjs/envVariables/extractEnvVariable/vite.d.ts +7 -0
  44. package/dist/cjs/envVariables/extractEnvVariable/vite_env.d.cjs +2 -0
  45. package/dist/cjs/envVariables/extractEnvVariable/vite_env.d.cjs.map +1 -0
  46. package/dist/cjs/envVariables/extractEnvVariable/vite_env.d.d.ts +2 -0
  47. package/dist/cjs/envVariables/formatEnvVariable.cjs +6 -4
  48. package/dist/cjs/envVariables/formatEnvVariable.cjs.map +1 -1
  49. package/dist/cjs/envVariables/formatEnvVariable.d.ts +6 -1
  50. package/dist/cjs/envVariables/getConfiguration.cjs +79 -116
  51. package/dist/cjs/envVariables/getConfiguration.cjs.map +1 -1
  52. package/dist/cjs/envVariables/getConfiguration.d.ts +7 -6
  53. package/dist/cjs/envVariables/index.cjs +2 -10
  54. package/dist/cjs/envVariables/index.cjs.map +1 -1
  55. package/dist/cjs/envVariables/index.d.ts +2 -1
  56. package/dist/cjs/envVariables/utils.cjs +7 -6
  57. package/dist/cjs/envVariables/utils.cjs.map +1 -1
  58. package/dist/cjs/envVariables/utils.d.ts +5 -5
  59. package/dist/cjs/index.cjs +2 -10
  60. package/dist/cjs/index.cjs.map +1 -1
  61. package/dist/cjs/index.d.ts +2 -1
  62. package/dist/cjs/types/config.cjs.map +1 -1
  63. package/dist/cjs/types/config.d.ts +253 -7
  64. package/dist/cjs/types/locales.cjs.map +1 -1
  65. package/dist/cjs/types/locales.d.ts +233 -0
  66. package/dist/esm/client.d.mts +1 -1
  67. package/dist/esm/client.mjs +2 -12
  68. package/dist/esm/client.mjs.map +1 -1
  69. package/dist/esm/configFile/buildConfigurationFields.d.mts +3 -0
  70. package/dist/esm/configFile/buildConfigurationFields.mjs +298 -42
  71. package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
  72. package/dist/esm/configFile/getConfiguration.d.mts +3 -0
  73. package/dist/esm/configFile/getConfiguration.mjs.map +1 -1
  74. package/dist/esm/configFile/index.d.mts +1 -0
  75. package/dist/esm/configFile/index.mjs +1 -0
  76. package/dist/esm/configFile/index.mjs.map +1 -1
  77. package/dist/esm/configFile/loadConfigurationFile.d.mts +6 -0
  78. package/dist/esm/configFile/loadConfigurationFile.mjs +8 -1
  79. package/dist/esm/configFile/loadConfigurationFile.mjs.map +1 -1
  80. package/dist/esm/configFile/searchConfigurationFile.d.mts +11 -0
  81. package/dist/esm/configFile/searchConfigurationFile.mjs.map +1 -1
  82. package/dist/esm/defaultValues/internationalization.d.mts +1 -1
  83. package/dist/esm/defaultValues/internationalization.mjs +1 -5
  84. package/dist/esm/defaultValues/internationalization.mjs.map +1 -1
  85. package/dist/esm/defaultValues/server.d.mts +6 -3
  86. package/dist/esm/defaultValues/server.mjs +13 -5
  87. package/dist/esm/defaultValues/server.mjs.map +1 -1
  88. package/dist/esm/envVariables/detectPlatform.d.mts +8 -0
  89. package/dist/esm/envVariables/detectPlatform.mjs +30 -0
  90. package/dist/esm/envVariables/detectPlatform.mjs.map +1 -0
  91. package/dist/esm/envVariables/extractEnvVariable/index.d.mts +7 -0
  92. package/dist/esm/envVariables/extractEnvVariable/index.mjs +20 -0
  93. package/dist/esm/envVariables/extractEnvVariable/index.mjs.map +1 -0
  94. package/dist/esm/envVariables/extractEnvVariable/next.d.mts +7 -0
  95. package/dist/esm/envVariables/extractEnvVariable/next.mjs +46 -0
  96. package/dist/esm/envVariables/extractEnvVariable/next.mjs.map +1 -0
  97. package/dist/esm/envVariables/extractEnvVariable/react_app.d.mts +7 -0
  98. package/dist/esm/envVariables/extractEnvVariable/react_app.mjs +46 -0
  99. package/dist/esm/envVariables/extractEnvVariable/react_app.mjs.map +1 -0
  100. package/dist/esm/envVariables/extractEnvVariable/types.d.mts +11 -0
  101. package/dist/esm/envVariables/extractEnvVariable/types.mjs +1 -0
  102. package/dist/esm/envVariables/extractEnvVariable/types.mjs.map +1 -0
  103. package/dist/esm/envVariables/extractEnvVariable/undefined_platform.d.mts +7 -0
  104. package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs +46 -0
  105. package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs.map +1 -0
  106. package/dist/esm/envVariables/extractEnvVariable/vite.d.mts +7 -0
  107. package/dist/esm/envVariables/extractEnvVariable/vite.mjs +53 -0
  108. package/dist/esm/envVariables/extractEnvVariable/vite.mjs.map +1 -0
  109. package/dist/esm/envVariables/extractEnvVariable/vite_env.d.d.mts +2 -0
  110. package/dist/esm/envVariables/extractEnvVariable/vite_env.d.mjs +1 -0
  111. package/dist/esm/envVariables/extractEnvVariable/vite_env.d.mjs.map +1 -0
  112. package/dist/esm/envVariables/formatEnvVariable.d.mts +6 -1
  113. package/dist/esm/envVariables/formatEnvVariable.mjs +6 -4
  114. package/dist/esm/envVariables/formatEnvVariable.mjs.map +1 -1
  115. package/dist/esm/envVariables/getConfiguration.d.mts +7 -6
  116. package/dist/esm/envVariables/getConfiguration.mjs +78 -111
  117. package/dist/esm/envVariables/getConfiguration.mjs.map +1 -1
  118. package/dist/esm/envVariables/index.d.mts +2 -1
  119. package/dist/esm/envVariables/index.mjs +2 -12
  120. package/dist/esm/envVariables/index.mjs.map +1 -1
  121. package/dist/esm/envVariables/utils.d.mts +5 -5
  122. package/dist/esm/envVariables/utils.mjs +7 -6
  123. package/dist/esm/envVariables/utils.mjs.map +1 -1
  124. package/dist/esm/index.d.mts +2 -1
  125. package/dist/esm/index.mjs +1 -9
  126. package/dist/esm/index.mjs.map +1 -1
  127. package/dist/esm/types/config.d.mts +253 -7
  128. package/dist/esm/types/locales.d.mts +233 -0
  129. package/dist/esm/types/locales.mjs.map +1 -1
  130. package/package.json +7 -7
  131. package/src/client.ts +1 -7
  132. package/src/configFile/buildConfigurationFields.ts +306 -46
  133. package/src/configFile/getConfiguration.ts +3 -0
  134. package/src/configFile/index.ts +1 -0
  135. package/src/configFile/loadConfigurationFile.ts +19 -1
  136. package/src/configFile/searchConfigurationFile.ts +11 -0
  137. package/src/defaultValues/server.ts +14 -4
  138. package/src/envVariables/detectPlatform.ts +41 -0
  139. package/src/envVariables/extractEnvVariable/index.ts +20 -0
  140. package/src/envVariables/extractEnvVariable/next.ts +57 -0
  141. package/src/envVariables/extractEnvVariable/react_app.ts +57 -0
  142. package/src/envVariables/extractEnvVariable/types.ts +10 -0
  143. package/src/envVariables/extractEnvVariable/undefined_platform.ts +52 -0
  144. package/src/envVariables/extractEnvVariable/vite.ts +65 -0
  145. package/src/envVariables/extractEnvVariable/vite_env.d.ts +9 -0
  146. package/src/envVariables/formatEnvVariable.ts +17 -11
  147. package/src/envVariables/getConfiguration.ts +85 -113
  148. package/src/envVariables/index.ts +1 -7
  149. package/src/envVariables/utils.ts +30 -14
  150. package/src/index.ts +0 -4
  151. package/src/types/config.ts +279 -63
  152. package/src/types/locales.ts +233 -233
@@ -19,11 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var client_exports = {};
20
20
  __export(client_exports, {
21
21
  Locales: () => import_locales.Locales,
22
- getConfiguration: () => import_getConfiguration.getConfiguration,
23
- intlayerConfiguration: () => import_getConfiguration.intlayerConfiguration,
24
- intlayerContentConfiguration: () => import_getConfiguration.intlayerContentConfiguration,
25
- intlayerIntlConfiguration: () => import_getConfiguration.intlayerIntlConfiguration,
26
- intlayerMiddlewareConfiguration: () => import_getConfiguration.intlayerMiddlewareConfiguration
22
+ getConfiguration: () => import_getConfiguration.getConfiguration
27
23
  });
28
24
  module.exports = __toCommonJS(client_exports);
29
25
  var import_locales = require('./types/locales.cjs');
@@ -31,10 +27,6 @@ var import_getConfiguration = require('./envVariables/getConfiguration.cjs');
31
27
  // Annotate the CommonJS export names for ESM import in node:
32
28
  0 && (module.exports = {
33
29
  Locales,
34
- getConfiguration,
35
- intlayerConfiguration,
36
- intlayerContentConfiguration,
37
- intlayerIntlConfiguration,
38
- intlayerMiddlewareConfiguration
30
+ getConfiguration
39
31
  });
40
32
  //# sourceMappingURL=client.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/client.ts"],"sourcesContent":["export type {\n CustomIntlayerConfig,\n PatternsContentConfig as FixedIntlayerConfig,\n IntlayerConfig,\n BaseContentConfig as NotDerivedConfiguration,\n BaseDerivedConfig as BaseDirDerivedConfiguration,\n ResultDirDerivedConfig as ResultDirDerivedConfiguration,\n} from './types/config';\nexport type { LocalesValues } from './types/locales';\nexport { Locales } from './types/locales';\nexport {\n getConfiguration,\n intlayerConfiguration,\n intlayerContentConfiguration,\n intlayerIntlConfiguration,\n intlayerMiddlewareConfiguration,\n} from './envVariables/getConfiguration';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,qBAAwB;AACxB,8BAMO;","names":[]}
1
+ {"version":3,"sources":["../../src/client.ts"],"sourcesContent":["export type {\n CustomIntlayerConfig,\n PatternsContentConfig as FixedIntlayerConfig,\n IntlayerConfig,\n BaseContentConfig as NotDerivedConfiguration,\n BaseDerivedConfig as BaseDirDerivedConfiguration,\n ResultDirDerivedConfig as ResultDirDerivedConfiguration,\n} from './types/config';\nexport type { LocalesValues } from './types/locales';\nexport { Locales } from './types/locales';\nexport { getConfiguration } from './envVariables/getConfiguration';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,qBAAwB;AACxB,8BAAiC;","names":[]}
@@ -1,3 +1,3 @@
1
1
  export { BaseDerivedConfig as BaseDirDerivedConfiguration, CustomIntlayerConfig, PatternsContentConfig as FixedIntlayerConfig, IntlayerConfig, BaseContentConfig as NotDerivedConfiguration, ResultDirDerivedConfig as ResultDirDerivedConfiguration } from './types/config.js';
2
2
  export { Locales, LocalesValues } from './types/locales.js';
3
- export { getConfiguration, intlayerConfiguration, intlayerContentConfiguration, intlayerIntlConfiguration, intlayerMiddlewareConfiguration } from './envVariables/getConfiguration.js';
3
+ export { getConfiguration } from './envVariables/getConfiguration.js';
@@ -28,107 +28,363 @@ var import_server = require('../defaultValues/server.cjs');
28
28
  let storedConfiguration;
29
29
  const buildInternationalizationFields = (customConfiguration) => ({
30
30
  /**
31
- * Internationalization configuration
31
+ * Locales available in the application
32
+ *
33
+ * Default: ['en']
34
+ *
32
35
  */
33
- // Locales available in the application
34
36
  locales: customConfiguration?.locales ?? import_internationalization.LOCALES,
35
- // Default locale of the application for fallback
37
+ /**
38
+ * Default locale of the application for fallback
39
+ *
40
+ * Default: 'en'
41
+ */
36
42
  defaultLocale: customConfiguration?.defaultLocale ?? import_internationalization.DEFAULT_LOCALE
37
43
  });
38
44
  const buildMiddlewareFields = (customConfiguration) => ({
39
45
  /**
40
- * Middleware configuration
46
+ * Header name to get the locale
47
+ *
48
+ * Default: 'x-intlayer-locale'
41
49
  */
42
- // Header name to get the locale
43
50
  headerName: customConfiguration?.headerName ?? import_middleware.HEADER_NAME,
44
- // Cookie name to get the locale
51
+ /**
52
+ * Cookie name to get the locale
53
+ *
54
+ * Default: 'intlayer-locale'
55
+ */
45
56
  cookieName: customConfiguration?.cookieName ?? import_middleware.COOKIE_NAME,
46
- // Prefix the default locale in the URL
57
+ /**
58
+ * Prefix the default locale in the URL
59
+ *
60
+ * Default: true
61
+ */
47
62
  prefixDefault: customConfiguration?.prefixDefault ?? import_middleware.PREFIX_DEFAULT,
48
- // Base path
63
+ /**
64
+ * Base path of the application URL
65
+ *
66
+ * Default: ''
67
+ *
68
+ * Example:
69
+ * - If the application is hosted at https://example.com/my-app
70
+ * - The base path is '/my-app'
71
+ * - The URL will be https://example.com/my-app/en
72
+ * - If the base path is not set, the URL will be https://example.com/en
73
+ */
49
74
  basePath: customConfiguration?.basePath ?? import_middleware.BASE_PATH,
50
- // Set cookie on server
75
+ /**
76
+ * Rule to set the cookie on the server
77
+ * - 'always': Set the cookie on every request
78
+ * - 'never': Never set the cookie
79
+ */
51
80
  serverSetCookie: customConfiguration?.serverSetCookie ?? import_middleware.SERVER_SET_COOKIE,
52
- // No prefix
81
+ /**
82
+ * No prefix in the URL
83
+ * - true: No prefix in the URL
84
+ * - false: Prefix in the URL
85
+ *
86
+ * Example:
87
+ * - If the application is hosted at https://example.com/my-app
88
+ * - The base path is '/my-app'
89
+ * - The URL will be https://example.com/my-app/en
90
+ * - If the base path is not set, the URL will be https://example.com/en
91
+ * - If no prefix is set, the URL will be https://example.com/en
92
+ * - If the no prefix is set to true, the URL will be https://example.com
93
+ *
94
+ * Default: false
95
+ */
53
96
  noPrefix: customConfiguration?.noPrefix ?? import_middleware.NO_PREFIX
54
97
  });
55
98
  const buildContentFields = (customConfiguration) => {
56
99
  const notDerivedContentConfig = {
57
100
  /**
58
- * Content configurations
101
+ * File extensions of content to look for to build the dictionaries
102
+ *
103
+ * - Default: ['.content.ts', '.content.js', '.content.cjs', '.content.mjs', '.content.json', '.content.tsx', '.content.jsx']
104
+ *
105
+ * - Example: ['.data.ts', '.data.js', '.data.json']
106
+ *
107
+ * Note:
108
+ * - Can exclude unused file extensions to improve performance
109
+ * - Avoid using common file extensions like '.ts', '.js', '.json' to avoid conflicts
59
110
  */
60
- // File extensions of content to look for
61
111
  fileExtensions: customConfiguration?.fileExtensions ?? import_server.FILE_EXTENSIONS,
62
- // Directory name of the project
112
+ /**
113
+ * Absolute path of the directory of the project
114
+ * - Default: process.cwd()
115
+ * - Example: '/path/to/project'
116
+ *
117
+ * Will be used to resolve all intlayer directories
118
+ *
119
+ * Note:
120
+ * - The base directory should be the root of the project
121
+ * - Can be changed to a custom directory to externalize either the content used in the project, or the intlayer application from the project
122
+ */
63
123
  baseDir: customConfiguration?.baseDir ?? process.cwd(),
64
- // Directory name where the content is stored
124
+ /**
125
+ * Directory name where the content is stored
126
+ *
127
+ * Default: 'src'
128
+ *
129
+ * Example:
130
+ * - 'data' -> '/path/to/project/data'
131
+ * - 'content' -> '/path/to/project/content'
132
+ * - 'locales' -> '/path/to/project/locales'
133
+ *
134
+ * Note: If this directory is not at the base directory level, update the contentDir field instead
135
+ */
65
136
  contentDirName: customConfiguration?.contentDirName ?? import_server.CONTENT_DIR_NAME,
66
- // Result directory name
137
+ /**
138
+ * Directory name where the result will be stored
139
+ *
140
+ * Default: '.intlayer'
141
+ *
142
+ * Example:
143
+ * - '.next'
144
+ * - 'outputOFIntlayer'
145
+ *
146
+ * Note: If this directory is not at the base directory level, update the resultDir field instead
147
+ */
67
148
  resultDirName: customConfiguration?.resultDirName ?? import_server.RESULT_DIR_NAME,
68
- // Module augmentation directory name
149
+ /**
150
+ *
151
+ * Directory name where the module augmentation will be stored
152
+ *
153
+ * Module augmentation allow better IDE suggestions and type checking
154
+ *
155
+ * Default: 'types'
156
+ *
157
+ * Example: 'intlayer-types'
158
+ *
159
+ * Note:
160
+ * - If this path changed, be sure to include it from the tsconfig.json file
161
+ * - If this directory is not at the base directory level, update the moduleAugmentationDir field instead
162
+ */
69
163
  moduleAugmentationDirName: customConfiguration?.moduleAugmentationDirName ?? import_server.MODULE_AUGMENTATION_DIR_NAME,
70
- // Bundle directory name
71
- bundleDirName: customConfiguration?.bundleDirName ?? import_server.BUNDLE_DIR_NAME,
72
- // Bundle file extension
73
- bundleFileExtension: customConfiguration?.bundleFileExtension ?? import_server.BUNDLE_FILE_EXTENSION,
74
- // Dictionary directory name
164
+ // @TODO: Make Module Augmentation optional by adding a flag in the configuration
165
+ /**
166
+ * Related to the intlayer result directory
167
+ *
168
+ * Directory name where the dictionaries will be stored
169
+ *
170
+ * Default: 'dictionary'
171
+ *
172
+ * Example: 'translations'
173
+ *
174
+ * Note:
175
+ * - If this directory is not at the result directory level, update the dictionariesDir field instead
176
+ *
177
+ */
75
178
  dictionariesDirName: customConfiguration?.dictionariesDirName ?? import_server.DICTIONARIES_DIR_NAME,
76
- // Types directory name
179
+ /**
180
+ * Related to the intlayer result directory
181
+ *
182
+ * Directory name where the dictionaries will be stored
183
+ *
184
+ * Default: 'dictionary'
185
+ *
186
+ * Example: 'translations'
187
+ *
188
+ * Note:
189
+ * - If this directory is not at the result directory level, update the dictionariesDir field instead
190
+ *
191
+ */
192
+ i18nDictionariesDirName: customConfiguration?.i18nDictionariesDirName ?? import_server.I18N_DICTIONARIES_DIR_NAME,
193
+ /**
194
+ * Related to the intlayer result directory
195
+ *
196
+ * Directory name where the dictionaries types will be stored
197
+ *
198
+ * Default: 'types'
199
+ *
200
+ * Example: 'intlayer-types'
201
+ *
202
+ * Note:
203
+ * - If this directory is not at the result directory level, update the typesDir field instead
204
+ *
205
+ */
77
206
  typeDirName: customConfiguration?.typeDirName ?? import_server.TYPES_DIR_NAME,
78
- // Main directory name
207
+ /**
208
+ * Related to the intlayer result directory
209
+ *
210
+ * Directory name where the main files will be stored
211
+ *
212
+ * Default: 'main'
213
+ *
214
+ * Example: 'intlayer-main'
215
+ *
216
+ * Note:
217
+ * - If this directory is not at the result directory level, update the mainDir field instead
218
+ */
79
219
  mainDirName: customConfiguration?.mainDirName ?? import_server.MAIN_DIR_NAME,
80
- // Directories to exclude
220
+ /**
221
+ * Should exclude some directories from the content search
222
+ *
223
+ * Default: ['node_modules']
224
+ *
225
+ * Not used yet
226
+ * @TODO Implement the exclusion or remove it
227
+ */
81
228
  excludedPath: customConfiguration?.excludedPath ?? import_server.EXCLUDED_PATHS
82
229
  };
83
230
  const baseDirDerivedConfiguration = {
84
- // Directory where the content is stored
231
+ /**
232
+ * Directory where the content is stored
233
+ *
234
+ * Relative to the base directory of the project
235
+ *
236
+ * Default: {{baseDir}} / {{contentDirName}}
237
+ *
238
+ * Example: '/path/to/project/src'
239
+ *
240
+ * Note:
241
+ * - Can be changed to a custom directory to externalize the content used in the project
242
+ * - If the content is not at the base directory level, update the contentDirName field instead
243
+ */
85
244
  contentDir: (0, import_path.join)(
86
245
  notDerivedContentConfig.baseDir,
87
246
  notDerivedContentConfig.contentDirName
88
247
  ),
89
- // Directory where the result will be stored
248
+ /**
249
+ * Directory where the result will be stored
250
+ *
251
+ * Relative to the base directory of the project
252
+ *
253
+ * Default: {{baseDir}} / {{resultDirName}}
254
+ *
255
+ * Example: '/path/to/project/.intlayer'
256
+ *
257
+ * Note:
258
+ * - Can be changed to a custom directory to externalize the intlayer application from the project
259
+ * - If the result is not at the base directory level, update the resultDirName field instead
260
+ */
90
261
  resultDir: (0, import_path.join)(
91
262
  notDerivedContentConfig.baseDir,
92
263
  notDerivedContentConfig.resultDirName
93
264
  ),
94
- // Directory where the module augmentation will be stored
265
+ /**
266
+ * Directory where the module augmentation will be stored
267
+ *
268
+ * Module augmentation allow better IDE suggestions and type checking
269
+ *
270
+ * Relative to the base directory of the project
271
+ *
272
+ * Default: {{baseDir}} / {{moduleAugmentationDirName}}
273
+ *
274
+ * Example: '/path/to/project/types'
275
+ *
276
+ * Note:
277
+ * - If this path changed, be sure to include it from the tsconfig.json file
278
+ * - If the module augmentation is not at the base directory level, update the moduleAugmentationDirName field instead
279
+ *
280
+ */
95
281
  moduleAugmentationDir: (0, import_path.join)(
96
282
  notDerivedContentConfig.baseDir,
97
283
  notDerivedContentConfig.moduleAugmentationDirName
98
- )
284
+ ),
285
+ /**
286
+ * Output format of the dictionary
287
+ *
288
+ * Default: ['intlayer']
289
+ *
290
+ * Note:
291
+ * - 'i18next' is not yet ensure a 1:1 mapping with the i18next library.
292
+ * - Removing 'intlayer' will break the compatibility with react-intlayer or next-intlayer
293
+ */
294
+ dictionaryOutput: customConfiguration?.dictionaryOutput ?? import_server.DICTIONARY_OUTPUT
99
295
  };
100
296
  const resultDirDerivedConfiguration = {
101
- // Directory where the bundle will be stored
102
- bundleDir: (0, import_path.join)(
103
- baseDirDerivedConfiguration.resultDir,
104
- notDerivedContentConfig.bundleDirName
105
- ),
106
- // Directory where the dictionaries will be stored
297
+ /**
298
+ * Directory where the dictionaries will be stored
299
+ *
300
+ * Relative to the result directory
301
+ *
302
+ * Default: {{resultDir}} / {{dictionariesDirName}}
303
+ *
304
+ * Example: '/path/to/project/.intlayer/dictionary'
305
+ *
306
+ * Note:
307
+ * - If the types are not at the result directory level, update the dictionariesDirName field instead
308
+ * - The dictionaries are stored in JSON format
309
+ * - The dictionaries are used to translate the content
310
+ * - The dictionaries are built from the content files
311
+ */
107
312
  dictionariesDir: (0, import_path.join)(
108
313
  baseDirDerivedConfiguration.resultDir,
109
314
  notDerivedContentConfig.dictionariesDirName
110
315
  ),
111
- // Directory where the types will be stored
316
+ /**
317
+ * Directory where the 18n dictionaries will be stored
318
+ *
319
+ * Relative to the result directory
320
+ *
321
+ * Default: {{resultDir}} / {{i18nDictionariesDirName}}
322
+ *
323
+ * Example: '/path/to/project/.intlayer/dictionary/i18n'
324
+ *
325
+ * Note:
326
+ * - If the types are not at the result directory level, update the i18nDictionariesDirName field instead
327
+ */
328
+ i18nDictionariesDir: (0, import_path.join)(
329
+ baseDirDerivedConfiguration.resultDir,
330
+ notDerivedContentConfig.i18nDictionariesDirName
331
+ ),
332
+ /**
333
+ * Directory where the dictionaries types will be stored
334
+ *
335
+ * Relative to the result directory
336
+ *
337
+ * Default: {{resultDir}} / {{typeDirName}}
338
+ *
339
+ * Example: '/path/to/project/.intlayer/types'
340
+ *
341
+ * Note:
342
+ * - If the types are not at the result directory level, update the typesDirName field instead
343
+ */
112
344
  typesDir: (0, import_path.join)(
113
345
  baseDirDerivedConfiguration.resultDir,
114
346
  notDerivedContentConfig.typeDirName
115
347
  ),
116
- // Directory where the main files will be stored
348
+ /**
349
+ * Directory where the main files will be stored
350
+ *
351
+ * Relative to the result directory
352
+ *
353
+ * Default: {{resultDir}} / {{mainDirName}}
354
+ *
355
+ * Example: '/path/to/project/.intlayer/main'
356
+ *
357
+ * Note:
358
+ *
359
+ * - If the main files are not at the result directory level, update the mainDirName field instead
360
+ */
117
361
  mainDir: (0, import_path.join)(
118
362
  baseDirDerivedConfiguration.resultDir,
119
363
  notDerivedContentConfig.mainDirName
120
364
  )
121
365
  };
122
366
  const patternsConfiguration = {
123
- // Pattern of files to watch
367
+ /**
368
+ * Pattern of files to watch
369
+ *
370
+ * Default: ['/**\/*.content.ts', '/**\/*.content.js', '/**\/*.content.json', '/**\/*.content.cjs', '/**\/*.content.mjs', '/**\/*.content.tsx', '/**\/*.content.jsx']
371
+ */
124
372
  watchedFilesPattern: notDerivedContentConfig.fileExtensions.map(
125
373
  (ext) => `/**/*${ext}`
126
374
  ),
127
- // Pattern of files to watch including the relative path
375
+ /**
376
+ * Pattern of files to watch including the relative path
377
+ *
378
+ * Default: ['{{contentDir}}/**\/*.content.ts', '{{contentDir}}/**\/*.content.js', '{{contentDir}}/**\/*.content.json', '{{contentDir}}/**\/*.content.cjs', '{{contentDir}}/**\/*.content.mjs', '{{contentDir}}/**\/*.content.tsx', '{{contentDir}}/**\/*.content.jsx']
379
+ */
128
380
  watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.map(
129
381
  (ext) => `${baseDirDerivedConfiguration.contentDir}/**/*${ext}`
130
382
  ),
131
- // Pattern of files to output
383
+ /**
384
+ * Pattern of dictionary to interpret
385
+ *
386
+ * Default: '{{dictionariesDir}}/**\/*.json'
387
+ */
132
388
  outputFilesPatternWithPath: `${resultDirDerivedConfiguration.dictionariesDir}/**/*.json`
133
389
  };
134
390
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/configFile/buildConfigurationFields.ts"],"sourcesContent":["import { join } from 'path';\nimport { DEFAULT_LOCALE, LOCALES } from '../defaultValues/internationalization';\nimport {\n BASE_PATH,\n COOKIE_NAME,\n HEADER_NAME,\n NO_PREFIX,\n PREFIX_DEFAULT,\n SERVER_SET_COOKIE,\n} from '../defaultValues/middleware';\nimport {\n BUNDLE_DIR_NAME,\n CONTENT_DIR_NAME,\n DICTIONARIES_DIR_NAME,\n FILE_EXTENSIONS,\n RESULT_DIR_NAME,\n EXCLUDED_PATHS,\n BUNDLE_FILE_EXTENSION,\n TYPES_DIR_NAME,\n MAIN_DIR_NAME,\n MODULE_AUGMENTATION_DIR_NAME,\n} from '../defaultValues/server';\nimport type {\n BaseDerivedConfig,\n ContentConfig,\n CustomIntlayerConfig,\n PatternsContentConfig,\n InternationalizationConfig,\n IntlayerConfig,\n MiddlewareConfig,\n BaseContentConfig,\n ResultDirDerivedConfig,\n} from '../types/config';\nimport type { GetConfigurationOptions } from './getConfiguration';\n\nlet storedConfiguration: IntlayerConfig;\n\nconst buildInternationalizationFields = (\n customConfiguration?: Partial<InternationalizationConfig>\n): InternationalizationConfig => ({\n /**\n * Internationalization configuration\n */\n\n // Locales available in the application\n locales: customConfiguration?.locales ?? LOCALES,\n\n // Default locale of the application for fallback\n defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,\n});\n\nconst buildMiddlewareFields = (\n customConfiguration?: Partial<MiddlewareConfig>\n): MiddlewareConfig => ({\n /**\n * Middleware configuration\n */\n\n // Header name to get the locale\n headerName: customConfiguration?.headerName ?? HEADER_NAME,\n\n // Cookie name to get the locale\n cookieName: customConfiguration?.cookieName ?? COOKIE_NAME,\n\n // Prefix the default locale in the URL\n prefixDefault: customConfiguration?.prefixDefault ?? PREFIX_DEFAULT,\n\n // Base path\n basePath: customConfiguration?.basePath ?? BASE_PATH,\n\n // Set cookie on server\n serverSetCookie: customConfiguration?.serverSetCookie ?? SERVER_SET_COOKIE,\n\n // No prefix\n noPrefix: customConfiguration?.noPrefix ?? NO_PREFIX,\n});\n\nconst buildContentFields = (\n customConfiguration?: Partial<ContentConfig>\n): ContentConfig => {\n const notDerivedContentConfig: BaseContentConfig = {\n /**\n * Content configurations\n */\n\n // File extensions of content to look for\n fileExtensions: customConfiguration?.fileExtensions ?? FILE_EXTENSIONS,\n\n // Directory name of the project\n baseDir: customConfiguration?.baseDir ?? process.cwd(),\n\n // Directory name where the content is stored\n contentDirName: customConfiguration?.contentDirName ?? CONTENT_DIR_NAME,\n\n // Result directory name\n resultDirName: customConfiguration?.resultDirName ?? RESULT_DIR_NAME,\n\n // Module augmentation directory name\n moduleAugmentationDirName:\n customConfiguration?.moduleAugmentationDirName ??\n MODULE_AUGMENTATION_DIR_NAME,\n\n // Bundle directory name\n bundleDirName: customConfiguration?.bundleDirName ?? BUNDLE_DIR_NAME,\n\n // Bundle file extension\n bundleFileExtension:\n customConfiguration?.bundleFileExtension ?? BUNDLE_FILE_EXTENSION,\n\n // Dictionary directory name\n dictionariesDirName:\n customConfiguration?.dictionariesDirName ?? DICTIONARIES_DIR_NAME,\n\n // Types directory name\n typeDirName: customConfiguration?.typeDirName ?? TYPES_DIR_NAME,\n\n // Main directory name\n mainDirName: customConfiguration?.mainDirName ?? MAIN_DIR_NAME,\n\n // Directories to exclude\n excludedPath: customConfiguration?.excludedPath ?? EXCLUDED_PATHS,\n };\n\n const baseDirDerivedConfiguration: BaseDerivedConfig = {\n // Directory where the content is stored\n contentDir: join(\n notDerivedContentConfig.baseDir,\n notDerivedContentConfig.contentDirName\n ),\n\n // Directory where the result will be stored\n resultDir: join(\n notDerivedContentConfig.baseDir,\n notDerivedContentConfig.resultDirName\n ),\n\n // Directory where the module augmentation will be stored\n moduleAugmentationDir: join(\n notDerivedContentConfig.baseDir,\n notDerivedContentConfig.moduleAugmentationDirName\n ),\n };\n\n const resultDirDerivedConfiguration: ResultDirDerivedConfig = {\n // Directory where the bundle will be stored\n bundleDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.bundleDirName\n ),\n\n // Directory where the dictionaries will be stored\n dictionariesDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.dictionariesDirName\n ),\n\n // Directory where the types will be stored\n typesDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.typeDirName\n ),\n\n // Directory where the main files will be stored\n mainDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.mainDirName\n ),\n };\n\n const patternsConfiguration: PatternsContentConfig = {\n // Pattern of files to watch\n watchedFilesPattern: notDerivedContentConfig.fileExtensions.map(\n (ext) => `/**/*${ext}`\n ),\n\n // Pattern of files to watch including the relative path\n watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.map(\n (ext) => `${baseDirDerivedConfiguration.contentDir}/**/*${ext}`\n ),\n\n // Pattern of files to output\n outputFilesPatternWithPath: `${resultDirDerivedConfiguration.dictionariesDir}/**/*.json`,\n };\n\n return {\n ...notDerivedContentConfig,\n ...baseDirDerivedConfiguration,\n ...resultDirDerivedConfiguration,\n ...patternsConfiguration,\n };\n};\n\nexport const buildConfigurationFields = (\n options: GetConfigurationOptions,\n customConfiguration?: CustomIntlayerConfig\n): IntlayerConfig => {\n const internationalizationConfig = buildInternationalizationFields(\n customConfiguration?.internationalization\n );\n\n const middlewareConfig = buildMiddlewareFields(\n customConfiguration?.middleware\n );\n\n const contentConfig = buildContentFields(customConfiguration?.content);\n\n storedConfiguration = {\n internationalization: internationalizationConfig,\n middleware: middlewareConfig,\n content: contentConfig,\n };\n\n return storedConfiguration;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AACrB,kCAAwC;AACxC,wBAOO;AACP,oBAWO;AAcP,IAAI;AAEJ,MAAM,kCAAkC,CAC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B;AAAA,EACF;AAEA,QAAM,gCAAwD;AAAA;AAAA,IAE5D,eAAW;AAAA,MACT,4BAA4B;AAAA,MAC5B,wBAAwB;AAAA,IAC1B;AAAA;AAAA,IAGA,qBAAiB;AAAA,MACf,4BAA4B;AAAA,MAC5B,wBAAwB;AAAA,IAC1B;AAAA;AAAA,IAGA,cAAU;AAAA,MACR,4BAA4B;AAAA,MAC5B,wBAAwB;AAAA,IAC1B;AAAA;AAAA,IAGA,aAAS;AAAA,MACP,4BAA4B;AAAA,MAC5B,wBAAwB;AAAA,IAC1B;AAAA,EACF;AAEA,QAAM,wBAA+C;AAAA;AAAA,IAEnD,qBAAqB,wBAAwB,eAAe;AAAA,MAC1D,CAAC,QAAQ,QAAQ,GAAG;AAAA,IACtB;AAAA;AAAA,IAGA,6BAA6B,wBAAwB,eAAe;AAAA,MAClE,CAAC,QAAQ,GAAG,4BAA4B,UAAU,QAAQ,GAAG;AAAA,IAC/D;AAAA;AAAA,IAGA,4BAA4B,GAAG,8BAA8B,eAAe;AAAA,EAC9E;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;AAEO,MAAM,2BAA2B,CACtC,SACA,wBACmB;AACnB,QAAM,6BAA6B;AAAA,IACjC,qBAAqB;AAAA,EACvB;AAEA,QAAM,mBAAmB;AAAA,IACvB,qBAAqB;AAAA,EACvB;AAEA,QAAM,gBAAgB,mBAAmB,qBAAqB,OAAO;AAErE,wBAAsB;AAAA,IACpB,sBAAsB;AAAA,IACtB,YAAY;AAAA,IACZ,SAAS;AAAA,EACX;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/configFile/buildConfigurationFields.ts"],"sourcesContent":["import { join } from 'path';\nimport { DEFAULT_LOCALE, LOCALES } from '../defaultValues/internationalization';\nimport {\n BASE_PATH,\n COOKIE_NAME,\n HEADER_NAME,\n NO_PREFIX,\n PREFIX_DEFAULT,\n SERVER_SET_COOKIE,\n} from '../defaultValues/middleware';\nimport {\n CONTENT_DIR_NAME,\n DICTIONARIES_DIR_NAME,\n FILE_EXTENSIONS,\n RESULT_DIR_NAME,\n EXCLUDED_PATHS,\n TYPES_DIR_NAME,\n MAIN_DIR_NAME,\n MODULE_AUGMENTATION_DIR_NAME,\n I18N_DICTIONARIES_DIR_NAME,\n DICTIONARY_OUTPUT,\n} from '../defaultValues/server';\nimport type {\n BaseDerivedConfig,\n ContentConfig,\n CustomIntlayerConfig,\n PatternsContentConfig,\n InternationalizationConfig,\n IntlayerConfig,\n MiddlewareConfig,\n BaseContentConfig,\n ResultDirDerivedConfig,\n} from '../types/config';\nimport type { GetConfigurationOptions } from './getConfiguration';\n\nlet storedConfiguration: IntlayerConfig;\n\n// @TODO - Add possibility of directories configurations to be arrays to allow multiple packages management\n\nconst buildInternationalizationFields = (\n customConfiguration?: Partial<InternationalizationConfig>\n): InternationalizationConfig => ({\n /**\n * Locales available in the application\n *\n * Default: ['en']\n *\n */\n locales: customConfiguration?.locales ?? LOCALES,\n\n /**\n * Default locale of the application for fallback\n *\n * Default: 'en'\n */\n defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,\n});\n\nconst buildMiddlewareFields = (\n customConfiguration?: Partial<MiddlewareConfig>\n): MiddlewareConfig => ({\n /**\n * Header name to get the locale\n *\n * Default: 'x-intlayer-locale'\n */\n headerName: customConfiguration?.headerName ?? HEADER_NAME,\n\n /**\n * Cookie name to get the locale\n *\n * Default: 'intlayer-locale'\n */\n cookieName: customConfiguration?.cookieName ?? COOKIE_NAME,\n\n /**\n * Prefix the default locale in the URL\n *\n * Default: true\n */\n prefixDefault: customConfiguration?.prefixDefault ?? PREFIX_DEFAULT,\n\n /**\n * Base path of the application URL\n *\n * Default: ''\n *\n * Example:\n * - If the application is hosted at https://example.com/my-app\n * - The base path is '/my-app'\n * - The URL will be https://example.com/my-app/en\n * - If the base path is not set, the URL will be https://example.com/en\n */\n basePath: customConfiguration?.basePath ?? BASE_PATH,\n\n /**\n * Rule to set the cookie on the server\n * - 'always': Set the cookie on every request\n * - 'never': Never set the cookie\n */\n serverSetCookie: customConfiguration?.serverSetCookie ?? SERVER_SET_COOKIE,\n\n /**\n * No prefix in the URL\n * - true: No prefix in the URL\n * - false: Prefix in the URL\n *\n * Example:\n * - If the application is hosted at https://example.com/my-app\n * - The base path is '/my-app'\n * - The URL will be https://example.com/my-app/en\n * - If the base path is not set, the URL will be https://example.com/en\n * - If no prefix is set, the URL will be https://example.com/en\n * - If the no prefix is set to true, the URL will be https://example.com\n *\n * Default: false\n */\n noPrefix: customConfiguration?.noPrefix ?? NO_PREFIX,\n});\n\nconst buildContentFields = (\n customConfiguration?: Partial<ContentConfig>\n): ContentConfig => {\n const notDerivedContentConfig: BaseContentConfig = {\n /**\n * File extensions of content to look for to build the dictionaries\n *\n * - Default: ['.content.ts', '.content.js', '.content.cjs', '.content.mjs', '.content.json', '.content.tsx', '.content.jsx']\n *\n * - Example: ['.data.ts', '.data.js', '.data.json']\n *\n * Note:\n * - Can exclude unused file extensions to improve performance\n * - Avoid using common file extensions like '.ts', '.js', '.json' to avoid conflicts\n */\n fileExtensions: customConfiguration?.fileExtensions ?? FILE_EXTENSIONS,\n\n /**\n * Absolute path of the directory of the project\n * - Default: process.cwd()\n * - Example: '/path/to/project'\n *\n * Will be used to resolve all intlayer directories\n *\n * Note:\n * - The base directory should be the root of the project\n * - Can be changed to a custom directory to externalize either the content used in the project, or the intlayer application from the project\n */\n baseDir: customConfiguration?.baseDir ?? process.cwd(),\n\n /**\n * Directory name where the content is stored\n *\n * Default: 'src'\n *\n * Example:\n * - 'data' -> '/path/to/project/data'\n * - 'content' -> '/path/to/project/content'\n * - 'locales' -> '/path/to/project/locales'\n *\n * Note: If this directory is not at the base directory level, update the contentDir field instead\n */\n contentDirName: customConfiguration?.contentDirName ?? CONTENT_DIR_NAME,\n\n /**\n * Directory name where the result will be stored\n *\n * Default: '.intlayer'\n *\n * Example:\n * - '.next'\n * - 'outputOFIntlayer'\n *\n * Note: If this directory is not at the base directory level, update the resultDir field instead\n */\n resultDirName: customConfiguration?.resultDirName ?? RESULT_DIR_NAME,\n\n /**\n *\n * Directory name where the module augmentation will be stored\n *\n * Module augmentation allow better IDE suggestions and type checking\n *\n * Default: 'types'\n *\n * Example: 'intlayer-types'\n *\n * Note:\n * - If this path changed, be sure to include it from the tsconfig.json file\n * - If this directory is not at the base directory level, update the moduleAugmentationDir field instead\n */\n moduleAugmentationDirName:\n customConfiguration?.moduleAugmentationDirName ??\n MODULE_AUGMENTATION_DIR_NAME,\n // @TODO: Make Module Augmentation optional by adding a flag in the configuration\n\n /**\n * Related to the intlayer result directory\n *\n * Directory name where the dictionaries will be stored\n *\n * Default: 'dictionary'\n *\n * Example: 'translations'\n *\n * Note:\n * - If this directory is not at the result directory level, update the dictionariesDir field instead\n *\n */\n dictionariesDirName:\n customConfiguration?.dictionariesDirName ?? DICTIONARIES_DIR_NAME,\n\n /**\n * Related to the intlayer result directory\n *\n * Directory name where the dictionaries will be stored\n *\n * Default: 'dictionary'\n *\n * Example: 'translations'\n *\n * Note:\n * - If this directory is not at the result directory level, update the dictionariesDir field instead\n *\n */\n i18nDictionariesDirName:\n customConfiguration?.i18nDictionariesDirName ??\n I18N_DICTIONARIES_DIR_NAME,\n\n /**\n * Related to the intlayer result directory\n *\n * Directory name where the dictionaries types will be stored\n *\n * Default: 'types'\n *\n * Example: 'intlayer-types'\n *\n * Note:\n * - If this directory is not at the result directory level, update the typesDir field instead\n *\n */\n typeDirName: customConfiguration?.typeDirName ?? TYPES_DIR_NAME,\n\n /**\n * Related to the intlayer result directory\n *\n * Directory name where the main files will be stored\n *\n * Default: 'main'\n *\n * Example: 'intlayer-main'\n *\n * Note:\n * - If this directory is not at the result directory level, update the mainDir field instead\n */\n mainDirName: customConfiguration?.mainDirName ?? MAIN_DIR_NAME,\n\n /**\n * Should exclude some directories from the content search\n *\n * Default: ['node_modules']\n *\n * Not used yet\n * @TODO Implement the exclusion or remove it\n */\n excludedPath: customConfiguration?.excludedPath ?? EXCLUDED_PATHS,\n };\n\n const baseDirDerivedConfiguration: BaseDerivedConfig = {\n /**\n * Directory where the content is stored\n *\n * Relative to the base directory of the project\n *\n * Default: {{baseDir}} / {{contentDirName}}\n *\n * Example: '/path/to/project/src'\n *\n * Note:\n * - Can be changed to a custom directory to externalize the content used in the project\n * - If the content is not at the base directory level, update the contentDirName field instead\n */\n contentDir: join(\n notDerivedContentConfig.baseDir,\n notDerivedContentConfig.contentDirName\n ),\n\n /**\n * Directory where the result will be stored\n *\n * Relative to the base directory of the project\n *\n * Default: {{baseDir}} / {{resultDirName}}\n *\n * Example: '/path/to/project/.intlayer'\n *\n * Note:\n * - Can be changed to a custom directory to externalize the intlayer application from the project\n * - If the result is not at the base directory level, update the resultDirName field instead\n */\n resultDir: join(\n notDerivedContentConfig.baseDir,\n notDerivedContentConfig.resultDirName\n ),\n\n /**\n * Directory where the module augmentation will be stored\n *\n * Module augmentation allow better IDE suggestions and type checking\n *\n * Relative to the base directory of the project\n *\n * Default: {{baseDir}} / {{moduleAugmentationDirName}}\n *\n * Example: '/path/to/project/types'\n *\n * Note:\n * - If this path changed, be sure to include it from the tsconfig.json file\n * - If the module augmentation is not at the base directory level, update the moduleAugmentationDirName field instead\n *\n */\n moduleAugmentationDir: join(\n notDerivedContentConfig.baseDir,\n notDerivedContentConfig.moduleAugmentationDirName\n ),\n\n /**\n * Output format of the dictionary\n *\n * Default: ['intlayer']\n *\n * Note:\n * - 'i18next' is not yet ensure a 1:1 mapping with the i18next library.\n * - Removing 'intlayer' will break the compatibility with react-intlayer or next-intlayer\n */\n dictionaryOutput:\n customConfiguration?.dictionaryOutput ?? DICTIONARY_OUTPUT,\n };\n\n const resultDirDerivedConfiguration: ResultDirDerivedConfig = {\n /**\n * Directory where the dictionaries will be stored\n *\n * Relative to the result directory\n *\n * Default: {{resultDir}} / {{dictionariesDirName}}\n *\n * Example: '/path/to/project/.intlayer/dictionary'\n *\n * Note:\n * - If the types are not at the result directory level, update the dictionariesDirName field instead\n * - The dictionaries are stored in JSON format\n * - The dictionaries are used to translate the content\n * - The dictionaries are built from the content files\n */\n dictionariesDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.dictionariesDirName\n ),\n\n /**\n * Directory where the 18n dictionaries will be stored\n *\n * Relative to the result directory\n *\n * Default: {{resultDir}} / {{i18nDictionariesDirName}}\n *\n * Example: '/path/to/project/.intlayer/dictionary/i18n'\n *\n * Note:\n * - If the types are not at the result directory level, update the i18nDictionariesDirName field instead\n */\n i18nDictionariesDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.i18nDictionariesDirName\n ),\n\n /**\n * Directory where the dictionaries types will be stored\n *\n * Relative to the result directory\n *\n * Default: {{resultDir}} / {{typeDirName}}\n *\n * Example: '/path/to/project/.intlayer/types'\n *\n * Note:\n * - If the types are not at the result directory level, update the typesDirName field instead\n */\n typesDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.typeDirName\n ),\n\n /**\n * Directory where the main files will be stored\n *\n * Relative to the result directory\n *\n * Default: {{resultDir}} / {{mainDirName}}\n *\n * Example: '/path/to/project/.intlayer/main'\n *\n * Note:\n *\n * - If the main files are not at the result directory level, update the mainDirName field instead\n */\n mainDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.mainDirName\n ),\n };\n\n const patternsConfiguration: PatternsContentConfig = {\n /**\n * Pattern of files to watch\n *\n * Default: ['/**\\/*.content.ts', '/**\\/*.content.js', '/**\\/*.content.json', '/**\\/*.content.cjs', '/**\\/*.content.mjs', '/**\\/*.content.tsx', '/**\\/*.content.jsx']\n */\n watchedFilesPattern: notDerivedContentConfig.fileExtensions.map(\n (ext) => `/**/*${ext}`\n ),\n\n /**\n * Pattern of files to watch including the relative path\n *\n * Default: ['{{contentDir}}/**\\/*.content.ts', '{{contentDir}}/**\\/*.content.js', '{{contentDir}}/**\\/*.content.json', '{{contentDir}}/**\\/*.content.cjs', '{{contentDir}}/**\\/*.content.mjs', '{{contentDir}}/**\\/*.content.tsx', '{{contentDir}}/**\\/*.content.jsx']\n */\n watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.map(\n (ext) => `${baseDirDerivedConfiguration.contentDir}/**/*${ext}`\n ),\n\n /**\n * Pattern of dictionary to interpret\n *\n * Default: '{{dictionariesDir}}/**\\/*.json'\n */\n outputFilesPatternWithPath: `${resultDirDerivedConfiguration.dictionariesDir}/**/*.json`,\n };\n\n return {\n ...notDerivedContentConfig,\n ...baseDirDerivedConfiguration,\n ...resultDirDerivedConfiguration,\n ...patternsConfiguration,\n };\n};\n\n/**\n * Build the configuration fields by merging the default values with the custom configuration\n */\nexport const buildConfigurationFields = (\n options: GetConfigurationOptions,\n customConfiguration?: CustomIntlayerConfig\n): IntlayerConfig => {\n const internationalizationConfig = buildInternationalizationFields(\n customConfiguration?.internationalization\n );\n\n const middlewareConfig = buildMiddlewareFields(\n customConfiguration?.middleware\n );\n\n const contentConfig = buildContentFields(customConfiguration?.content);\n\n storedConfiguration = {\n internationalization: internationalizationConfig,\n middleware: middlewareConfig,\n content: contentConfig,\n };\n\n return storedConfiguration;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AACrB,kCAAwC;AACxC,wBAOO;AACP,oBAWO;AAcP,IAAI;AAIJ,MAAM,kCAAkC,CACtC,yBACgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOhC,SAAS,qBAAqB,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOzC,eAAe,qBAAqB,iBAAiB;AACvD;AAEA,MAAM,wBAAwB,CAC5B,yBACsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtB,YAAY,qBAAqB,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO/C,YAAY,qBAAqB,cAAc;AAAA;AAAA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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcA,cAAU;AAAA,MACR,4BAA4B;AAAA,MAC5B,wBAAwB;AAAA,IAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAeA,aAAS;AAAA,MACP,4BAA4B;AAAA,MAC5B,wBAAwB;AAAA,IAC1B;AAAA,EACF;AAEA,QAAM,wBAA+C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMnD,qBAAqB,wBAAwB,eAAe;AAAA,MAC1D,CAAC,QAAQ,QAAQ,GAAG;AAAA,IACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,6BAA6B,wBAAwB,eAAe;AAAA,MAClE,CAAC,QAAQ,GAAG,4BAA4B,UAAU,QAAQ,GAAG;AAAA,IAC/D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,4BAA4B,GAAG,8BAA8B,eAAe;AAAA,EAC9E;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;AAKO,MAAM,2BAA2B,CACtC,SACA,wBACmB;AACnB,QAAM,6BAA6B;AAAA,IACjC,qBAAqB;AAAA,EACvB;AAEA,QAAM,mBAAmB;AAAA,IACvB,qBAAqB;AAAA,EACvB;AAEA,QAAM,gBAAgB,mBAAmB,qBAAqB,OAAO;AAErE,wBAAsB;AAAA,IACpB,sBAAsB;AAAA,IACtB,YAAY;AAAA,IACZ,SAAS;AAAA,EACX;AAEA,SAAO;AACT;","names":[]}
@@ -2,6 +2,9 @@ import { CustomIntlayerConfig, IntlayerConfig } from '../types/config.js';
2
2
  import { GetConfigurationOptions } from './getConfiguration.js';
3
3
  import '../types/locales.js';
4
4
 
5
+ /**
6
+ * Build the configuration fields by merging the default values with the custom configuration
7
+ */
5
8
  declare const buildConfigurationFields: (options: GetConfigurationOptions, customConfiguration?: CustomIntlayerConfig) => IntlayerConfig;
6
9
 
7
10
  export { buildConfigurationFields };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/configFile/getConfiguration.ts"],"sourcesContent":["import { relative } from 'path';\nimport type { CustomIntlayerConfig, IntlayerConfig } from '../types/config';\nimport { buildConfigurationFields } from './buildConfigurationFields';\nimport { loadConfigurationFile } from './loadConfigurationFile';\nimport { searchConfigurationFile } from './searchConfigurationFile';\n\nlet storedConfiguration: IntlayerConfig | undefined;\nlet storedConfigurationFilePath: string | undefined;\nlet storedNumCustomConfiguration: number | undefined;\n\nexport type GetConfigurationOptions = {\n baseDir: string;\n verbose: boolean;\n};\n\nconst BASE_DIR_PATH = process.env.INTLAYER_BASE_DIR_PATH ?? process.cwd();\nconst defaultOptions: GetConfigurationOptions = {\n baseDir: BASE_DIR_PATH,\n verbose: false,\n};\n\nexport const getConfiguration = (\n options?: Partial<GetConfigurationOptions>\n): IntlayerConfig => {\n const mergedOptions = { ...defaultOptions, ...options };\n const { baseDir, verbose } = mergedOptions;\n\n if (!storedConfiguration) {\n // Search for configuration files\n const { configurationFilePath, numCustomConfiguration } =\n searchConfigurationFile(baseDir);\n\n // Load the custom configuration\n let customConfiguration: CustomIntlayerConfig | undefined;\n if (configurationFilePath) {\n customConfiguration = loadConfigurationFile(configurationFilePath);\n }\n\n // Save the configuration to avoid reading the file again\n storedConfiguration = buildConfigurationFields(\n mergedOptions,\n customConfiguration\n );\n storedConfigurationFilePath = configurationFilePath;\n storedNumCustomConfiguration = numCustomConfiguration;\n }\n\n // Log warning if multiple configuration files are found\n if (verbose)\n logConfigFileResult(\n storedNumCustomConfiguration,\n storedConfigurationFilePath\n );\n\n return storedConfiguration;\n};\n\nconst logConfigFileResult = (\n numCustomConfiguration?: number,\n configurationFilePath?: string\n) => {\n if (numCustomConfiguration === 0) {\n console.info('Configuration file not found, using default configuration.');\n } else {\n const relativeOutputPath = relative(BASE_DIR_PATH, configurationFilePath!);\n\n if (numCustomConfiguration === 1) {\n console.info(`Configuration file found: ${relativeOutputPath}.`);\n } else {\n console.warn(\n `Multiple configuration files found, using ${relativeOutputPath}.`\n );\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyB;AAEzB,sCAAyC;AACzC,mCAAsC;AACtC,qCAAwC;AAExC,IAAI;AACJ,IAAI;AACJ,IAAI;AAOJ,MAAM,gBAAgB,QAAQ,IAAI,0BAA0B,QAAQ,IAAI;AACxE,MAAM,iBAA0C;AAAA,EAC9C,SAAS;AAAA,EACT,SAAS;AACX;AAEO,MAAM,mBAAmB,CAC9B,YACmB;AACnB,QAAM,gBAAgB,EAAE,GAAG,gBAAgB,GAAG,QAAQ;AACtD,QAAM,EAAE,SAAS,QAAQ,IAAI;AAE7B,MAAI,CAAC,qBAAqB;AAExB,UAAM,EAAE,uBAAuB,uBAAuB,QACpD,wDAAwB,OAAO;AAGjC,QAAI;AACJ,QAAI,uBAAuB;AACzB,gCAAsB,oDAAsB,qBAAqB;AAAA,IACnE;AAGA,8BAAsB;AAAA,MACpB;AAAA,MACA;AAAA,IACF;AACA,kCAA8B;AAC9B,mCAA+B;AAAA,EACjC;AAGA,MAAI;AACF;AAAA,MACE;AAAA,MACA;AAAA,IACF;AAEF,SAAO;AACT;AAEA,MAAM,sBAAsB,CAC1B,wBACA,0BACG;AACH,MAAI,2BAA2B,GAAG;AAChC,YAAQ,KAAK,4DAA4D;AAAA,EAC3E,OAAO;AACL,UAAM,yBAAqB,sBAAS,eAAe,qBAAsB;AAEzE,QAAI,2BAA2B,GAAG;AAChC,cAAQ,KAAK,6BAA6B,kBAAkB,GAAG;AAAA,IACjE,OAAO;AACL,cAAQ;AAAA,QACN,6CAA6C,kBAAkB;AAAA,MACjE;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/configFile/getConfiguration.ts"],"sourcesContent":["import { relative } from 'path';\nimport type { CustomIntlayerConfig, IntlayerConfig } from '../types/config';\nimport { buildConfigurationFields } from './buildConfigurationFields';\nimport { loadConfigurationFile } from './loadConfigurationFile';\nimport { searchConfigurationFile } from './searchConfigurationFile';\n\nlet storedConfiguration: IntlayerConfig | undefined;\nlet storedConfigurationFilePath: string | undefined;\nlet storedNumCustomConfiguration: number | undefined;\n\nexport type GetConfigurationOptions = {\n baseDir: string;\n verbose: boolean;\n};\n\nconst BASE_DIR_PATH = process.env.INTLAYER_BASE_DIR_PATH ?? process.cwd();\nconst defaultOptions: GetConfigurationOptions = {\n baseDir: BASE_DIR_PATH,\n verbose: false,\n};\n\n/**\n * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)\n */\nexport const getConfiguration = (\n options?: Partial<GetConfigurationOptions>\n): IntlayerConfig => {\n const mergedOptions = { ...defaultOptions, ...options };\n const { baseDir, verbose } = mergedOptions;\n\n if (!storedConfiguration) {\n // Search for configuration files\n const { configurationFilePath, numCustomConfiguration } =\n searchConfigurationFile(baseDir);\n\n // Load the custom configuration\n let customConfiguration: CustomIntlayerConfig | undefined;\n if (configurationFilePath) {\n customConfiguration = loadConfigurationFile(configurationFilePath);\n }\n\n // Save the configuration to avoid reading the file again\n storedConfiguration = buildConfigurationFields(\n mergedOptions,\n customConfiguration\n );\n storedConfigurationFilePath = configurationFilePath;\n storedNumCustomConfiguration = numCustomConfiguration;\n }\n\n // Log warning if multiple configuration files are found\n if (verbose)\n logConfigFileResult(\n storedNumCustomConfiguration,\n storedConfigurationFilePath\n );\n\n return storedConfiguration;\n};\n\nconst logConfigFileResult = (\n numCustomConfiguration?: number,\n configurationFilePath?: string\n) => {\n if (numCustomConfiguration === 0) {\n console.info('Configuration file not found, using default configuration.');\n } else {\n const relativeOutputPath = relative(BASE_DIR_PATH, configurationFilePath!);\n\n if (numCustomConfiguration === 1) {\n console.info(`Configuration file found: ${relativeOutputPath}.`);\n } else {\n console.warn(\n `Multiple configuration files found, using ${relativeOutputPath}.`\n );\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyB;AAEzB,sCAAyC;AACzC,mCAAsC;AACtC,qCAAwC;AAExC,IAAI;AACJ,IAAI;AACJ,IAAI;AAOJ,MAAM,gBAAgB,QAAQ,IAAI,0BAA0B,QAAQ,IAAI;AACxE,MAAM,iBAA0C;AAAA,EAC9C,SAAS;AAAA,EACT,SAAS;AACX;AAKO,MAAM,mBAAmB,CAC9B,YACmB;AACnB,QAAM,gBAAgB,EAAE,GAAG,gBAAgB,GAAG,QAAQ;AACtD,QAAM,EAAE,SAAS,QAAQ,IAAI;AAE7B,MAAI,CAAC,qBAAqB;AAExB,UAAM,EAAE,uBAAuB,uBAAuB,QACpD,wDAAwB,OAAO;AAGjC,QAAI;AACJ,QAAI,uBAAuB;AACzB,gCAAsB,oDAAsB,qBAAqB;AAAA,IACnE;AAGA,8BAAsB;AAAA,MACpB;AAAA,MACA;AAAA,IACF;AACA,kCAA8B;AAC9B,mCAA+B;AAAA,EACjC;AAGA,MAAI;AACF;AAAA,MACE;AAAA,MACA;AAAA,IACF;AAEF,SAAO;AACT;AAEA,MAAM,sBAAsB,CAC1B,wBACA,0BACG;AACH,MAAI,2BAA2B,GAAG;AAChC,YAAQ,KAAK,4DAA4D;AAAA,EAC3E,OAAO;AACL,UAAM,yBAAqB,sBAAS,eAAe,qBAAsB;AAEzE,QAAI,2BAA2B,GAAG;AAChC,cAAQ,KAAK,6BAA6B,kBAAkB,GAAG;AAAA,IACjE,OAAO;AACL,cAAQ;AAAA,QACN,6CAA6C,kBAAkB;AAAA,MACjE;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -5,6 +5,9 @@ type GetConfigurationOptions = {
5
5
  baseDir: string;
6
6
  verbose: boolean;
7
7
  };
8
+ /**
9
+ * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)
10
+ */
8
11
  declare const getConfiguration: (options?: Partial<GetConfigurationOptions>) => IntlayerConfig;
9
12
 
10
13
  export { type GetConfigurationOptions, getConfiguration };
@@ -16,8 +16,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  var configFile_exports = {};
17
17
  module.exports = __toCommonJS(configFile_exports);
18
18
  __reExport(configFile_exports, require('./getConfiguration.cjs'), module.exports);
19
+ __reExport(configFile_exports, require('./searchConfigurationFile.cjs'), module.exports);
19
20
  // Annotate the CommonJS export names for ESM import in node:
20
21
  0 && (module.exports = {
21
- ...require('./getConfiguration.cjs')
22
+ ...require('./getConfiguration.cjs'),
23
+ ...require('./searchConfigurationFile.cjs')
22
24
  });
23
25
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/configFile/index.ts"],"sourcesContent":["export * from './getConfiguration';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,+BAAd;","names":[]}
1
+ {"version":3,"sources":["../../../src/configFile/index.ts"],"sourcesContent":["export * from './getConfiguration';\nexport * from './searchConfigurationFile';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,+BAAd;AACA,+BAAc,sCADd;","names":[]}
@@ -1,3 +1,4 @@
1
1
  export { GetConfigurationOptions, getConfiguration } from './getConfiguration.js';
2
+ export { searchConfigurationFile } from './searchConfigurationFile.js';
2
3
  import '../types/config.js';
3
4
  import '../types/locales.js';
@@ -53,6 +53,9 @@ const transformationOption = {
53
53
  write: false,
54
54
  bundle: true
55
55
  };
56
+ const filterValidConfiguration = (configuration) => {
57
+ return configuration;
58
+ };
56
59
  const loadConfigurationFile = (configFilePath) => {
57
60
  let customConfiguration = void 0;
58
61
  const configFileExtension = configFilePath.split(".").pop() ?? "";
@@ -79,7 +82,11 @@ const loadConfigurationFile = (configFilePath) => {
79
82
  } else if (sandboxContext.module.exports && Object.keys(sandboxContext.module.exports).length > 0) {
80
83
  customConfiguration = sandboxContext.module.exports;
81
84
  }
82
- return customConfiguration;
85
+ if (typeof customConfiguration === "undefined") {
86
+ console.error("Configuration file could not be loaded.");
87
+ return void 0;
88
+ }
89
+ return filterValidConfiguration(customConfiguration);
83
90
  } catch (error) {
84
91
  console.error("Error:", error);
85
92
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/configFile/loadConfigurationFile.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { createRequire } from 'module';\nimport { type Context, runInNewContext } from 'vm';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport type { CustomIntlayerConfig } from '../types/config';\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\nexport const loadConfigurationFile = (\n configFilePath: string\n): CustomIntlayerConfig | undefined => {\n let customConfiguration: CustomIntlayerConfig | undefined = undefined;\n\n const configFileExtension = configFilePath.split('.').pop() ?? '';\n\n try {\n if (configFileExtension === 'json') {\n // Assume JSON\n return require(configFilePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [configFilePath],\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 customConfiguration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n customConfiguration = 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 customConfiguration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n customConfiguration = sandboxContext.module.exports;\n }\n\n return customConfiguration;\n } catch (error) {\n console.error('Error:', error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA8B;AAC9B,gBAA8C;AAC9C,qBAA+D;AAH/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;AAEO,MAAM,wBAAwB,CACnC,mBACqC;AACrC,MAAI,sBAAwD;AAE5D,QAAM,sBAAsB,eAAe,MAAM,GAAG,EAAE,IAAI,KAAK;AAE/D,MAAI;AACF,QAAI,wBAAwB,QAAQ;AAElC,aAAO,QAAQ,cAAc;AAAA,IAC/B;AAIA,UAAM,mBAA4B,0BAAU;AAAA,MAC1C,aAAa,CAAC,cAAc;AAAA,MAE5B,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,4BAAsB,eAAe,QAAQ;AAAA,IAC/C,WACE,eAAe,OAAO,QAAQ,YAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,QAAQ,EAAE,SAAS,GAC7D;AAEA,4BAAsB,eAAe,OAAO,QAAQ;AAAA,IACtD,WACE,eAAe,OAAO,QAAQ,WAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,OAAO,EAAE,SAAS,GAC5D;AAEA,4BAAsB,eAAe,OAAO,QAAQ;AAAA,IACtD,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,4BAAsB,eAAe,OAAO;AAAA,IAC9C;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,UAAU,KAAK;AAAA,EAC/B;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/configFile/loadConfigurationFile.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { createRequire } from 'module';\nimport { type Context, runInNewContext } from 'vm';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport type { CustomIntlayerConfig } from '../types/config';\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 filterValidConfiguration = (\n configuration: CustomIntlayerConfig\n): CustomIntlayerConfig => {\n // @TODO Implement filtering of valid configuration\n return configuration;\n};\n\n/**\n * Load the configuration file from the given path\n * Example of configuration file: intlayer.config.js\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadConfigurationFile = (\n configFilePath: string\n): CustomIntlayerConfig | undefined => {\n let customConfiguration: CustomIntlayerConfig | undefined = undefined;\n\n const configFileExtension = configFilePath.split('.').pop() ?? '';\n\n try {\n if (configFileExtension === 'json') {\n // Assume JSON\n return require(configFilePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [configFilePath],\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 customConfiguration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n customConfiguration = 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 customConfiguration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n customConfiguration = sandboxContext.module.exports;\n }\n\n if (typeof customConfiguration === 'undefined') {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n return filterValidConfiguration(customConfiguration);\n } catch (error) {\n console.error('Error:', error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA8B;AAC9B,gBAA8C;AAC9C,qBAA+D;AAH/D;AAMA,MAAM,aAAa,OAAO,YAAY,QAAQ;AAE9C,M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,OAAO,KAAK,eAAe,OAAO,QAAQ,OAAO,EAAE,SAAS,GAC5D;AAEA,4BAAsB,eAAe,OAAO,QAAQ;AAAA,IACtD,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,4BAAsB,eAAe,OAAO;AAAA,IAC9C;AAEA,QAAI,OAAO,wBAAwB,aAAa;AAC9C,cAAQ,MAAM,yCAAyC;AACvD,aAAO;AAAA,IACT;AAEA,WAAO,yBAAyB,mBAAmB;AAAA,EACrD,SAAS,OAAO;AACd,YAAQ,MAAM,UAAU,KAAK;AAAA,EAC/B;AACF;","names":[]}
@@ -1,6 +1,12 @@
1
1
  import { CustomIntlayerConfig } from '../types/config.js';
2
2
  import '../types/locales.js';
3
3
 
4
+ /**
5
+ * Load the configuration file from the given path
6
+ * Example of configuration file: intlayer.config.js
7
+ *
8
+ * Accepts JSON, JS, MJS and TS files as configuration
9
+ */
4
10
  declare const loadConfigurationFile: (configFilePath: string) => CustomIntlayerConfig | undefined;
5
11
 
6
12
  export { loadConfigurationFile };