@intlayer/config 1.0.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/LICENSE +21 -0
- package/dist/cjs/client.cjs +48 -0
- package/dist/cjs/client.cjs.map +1 -0
- package/dist/cjs/client.d.ts +16 -0
- package/dist/cjs/configFile/buildConfigurationFields.cjs +182 -0
- package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -0
- package/dist/cjs/configFile/buildConfigurationFields.d.ts +10 -0
- package/dist/cjs/configFile/getConfiguration.cjs +90 -0
- package/dist/cjs/configFile/getConfiguration.cjs.map +1 -0
- package/dist/cjs/configFile/getConfiguration.d.ts +12 -0
- package/dist/cjs/configFile/index.cjs +35 -0
- package/dist/cjs/configFile/index.cjs.map +1 -0
- package/dist/cjs/configFile/index.d.ts +6 -0
- package/dist/cjs/configFile/loadConfigurationFile.cjs +110 -0
- package/dist/cjs/configFile/loadConfigurationFile.cjs.map +1 -0
- package/dist/cjs/configFile/loadConfigurationFile.d.ts +8 -0
- package/dist/cjs/configFile/searchConfigurationFile.cjs +63 -0
- package/dist/cjs/configFile/searchConfigurationFile.cjs.map +1 -0
- package/dist/cjs/configFile/searchConfigurationFile.d.ts +9 -0
- package/dist/cjs/defaultValues/internationalization.cjs +42 -0
- package/dist/cjs/defaultValues/internationalization.cjs.map +1 -0
- package/dist/cjs/defaultValues/internationalization.d.ts +6 -0
- package/dist/cjs/defaultValues/locales.cjs +266 -0
- package/dist/cjs/defaultValues/locales.cjs.map +1 -0
- package/dist/cjs/defaultValues/locales.d.ts +234 -0
- package/dist/cjs/defaultValues/middleware.cjs +49 -0
- package/dist/cjs/defaultValues/middleware.cjs.map +1 -0
- package/dist/cjs/defaultValues/middleware.d.ts +15 -0
- package/dist/cjs/defaultValues/server.cjs +61 -0
- package/dist/cjs/defaultValues/server.cjs.map +1 -0
- package/dist/cjs/defaultValues/server.d.ts +23 -0
- package/dist/cjs/envVariables/formatEnvVariable.cjs +52 -0
- package/dist/cjs/envVariables/formatEnvVariable.cjs.map +1 -0
- package/dist/cjs/envVariables/formatEnvVariable.d.ts +3 -0
- package/dist/cjs/envVariables/getConfiguration.cjs +170 -0
- package/dist/cjs/envVariables/getConfiguration.cjs.map +1 -0
- package/dist/cjs/envVariables/getConfiguration.d.ts +21 -0
- package/dist/cjs/envVariables/index.cjs +48 -0
- package/dist/cjs/envVariables/index.cjs.map +1 -0
- package/dist/cjs/envVariables/index.d.ts +10 -0
- package/dist/cjs/envVariables/utils.cjs +56 -0
- package/dist/cjs/envVariables/utils.cjs.map +1 -0
- package/dist/cjs/envVariables/utils.d.ts +16 -0
- package/dist/cjs/index.cjs +53 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +22 -0
- package/dist/cjs/types/index.cjs +21 -0
- package/dist/cjs/types/index.cjs.map +1 -0
- package/dist/cjs/types/index.d.ts +89 -0
- package/dist/esm/client.d.mts +16 -0
- package/dist/esm/client.mjs +17 -0
- package/dist/esm/client.mjs.map +1 -0
- package/dist/esm/configFile/buildConfigurationFields.d.mts +10 -0
- package/dist/esm/configFile/buildConfigurationFields.mjs +159 -0
- package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -0
- package/dist/esm/configFile/getConfiguration.d.mts +12 -0
- package/dist/esm/configFile/getConfiguration.mjs +52 -0
- package/dist/esm/configFile/getConfiguration.mjs.map +1 -0
- package/dist/esm/configFile/index.d.mts +6 -0
- package/dist/esm/configFile/index.mjs +2 -0
- package/dist/esm/configFile/index.mjs.map +1 -0
- package/dist/esm/configFile/loadConfigurationFile.d.mts +8 -0
- package/dist/esm/configFile/loadConfigurationFile.mjs +76 -0
- package/dist/esm/configFile/loadConfigurationFile.mjs.map +1 -0
- package/dist/esm/configFile/searchConfigurationFile.d.mts +9 -0
- package/dist/esm/configFile/searchConfigurationFile.mjs +32 -0
- package/dist/esm/configFile/searchConfigurationFile.mjs.map +1 -0
- package/dist/esm/defaultValues/internationalization.d.mts +6 -0
- package/dist/esm/defaultValues/internationalization.mjs +5 -0
- package/dist/esm/defaultValues/internationalization.mjs.map +1 -0
- package/dist/esm/defaultValues/locales.d.mts +234 -0
- package/dist/esm/defaultValues/locales.mjs +235 -0
- package/dist/esm/defaultValues/locales.mjs.map +1 -0
- package/dist/esm/defaultValues/middleware.d.mts +15 -0
- package/dist/esm/defaultValues/middleware.mjs +15 -0
- package/dist/esm/defaultValues/middleware.mjs.map +1 -0
- package/dist/esm/defaultValues/server.d.mts +23 -0
- package/dist/esm/defaultValues/server.mjs +23 -0
- package/dist/esm/defaultValues/server.mjs.map +1 -0
- package/dist/esm/envVariables/formatEnvVariable.d.mts +3 -0
- package/dist/esm/envVariables/formatEnvVariable.mjs +21 -0
- package/dist/esm/envVariables/formatEnvVariable.mjs.map +1 -0
- package/dist/esm/envVariables/getConfiguration.d.mts +21 -0
- package/dist/esm/envVariables/getConfiguration.mjs +110 -0
- package/dist/esm/envVariables/getConfiguration.mjs.map +1 -0
- package/dist/esm/envVariables/index.d.mts +10 -0
- package/dist/esm/envVariables/index.mjs +17 -0
- package/dist/esm/envVariables/index.mjs.map +1 -0
- package/dist/esm/envVariables/utils.d.mts +16 -0
- package/dist/esm/envVariables/utils.mjs +25 -0
- package/dist/esm/envVariables/utils.mjs.map +1 -0
- package/dist/esm/index.d.mts +22 -0
- package/dist/esm/index.mjs +21 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/types/index.d.mts +89 -0
- package/dist/esm/types/index.mjs +1 -0
- package/dist/esm/types/index.mjs.map +1 -0
- package/package.json +88 -0
- package/src/client.ts +16 -0
- package/src/configFile/buildConfigurationFields.ts +214 -0
- package/src/configFile/getConfiguration.ts +75 -0
- package/src/configFile/index.ts +1 -0
- package/src/configFile/loadConfigurationFile.ts +97 -0
- package/src/configFile/searchConfigurationFile.ts +48 -0
- package/src/defaultValues/internationalization.ts +9 -0
- package/src/defaultValues/locales.ts +463 -0
- package/src/defaultValues/middleware.ts +11 -0
- package/src/defaultValues/server.ts +18 -0
- package/src/envVariables/formatEnvVariable.ts +32 -0
- package/src/envVariables/getConfiguration.ts +121 -0
- package/src/envVariables/index.ts +8 -0
- package/src/envVariables/utils.ts +47 -0
- package/src/index.ts +23 -0
- package/src/types/index.ts +144 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function getEnvValue(value: unknown, type: 'boolean'): boolean | undefined;
|
|
2
|
+
function getEnvValue(value: unknown, type: 'number'): number | undefined;
|
|
3
|
+
function getEnvValue<T extends string>(
|
|
4
|
+
value: unknown,
|
|
5
|
+
type: 'string'
|
|
6
|
+
): T | undefined;
|
|
7
|
+
function getEnvValue<T>(value: unknown, type: 'object'): T | undefined;
|
|
8
|
+
function getEnvValue<T>(value: unknown, type: 'array'): T[] | undefined;
|
|
9
|
+
function getEnvValue(
|
|
10
|
+
value: unknown,
|
|
11
|
+
type: 'string' | 'boolean' | 'number' | 'object' | 'array'
|
|
12
|
+
) {
|
|
13
|
+
// Handle cases where the environment variable is not set
|
|
14
|
+
if (value === undefined) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
switch (type) {
|
|
20
|
+
case 'boolean':
|
|
21
|
+
// Convert string to boolean explicitly
|
|
22
|
+
return value === 'true' || value === '1';
|
|
23
|
+
|
|
24
|
+
case 'number':
|
|
25
|
+
// Convert string to number, return undefined if conversion fails
|
|
26
|
+
return Number(value);
|
|
27
|
+
|
|
28
|
+
case 'string':
|
|
29
|
+
// Return the string directly
|
|
30
|
+
return value;
|
|
31
|
+
|
|
32
|
+
case 'object':
|
|
33
|
+
case 'array':
|
|
34
|
+
// Attempt to parse the value as JSON
|
|
35
|
+
return JSON.parse(value as string);
|
|
36
|
+
|
|
37
|
+
default:
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
} catch (error) {
|
|
41
|
+
// Log error and return undefined if any error occurs during parsing
|
|
42
|
+
console.error(`Error parsing environment variable`);
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { getEnvValue };
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { getConfiguration } from './configFile/getConfiguration';
|
|
2
|
+
|
|
3
|
+
export type {
|
|
4
|
+
InternationalizationConfig,
|
|
5
|
+
ServerSetCookieRule,
|
|
6
|
+
MiddlewareConfig,
|
|
7
|
+
CustomIntlayerConfig,
|
|
8
|
+
BaseContentConfig,
|
|
9
|
+
BaseDerivedConfig,
|
|
10
|
+
ResultDirDerivedConfig,
|
|
11
|
+
PatternsContentConfig,
|
|
12
|
+
ContentConfig,
|
|
13
|
+
IntlayerConfig,
|
|
14
|
+
} from './types';
|
|
15
|
+
export { Locales } from './defaultValues/locales';
|
|
16
|
+
export {
|
|
17
|
+
formatEnvVariable,
|
|
18
|
+
intlayerIntlConfiguration,
|
|
19
|
+
intlayerMiddlewareConfiguration,
|
|
20
|
+
intlayerContentConfiguration,
|
|
21
|
+
intlayerConfiguration,
|
|
22
|
+
getConfiguration as getClientConfiguration,
|
|
23
|
+
} from './envVariables/index';
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { Locales } from '../defaultValues/locales';
|
|
2
|
+
|
|
3
|
+
export type InternationalizationConfig = {
|
|
4
|
+
// Available languages in the app
|
|
5
|
+
locales: Locales[]; // default [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH]
|
|
6
|
+
|
|
7
|
+
// Default language
|
|
8
|
+
defaultLocale: Locales; // default Locales.ENGLISH
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type ServerSetCookieRule = 'always' | 'never';
|
|
12
|
+
export type MiddlewareConfig = {
|
|
13
|
+
// Header name to get the language
|
|
14
|
+
headerName: string; // default 'x-intlayer-locale'
|
|
15
|
+
|
|
16
|
+
// Cookie name to get the language
|
|
17
|
+
cookieName: string; // default 'NEXT_LOCALE'
|
|
18
|
+
|
|
19
|
+
// Prefix the default language in the URL
|
|
20
|
+
prefixDefault: boolean; // default false
|
|
21
|
+
|
|
22
|
+
// Base path
|
|
23
|
+
basePath: string; // default ''
|
|
24
|
+
|
|
25
|
+
// Set cookie on server
|
|
26
|
+
serverSetCookie: ServerSetCookieRule; // default 'always'
|
|
27
|
+
|
|
28
|
+
// No prefix
|
|
29
|
+
noPrefix: boolean; // default false;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type CustomIntlayerConfig = {
|
|
33
|
+
/**
|
|
34
|
+
* Internationalization configuration
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
internationalization?: Partial<InternationalizationConfig>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Middleware configuration
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
middleware?: Partial<MiddlewareConfig>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Content configuration
|
|
47
|
+
*/
|
|
48
|
+
content?: Partial<ContentConfig>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type IntlayerConfig = {
|
|
52
|
+
/**
|
|
53
|
+
* Internationalization configuration
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
internationalization: InternationalizationConfig;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Middleware configuration
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
middleware: MiddlewareConfig;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Content configuration
|
|
66
|
+
*/
|
|
67
|
+
content: ContentConfig;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type BaseContentConfig = {
|
|
71
|
+
// File extensions of content to look for
|
|
72
|
+
fileExtensions: string[]; // default ['.content.ts', '.content.js', '.content.json']
|
|
73
|
+
|
|
74
|
+
// Directory of the project
|
|
75
|
+
baseDir: string; // default process.cwd()
|
|
76
|
+
|
|
77
|
+
// Directory name where the content is stored
|
|
78
|
+
contentDirName: string; // default 'src'
|
|
79
|
+
|
|
80
|
+
// Directories to exclude
|
|
81
|
+
excludedPath: string[]; // default ['node_modules']
|
|
82
|
+
|
|
83
|
+
// Result directory name
|
|
84
|
+
resultDirName: string; // default '.intlayer'
|
|
85
|
+
|
|
86
|
+
// Module augmentation directory name
|
|
87
|
+
moduleAugmentationDirName: string; // default 'types'
|
|
88
|
+
|
|
89
|
+
// Bundle directory name
|
|
90
|
+
bundleDirName: string; // default 'bundle'
|
|
91
|
+
|
|
92
|
+
// Bundle file extension
|
|
93
|
+
bundleFileExtension: string; // default '.bundle.js'
|
|
94
|
+
|
|
95
|
+
// Dictionary directory name
|
|
96
|
+
dictionariesDirName: string; // default 'dictionary'
|
|
97
|
+
|
|
98
|
+
// Types directory name
|
|
99
|
+
typeDirName: string; // default 'types'
|
|
100
|
+
|
|
101
|
+
// Main directory name
|
|
102
|
+
mainDirName: string; // default 'main'
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export type BaseDerivedConfig = {
|
|
106
|
+
// Directory to watch - emplacement where the content is stored
|
|
107
|
+
contentDir: string; // default {{baseDir}} / {{contentDirName}}
|
|
108
|
+
|
|
109
|
+
// Result directory
|
|
110
|
+
resultDir: string; // default {{baseDir}} / {{resultDirName}}
|
|
111
|
+
|
|
112
|
+
// Result directory
|
|
113
|
+
moduleAugmentationDir: string; // default {{baseDir}} / {{moduleAugmentationDirName}}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type ResultDirDerivedConfig = {
|
|
117
|
+
// Bundle directory
|
|
118
|
+
bundleDir: string; // default {{resultDir}} / {{bundleDirName}}
|
|
119
|
+
|
|
120
|
+
// Dictionary directory
|
|
121
|
+
dictionariesDir: string; // default {{resultDir}} / {{dictionaryDirName}}
|
|
122
|
+
|
|
123
|
+
// Types directory
|
|
124
|
+
typesDir: string; // default {{resultDir}} / {{typeDirName}}
|
|
125
|
+
|
|
126
|
+
// Main directory
|
|
127
|
+
mainDir: string; // default {{resultDir}} / {{mainDirName}}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export type PatternsContentConfig = {
|
|
131
|
+
// Pattern of files to watch
|
|
132
|
+
watchedFilesPattern: string[];
|
|
133
|
+
|
|
134
|
+
// Pattern of files to watch including the relative path
|
|
135
|
+
watchedFilesPatternWithPath: string[];
|
|
136
|
+
|
|
137
|
+
// Pattern of files to output
|
|
138
|
+
outputFilesPatternWithPath: string;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export type ContentConfig = BaseContentConfig &
|
|
142
|
+
BaseDerivedConfig &
|
|
143
|
+
ResultDirDerivedConfig &
|
|
144
|
+
PatternsContentConfig;
|