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