@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
@@ -9,121 +9,377 @@ import {
9
9
  SERVER_SET_COOKIE
10
10
  } from '../defaultValues/middleware.mjs';
11
11
  import {
12
- BUNDLE_DIR_NAME,
13
12
  CONTENT_DIR_NAME,
14
13
  DICTIONARIES_DIR_NAME,
15
14
  FILE_EXTENSIONS,
16
15
  RESULT_DIR_NAME,
17
16
  EXCLUDED_PATHS,
18
- BUNDLE_FILE_EXTENSION,
19
17
  TYPES_DIR_NAME,
20
18
  MAIN_DIR_NAME,
21
- MODULE_AUGMENTATION_DIR_NAME
19
+ MODULE_AUGMENTATION_DIR_NAME,
20
+ I18N_DICTIONARIES_DIR_NAME,
21
+ DICTIONARY_OUTPUT
22
22
  } from '../defaultValues/server.mjs';
23
23
  let storedConfiguration;
24
24
  const buildInternationalizationFields = (customConfiguration) => ({
25
25
  /**
26
- * Internationalization configuration
26
+ * Locales available in the application
27
+ *
28
+ * Default: ['en']
29
+ *
27
30
  */
28
- // Locales available in the application
29
31
  locales: customConfiguration?.locales ?? LOCALES,
30
- // Default locale of the application for fallback
32
+ /**
33
+ * Default locale of the application for fallback
34
+ *
35
+ * Default: 'en'
36
+ */
31
37
  defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE
32
38
  });
33
39
  const buildMiddlewareFields = (customConfiguration) => ({
34
40
  /**
35
- * Middleware configuration
41
+ * Header name to get the locale
42
+ *
43
+ * Default: 'x-intlayer-locale'
36
44
  */
37
- // Header name to get the locale
38
45
  headerName: customConfiguration?.headerName ?? HEADER_NAME,
39
- // Cookie name to get the locale
46
+ /**
47
+ * Cookie name to get the locale
48
+ *
49
+ * Default: 'intlayer-locale'
50
+ */
40
51
  cookieName: customConfiguration?.cookieName ?? COOKIE_NAME,
41
- // Prefix the default locale in the URL
52
+ /**
53
+ * Prefix the default locale in the URL
54
+ *
55
+ * Default: true
56
+ */
42
57
  prefixDefault: customConfiguration?.prefixDefault ?? PREFIX_DEFAULT,
43
- // Base path
58
+ /**
59
+ * Base path of the application URL
60
+ *
61
+ * Default: ''
62
+ *
63
+ * Example:
64
+ * - If the application is hosted at https://example.com/my-app
65
+ * - The base path is '/my-app'
66
+ * - The URL will be https://example.com/my-app/en
67
+ * - If the base path is not set, the URL will be https://example.com/en
68
+ */
44
69
  basePath: customConfiguration?.basePath ?? BASE_PATH,
45
- // Set cookie on server
70
+ /**
71
+ * Rule to set the cookie on the server
72
+ * - 'always': Set the cookie on every request
73
+ * - 'never': Never set the cookie
74
+ */
46
75
  serverSetCookie: customConfiguration?.serverSetCookie ?? SERVER_SET_COOKIE,
47
- // No prefix
76
+ /**
77
+ * No prefix in the URL
78
+ * - true: No prefix in the URL
79
+ * - false: Prefix in the URL
80
+ *
81
+ * Example:
82
+ * - If the application is hosted at https://example.com/my-app
83
+ * - The base path is '/my-app'
84
+ * - The URL will be https://example.com/my-app/en
85
+ * - If the base path is not set, the URL will be https://example.com/en
86
+ * - If no prefix is set, the URL will be https://example.com/en
87
+ * - If the no prefix is set to true, the URL will be https://example.com
88
+ *
89
+ * Default: false
90
+ */
48
91
  noPrefix: customConfiguration?.noPrefix ?? NO_PREFIX
49
92
  });
50
93
  const buildContentFields = (customConfiguration) => {
51
94
  const notDerivedContentConfig = {
52
95
  /**
53
- * Content configurations
96
+ * File extensions of content to look for to build the dictionaries
97
+ *
98
+ * - Default: ['.content.ts', '.content.js', '.content.cjs', '.content.mjs', '.content.json', '.content.tsx', '.content.jsx']
99
+ *
100
+ * - Example: ['.data.ts', '.data.js', '.data.json']
101
+ *
102
+ * Note:
103
+ * - Can exclude unused file extensions to improve performance
104
+ * - Avoid using common file extensions like '.ts', '.js', '.json' to avoid conflicts
54
105
  */
55
- // File extensions of content to look for
56
106
  fileExtensions: customConfiguration?.fileExtensions ?? FILE_EXTENSIONS,
57
- // Directory name of the project
107
+ /**
108
+ * Absolute path of the directory of the project
109
+ * - Default: process.cwd()
110
+ * - Example: '/path/to/project'
111
+ *
112
+ * Will be used to resolve all intlayer directories
113
+ *
114
+ * Note:
115
+ * - The base directory should be the root of the project
116
+ * - Can be changed to a custom directory to externalize either the content used in the project, or the intlayer application from the project
117
+ */
58
118
  baseDir: customConfiguration?.baseDir ?? process.cwd(),
59
- // Directory name where the content is stored
119
+ /**
120
+ * Directory name where the content is stored
121
+ *
122
+ * Default: 'src'
123
+ *
124
+ * Example:
125
+ * - 'data' -> '/path/to/project/data'
126
+ * - 'content' -> '/path/to/project/content'
127
+ * - 'locales' -> '/path/to/project/locales'
128
+ *
129
+ * Note: If this directory is not at the base directory level, update the contentDir field instead
130
+ */
60
131
  contentDirName: customConfiguration?.contentDirName ?? CONTENT_DIR_NAME,
61
- // Result directory name
132
+ /**
133
+ * Directory name where the result will be stored
134
+ *
135
+ * Default: '.intlayer'
136
+ *
137
+ * Example:
138
+ * - '.next'
139
+ * - 'outputOFIntlayer'
140
+ *
141
+ * Note: If this directory is not at the base directory level, update the resultDir field instead
142
+ */
62
143
  resultDirName: customConfiguration?.resultDirName ?? RESULT_DIR_NAME,
63
- // Module augmentation directory name
144
+ /**
145
+ *
146
+ * Directory name where the module augmentation will be stored
147
+ *
148
+ * Module augmentation allow better IDE suggestions and type checking
149
+ *
150
+ * Default: 'types'
151
+ *
152
+ * Example: 'intlayer-types'
153
+ *
154
+ * Note:
155
+ * - If this path changed, be sure to include it from the tsconfig.json file
156
+ * - If this directory is not at the base directory level, update the moduleAugmentationDir field instead
157
+ */
64
158
  moduleAugmentationDirName: customConfiguration?.moduleAugmentationDirName ?? MODULE_AUGMENTATION_DIR_NAME,
65
- // Bundle directory name
66
- bundleDirName: customConfiguration?.bundleDirName ?? BUNDLE_DIR_NAME,
67
- // Bundle file extension
68
- bundleFileExtension: customConfiguration?.bundleFileExtension ?? BUNDLE_FILE_EXTENSION,
69
- // Dictionary directory name
159
+ // @TODO: Make Module Augmentation optional by adding a flag in the configuration
160
+ /**
161
+ * Related to the intlayer result directory
162
+ *
163
+ * Directory name where the dictionaries will be stored
164
+ *
165
+ * Default: 'dictionary'
166
+ *
167
+ * Example: 'translations'
168
+ *
169
+ * Note:
170
+ * - If this directory is not at the result directory level, update the dictionariesDir field instead
171
+ *
172
+ */
70
173
  dictionariesDirName: customConfiguration?.dictionariesDirName ?? DICTIONARIES_DIR_NAME,
71
- // Types directory name
174
+ /**
175
+ * Related to the intlayer result directory
176
+ *
177
+ * Directory name where the dictionaries will be stored
178
+ *
179
+ * Default: 'dictionary'
180
+ *
181
+ * Example: 'translations'
182
+ *
183
+ * Note:
184
+ * - If this directory is not at the result directory level, update the dictionariesDir field instead
185
+ *
186
+ */
187
+ i18nDictionariesDirName: customConfiguration?.i18nDictionariesDirName ?? I18N_DICTIONARIES_DIR_NAME,
188
+ /**
189
+ * Related to the intlayer result directory
190
+ *
191
+ * Directory name where the dictionaries types will be stored
192
+ *
193
+ * Default: 'types'
194
+ *
195
+ * Example: 'intlayer-types'
196
+ *
197
+ * Note:
198
+ * - If this directory is not at the result directory level, update the typesDir field instead
199
+ *
200
+ */
72
201
  typeDirName: customConfiguration?.typeDirName ?? TYPES_DIR_NAME,
73
- // Main directory name
202
+ /**
203
+ * Related to the intlayer result directory
204
+ *
205
+ * Directory name where the main files will be stored
206
+ *
207
+ * Default: 'main'
208
+ *
209
+ * Example: 'intlayer-main'
210
+ *
211
+ * Note:
212
+ * - If this directory is not at the result directory level, update the mainDir field instead
213
+ */
74
214
  mainDirName: customConfiguration?.mainDirName ?? MAIN_DIR_NAME,
75
- // Directories to exclude
215
+ /**
216
+ * Should exclude some directories from the content search
217
+ *
218
+ * Default: ['node_modules']
219
+ *
220
+ * Not used yet
221
+ * @TODO Implement the exclusion or remove it
222
+ */
76
223
  excludedPath: customConfiguration?.excludedPath ?? EXCLUDED_PATHS
77
224
  };
78
225
  const baseDirDerivedConfiguration = {
79
- // Directory where the content is stored
226
+ /**
227
+ * Directory where the content is stored
228
+ *
229
+ * Relative to the base directory of the project
230
+ *
231
+ * Default: {{baseDir}} / {{contentDirName}}
232
+ *
233
+ * Example: '/path/to/project/src'
234
+ *
235
+ * Note:
236
+ * - Can be changed to a custom directory to externalize the content used in the project
237
+ * - If the content is not at the base directory level, update the contentDirName field instead
238
+ */
80
239
  contentDir: join(
81
240
  notDerivedContentConfig.baseDir,
82
241
  notDerivedContentConfig.contentDirName
83
242
  ),
84
- // Directory where the result will be stored
243
+ /**
244
+ * Directory where the result will be stored
245
+ *
246
+ * Relative to the base directory of the project
247
+ *
248
+ * Default: {{baseDir}} / {{resultDirName}}
249
+ *
250
+ * Example: '/path/to/project/.intlayer'
251
+ *
252
+ * Note:
253
+ * - Can be changed to a custom directory to externalize the intlayer application from the project
254
+ * - If the result is not at the base directory level, update the resultDirName field instead
255
+ */
85
256
  resultDir: join(
86
257
  notDerivedContentConfig.baseDir,
87
258
  notDerivedContentConfig.resultDirName
88
259
  ),
89
- // Directory where the module augmentation will be stored
260
+ /**
261
+ * Directory where the module augmentation will be stored
262
+ *
263
+ * Module augmentation allow better IDE suggestions and type checking
264
+ *
265
+ * Relative to the base directory of the project
266
+ *
267
+ * Default: {{baseDir}} / {{moduleAugmentationDirName}}
268
+ *
269
+ * Example: '/path/to/project/types'
270
+ *
271
+ * Note:
272
+ * - If this path changed, be sure to include it from the tsconfig.json file
273
+ * - If the module augmentation is not at the base directory level, update the moduleAugmentationDirName field instead
274
+ *
275
+ */
90
276
  moduleAugmentationDir: join(
91
277
  notDerivedContentConfig.baseDir,
92
278
  notDerivedContentConfig.moduleAugmentationDirName
93
- )
279
+ ),
280
+ /**
281
+ * Output format of the dictionary
282
+ *
283
+ * Default: ['intlayer']
284
+ *
285
+ * Note:
286
+ * - 'i18next' is not yet ensure a 1:1 mapping with the i18next library.
287
+ * - Removing 'intlayer' will break the compatibility with react-intlayer or next-intlayer
288
+ */
289
+ dictionaryOutput: customConfiguration?.dictionaryOutput ?? DICTIONARY_OUTPUT
94
290
  };
95
291
  const resultDirDerivedConfiguration = {
96
- // Directory where the bundle will be stored
97
- bundleDir: join(
98
- baseDirDerivedConfiguration.resultDir,
99
- notDerivedContentConfig.bundleDirName
100
- ),
101
- // Directory where the dictionaries will be stored
292
+ /**
293
+ * Directory where the dictionaries will be stored
294
+ *
295
+ * Relative to the result directory
296
+ *
297
+ * Default: {{resultDir}} / {{dictionariesDirName}}
298
+ *
299
+ * Example: '/path/to/project/.intlayer/dictionary'
300
+ *
301
+ * Note:
302
+ * - If the types are not at the result directory level, update the dictionariesDirName field instead
303
+ * - The dictionaries are stored in JSON format
304
+ * - The dictionaries are used to translate the content
305
+ * - The dictionaries are built from the content files
306
+ */
102
307
  dictionariesDir: join(
103
308
  baseDirDerivedConfiguration.resultDir,
104
309
  notDerivedContentConfig.dictionariesDirName
105
310
  ),
106
- // Directory where the types will be stored
311
+ /**
312
+ * Directory where the 18n dictionaries will be stored
313
+ *
314
+ * Relative to the result directory
315
+ *
316
+ * Default: {{resultDir}} / {{i18nDictionariesDirName}}
317
+ *
318
+ * Example: '/path/to/project/.intlayer/dictionary/i18n'
319
+ *
320
+ * Note:
321
+ * - If the types are not at the result directory level, update the i18nDictionariesDirName field instead
322
+ */
323
+ i18nDictionariesDir: join(
324
+ baseDirDerivedConfiguration.resultDir,
325
+ notDerivedContentConfig.i18nDictionariesDirName
326
+ ),
327
+ /**
328
+ * Directory where the dictionaries types will be stored
329
+ *
330
+ * Relative to the result directory
331
+ *
332
+ * Default: {{resultDir}} / {{typeDirName}}
333
+ *
334
+ * Example: '/path/to/project/.intlayer/types'
335
+ *
336
+ * Note:
337
+ * - If the types are not at the result directory level, update the typesDirName field instead
338
+ */
107
339
  typesDir: join(
108
340
  baseDirDerivedConfiguration.resultDir,
109
341
  notDerivedContentConfig.typeDirName
110
342
  ),
111
- // Directory where the main files will be stored
343
+ /**
344
+ * Directory where the main files will be stored
345
+ *
346
+ * Relative to the result directory
347
+ *
348
+ * Default: {{resultDir}} / {{mainDirName}}
349
+ *
350
+ * Example: '/path/to/project/.intlayer/main'
351
+ *
352
+ * Note:
353
+ *
354
+ * - If the main files are not at the result directory level, update the mainDirName field instead
355
+ */
112
356
  mainDir: join(
113
357
  baseDirDerivedConfiguration.resultDir,
114
358
  notDerivedContentConfig.mainDirName
115
359
  )
116
360
  };
117
361
  const patternsConfiguration = {
118
- // Pattern of files to watch
362
+ /**
363
+ * Pattern of files to watch
364
+ *
365
+ * Default: ['/**\/*.content.ts', '/**\/*.content.js', '/**\/*.content.json', '/**\/*.content.cjs', '/**\/*.content.mjs', '/**\/*.content.tsx', '/**\/*.content.jsx']
366
+ */
119
367
  watchedFilesPattern: notDerivedContentConfig.fileExtensions.map(
120
368
  (ext) => `/**/*${ext}`
121
369
  ),
122
- // Pattern of files to watch including the relative path
370
+ /**
371
+ * Pattern of files to watch including the relative path
372
+ *
373
+ * Default: ['{{contentDir}}/**\/*.content.ts', '{{contentDir}}/**\/*.content.js', '{{contentDir}}/**\/*.content.json', '{{contentDir}}/**\/*.content.cjs', '{{contentDir}}/**\/*.content.mjs', '{{contentDir}}/**\/*.content.tsx', '{{contentDir}}/**\/*.content.jsx']
374
+ */
123
375
  watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.map(
124
376
  (ext) => `${baseDirDerivedConfiguration.contentDir}/**/*${ext}`
125
377
  ),
126
- // Pattern of files to output
378
+ /**
379
+ * Pattern of dictionary to interpret
380
+ *
381
+ * Default: '{{dictionariesDir}}/**\/*.json'
382
+ */
127
383
  outputFilesPatternWithPath: `${resultDirDerivedConfiguration.dictionariesDir}/**/*.json`
128
384
  };
129
385
  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,SAAS,YAAY;AACrB,SAAS,gBAAgB,eAAe;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAcP,IAAI;AAEJ,MAAM,kCAAkC,CACtC,yBACgC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhC,SAAS,qBAAqB,WAAW;AAAA;AAAA,EAGzC,eAAe,qBAAqB,iBAAiB;AACvD;AAEA,MAAM,wBAAwB,CAC5B,yBACsB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtB,YAAY,qBAAqB,cAAc;AAAA;AAAA,EAG/C,YAAY,qBAAqB,cAAc;AAAA;AAAA,EAG/C,eAAe,qBAAqB,iBAAiB;AAAA;AAAA,EAGrD,UAAU,qBAAqB,YAAY;AAAA;AAAA,EAG3C,iBAAiB,qBAAqB,mBAAmB;AAA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;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,SAAS,YAAY;AACrB,SAAS,gBAAgB,eAAe;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;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;AAAA;AAAA;AAAA;AAAA,EAO/C,eAAe,qBAAqB,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAarD,UAAU,qBAAqB,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO3C,iBAAiB,qBAAqB,mBAAmB;AAAA;AAAA;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,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":[]}
@@ -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 };
@@ -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,SAAS,gBAAgB;AAEzB,SAAS,gCAAgC;AACzC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;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,IACpD,wBAAwB,OAAO;AAGjC,QAAI;AACJ,QAAI,uBAAuB;AACzB,4BAAsB,sBAAsB,qBAAqB;AAAA,IACnE;AAGA,0BAAsB;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,qBAAqB,SAAS,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,SAAS,gBAAgB;AAEzB,SAAS,gCAAgC;AACzC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;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,IACpD,wBAAwB,OAAO;AAGjC,QAAI;AACJ,QAAI,uBAAuB;AACzB,4BAAsB,sBAAsB,qBAAqB;AAAA,IACnE;AAGA,0BAAsB;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,qBAAqB,SAAS,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,3 +1,4 @@
1
1
  export { GetConfigurationOptions, getConfiguration } from './getConfiguration.mjs';
2
+ export { searchConfigurationFile } from './searchConfigurationFile.mjs';
2
3
  import '../types/config.mjs';
3
4
  import '../types/locales.mjs';
@@ -1,2 +1,3 @@
1
1
  export * from './getConfiguration.mjs';
2
+ export * from './searchConfigurationFile.mjs';
2
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/configFile/index.ts"],"sourcesContent":["export * from './getConfiguration';\n"],"mappings":"AAAA,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/configFile/index.ts"],"sourcesContent":["export * from './getConfiguration';\nexport * from './searchConfigurationFile';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
@@ -1,6 +1,12 @@
1
1
  import { CustomIntlayerConfig } from '../types/config.mjs';
2
2
  import '../types/locales.mjs';
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 };
@@ -29,6 +29,9 @@ const transformationOption = {
29
29
  write: false,
30
30
  bundle: true
31
31
  };
32
+ const filterValidConfiguration = (configuration) => {
33
+ return configuration;
34
+ };
32
35
  const loadConfigurationFile = (configFilePath) => {
33
36
  let customConfiguration = void 0;
34
37
  const configFileExtension = configFilePath.split(".").pop() ?? "";
@@ -55,7 +58,11 @@ const loadConfigurationFile = (configFilePath) => {
55
58
  } else if (sandboxContext.module.exports && Object.keys(sandboxContext.module.exports).length > 0) {
56
59
  customConfiguration = sandboxContext.module.exports;
57
60
  }
58
- return customConfiguration;
61
+ if (typeof customConfiguration === "undefined") {
62
+ console.error("Configuration file could not be loaded.");
63
+ return void 0;
64
+ }
65
+ return filterValidConfiguration(customConfiguration);
59
66
  } catch (error) {
60
67
  console.error("Error:", error);
61
68
  }
@@ -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":"AACA,SAAS,qBAAqB;AAC9B,SAAuB,uBAAuB;AAC9C,SAA4B,iBAAmC;AAG/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,OA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F;","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":"AACA,SAAS,qBAAqB;AAC9B,SAAuB,uBAAuB;AAC9C,SAA4B,iBAAmC;AAG/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,2BAA2B,CAC/B,kBACyB;AAEzB,SAAO;AACT;AAQO,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,eAA4B,UAAU;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,oBAAgB,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,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":[]}
@@ -2,6 +2,17 @@ type SearchConfigurationFileResult = {
2
2
  configurationFilePath?: string;
3
3
  numCustomConfiguration: number;
4
4
  };
5
+ /**
6
+ * Search for the configuration file in the given path
7
+ *
8
+ * List of detected configuration files:
9
+ * - intlayer.config.ts
10
+ * - intlayer.config.js
11
+ * - intlayer.config.json
12
+ * - intlayer.config.cjs
13
+ * - intlayer.config.mjs
14
+ * - .intlayerrc
15
+ */
5
16
  declare const searchConfigurationFile: (configFilePath: string) => SearchConfigurationFileResult;
6
17
 
7
18
  export { searchConfigurationFile };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/configFile/searchConfigurationFile.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport { resolve } from 'path';\n\nconst EXTENSION = ['ts', 'js', 'json', 'cjs', 'mjs', ''];\nconst CONFIGURATION_FILE_NAME_1 = 'intlayer.config';\nconst CONFIGURATION_FILE_NAME_2 = '.intlayerrc';\n\nconst intLayerConfigFiles = EXTENSION.filter(\n (extension) => extension !== ''\n).map((ext) => `${CONFIGURATION_FILE_NAME_1}.${ext}`);\n\nconst configurationFiles = [...intLayerConfigFiles, CONFIGURATION_FILE_NAME_2];\n\ntype SearchConfigurationFileResult = {\n configurationFilePath?: string;\n numCustomConfiguration: number;\n};\n\nexport const searchConfigurationFile = (\n configFilePath: string\n): SearchConfigurationFileResult => {\n let configurationFilePath: string | undefined = undefined;\n let numCustomConfiguration = 0;\n\n for (const fileName of configurationFiles) {\n try {\n const filePath = resolve(configFilePath, fileName);\n\n // Check if the file exists\n if (!existsSync(filePath)) {\n continue;\n } else {\n numCustomConfiguration += 1;\n\n if (!configurationFilePath) {\n configurationFilePath = filePath;\n }\n }\n } catch (error) {\n // Return \"Cannot use import statement outside a module\"\n console.error(`${fileName}: ${error as string}`);\n\n continue;\n }\n }\n\n return { configurationFilePath, numCustomConfiguration };\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAExB,MAAM,YAAY,CAAC,MAAM,MAAM,QAAQ,OAAO,OAAO,EAAE;AACvD,MAAM,4BAA4B;AAClC,MAAM,4BAA4B;AAElC,MAAM,sBAAsB,UAAU;AAAA,EACpC,CAAC,cAAc,cAAc;AAC/B,EAAE,IAAI,CAAC,QAAQ,GAAG,yBAAyB,IAAI,GAAG,EAAE;AAEpD,MAAM,qBAAqB,CAAC,GAAG,qBAAqB,yBAAyB;AAOtE,MAAM,0BAA0B,CACrC,mBACkC;AAClC,MAAI,wBAA4C;AAChD,MAAI,yBAAyB;AAE7B,aAAW,YAAY,oBAAoB;AACzC,QAAI;AACF,YAAM,WAAW,QAAQ,gBAAgB,QAAQ;AAGjD,UAAI,CAAC,WAAW,QAAQ,GAAG;AACzB;AAAA,MACF,OAAO;AACL,kCAA0B;AAE1B,YAAI,CAAC,uBAAuB;AAC1B,kCAAwB;AAAA,QAC1B;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AAEd,cAAQ,MAAM,GAAG,QAAQ,KAAK,KAAe,EAAE;AAE/C;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,uBAAuB,uBAAuB;AACzD;","names":[]}
1
+ {"version":3,"sources":["../../../src/configFile/searchConfigurationFile.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport { resolve } from 'path';\n\nconst EXTENSION = ['ts', 'js', 'json', 'cjs', 'mjs', ''];\nconst CONFIGURATION_FILE_NAME_1 = 'intlayer.config';\nconst CONFIGURATION_FILE_NAME_2 = '.intlayerrc';\n\nconst intLayerConfigFiles = EXTENSION.filter(\n (extension) => extension !== ''\n).map((ext) => `${CONFIGURATION_FILE_NAME_1}.${ext}`);\n\nconst configurationFiles = [...intLayerConfigFiles, CONFIGURATION_FILE_NAME_2];\n\ntype SearchConfigurationFileResult = {\n configurationFilePath?: string;\n numCustomConfiguration: number;\n};\n\n/**\n * Search for the configuration file in the given path\n *\n * List of detected configuration files:\n * - intlayer.config.ts\n * - intlayer.config.js\n * - intlayer.config.json\n * - intlayer.config.cjs\n * - intlayer.config.mjs\n * - .intlayerrc\n */\nexport const searchConfigurationFile = (\n configFilePath: string\n): SearchConfigurationFileResult => {\n let configurationFilePath: string | undefined = undefined;\n let numCustomConfiguration = 0;\n\n for (const fileName of configurationFiles) {\n try {\n const filePath = resolve(configFilePath, fileName);\n\n // Check if the file exists\n if (!existsSync(filePath)) {\n continue;\n } else {\n numCustomConfiguration += 1;\n\n if (!configurationFilePath) {\n configurationFilePath = filePath;\n }\n }\n } catch (error) {\n // Return \"Cannot use import statement outside a module\"\n console.error(`${fileName}: ${error as string}`);\n\n continue;\n }\n }\n\n return { configurationFilePath, numCustomConfiguration };\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAExB,MAAM,YAAY,CAAC,MAAM,MAAM,QAAQ,OAAO,OAAO,EAAE;AACvD,MAAM,4BAA4B;AAClC,MAAM,4BAA4B;AAElC,MAAM,sBAAsB,UAAU;AAAA,EACpC,CAAC,cAAc,cAAc;AAC/B,EAAE,IAAI,CAAC,QAAQ,GAAG,yBAAyB,IAAI,GAAG,EAAE;AAEpD,MAAM,qBAAqB,CAAC,GAAG,qBAAqB,yBAAyB;AAkBtE,MAAM,0BAA0B,CACrC,mBACkC;AAClC,MAAI,wBAA4C;AAChD,MAAI,yBAAyB;AAE7B,aAAW,YAAY,oBAAoB;AACzC,QAAI;AACF,YAAM,WAAW,QAAQ,gBAAgB,QAAQ;AAGjD,UAAI,CAAC,WAAW,QAAQ,GAAG;AACzB;AAAA,MACF,OAAO;AACL,kCAA0B;AAE1B,YAAI,CAAC,uBAAuB;AAC1B,kCAAwB;AAAA,QAC1B;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AAEd,cAAQ,MAAM,GAAG,QAAQ,KAAK,KAAe,EAAE;AAE/C;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,uBAAuB,uBAAuB;AACzD;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import { Locales } from '../types/locales.mjs';
2
2
 
3
3
  declare const LOCALES: Locales[];
4
- declare const DEFAULT_LOCALE = Locales.ENGLISH;
4
+ declare const DEFAULT_LOCALE: Locales;
5
5
 
6
6
  export { DEFAULT_LOCALE, LOCALES };
@@ -1,9 +1,5 @@
1
1
  import { Locales } from '../types/locales.mjs';
2
- const LOCALES = [
3
- Locales.ENGLISH,
4
- Locales.FRENCH,
5
- Locales.SPANISH
6
- ];
2
+ const LOCALES = [Locales.ENGLISH];
7
3
  const DEFAULT_LOCALE = Locales.ENGLISH;
8
4
  export {
9
5
  DEFAULT_LOCALE,