@intlayer/config 2.0.0 → 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.
- package/dist/cjs/configFile/buildConfigurationFields.cjs +21 -1
- package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
- package/dist/cjs/defaultValues/editor.cjs +3 -0
- package/dist/cjs/defaultValues/editor.cjs.map +1 -1
- package/dist/cjs/defaultValues/editor.d.ts +2 -1
- package/dist/cjs/envVariables/extractEnvVariable/next.cjs +2 -1
- package/dist/cjs/envVariables/extractEnvVariable/next.cjs.map +1 -1
- package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs +2 -1
- package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs.map +1 -1
- package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs +2 -1
- package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs.map +1 -1
- package/dist/cjs/envVariables/extractEnvVariable/vite.cjs +2 -1
- package/dist/cjs/envVariables/extractEnvVariable/vite.cjs.map +1 -1
- package/dist/cjs/envVariables/getConfiguration.cjs +2 -1
- package/dist/cjs/envVariables/getConfiguration.cjs.map +1 -1
- package/dist/cjs/types/config.cjs.map +1 -1
- package/dist/cjs/types/config.d.ts +20 -0
- package/dist/esm/configFile/buildConfigurationFields.mjs +21 -1
- package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
- package/dist/esm/defaultValues/editor.d.mts +2 -1
- package/dist/esm/defaultValues/editor.mjs +2 -0
- package/dist/esm/defaultValues/editor.mjs.map +1 -1
- package/dist/esm/envVariables/extractEnvVariable/next.mjs +2 -1
- package/dist/esm/envVariables/extractEnvVariable/next.mjs.map +1 -1
- package/dist/esm/envVariables/extractEnvVariable/react_app.mjs +2 -1
- package/dist/esm/envVariables/extractEnvVariable/react_app.mjs.map +1 -1
- package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs +2 -1
- package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs.map +1 -1
- package/dist/esm/envVariables/extractEnvVariable/vite.mjs +2 -1
- package/dist/esm/envVariables/extractEnvVariable/vite.mjs.map +1 -1
- package/dist/esm/envVariables/getConfiguration.mjs +2 -1
- package/dist/esm/envVariables/getConfiguration.mjs.map +1 -1
- package/dist/esm/types/config.d.mts +20 -0
- package/package.json +2 -3
- package/src/client.ts +0 -11
- package/src/configFile/buildConfigurationFields.ts +0 -503
- package/src/configFile/getConfiguration.ts +0 -78
- package/src/configFile/index.ts +0 -2
- package/src/configFile/loadConfigurationFile.ts +0 -115
- package/src/configFile/searchConfigurationFile.ts +0 -59
- package/src/defaultValues/editor.ts +0 -1
- package/src/defaultValues/internationalization.ts +0 -8
- package/src/defaultValues/middleware.ts +0 -11
- package/src/defaultValues/server.ts +0 -28
- package/src/envVariables/detectPlatform.ts +0 -41
- package/src/envVariables/extractEnvVariable/index.ts +0 -20
- package/src/envVariables/extractEnvVariable/next.ts +0 -64
- package/src/envVariables/extractEnvVariable/react_app.ts +0 -64
- package/src/envVariables/extractEnvVariable/types.ts +0 -10
- package/src/envVariables/extractEnvVariable/undefined_platform.ts +0 -59
- package/src/envVariables/extractEnvVariable/vite.ts +0 -72
- package/src/envVariables/extractEnvVariable/vite_env.d.ts +0 -9
- package/src/envVariables/formatEnvVariable.ts +0 -39
- package/src/envVariables/getConfiguration.ts +0 -109
- package/src/envVariables/index.ts +0 -2
- package/src/envVariables/utils.ts +0 -64
- package/src/types/config.ts +0 -395
- package/src/types/locales.ts +0 -469
|
@@ -1,503 +0,0 @@
|
|
|
1
|
-
import { join } from 'path';
|
|
2
|
-
import {
|
|
3
|
-
DEFAULT_LOCALE,
|
|
4
|
-
LOCALES,
|
|
5
|
-
STRICT_MODE,
|
|
6
|
-
} from '../defaultValues/internationalization';
|
|
7
|
-
import {
|
|
8
|
-
BASE_PATH,
|
|
9
|
-
COOKIE_NAME,
|
|
10
|
-
HEADER_NAME,
|
|
11
|
-
NO_PREFIX,
|
|
12
|
-
PREFIX_DEFAULT,
|
|
13
|
-
SERVER_SET_COOKIE,
|
|
14
|
-
} from '../defaultValues/middleware';
|
|
15
|
-
import {
|
|
16
|
-
CONTENT_DIR_NAME,
|
|
17
|
-
DICTIONARIES_DIR_NAME,
|
|
18
|
-
FILE_EXTENSIONS,
|
|
19
|
-
RESULT_DIR_NAME,
|
|
20
|
-
EXCLUDED_PATHS,
|
|
21
|
-
TYPES_DIR_NAME,
|
|
22
|
-
MAIN_DIR_NAME,
|
|
23
|
-
MODULE_AUGMENTATION_DIR_NAME,
|
|
24
|
-
I18N_DICTIONARIES_DIR_NAME,
|
|
25
|
-
DICTIONARY_OUTPUT,
|
|
26
|
-
} from '../defaultValues/server';
|
|
27
|
-
import type {
|
|
28
|
-
BaseDerivedConfig,
|
|
29
|
-
ContentConfig,
|
|
30
|
-
CustomIntlayerConfig,
|
|
31
|
-
PatternsContentConfig,
|
|
32
|
-
InternationalizationConfig,
|
|
33
|
-
IntlayerConfig,
|
|
34
|
-
MiddlewareConfig,
|
|
35
|
-
BaseContentConfig,
|
|
36
|
-
ResultDirDerivedConfig,
|
|
37
|
-
EditorConfig,
|
|
38
|
-
} from '../types/config';
|
|
39
|
-
import type { GetConfigurationOptions } from './getConfiguration';
|
|
40
|
-
|
|
41
|
-
let storedConfiguration: IntlayerConfig;
|
|
42
|
-
|
|
43
|
-
// @TODO - Add possibility of directories configurations to be arrays to allow multiple packages management
|
|
44
|
-
|
|
45
|
-
const buildInternationalizationFields = (
|
|
46
|
-
customConfiguration?: Partial<InternationalizationConfig>
|
|
47
|
-
): InternationalizationConfig => ({
|
|
48
|
-
/**
|
|
49
|
-
* Locales available in the application
|
|
50
|
-
*
|
|
51
|
-
* Default: ['en']
|
|
52
|
-
*
|
|
53
|
-
*/
|
|
54
|
-
locales: customConfiguration?.locales ?? LOCALES,
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Ensure strong implementations of internationalized content using typescript.
|
|
58
|
-
* - If set to "strict", the translation `t` function will require each declared locales to be defined. If one locale is missing, or if a locale is not declared in your config, it will throw an error.
|
|
59
|
-
* - If set to "required_only", the translation `t` function will require each declared locales to be defined. If one locale is missing, it will throw a warning. But will accept if a locale is not declared in your config, but exist.
|
|
60
|
-
* - If set to "loose", the translation `t` function will accept any existing locale.
|
|
61
|
-
*
|
|
62
|
-
* Default: "required_only"
|
|
63
|
-
*/
|
|
64
|
-
strictMode: customConfiguration?.strictMode ?? STRICT_MODE,
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Default locale of the application for fallback
|
|
68
|
-
*
|
|
69
|
-
* Default: 'en'
|
|
70
|
-
*/
|
|
71
|
-
defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const buildMiddlewareFields = (
|
|
75
|
-
customConfiguration?: Partial<MiddlewareConfig>
|
|
76
|
-
): MiddlewareConfig => ({
|
|
77
|
-
/**
|
|
78
|
-
* Header name to get the locale
|
|
79
|
-
*
|
|
80
|
-
* Default: 'x-intlayer-locale'
|
|
81
|
-
*/
|
|
82
|
-
headerName: customConfiguration?.headerName ?? HEADER_NAME,
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Cookie name to get the locale
|
|
86
|
-
*
|
|
87
|
-
* Default: 'intlayer-locale'
|
|
88
|
-
*/
|
|
89
|
-
cookieName: customConfiguration?.cookieName ?? COOKIE_NAME,
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Prefix the default locale in the URL
|
|
93
|
-
*
|
|
94
|
-
* Default: true
|
|
95
|
-
*/
|
|
96
|
-
prefixDefault: customConfiguration?.prefixDefault ?? PREFIX_DEFAULT,
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Base path of the application URL
|
|
100
|
-
*
|
|
101
|
-
* Default: ''
|
|
102
|
-
*
|
|
103
|
-
* Example:
|
|
104
|
-
* - If the application is hosted at https://example.com/my-app
|
|
105
|
-
* - The base path is '/my-app'
|
|
106
|
-
* - The URL will be https://example.com/my-app/en
|
|
107
|
-
* - If the base path is not set, the URL will be https://example.com/en
|
|
108
|
-
*/
|
|
109
|
-
basePath: customConfiguration?.basePath ?? BASE_PATH,
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Rule to set the cookie on the server
|
|
113
|
-
* - 'always': Set the cookie on every request
|
|
114
|
-
* - 'never': Never set the cookie
|
|
115
|
-
*/
|
|
116
|
-
serverSetCookie: customConfiguration?.serverSetCookie ?? SERVER_SET_COOKIE,
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* No prefix in the URL
|
|
120
|
-
* - true: No prefix in the URL
|
|
121
|
-
* - false: Prefix in the URL
|
|
122
|
-
*
|
|
123
|
-
* Example:
|
|
124
|
-
* - If the application is hosted at https://example.com/my-app
|
|
125
|
-
* - The base path is '/my-app'
|
|
126
|
-
* - The URL will be https://example.com/my-app/en
|
|
127
|
-
* - If the base path is not set, the URL will be https://example.com/en
|
|
128
|
-
* - If no prefix is set, the URL will be https://example.com/en
|
|
129
|
-
* - If the no prefix is set to true, the URL will be https://example.com
|
|
130
|
-
*
|
|
131
|
-
* Default: false
|
|
132
|
-
*/
|
|
133
|
-
noPrefix: customConfiguration?.noPrefix ?? NO_PREFIX,
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const buildContentFields = (
|
|
137
|
-
customConfiguration?: Partial<ContentConfig>
|
|
138
|
-
): ContentConfig => {
|
|
139
|
-
const notDerivedContentConfig: BaseContentConfig = {
|
|
140
|
-
/**
|
|
141
|
-
* File extensions of content to look for to build the dictionaries
|
|
142
|
-
*
|
|
143
|
-
* - Default: ['.content.ts', '.content.js', '.content.cjs', '.content.mjs', '.content.json', '.content.tsx', '.content.jsx']
|
|
144
|
-
*
|
|
145
|
-
* - Example: ['.data.ts', '.data.js', '.data.json']
|
|
146
|
-
*
|
|
147
|
-
* Note:
|
|
148
|
-
* - Can exclude unused file extensions to improve performance
|
|
149
|
-
* - Avoid using common file extensions like '.ts', '.js', '.json' to avoid conflicts
|
|
150
|
-
*/
|
|
151
|
-
fileExtensions: customConfiguration?.fileExtensions ?? FILE_EXTENSIONS,
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Absolute path of the directory of the project
|
|
155
|
-
* - Default: process.cwd()
|
|
156
|
-
* - Example: '/path/to/project'
|
|
157
|
-
*
|
|
158
|
-
* Will be used to resolve all intlayer directories
|
|
159
|
-
*
|
|
160
|
-
* Note:
|
|
161
|
-
* - The base directory should be the root of the project
|
|
162
|
-
* - Can be changed to a custom directory to externalize either the content used in the project, or the intlayer application from the project
|
|
163
|
-
*/
|
|
164
|
-
baseDir: customConfiguration?.baseDir ?? process.cwd(),
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Directory name where the content is stored
|
|
168
|
-
*
|
|
169
|
-
* Default: 'src'
|
|
170
|
-
*
|
|
171
|
-
* Example:
|
|
172
|
-
* - 'data' -> '/path/to/project/data'
|
|
173
|
-
* - 'content' -> '/path/to/project/content'
|
|
174
|
-
* - 'locales' -> '/path/to/project/locales'
|
|
175
|
-
*
|
|
176
|
-
* Note: If this directory is not at the base directory level, update the contentDir field instead
|
|
177
|
-
*/
|
|
178
|
-
contentDirName: customConfiguration?.contentDirName ?? CONTENT_DIR_NAME,
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Directory name where the result will be stored
|
|
182
|
-
*
|
|
183
|
-
* Default: '.intlayer'
|
|
184
|
-
*
|
|
185
|
-
* Example:
|
|
186
|
-
* - '.next'
|
|
187
|
-
* - 'outputOFIntlayer'
|
|
188
|
-
*
|
|
189
|
-
* Note: If this directory is not at the base directory level, update the resultDir field instead
|
|
190
|
-
*/
|
|
191
|
-
resultDirName: customConfiguration?.resultDirName ?? RESULT_DIR_NAME,
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
*
|
|
195
|
-
* Directory name where the module augmentation will be stored
|
|
196
|
-
*
|
|
197
|
-
* Module augmentation allow better IDE suggestions and type checking
|
|
198
|
-
*
|
|
199
|
-
* Default: 'types'
|
|
200
|
-
*
|
|
201
|
-
* Example: 'intlayer-types'
|
|
202
|
-
*
|
|
203
|
-
* Note:
|
|
204
|
-
* - If this path changed, be sure to include it from the tsconfig.json file
|
|
205
|
-
* - If this directory is not at the base directory level, update the moduleAugmentationDir field instead
|
|
206
|
-
*/
|
|
207
|
-
moduleAugmentationDirName:
|
|
208
|
-
customConfiguration?.moduleAugmentationDirName ??
|
|
209
|
-
MODULE_AUGMENTATION_DIR_NAME,
|
|
210
|
-
// @TODO: Make Module Augmentation optional by adding a flag in the configuration
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Related to the intlayer result directory
|
|
214
|
-
*
|
|
215
|
-
* Directory name where the dictionaries will be stored
|
|
216
|
-
*
|
|
217
|
-
* Default: 'dictionary'
|
|
218
|
-
*
|
|
219
|
-
* Example: 'translations'
|
|
220
|
-
*
|
|
221
|
-
* Note:
|
|
222
|
-
* - If this directory is not at the result directory level, update the dictionariesDir field instead
|
|
223
|
-
*
|
|
224
|
-
*/
|
|
225
|
-
dictionariesDirName:
|
|
226
|
-
customConfiguration?.dictionariesDirName ?? DICTIONARIES_DIR_NAME,
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Related to the intlayer result directory
|
|
230
|
-
*
|
|
231
|
-
* Directory name where the dictionaries will be stored
|
|
232
|
-
*
|
|
233
|
-
* Default: 'dictionary'
|
|
234
|
-
*
|
|
235
|
-
* Example: 'translations'
|
|
236
|
-
*
|
|
237
|
-
* Note:
|
|
238
|
-
* - If this directory is not at the result directory level, update the dictionariesDir field instead
|
|
239
|
-
*
|
|
240
|
-
*/
|
|
241
|
-
i18nDictionariesDirName:
|
|
242
|
-
customConfiguration?.i18nDictionariesDirName ??
|
|
243
|
-
I18N_DICTIONARIES_DIR_NAME,
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Related to the intlayer result directory
|
|
247
|
-
*
|
|
248
|
-
* Directory name where the dictionaries types will be stored
|
|
249
|
-
*
|
|
250
|
-
* Default: 'types'
|
|
251
|
-
*
|
|
252
|
-
* Example: 'intlayer-types'
|
|
253
|
-
*
|
|
254
|
-
* Note:
|
|
255
|
-
* - If this directory is not at the result directory level, update the typesDir field instead
|
|
256
|
-
*
|
|
257
|
-
*/
|
|
258
|
-
typeDirName: customConfiguration?.typeDirName ?? TYPES_DIR_NAME,
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Related to the intlayer result directory
|
|
262
|
-
*
|
|
263
|
-
* Directory name where the main files will be stored
|
|
264
|
-
*
|
|
265
|
-
* Default: 'main'
|
|
266
|
-
*
|
|
267
|
-
* Example: 'intlayer-main'
|
|
268
|
-
*
|
|
269
|
-
* Note:
|
|
270
|
-
* - If this directory is not at the result directory level, update the mainDir field instead
|
|
271
|
-
*/
|
|
272
|
-
mainDirName: customConfiguration?.mainDirName ?? MAIN_DIR_NAME,
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Should exclude some directories from the content search
|
|
276
|
-
*
|
|
277
|
-
* Default: ['node_modules']
|
|
278
|
-
*
|
|
279
|
-
* Not used yet
|
|
280
|
-
* @TODO Implement the exclusion or remove it
|
|
281
|
-
*/
|
|
282
|
-
excludedPath: customConfiguration?.excludedPath ?? EXCLUDED_PATHS,
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
const baseDirDerivedConfiguration: BaseDerivedConfig = {
|
|
286
|
-
/**
|
|
287
|
-
* Directory where the content is stored
|
|
288
|
-
*
|
|
289
|
-
* Relative to the base directory of the project
|
|
290
|
-
*
|
|
291
|
-
* Default: {{baseDir}} / {{contentDirName}}
|
|
292
|
-
*
|
|
293
|
-
* Example: '/path/to/project/src'
|
|
294
|
-
*
|
|
295
|
-
* Note:
|
|
296
|
-
* - Can be changed to a custom directory to externalize the content used in the project
|
|
297
|
-
* - If the content is not at the base directory level, update the contentDirName field instead
|
|
298
|
-
*/
|
|
299
|
-
contentDir: join(
|
|
300
|
-
notDerivedContentConfig.baseDir,
|
|
301
|
-
notDerivedContentConfig.contentDirName
|
|
302
|
-
),
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Directory where the result will be stored
|
|
306
|
-
*
|
|
307
|
-
* Relative to the base directory of the project
|
|
308
|
-
*
|
|
309
|
-
* Default: {{baseDir}} / {{resultDirName}}
|
|
310
|
-
*
|
|
311
|
-
* Example: '/path/to/project/.intlayer'
|
|
312
|
-
*
|
|
313
|
-
* Note:
|
|
314
|
-
* - Can be changed to a custom directory to externalize the intlayer application from the project
|
|
315
|
-
* - If the result is not at the base directory level, update the resultDirName field instead
|
|
316
|
-
*/
|
|
317
|
-
resultDir: join(
|
|
318
|
-
notDerivedContentConfig.baseDir,
|
|
319
|
-
notDerivedContentConfig.resultDirName
|
|
320
|
-
),
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Directory where the module augmentation will be stored
|
|
324
|
-
*
|
|
325
|
-
* Module augmentation allow better IDE suggestions and type checking
|
|
326
|
-
*
|
|
327
|
-
* Relative to the base directory of the project
|
|
328
|
-
*
|
|
329
|
-
* Default: {{baseDir}} / {{moduleAugmentationDirName}}
|
|
330
|
-
*
|
|
331
|
-
* Example: '/path/to/project/types'
|
|
332
|
-
*
|
|
333
|
-
* Note:
|
|
334
|
-
* - If this path changed, be sure to include it from the tsconfig.json file
|
|
335
|
-
* - If the module augmentation is not at the base directory level, update the moduleAugmentationDirName field instead
|
|
336
|
-
*
|
|
337
|
-
*/
|
|
338
|
-
moduleAugmentationDir: join(
|
|
339
|
-
notDerivedContentConfig.baseDir,
|
|
340
|
-
notDerivedContentConfig.moduleAugmentationDirName
|
|
341
|
-
),
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Output format of the dictionary
|
|
345
|
-
*
|
|
346
|
-
* Default: ['intlayer']
|
|
347
|
-
*
|
|
348
|
-
* Note:
|
|
349
|
-
* - 'i18next' is not yet ensure a 1:1 mapping with the i18next library.
|
|
350
|
-
* - Removing 'intlayer' will break the compatibility with react-intlayer or next-intlayer
|
|
351
|
-
*/
|
|
352
|
-
dictionaryOutput:
|
|
353
|
-
customConfiguration?.dictionaryOutput ?? DICTIONARY_OUTPUT,
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
const resultDirDerivedConfiguration: ResultDirDerivedConfig = {
|
|
357
|
-
/**
|
|
358
|
-
* Directory where the dictionaries will be stored
|
|
359
|
-
*
|
|
360
|
-
* Relative to the result directory
|
|
361
|
-
*
|
|
362
|
-
* Default: {{resultDir}} / {{dictionariesDirName}}
|
|
363
|
-
*
|
|
364
|
-
* Example: '/path/to/project/.intlayer/dictionary'
|
|
365
|
-
*
|
|
366
|
-
* Note:
|
|
367
|
-
* - If the types are not at the result directory level, update the dictionariesDirName field instead
|
|
368
|
-
* - The dictionaries are stored in JSON format
|
|
369
|
-
* - The dictionaries are used to translate the content
|
|
370
|
-
* - The dictionaries are built from the content files
|
|
371
|
-
*/
|
|
372
|
-
dictionariesDir: join(
|
|
373
|
-
baseDirDerivedConfiguration.resultDir,
|
|
374
|
-
notDerivedContentConfig.dictionariesDirName
|
|
375
|
-
),
|
|
376
|
-
|
|
377
|
-
/**
|
|
378
|
-
* Directory where the 18n dictionaries will be stored
|
|
379
|
-
*
|
|
380
|
-
* Relative to the result directory
|
|
381
|
-
*
|
|
382
|
-
* Default: {{resultDir}} / {{i18nDictionariesDirName}}
|
|
383
|
-
*
|
|
384
|
-
* Example: '/path/to/project/.intlayer/dictionary/i18n'
|
|
385
|
-
*
|
|
386
|
-
* Note:
|
|
387
|
-
* - If the types are not at the result directory level, update the i18nDictionariesDirName field instead
|
|
388
|
-
*/
|
|
389
|
-
i18nDictionariesDir: join(
|
|
390
|
-
baseDirDerivedConfiguration.resultDir,
|
|
391
|
-
notDerivedContentConfig.i18nDictionariesDirName
|
|
392
|
-
),
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Directory where the dictionaries types will be stored
|
|
396
|
-
*
|
|
397
|
-
* Relative to the result directory
|
|
398
|
-
*
|
|
399
|
-
* Default: {{resultDir}} / {{typeDirName}}
|
|
400
|
-
*
|
|
401
|
-
* Example: '/path/to/project/.intlayer/types'
|
|
402
|
-
*
|
|
403
|
-
* Note:
|
|
404
|
-
* - If the types are not at the result directory level, update the typesDirName field instead
|
|
405
|
-
*/
|
|
406
|
-
typesDir: join(
|
|
407
|
-
baseDirDerivedConfiguration.resultDir,
|
|
408
|
-
notDerivedContentConfig.typeDirName
|
|
409
|
-
),
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Directory where the main files will be stored
|
|
413
|
-
*
|
|
414
|
-
* Relative to the result directory
|
|
415
|
-
*
|
|
416
|
-
* Default: {{resultDir}} / {{mainDirName}}
|
|
417
|
-
*
|
|
418
|
-
* Example: '/path/to/project/.intlayer/main'
|
|
419
|
-
*
|
|
420
|
-
* Note:
|
|
421
|
-
*
|
|
422
|
-
* - If the main files are not at the result directory level, update the mainDirName field instead
|
|
423
|
-
*/
|
|
424
|
-
mainDir: join(
|
|
425
|
-
baseDirDerivedConfiguration.resultDir,
|
|
426
|
-
notDerivedContentConfig.mainDirName
|
|
427
|
-
),
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
const patternsConfiguration: PatternsContentConfig = {
|
|
431
|
-
/**
|
|
432
|
-
* Pattern of files to watch
|
|
433
|
-
*
|
|
434
|
-
* Default: ['/**\/*.content.ts', '/**\/*.content.js', '/**\/*.content.json', '/**\/*.content.cjs', '/**\/*.content.mjs', '/**\/*.content.tsx', '/**\/*.content.jsx']
|
|
435
|
-
*/
|
|
436
|
-
watchedFilesPattern: notDerivedContentConfig.fileExtensions.map(
|
|
437
|
-
(ext) => `/**/*${ext}`
|
|
438
|
-
),
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Pattern of files to watch including the relative path
|
|
442
|
-
*
|
|
443
|
-
* Default: ['{{contentDir}}/**\/*.content.ts', '{{contentDir}}/**\/*.content.js', '{{contentDir}}/**\/*.content.json', '{{contentDir}}/**\/*.content.cjs', '{{contentDir}}/**\/*.content.mjs', '{{contentDir}}/**\/*.content.tsx', '{{contentDir}}/**\/*.content.jsx']
|
|
444
|
-
*/
|
|
445
|
-
watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.map(
|
|
446
|
-
(ext) => `${baseDirDerivedConfiguration.contentDir}/**/*${ext}`
|
|
447
|
-
),
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Pattern of dictionary to interpret
|
|
451
|
-
*
|
|
452
|
-
* Default: '{{dictionariesDir}}/**\/*.json'
|
|
453
|
-
*/
|
|
454
|
-
outputFilesPatternWithPath: `${resultDirDerivedConfiguration.dictionariesDir}/**/*.json`,
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
return {
|
|
458
|
-
...notDerivedContentConfig,
|
|
459
|
-
...baseDirDerivedConfiguration,
|
|
460
|
-
...resultDirDerivedConfiguration,
|
|
461
|
-
...patternsConfiguration,
|
|
462
|
-
};
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
const buildEditorFields = (
|
|
466
|
-
customConfiguration?: Partial<EditorConfig>
|
|
467
|
-
): EditorConfig => ({
|
|
468
|
-
/**
|
|
469
|
-
* Port of the editor server
|
|
470
|
-
*
|
|
471
|
-
* Default: 4000
|
|
472
|
-
*/
|
|
473
|
-
port: customConfiguration?.port ?? 4000,
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
* Build the configuration fields by merging the default values with the custom configuration
|
|
478
|
-
*/
|
|
479
|
-
export const buildConfigurationFields = (
|
|
480
|
-
options: GetConfigurationOptions,
|
|
481
|
-
customConfiguration?: CustomIntlayerConfig
|
|
482
|
-
): IntlayerConfig => {
|
|
483
|
-
const internationalizationConfig = buildInternationalizationFields(
|
|
484
|
-
customConfiguration?.internationalization
|
|
485
|
-
);
|
|
486
|
-
|
|
487
|
-
const middlewareConfig = buildMiddlewareFields(
|
|
488
|
-
customConfiguration?.middleware
|
|
489
|
-
);
|
|
490
|
-
|
|
491
|
-
const contentConfig = buildContentFields(customConfiguration?.content);
|
|
492
|
-
|
|
493
|
-
const editorConfig = buildEditorFields(customConfiguration?.editor);
|
|
494
|
-
|
|
495
|
-
storedConfiguration = {
|
|
496
|
-
internationalization: internationalizationConfig,
|
|
497
|
-
middleware: middlewareConfig,
|
|
498
|
-
content: contentConfig,
|
|
499
|
-
editor: editorConfig,
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
return storedConfiguration;
|
|
503
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { relative } from 'path';
|
|
2
|
-
import type { CustomIntlayerConfig, IntlayerConfig } from '../types/config';
|
|
3
|
-
import { buildConfigurationFields } from './buildConfigurationFields';
|
|
4
|
-
import { loadConfigurationFile } from './loadConfigurationFile';
|
|
5
|
-
import { searchConfigurationFile } from './searchConfigurationFile';
|
|
6
|
-
|
|
7
|
-
let storedConfiguration: IntlayerConfig | undefined;
|
|
8
|
-
let storedConfigurationFilePath: string | undefined;
|
|
9
|
-
let storedNumCustomConfiguration: number | undefined;
|
|
10
|
-
|
|
11
|
-
export type GetConfigurationOptions = {
|
|
12
|
-
baseDir: string;
|
|
13
|
-
verbose: boolean;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const BASE_DIR_PATH = process.env.INTLAYER_BASE_DIR_PATH ?? process.cwd();
|
|
17
|
-
const defaultOptions: GetConfigurationOptions = {
|
|
18
|
-
baseDir: BASE_DIR_PATH,
|
|
19
|
-
verbose: false,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)
|
|
24
|
-
*/
|
|
25
|
-
export const getConfiguration = (
|
|
26
|
-
options?: Partial<GetConfigurationOptions>
|
|
27
|
-
): IntlayerConfig => {
|
|
28
|
-
const mergedOptions = { ...defaultOptions, ...options };
|
|
29
|
-
const { baseDir, verbose } = mergedOptions;
|
|
30
|
-
|
|
31
|
-
if (!storedConfiguration) {
|
|
32
|
-
// Search for configuration files
|
|
33
|
-
const { configurationFilePath, numCustomConfiguration } =
|
|
34
|
-
searchConfigurationFile(baseDir);
|
|
35
|
-
|
|
36
|
-
// Load the custom configuration
|
|
37
|
-
let customConfiguration: CustomIntlayerConfig | undefined;
|
|
38
|
-
if (configurationFilePath) {
|
|
39
|
-
customConfiguration = loadConfigurationFile(configurationFilePath);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Save the configuration to avoid reading the file again
|
|
43
|
-
storedConfiguration = buildConfigurationFields(
|
|
44
|
-
mergedOptions,
|
|
45
|
-
customConfiguration
|
|
46
|
-
);
|
|
47
|
-
storedConfigurationFilePath = configurationFilePath;
|
|
48
|
-
storedNumCustomConfiguration = numCustomConfiguration;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Log warning if multiple configuration files are found
|
|
52
|
-
if (verbose)
|
|
53
|
-
logConfigFileResult(
|
|
54
|
-
storedNumCustomConfiguration,
|
|
55
|
-
storedConfigurationFilePath
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
return storedConfiguration;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const logConfigFileResult = (
|
|
62
|
-
numCustomConfiguration?: number,
|
|
63
|
-
configurationFilePath?: string
|
|
64
|
-
) => {
|
|
65
|
-
if (numCustomConfiguration === 0) {
|
|
66
|
-
console.info('Configuration file not found, using default configuration.');
|
|
67
|
-
} else {
|
|
68
|
-
const relativeOutputPath = relative(BASE_DIR_PATH, configurationFilePath!);
|
|
69
|
-
|
|
70
|
-
if (numCustomConfiguration === 1) {
|
|
71
|
-
console.info(`Configuration file found: ${relativeOutputPath}.`);
|
|
72
|
-
} else {
|
|
73
|
-
console.warn(
|
|
74
|
-
`Multiple configuration files found, using ${relativeOutputPath}.`
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
package/src/configFile/index.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
import { createRequire } from 'module';
|
|
3
|
-
import { type Context, runInNewContext } from 'vm';
|
|
4
|
-
import { type BuildOptions, buildSync, type BuildResult } from 'esbuild';
|
|
5
|
-
import type { CustomIntlayerConfig } from '../types/config';
|
|
6
|
-
|
|
7
|
-
const isESModule = typeof import.meta.url === 'string';
|
|
8
|
-
|
|
9
|
-
const sandboxContext: Context = {
|
|
10
|
-
exports: {
|
|
11
|
-
default: {},
|
|
12
|
-
},
|
|
13
|
-
module: {
|
|
14
|
-
exports: {},
|
|
15
|
-
},
|
|
16
|
-
console,
|
|
17
|
-
require: isESModule ? createRequire(import.meta.url) : require,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const transformationOption: BuildOptions = {
|
|
21
|
-
loader: {
|
|
22
|
-
'.js': 'js',
|
|
23
|
-
'.jsx': 'jsx',
|
|
24
|
-
'.mjs': 'js',
|
|
25
|
-
'.ts': 'ts',
|
|
26
|
-
'.tsx': 'tsx',
|
|
27
|
-
'.cjs': 'js',
|
|
28
|
-
'.json': 'json',
|
|
29
|
-
},
|
|
30
|
-
format: 'cjs', // Output format as commonjs
|
|
31
|
-
target: 'es2017',
|
|
32
|
-
packages: 'external',
|
|
33
|
-
write: false,
|
|
34
|
-
bundle: true,
|
|
35
|
-
};
|
|
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
|
-
*/
|
|
50
|
-
export const loadConfigurationFile = (
|
|
51
|
-
configFilePath: string
|
|
52
|
-
): CustomIntlayerConfig | undefined => {
|
|
53
|
-
let customConfiguration: CustomIntlayerConfig | undefined = undefined;
|
|
54
|
-
|
|
55
|
-
const configFileExtension = configFilePath.split('.').pop() ?? '';
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
if (configFileExtension === 'json') {
|
|
59
|
-
// Assume JSON
|
|
60
|
-
return require(configFilePath);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Rest is JS, MJS or TS
|
|
64
|
-
|
|
65
|
-
const moduleResult: BuildResult = buildSync({
|
|
66
|
-
entryPoints: [configFilePath],
|
|
67
|
-
|
|
68
|
-
...transformationOption,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const moduleResultString = moduleResult.outputFiles?.[0].text;
|
|
72
|
-
|
|
73
|
-
if (!moduleResultString) {
|
|
74
|
-
console.error('Configuration file could not be loaded.');
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
runInNewContext(moduleResultString, sandboxContext);
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
sandboxContext.exports.default &&
|
|
82
|
-
Object.keys(sandboxContext.exports.default).length > 0
|
|
83
|
-
) {
|
|
84
|
-
// ES Module
|
|
85
|
-
customConfiguration = sandboxContext.exports.default;
|
|
86
|
-
} else if (
|
|
87
|
-
sandboxContext.module.exports.defaults &&
|
|
88
|
-
Object.keys(sandboxContext.module.exports.defaults).length > 0
|
|
89
|
-
) {
|
|
90
|
-
// CommonJS
|
|
91
|
-
customConfiguration = sandboxContext.module.exports.default;
|
|
92
|
-
} else if (
|
|
93
|
-
sandboxContext.module.exports.default &&
|
|
94
|
-
Object.keys(sandboxContext.module.exports.default).length > 0
|
|
95
|
-
) {
|
|
96
|
-
// ES Module
|
|
97
|
-
customConfiguration = sandboxContext.module.exports.default;
|
|
98
|
-
} else if (
|
|
99
|
-
sandboxContext.module.exports &&
|
|
100
|
-
Object.keys(sandboxContext.module.exports).length > 0
|
|
101
|
-
) {
|
|
102
|
-
// Other
|
|
103
|
-
customConfiguration = sandboxContext.module.exports;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (typeof customConfiguration === 'undefined') {
|
|
107
|
-
console.error('Configuration file could not be loaded.');
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return filterValidConfiguration(customConfiguration);
|
|
112
|
-
} catch (error) {
|
|
113
|
-
console.error('Error:', error);
|
|
114
|
-
}
|
|
115
|
-
};
|