@intlayer/config 1.2.1 → 2.0.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 (76) hide show
  1. package/dist/cjs/client.cjs.map +1 -1
  2. package/dist/cjs/client.d.ts +1 -1
  3. package/dist/cjs/configFile/buildConfigurationFields.cjs +40 -1
  4. package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
  5. package/dist/cjs/defaultValues/editor.cjs +32 -0
  6. package/dist/cjs/defaultValues/editor.cjs.map +1 -0
  7. package/dist/cjs/defaultValues/editor.d.ts +4 -0
  8. package/dist/cjs/defaultValues/internationalization.cjs +5 -2
  9. package/dist/cjs/defaultValues/internationalization.cjs.map +1 -1
  10. package/dist/cjs/defaultValues/internationalization.d.ts +3 -1
  11. package/dist/cjs/envVariables/extractEnvVariable/next.cjs +7 -1
  12. package/dist/cjs/envVariables/extractEnvVariable/next.cjs.map +1 -1
  13. package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs +7 -1
  14. package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs.map +1 -1
  15. package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs +7 -1
  16. package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs.map +1 -1
  17. package/dist/cjs/envVariables/extractEnvVariable/vite.cjs +7 -1
  18. package/dist/cjs/envVariables/extractEnvVariable/vite.cjs.map +1 -1
  19. package/dist/cjs/envVariables/formatEnvVariable.cjs +2 -1
  20. package/dist/cjs/envVariables/formatEnvVariable.cjs.map +1 -1
  21. package/dist/cjs/envVariables/getConfiguration.cjs +10 -1
  22. package/dist/cjs/envVariables/getConfiguration.cjs.map +1 -1
  23. package/dist/cjs/index.cjs.map +1 -1
  24. package/dist/cjs/index.d.ts +1 -1
  25. package/dist/cjs/types/config.cjs.map +1 -1
  26. package/dist/cjs/types/config.d.ts +52 -1
  27. package/dist/esm/client.d.mts +1 -1
  28. package/dist/esm/client.mjs.map +1 -1
  29. package/dist/esm/configFile/buildConfigurationFields.mjs +45 -2
  30. package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
  31. package/dist/esm/defaultValues/editor.d.mts +4 -0
  32. package/dist/esm/defaultValues/editor.mjs +7 -0
  33. package/dist/esm/defaultValues/editor.mjs.map +1 -0
  34. package/dist/esm/defaultValues/internationalization.d.mts +3 -1
  35. package/dist/esm/defaultValues/internationalization.mjs +3 -1
  36. package/dist/esm/defaultValues/internationalization.mjs.map +1 -1
  37. package/dist/esm/envVariables/extractEnvVariable/next.mjs +7 -1
  38. package/dist/esm/envVariables/extractEnvVariable/next.mjs.map +1 -1
  39. package/dist/esm/envVariables/extractEnvVariable/react_app.mjs +7 -1
  40. package/dist/esm/envVariables/extractEnvVariable/react_app.mjs.map +1 -1
  41. package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs +7 -1
  42. package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs.map +1 -1
  43. package/dist/esm/envVariables/extractEnvVariable/vite.mjs +7 -1
  44. package/dist/esm/envVariables/extractEnvVariable/vite.mjs.map +1 -1
  45. package/dist/esm/envVariables/formatEnvVariable.mjs +2 -1
  46. package/dist/esm/envVariables/formatEnvVariable.mjs.map +1 -1
  47. package/dist/esm/envVariables/getConfiguration.mjs +10 -1
  48. package/dist/esm/envVariables/getConfiguration.mjs.map +1 -1
  49. package/dist/esm/index.d.mts +1 -1
  50. package/dist/esm/index.mjs.map +1 -1
  51. package/dist/esm/types/config.d.mts +52 -1
  52. package/package.json +2 -3
  53. package/src/index.ts +1 -0
  54. package/src/client.ts +0 -11
  55. package/src/configFile/buildConfigurationFields.ts +0 -474
  56. package/src/configFile/getConfiguration.ts +0 -78
  57. package/src/configFile/index.ts +0 -2
  58. package/src/configFile/loadConfigurationFile.ts +0 -115
  59. package/src/configFile/searchConfigurationFile.ts +0 -59
  60. package/src/defaultValues/internationalization.ts +0 -5
  61. package/src/defaultValues/middleware.ts +0 -11
  62. package/src/defaultValues/server.ts +0 -28
  63. package/src/envVariables/detectPlatform.ts +0 -41
  64. package/src/envVariables/extractEnvVariable/index.ts +0 -20
  65. package/src/envVariables/extractEnvVariable/next.ts +0 -57
  66. package/src/envVariables/extractEnvVariable/react_app.ts +0 -57
  67. package/src/envVariables/extractEnvVariable/types.ts +0 -10
  68. package/src/envVariables/extractEnvVariable/undefined_platform.ts +0 -52
  69. package/src/envVariables/extractEnvVariable/vite.ts +0 -65
  70. package/src/envVariables/extractEnvVariable/vite_env.d.ts +0 -9
  71. package/src/envVariables/formatEnvVariable.ts +0 -38
  72. package/src/envVariables/getConfiguration.ts +0 -99
  73. package/src/envVariables/index.ts +0 -2
  74. package/src/envVariables/utils.ts +0 -64
  75. package/src/types/config.ts +0 -360
  76. package/src/types/locales.ts +0 -469
@@ -1,64 +0,0 @@
1
- function getEnvValue(
2
- value: unknown,
3
- type: 'boolean',
4
- verbose?: boolean
5
- ): boolean | undefined;
6
- function getEnvValue(
7
- value: unknown,
8
- type: 'number',
9
- verbose?: boolean
10
- ): number | undefined;
11
- function getEnvValue<T extends string>(
12
- value: unknown,
13
- type: 'string',
14
- verbose?: boolean
15
- ): T | undefined;
16
- function getEnvValue<T>(
17
- value: unknown,
18
- type: 'object',
19
- verbose?: boolean
20
- ): T | undefined;
21
- function getEnvValue<T>(
22
- value: unknown,
23
- type: 'array',
24
- verbose?: boolean
25
- ): T[] | undefined;
26
- function getEnvValue(
27
- value: unknown,
28
- type: 'string' | 'boolean' | 'number' | 'object' | 'array',
29
- verbose = false
30
- ) {
31
- try {
32
- switch (type) {
33
- case 'boolean':
34
- // Convert string to boolean explicitly
35
- return value === 'true' || value === '1';
36
-
37
- case 'number':
38
- // Convert string to number, return undefined if conversion fails
39
- return Number(value);
40
-
41
- case 'string':
42
- // Return the string directly
43
- return value ?? '';
44
-
45
- case 'object':
46
- case 'array':
47
- // Attempt to parse the value as JSON
48
- return JSON.parse(value as string);
49
-
50
- default:
51
- return undefined;
52
- }
53
- } catch (error) {
54
- // Log error and return undefined if any error occurs during parsing
55
- if (verbose) {
56
- console.error(
57
- `Error parsing environment variable, parsing : ${((value ?? '') as string).toString()}`
58
- );
59
- }
60
- return undefined;
61
- }
62
- }
63
-
64
- export { getEnvValue };
@@ -1,360 +0,0 @@
1
- import type { Locales } from './locales';
2
-
3
- /**
4
- * Configuration for internationalization settings
5
- */
6
- export type InternationalizationConfig = {
7
- /**
8
- * Locales available in the application
9
- *
10
- * Default: [Locales.ENGLISH]
11
- *
12
- * You can define a list of available locales to support in the application.
13
- */
14
- locales: Locales[];
15
-
16
- /**
17
- * Default locale of the application for fallback
18
- *
19
- * Default: Locales.ENGLISH
20
- *
21
- * Used to specify a fallback locale in case no other locale is set.
22
- */
23
- defaultLocale: Locales;
24
- };
25
-
26
- export type ServerSetCookieRule = 'always' | 'never';
27
-
28
- /**
29
- * Configuration for middleware behaviors
30
- */
31
- export type MiddlewareConfig = {
32
- /**
33
- * Header name to get the locale from the request
34
- *
35
- * Default: 'x-intlayer-locale'
36
- *
37
- * The HTTP header key used to determine the current locale.
38
- */
39
- headerName: string;
40
-
41
- /**
42
- * Cookie name to store the locale information
43
- *
44
- * Default: 'NEXT_LOCALE'
45
- *
46
- * The cookie key where the locale information is stored.
47
- */
48
- cookieName: string;
49
-
50
- /**
51
- * Whether to prefix the default locale in the URL
52
- *
53
- * Default: false
54
- *
55
- * When set to true, the default locale is prefixed in the URL for localization purposes.
56
- */
57
- prefixDefault: boolean;
58
-
59
- /**
60
- * Base path for application URLs
61
- *
62
- * Default: ''
63
- *
64
- * Defines the base path where the application is accessible from.
65
- */
66
- basePath: string;
67
-
68
- /**
69
- * Strategy for setting the locale cookie on the server
70
- *
71
- * Default: 'always'
72
- *
73
- * This setting controls when the server sets the locale cookie. It can either set the cookie on every request or never set it.
74
- */
75
- serverSetCookie: ServerSetCookieRule;
76
-
77
- /**
78
- * Indicates if no prefix should be used in the URL for locale
79
- *
80
- * Default: false
81
- *
82
- * If true, no locale-based prefix is used in the URL.
83
- */
84
- noPrefix: boolean;
85
- };
86
-
87
- /**
88
- * Custom configuration that can be provided to override default settings
89
- */
90
- export type CustomIntlayerConfig = {
91
- /**
92
- * Custom internationalization configuration
93
- */
94
- internationalization?: Partial<InternationalizationConfig>;
95
-
96
- /**
97
- * Custom middleware configuration
98
- */
99
- middleware?: Partial<MiddlewareConfig>;
100
-
101
- /**
102
- * Custom content configuration
103
- */
104
- content?: Partial<ContentConfig>;
105
- };
106
-
107
- /**
108
- * Combined configuration for internationalization, middleware, and content
109
- */
110
- export type IntlayerConfig = {
111
- /**
112
- * Internationalization configuration
113
- */
114
- internationalization: InternationalizationConfig;
115
-
116
- /**
117
- * Middleware configuration
118
- */
119
- middleware: MiddlewareConfig;
120
-
121
- /**
122
- * Content configuration
123
- */
124
- content: ContentConfig;
125
- };
126
-
127
- /**
128
- * Base configuration for content handling
129
- */
130
- export type BaseContentConfig = {
131
- /**
132
- * File extensions of content to look for
133
- *
134
- * Default: ['.content.ts', '.content.js', '.content.cjs', '.content.mjs', '.content.json', '.content.tsx', '.content.jsx']
135
- *
136
- * List of file extensions to scan for content.
137
- */
138
- fileExtensions: string[];
139
-
140
- /**
141
- * Absolute path of the project's base directory
142
- *
143
- * Default: process.cwd()
144
- *
145
- * The root directory of the project, typically used for resolving other paths.
146
- */
147
- baseDir: string;
148
-
149
- /**
150
- * Name of the directory where the content is stored
151
- *
152
- * Default: 'src'
153
- *
154
- * Specifies the directory where the primary content is stored.
155
- */
156
- contentDirName: string;
157
-
158
- /**
159
- * Directories to be excluded from content processing
160
- *
161
- * Default: ['node_modules']
162
- *
163
- * A list of directories to exclude from content processing.
164
- */
165
- excludedPath: string[];
166
-
167
- /**
168
- * Name of the directory where results are stored
169
- *
170
- * Default: '.intlayer'
171
- *
172
- * The directory for storing intermediate or output results.
173
- */
174
- resultDirName: string;
175
-
176
- /**
177
- * Name of the directory for module augmentation
178
- *
179
- * Default: 'types'
180
- *
181
- * Defines the directory for additional module types.
182
- */
183
- moduleAugmentationDirName: string;
184
-
185
- /**
186
- * Name of the directory where dictionaries are stored
187
- *
188
- * Default: 'dictionary'
189
- *
190
- * The directory for storing localization dictionaries.
191
- *
192
- * Note:
193
- * - Ensure the dictionaries output includes intlayer to build the dictionaries for intlayer
194
- */
195
- dictionariesDirName: string;
196
-
197
- /**
198
- * Name of the directory where dictionaries are stored
199
- *
200
- * Default: 'i18n_dictionary'
201
- *
202
- * The directory for storing localization dictionaries.
203
- *
204
- * Note:
205
- * - Ensure the dictionaries output includes 'i18next' to build the dictionaries for i18next
206
- */
207
- i18nDictionariesDirName: string;
208
-
209
- /**
210
- * Name of the directory where dictionary types are stored
211
- *
212
- * Default: 'types'
213
- *
214
- * The directory for storing dictionary type definitions.
215
- */
216
- typeDirName: string;
217
-
218
- /**
219
- * Name of the directory where the main files are stored
220
- *
221
- * Default: 'main'
222
- *
223
- * Specifies the directory for storing main application files.
224
- */
225
- mainDirName: string;
226
- };
227
-
228
- export type DictionaryOutput = 'intlayer' | 'i18next';
229
-
230
- /**
231
- * Configuration derived based on the base content configuration
232
- */
233
- export type BaseDerivedConfig = {
234
- /**
235
- * Directory where the content is stored, relative to the base directory
236
- *
237
- * Default: {{baseDir}} / {{contentDirName}}
238
- *
239
- * Derived content directory based on the base configuration.
240
- */
241
- contentDir: string;
242
-
243
- /**
244
- * Directory where the results are stored, relative to the base directory
245
- *
246
- * Default: {{baseDir}} / {{resultDirName}}
247
- *
248
- * Derived results directory based on the base configuration.
249
- */
250
- resultDir: string;
251
-
252
- /**
253
- * Directory for module augmentation, relative to the base directory
254
- *
255
- * Default: {{baseDir}} / {{moduleAugmentationDirName}}
256
- *
257
- * Defines the derived path for module augmentation.
258
- */
259
- moduleAugmentationDir: string;
260
-
261
- /**
262
- * Type of dictionary to use as an output
263
- *
264
- * Default: ['intlayer']
265
- *
266
- * The type of dictionary to use as an output. It can be either 'intlayer' or 'i18next'.
267
- *
268
- * Note:
269
- * - 'i18next' is not yet ensure a 1:1 mapping with the i18next library.
270
- * - Removing 'intlayer' will break the compatibility with react-intlayer or next-intlayer
271
- *
272
- */
273
- dictionaryOutput: DictionaryOutput[];
274
- };
275
-
276
- /**
277
- * Configuration derived based on the result directory
278
- */
279
- export type ResultDirDerivedConfig = {
280
- /**
281
- * Directory where dictionaries are stored, relative to the result directory
282
- *
283
- * Default: {{resultDir}} / {{dictionariesDirName}}
284
- *
285
- * Specifies the derived path for dictionaries relative to the result directory.
286
- */
287
- dictionariesDir: string;
288
-
289
- /**
290
- *
291
- * Directory where dictionaries are stored, relative to the result directory
292
- *
293
- * Default: {{resultDir}} / {{i18nDictionariesDirName}}
294
- *
295
- * Specifies the derived path for dictionaries relative to the result directory.
296
- *
297
- * Note:
298
- * - Ensure the i18n dictionaries output includes i18next to build the dictionaries for i18next
299
- */
300
- i18nDictionariesDir: string;
301
-
302
- /**
303
- * Directory where dictionary types are stored, relative to the result directory
304
- *
305
- * Default: {{resultDir}} / {{typeDirName}}
306
- *
307
- * Specifies the derived path for dictionary types relative to the result directory.
308
- */
309
- typesDir: string;
310
-
311
- /**
312
- * Directory where the main files are stored, relative to the result directory
313
- *
314
- * Default: {{resultDir}} / {{mainDirName}}
315
- *
316
- * Specifies the derived path for the main files relative to the result directory.
317
- */
318
- mainDir: string;
319
- };
320
-
321
- /**
322
- * Configuration for content patterns
323
- */
324
- export type PatternsContentConfig = {
325
- /**
326
- * Patterns of files to watch for changes
327
- *
328
- * Default: ['/**\/*.content.ts', '/**\/*.content.js', '/**\/*.content.json', '/**\/*.content.cjs', '/**\/*.content.mjs', '/**\/*.content.tsx', '/**\/*.content.jsx']
329
- *
330
- * Defines file patterns for content to watch for changes.
331
- */
332
- watchedFilesPattern: string[];
333
-
334
- /**
335
- * Patterns of files to watch for changes including the relative path
336
- *
337
- * Default: ['{{contentDir}}/**\/*.content.ts', '{{contentDir}}/**\/*.content.js', '{{contentDir}}/**\/*.content.json', '{{contentDir}}/**\/*.content.cjs', '{{contentDir}}/**\/*.content.mjs', '{{contentDir}}/**\/*.content.tsx', '{{contentDir}}/**\/*.content.jsx']
338
- *
339
- * Specifies the file patterns for content to watch, including relative paths.
340
- */
341
- watchedFilesPatternWithPath: string[];
342
-
343
- /**
344
- * Pattern for output files including the relative path
345
- *
346
- * Default: '{{dictionariesDir}}/**\/*.json'
347
- *
348
- * Defines the pattern for output files, including the relative path.
349
- */
350
- outputFilesPatternWithPath: string;
351
- };
352
-
353
- // @TODO: Implement exclusion of non configurable fields, to not allow them to be set in the config
354
- /**
355
- * General configuration derived from the config file
356
- */
357
- export type ContentConfig = BaseContentConfig &
358
- BaseDerivedConfig &
359
- ResultDirDerivedConfig &
360
- PatternsContentConfig;