@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,16 +9,16 @@ import {
9
9
  SERVER_SET_COOKIE,
10
10
  } from '../defaultValues/middleware';
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
19
  MODULE_AUGMENTATION_DIR_NAME,
20
+ I18N_DICTIONARIES_DIR_NAME,
21
+ DICTIONARY_OUTPUT,
22
22
  } from '../defaultValues/server';
23
23
  import type {
24
24
  BaseDerivedConfig,
@@ -35,17 +35,24 @@ import type { GetConfigurationOptions } from './getConfiguration';
35
35
 
36
36
  let storedConfiguration: IntlayerConfig;
37
37
 
38
+ // @TODO - Add possibility of directories configurations to be arrays to allow multiple packages management
39
+
38
40
  const buildInternationalizationFields = (
39
41
  customConfiguration?: Partial<InternationalizationConfig>
40
42
  ): InternationalizationConfig => ({
41
43
  /**
42
- * Internationalization configuration
44
+ * Locales available in the application
45
+ *
46
+ * Default: ['en']
47
+ *
43
48
  */
44
-
45
- // Locales available in the application
46
49
  locales: customConfiguration?.locales ?? LOCALES,
47
50
 
48
- // Default locale of the application for fallback
51
+ /**
52
+ * Default locale of the application for fallback
53
+ *
54
+ * Default: 'en'
55
+ */
49
56
  defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,
50
57
  });
51
58
 
@@ -53,25 +60,61 @@ const buildMiddlewareFields = (
53
60
  customConfiguration?: Partial<MiddlewareConfig>
54
61
  ): MiddlewareConfig => ({
55
62
  /**
56
- * Middleware configuration
63
+ * Header name to get the locale
64
+ *
65
+ * Default: 'x-intlayer-locale'
57
66
  */
58
-
59
- // Header name to get the locale
60
67
  headerName: customConfiguration?.headerName ?? HEADER_NAME,
61
68
 
62
- // Cookie name to get the locale
69
+ /**
70
+ * Cookie name to get the locale
71
+ *
72
+ * Default: 'intlayer-locale'
73
+ */
63
74
  cookieName: customConfiguration?.cookieName ?? COOKIE_NAME,
64
75
 
65
- // Prefix the default locale in the URL
76
+ /**
77
+ * Prefix the default locale in the URL
78
+ *
79
+ * Default: true
80
+ */
66
81
  prefixDefault: customConfiguration?.prefixDefault ?? PREFIX_DEFAULT,
67
82
 
68
- // Base path
83
+ /**
84
+ * Base path of the application URL
85
+ *
86
+ * Default: ''
87
+ *
88
+ * Example:
89
+ * - If the application is hosted at https://example.com/my-app
90
+ * - The base path is '/my-app'
91
+ * - The URL will be https://example.com/my-app/en
92
+ * - If the base path is not set, the URL will be https://example.com/en
93
+ */
69
94
  basePath: customConfiguration?.basePath ?? BASE_PATH,
70
95
 
71
- // Set cookie on server
96
+ /**
97
+ * Rule to set the cookie on the server
98
+ * - 'always': Set the cookie on every request
99
+ * - 'never': Never set the cookie
100
+ */
72
101
  serverSetCookie: customConfiguration?.serverSetCookie ?? SERVER_SET_COOKIE,
73
102
 
74
- // No prefix
103
+ /**
104
+ * No prefix in the URL
105
+ * - true: No prefix in the URL
106
+ * - false: Prefix in the URL
107
+ *
108
+ * Example:
109
+ * - If the application is hosted at https://example.com/my-app
110
+ * - The base path is '/my-app'
111
+ * - The URL will be https://example.com/my-app/en
112
+ * - If the base path is not set, the URL will be https://example.com/en
113
+ * - If no prefix is set, the URL will be https://example.com/en
114
+ * - If the no prefix is set to true, the URL will be https://example.com
115
+ *
116
+ * Default: false
117
+ */
75
118
  noPrefix: customConfiguration?.noPrefix ?? NO_PREFIX,
76
119
  });
77
120
 
@@ -80,87 +123,289 @@ const buildContentFields = (
80
123
  ): ContentConfig => {
81
124
  const notDerivedContentConfig: BaseContentConfig = {
82
125
  /**
83
- * Content configurations
126
+ * File extensions of content to look for to build the dictionaries
127
+ *
128
+ * - Default: ['.content.ts', '.content.js', '.content.cjs', '.content.mjs', '.content.json', '.content.tsx', '.content.jsx']
129
+ *
130
+ * - Example: ['.data.ts', '.data.js', '.data.json']
131
+ *
132
+ * Note:
133
+ * - Can exclude unused file extensions to improve performance
134
+ * - Avoid using common file extensions like '.ts', '.js', '.json' to avoid conflicts
84
135
  */
85
-
86
- // File extensions of content to look for
87
136
  fileExtensions: customConfiguration?.fileExtensions ?? FILE_EXTENSIONS,
88
137
 
89
- // Directory name of the project
138
+ /**
139
+ * Absolute path of the directory of the project
140
+ * - Default: process.cwd()
141
+ * - Example: '/path/to/project'
142
+ *
143
+ * Will be used to resolve all intlayer directories
144
+ *
145
+ * Note:
146
+ * - The base directory should be the root of the project
147
+ * - Can be changed to a custom directory to externalize either the content used in the project, or the intlayer application from the project
148
+ */
90
149
  baseDir: customConfiguration?.baseDir ?? process.cwd(),
91
150
 
92
- // Directory name where the content is stored
151
+ /**
152
+ * Directory name where the content is stored
153
+ *
154
+ * Default: 'src'
155
+ *
156
+ * Example:
157
+ * - 'data' -> '/path/to/project/data'
158
+ * - 'content' -> '/path/to/project/content'
159
+ * - 'locales' -> '/path/to/project/locales'
160
+ *
161
+ * Note: If this directory is not at the base directory level, update the contentDir field instead
162
+ */
93
163
  contentDirName: customConfiguration?.contentDirName ?? CONTENT_DIR_NAME,
94
164
 
95
- // Result directory name
165
+ /**
166
+ * Directory name where the result will be stored
167
+ *
168
+ * Default: '.intlayer'
169
+ *
170
+ * Example:
171
+ * - '.next'
172
+ * - 'outputOFIntlayer'
173
+ *
174
+ * Note: If this directory is not at the base directory level, update the resultDir field instead
175
+ */
96
176
  resultDirName: customConfiguration?.resultDirName ?? RESULT_DIR_NAME,
97
177
 
98
- // Module augmentation directory name
178
+ /**
179
+ *
180
+ * Directory name where the module augmentation will be stored
181
+ *
182
+ * Module augmentation allow better IDE suggestions and type checking
183
+ *
184
+ * Default: 'types'
185
+ *
186
+ * Example: 'intlayer-types'
187
+ *
188
+ * Note:
189
+ * - If this path changed, be sure to include it from the tsconfig.json file
190
+ * - If this directory is not at the base directory level, update the moduleAugmentationDir field instead
191
+ */
99
192
  moduleAugmentationDirName:
100
193
  customConfiguration?.moduleAugmentationDirName ??
101
194
  MODULE_AUGMENTATION_DIR_NAME,
195
+ // @TODO: Make Module Augmentation optional by adding a flag in the configuration
102
196
 
103
- // Bundle directory name
104
- bundleDirName: customConfiguration?.bundleDirName ?? BUNDLE_DIR_NAME,
105
-
106
- // Bundle file extension
107
- bundleFileExtension:
108
- customConfiguration?.bundleFileExtension ?? BUNDLE_FILE_EXTENSION,
109
-
110
- // Dictionary directory name
197
+ /**
198
+ * Related to the intlayer result directory
199
+ *
200
+ * Directory name where the dictionaries will be stored
201
+ *
202
+ * Default: 'dictionary'
203
+ *
204
+ * Example: 'translations'
205
+ *
206
+ * Note:
207
+ * - If this directory is not at the result directory level, update the dictionariesDir field instead
208
+ *
209
+ */
111
210
  dictionariesDirName:
112
211
  customConfiguration?.dictionariesDirName ?? DICTIONARIES_DIR_NAME,
113
212
 
114
- // Types directory name
213
+ /**
214
+ * Related to the intlayer result directory
215
+ *
216
+ * Directory name where the dictionaries will be stored
217
+ *
218
+ * Default: 'dictionary'
219
+ *
220
+ * Example: 'translations'
221
+ *
222
+ * Note:
223
+ * - If this directory is not at the result directory level, update the dictionariesDir field instead
224
+ *
225
+ */
226
+ i18nDictionariesDirName:
227
+ customConfiguration?.i18nDictionariesDirName ??
228
+ I18N_DICTIONARIES_DIR_NAME,
229
+
230
+ /**
231
+ * Related to the intlayer result directory
232
+ *
233
+ * Directory name where the dictionaries types will be stored
234
+ *
235
+ * Default: 'types'
236
+ *
237
+ * Example: 'intlayer-types'
238
+ *
239
+ * Note:
240
+ * - If this directory is not at the result directory level, update the typesDir field instead
241
+ *
242
+ */
115
243
  typeDirName: customConfiguration?.typeDirName ?? TYPES_DIR_NAME,
116
244
 
117
- // Main directory name
245
+ /**
246
+ * Related to the intlayer result directory
247
+ *
248
+ * Directory name where the main files will be stored
249
+ *
250
+ * Default: 'main'
251
+ *
252
+ * Example: 'intlayer-main'
253
+ *
254
+ * Note:
255
+ * - If this directory is not at the result directory level, update the mainDir field instead
256
+ */
118
257
  mainDirName: customConfiguration?.mainDirName ?? MAIN_DIR_NAME,
119
258
 
120
- // Directories to exclude
259
+ /**
260
+ * Should exclude some directories from the content search
261
+ *
262
+ * Default: ['node_modules']
263
+ *
264
+ * Not used yet
265
+ * @TODO Implement the exclusion or remove it
266
+ */
121
267
  excludedPath: customConfiguration?.excludedPath ?? EXCLUDED_PATHS,
122
268
  };
123
269
 
124
270
  const baseDirDerivedConfiguration: BaseDerivedConfig = {
125
- // Directory where the content is stored
271
+ /**
272
+ * Directory where the content is stored
273
+ *
274
+ * Relative to the base directory of the project
275
+ *
276
+ * Default: {{baseDir}} / {{contentDirName}}
277
+ *
278
+ * Example: '/path/to/project/src'
279
+ *
280
+ * Note:
281
+ * - Can be changed to a custom directory to externalize the content used in the project
282
+ * - If the content is not at the base directory level, update the contentDirName field instead
283
+ */
126
284
  contentDir: join(
127
285
  notDerivedContentConfig.baseDir,
128
286
  notDerivedContentConfig.contentDirName
129
287
  ),
130
288
 
131
- // Directory where the result will be stored
289
+ /**
290
+ * Directory where the result will be stored
291
+ *
292
+ * Relative to the base directory of the project
293
+ *
294
+ * Default: {{baseDir}} / {{resultDirName}}
295
+ *
296
+ * Example: '/path/to/project/.intlayer'
297
+ *
298
+ * Note:
299
+ * - Can be changed to a custom directory to externalize the intlayer application from the project
300
+ * - If the result is not at the base directory level, update the resultDirName field instead
301
+ */
132
302
  resultDir: join(
133
303
  notDerivedContentConfig.baseDir,
134
304
  notDerivedContentConfig.resultDirName
135
305
  ),
136
306
 
137
- // Directory where the module augmentation will be stored
307
+ /**
308
+ * Directory where the module augmentation will be stored
309
+ *
310
+ * Module augmentation allow better IDE suggestions and type checking
311
+ *
312
+ * Relative to the base directory of the project
313
+ *
314
+ * Default: {{baseDir}} / {{moduleAugmentationDirName}}
315
+ *
316
+ * Example: '/path/to/project/types'
317
+ *
318
+ * Note:
319
+ * - If this path changed, be sure to include it from the tsconfig.json file
320
+ * - If the module augmentation is not at the base directory level, update the moduleAugmentationDirName field instead
321
+ *
322
+ */
138
323
  moduleAugmentationDir: join(
139
324
  notDerivedContentConfig.baseDir,
140
325
  notDerivedContentConfig.moduleAugmentationDirName
141
326
  ),
327
+
328
+ /**
329
+ * Output format of the dictionary
330
+ *
331
+ * Default: ['intlayer']
332
+ *
333
+ * Note:
334
+ * - 'i18next' is not yet ensure a 1:1 mapping with the i18next library.
335
+ * - Removing 'intlayer' will break the compatibility with react-intlayer or next-intlayer
336
+ */
337
+ dictionaryOutput:
338
+ customConfiguration?.dictionaryOutput ?? DICTIONARY_OUTPUT,
142
339
  };
143
340
 
144
341
  const resultDirDerivedConfiguration: ResultDirDerivedConfig = {
145
- // Directory where the bundle will be stored
146
- bundleDir: join(
342
+ /**
343
+ * Directory where the dictionaries will be stored
344
+ *
345
+ * Relative to the result directory
346
+ *
347
+ * Default: {{resultDir}} / {{dictionariesDirName}}
348
+ *
349
+ * Example: '/path/to/project/.intlayer/dictionary'
350
+ *
351
+ * Note:
352
+ * - If the types are not at the result directory level, update the dictionariesDirName field instead
353
+ * - The dictionaries are stored in JSON format
354
+ * - The dictionaries are used to translate the content
355
+ * - The dictionaries are built from the content files
356
+ */
357
+ dictionariesDir: join(
147
358
  baseDirDerivedConfiguration.resultDir,
148
- notDerivedContentConfig.bundleDirName
359
+ notDerivedContentConfig.dictionariesDirName
149
360
  ),
150
361
 
151
- // Directory where the dictionaries will be stored
152
- dictionariesDir: join(
362
+ /**
363
+ * Directory where the 18n dictionaries will be stored
364
+ *
365
+ * Relative to the result directory
366
+ *
367
+ * Default: {{resultDir}} / {{i18nDictionariesDirName}}
368
+ *
369
+ * Example: '/path/to/project/.intlayer/dictionary/i18n'
370
+ *
371
+ * Note:
372
+ * - If the types are not at the result directory level, update the i18nDictionariesDirName field instead
373
+ */
374
+ i18nDictionariesDir: join(
153
375
  baseDirDerivedConfiguration.resultDir,
154
- notDerivedContentConfig.dictionariesDirName
376
+ notDerivedContentConfig.i18nDictionariesDirName
155
377
  ),
156
378
 
157
- // Directory where the types will be stored
379
+ /**
380
+ * Directory where the dictionaries types will be stored
381
+ *
382
+ * Relative to the result directory
383
+ *
384
+ * Default: {{resultDir}} / {{typeDirName}}
385
+ *
386
+ * Example: '/path/to/project/.intlayer/types'
387
+ *
388
+ * Note:
389
+ * - If the types are not at the result directory level, update the typesDirName field instead
390
+ */
158
391
  typesDir: join(
159
392
  baseDirDerivedConfiguration.resultDir,
160
393
  notDerivedContentConfig.typeDirName
161
394
  ),
162
395
 
163
- // Directory where the main files will be stored
396
+ /**
397
+ * Directory where the main files will be stored
398
+ *
399
+ * Relative to the result directory
400
+ *
401
+ * Default: {{resultDir}} / {{mainDirName}}
402
+ *
403
+ * Example: '/path/to/project/.intlayer/main'
404
+ *
405
+ * Note:
406
+ *
407
+ * - If the main files are not at the result directory level, update the mainDirName field instead
408
+ */
164
409
  mainDir: join(
165
410
  baseDirDerivedConfiguration.resultDir,
166
411
  notDerivedContentConfig.mainDirName
@@ -168,17 +413,29 @@ const buildContentFields = (
168
413
  };
169
414
 
170
415
  const patternsConfiguration: PatternsContentConfig = {
171
- // Pattern of files to watch
416
+ /**
417
+ * Pattern of files to watch
418
+ *
419
+ * Default: ['/**\/*.content.ts', '/**\/*.content.js', '/**\/*.content.json', '/**\/*.content.cjs', '/**\/*.content.mjs', '/**\/*.content.tsx', '/**\/*.content.jsx']
420
+ */
172
421
  watchedFilesPattern: notDerivedContentConfig.fileExtensions.map(
173
422
  (ext) => `/**/*${ext}`
174
423
  ),
175
424
 
176
- // Pattern of files to watch including the relative path
425
+ /**
426
+ * Pattern of files to watch including the relative path
427
+ *
428
+ * Default: ['{{contentDir}}/**\/*.content.ts', '{{contentDir}}/**\/*.content.js', '{{contentDir}}/**\/*.content.json', '{{contentDir}}/**\/*.content.cjs', '{{contentDir}}/**\/*.content.mjs', '{{contentDir}}/**\/*.content.tsx', '{{contentDir}}/**\/*.content.jsx']
429
+ */
177
430
  watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.map(
178
431
  (ext) => `${baseDirDerivedConfiguration.contentDir}/**/*${ext}`
179
432
  ),
180
433
 
181
- // Pattern of files to output
434
+ /**
435
+ * Pattern of dictionary to interpret
436
+ *
437
+ * Default: '{{dictionariesDir}}/**\/*.json'
438
+ */
182
439
  outputFilesPatternWithPath: `${resultDirDerivedConfiguration.dictionariesDir}/**/*.json`,
183
440
  };
184
441
 
@@ -190,6 +447,9 @@ const buildContentFields = (
190
447
  };
191
448
  };
192
449
 
450
+ /**
451
+ * Build the configuration fields by merging the default values with the custom configuration
452
+ */
193
453
  export const buildConfigurationFields = (
194
454
  options: GetConfigurationOptions,
195
455
  customConfiguration?: CustomIntlayerConfig
@@ -19,6 +19,9 @@ const defaultOptions: GetConfigurationOptions = {
19
19
  verbose: false,
20
20
  };
21
21
 
22
+ /**
23
+ * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)
24
+ */
22
25
  export const getConfiguration = (
23
26
  options?: Partial<GetConfigurationOptions>
24
27
  ): IntlayerConfig => {
@@ -1 +1,2 @@
1
1
  export * from './getConfiguration';
2
+ export * from './searchConfigurationFile';
@@ -34,6 +34,19 @@ const transformationOption: BuildOptions = {
34
34
  bundle: true,
35
35
  };
36
36
 
37
+ const filterValidConfiguration = (
38
+ configuration: CustomIntlayerConfig
39
+ ): CustomIntlayerConfig => {
40
+ // @TODO Implement filtering of valid configuration
41
+ return configuration;
42
+ };
43
+
44
+ /**
45
+ * Load the configuration file from the given path
46
+ * Example of configuration file: intlayer.config.js
47
+ *
48
+ * Accepts JSON, JS, MJS and TS files as configuration
49
+ */
37
50
  export const loadConfigurationFile = (
38
51
  configFilePath: string
39
52
  ): CustomIntlayerConfig | undefined => {
@@ -90,7 +103,12 @@ export const loadConfigurationFile = (
90
103
  customConfiguration = sandboxContext.module.exports;
91
104
  }
92
105
 
93
- return customConfiguration;
106
+ if (typeof customConfiguration === 'undefined') {
107
+ console.error('Configuration file could not be loaded.');
108
+ return undefined;
109
+ }
110
+
111
+ return filterValidConfiguration(customConfiguration);
94
112
  } catch (error) {
95
113
  console.error('Error:', error);
96
114
  }
@@ -16,6 +16,17 @@ type SearchConfigurationFileResult = {
16
16
  numCustomConfiguration: number;
17
17
  };
18
18
 
19
+ /**
20
+ * Search for the configuration file in the given path
21
+ *
22
+ * List of detected configuration files:
23
+ * - intlayer.config.ts
24
+ * - intlayer.config.js
25
+ * - intlayer.config.json
26
+ * - intlayer.config.cjs
27
+ * - intlayer.config.mjs
28
+ * - .intlayerrc
29
+ */
19
30
  export const searchConfigurationFile = (
20
31
  configFilePath: string
21
32
  ): SearchConfigurationFileResult => {
@@ -1,4 +1,14 @@
1
- export const FILE_EXTENSIONS = ['.content.ts', '.content.js', '.content.json'];
1
+ import type { DictionaryOutput } from '../types/config';
2
+
3
+ export const FILE_EXTENSIONS = [
4
+ '.content.ts',
5
+ '.content.js',
6
+ '.content.cjs',
7
+ '.content.mjs',
8
+ '.content.json',
9
+ '.content.tsx',
10
+ '.content.jsx',
11
+ ];
2
12
  export const EXCLUDED_PATHS = ['node_modules'];
3
13
 
4
14
  export const CONTENT_DIR_NAME = 'src';
@@ -7,12 +17,12 @@ export const RESULT_DIR_NAME = '.intlayer';
7
17
 
8
18
  export const MODULE_AUGMENTATION_DIR_NAME = 'types';
9
19
 
10
- export const BUNDLE_DIR_NAME = 'bundle';
11
-
12
- export const BUNDLE_FILE_EXTENSION = '.bundle.js';
20
+ export const DICTIONARY_OUTPUT: DictionaryOutput[] = ['intlayer'];
13
21
 
14
22
  export const DICTIONARIES_DIR_NAME = 'dictionary';
15
23
 
24
+ export const I18N_DICTIONARIES_DIR_NAME = 'i18n_dictionary';
25
+
16
26
  export const TYPES_DIR_NAME = 'types';
17
27
 
18
28
  export const MAIN_DIR_NAME = 'main';
@@ -0,0 +1,41 @@
1
+ export type Platform = 'next' | 'vite' | 'react_app' | 'unknown';
2
+
3
+ export const getPlatform = (): Platform => {
4
+ if (
5
+ // eslint-disable-next-line
6
+ typeof import.meta !== 'undefined' &&
7
+ typeof import.meta.env !== 'undefined' &&
8
+ typeof import.meta.env.VITE_INTLAYER_DEFAULT_LOCALE !== 'undefined'
9
+ ) {
10
+ // Likely Vite
11
+ return 'vite';
12
+ } else if (
13
+ typeof process.env.NEXT_PUBLIC_INTLAYER_DEFAULT_LOCALE !== 'undefined'
14
+ ) {
15
+ // Likely Next.js
16
+ return 'next';
17
+ } else if (
18
+ typeof process.env.REACT_APP_INTLAYER_DEFAULT_LOCALE !== 'undefined'
19
+ ) {
20
+ // Likely Create React App
21
+ return 'react_app';
22
+ }
23
+
24
+ return 'unknown';
25
+ };
26
+
27
+ /**
28
+ * Get the prefix for the environment variables to be used in the platform
29
+ */
30
+ export const getPrefix = (platform: Platform): string => {
31
+ switch (platform) {
32
+ case 'next':
33
+ return 'NEXT_PUBLIC_INTLAYER_';
34
+ case 'vite':
35
+ return 'VITE_INTLAYER_';
36
+ case 'react_app':
37
+ return 'REACT_APP_INTLAYER_';
38
+ default:
39
+ return '';
40
+ }
41
+ };
@@ -0,0 +1,20 @@
1
+ import { type Platform, getPlatform } from '../detectPlatform';
2
+ import { extractNextEnvVariable } from './next';
3
+ import { extractReactAppEnvVariable } from './react_app';
4
+ import type { IntlayerConfigEnvVariable } from './types';
5
+ import { extractEmptyEnvVariable } from './undefined_platform';
6
+ import { extractViteEnvVariable } from './vite';
7
+
8
+ export const extractEnvVariable = (): IntlayerConfigEnvVariable => {
9
+ const platform: Platform = getPlatform();
10
+
11
+ if (platform === 'vite') {
12
+ return extractViteEnvVariable();
13
+ } else if (platform === 'next') {
14
+ return extractNextEnvVariable();
15
+ } else if (platform === 'react_app') {
16
+ return extractReactAppEnvVariable();
17
+ }
18
+
19
+ return extractEmptyEnvVariable();
20
+ };