@intlayer/config 2.0.0 → 2.0.2

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 (58) hide show
  1. package/dist/cjs/configFile/buildConfigurationFields.cjs +21 -1
  2. package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
  3. package/dist/cjs/defaultValues/editor.cjs +3 -0
  4. package/dist/cjs/defaultValues/editor.cjs.map +1 -1
  5. package/dist/cjs/defaultValues/editor.d.ts +2 -1
  6. package/dist/cjs/envVariables/extractEnvVariable/next.cjs +2 -1
  7. package/dist/cjs/envVariables/extractEnvVariable/next.cjs.map +1 -1
  8. package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs +2 -1
  9. package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs.map +1 -1
  10. package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs +2 -1
  11. package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs.map +1 -1
  12. package/dist/cjs/envVariables/extractEnvVariable/vite.cjs +2 -1
  13. package/dist/cjs/envVariables/extractEnvVariable/vite.cjs.map +1 -1
  14. package/dist/cjs/envVariables/getConfiguration.cjs +2 -1
  15. package/dist/cjs/envVariables/getConfiguration.cjs.map +1 -1
  16. package/dist/cjs/types/config.cjs.map +1 -1
  17. package/dist/cjs/types/config.d.ts +20 -0
  18. package/dist/esm/configFile/buildConfigurationFields.mjs +21 -1
  19. package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
  20. package/dist/esm/defaultValues/editor.d.mts +2 -1
  21. package/dist/esm/defaultValues/editor.mjs +2 -0
  22. package/dist/esm/defaultValues/editor.mjs.map +1 -1
  23. package/dist/esm/envVariables/extractEnvVariable/next.mjs +2 -1
  24. package/dist/esm/envVariables/extractEnvVariable/next.mjs.map +1 -1
  25. package/dist/esm/envVariables/extractEnvVariable/react_app.mjs +2 -1
  26. package/dist/esm/envVariables/extractEnvVariable/react_app.mjs.map +1 -1
  27. package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs +2 -1
  28. package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs.map +1 -1
  29. package/dist/esm/envVariables/extractEnvVariable/vite.mjs +2 -1
  30. package/dist/esm/envVariables/extractEnvVariable/vite.mjs.map +1 -1
  31. package/dist/esm/envVariables/getConfiguration.mjs +2 -1
  32. package/dist/esm/envVariables/getConfiguration.mjs.map +1 -1
  33. package/dist/esm/types/config.d.mts +20 -0
  34. package/package.json +9 -10
  35. package/src/client.ts +0 -11
  36. package/src/configFile/buildConfigurationFields.ts +0 -503
  37. package/src/configFile/getConfiguration.ts +0 -78
  38. package/src/configFile/index.ts +0 -2
  39. package/src/configFile/loadConfigurationFile.ts +0 -115
  40. package/src/configFile/searchConfigurationFile.ts +0 -59
  41. package/src/defaultValues/editor.ts +0 -1
  42. package/src/defaultValues/internationalization.ts +0 -8
  43. package/src/defaultValues/middleware.ts +0 -11
  44. package/src/defaultValues/server.ts +0 -28
  45. package/src/envVariables/detectPlatform.ts +0 -41
  46. package/src/envVariables/extractEnvVariable/index.ts +0 -20
  47. package/src/envVariables/extractEnvVariable/next.ts +0 -64
  48. package/src/envVariables/extractEnvVariable/react_app.ts +0 -64
  49. package/src/envVariables/extractEnvVariable/types.ts +0 -10
  50. package/src/envVariables/extractEnvVariable/undefined_platform.ts +0 -59
  51. package/src/envVariables/extractEnvVariable/vite.ts +0 -72
  52. package/src/envVariables/extractEnvVariable/vite_env.d.ts +0 -9
  53. package/src/envVariables/formatEnvVariable.ts +0 -39
  54. package/src/envVariables/getConfiguration.ts +0 -109
  55. package/src/envVariables/index.ts +0 -2
  56. package/src/envVariables/utils.ts +0 -64
  57. package/src/types/config.ts +0 -395
  58. package/src/types/locales.ts +0 -469
@@ -1,59 +0,0 @@
1
- import { existsSync } from 'fs';
2
- import { resolve } from 'path';
3
-
4
- const EXTENSION = ['ts', 'js', 'json', 'cjs', 'mjs', ''];
5
- const CONFIGURATION_FILE_NAME_1 = 'intlayer.config';
6
- const CONFIGURATION_FILE_NAME_2 = '.intlayerrc';
7
-
8
- const intLayerConfigFiles = EXTENSION.filter(
9
- (extension) => extension !== ''
10
- ).map((ext) => `${CONFIGURATION_FILE_NAME_1}.${ext}`);
11
-
12
- const configurationFiles = [...intLayerConfigFiles, CONFIGURATION_FILE_NAME_2];
13
-
14
- type SearchConfigurationFileResult = {
15
- configurationFilePath?: string;
16
- numCustomConfiguration: number;
17
- };
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
- */
30
- export const searchConfigurationFile = (
31
- configFilePath: string
32
- ): SearchConfigurationFileResult => {
33
- let configurationFilePath: string | undefined = undefined;
34
- let numCustomConfiguration = 0;
35
-
36
- for (const fileName of configurationFiles) {
37
- try {
38
- const filePath = resolve(configFilePath, fileName);
39
-
40
- // Check if the file exists
41
- if (!existsSync(filePath)) {
42
- continue;
43
- } else {
44
- numCustomConfiguration += 1;
45
-
46
- if (!configurationFilePath) {
47
- configurationFilePath = filePath;
48
- }
49
- }
50
- } catch (error) {
51
- // Return "Cannot use import statement outside a module"
52
- console.error(`${fileName}: ${error as string}`);
53
-
54
- continue;
55
- }
56
- }
57
-
58
- return { configurationFilePath, numCustomConfiguration };
59
- };
@@ -1 +0,0 @@
1
- export const PORT = 4000;
@@ -1,8 +0,0 @@
1
- import type { StrictMode } from '../types/config';
2
- import { Locales } from '../types/locales';
3
-
4
- export const LOCALES: Locales[] = [Locales.ENGLISH];
5
-
6
- export const DEFAULT_LOCALE: Locales = Locales.ENGLISH;
7
-
8
- export const STRICT_MODE: StrictMode = 'required_only';
@@ -1,11 +0,0 @@
1
- export const HEADER_NAME = 'x-intlayer-locale';
2
-
3
- export const COOKIE_NAME = 'NEXT_LOCALE';
4
-
5
- export const PREFIX_DEFAULT = false;
6
-
7
- export const BASE_PATH = '';
8
-
9
- export const SERVER_SET_COOKIE = 'always';
10
-
11
- export const NO_PREFIX = false;
@@ -1,28 +0,0 @@
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
- ];
12
- export const EXCLUDED_PATHS = ['node_modules'];
13
-
14
- export const CONTENT_DIR_NAME = 'src';
15
-
16
- export const RESULT_DIR_NAME = '.intlayer';
17
-
18
- export const MODULE_AUGMENTATION_DIR_NAME = 'types';
19
-
20
- export const DICTIONARY_OUTPUT: DictionaryOutput[] = ['intlayer'];
21
-
22
- export const DICTIONARIES_DIR_NAME = 'dictionary';
23
-
24
- export const I18N_DICTIONARIES_DIR_NAME = 'i18n_dictionary';
25
-
26
- export const TYPES_DIR_NAME = 'types';
27
-
28
- export const MAIN_DIR_NAME = 'main';
@@ -1,41 +0,0 @@
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
- };
@@ -1,20 +0,0 @@
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
- };
@@ -1,64 +0,0 @@
1
- import type {
2
- InternationalizationConfig,
3
- MiddlewareConfig,
4
- ContentConfig,
5
- EditorConfig,
6
- } from '../../types/config';
7
- import type { IntlayerConfigEnvVariable, ReplaceValue } from './types';
8
-
9
- export const extractNextEnvVariable = (): IntlayerConfigEnvVariable => {
10
- const internationalization: ReplaceValue<InternationalizationConfig> = {
11
- locales: process.env.NEXT_PUBLIC_INTLAYER_LOCALES,
12
- strictMode: process.env.NEXT_PUBLIC_INTLAYER_STRICT_MODE,
13
- defaultLocale: process.env.NEXT_PUBLIC_INTLAYER_DEFAULT_LOCALE,
14
- };
15
-
16
- const middleware: ReplaceValue<MiddlewareConfig> = {
17
- headerName: process.env.NEXT_PUBLIC_INTLAYER_HEADER_NAME,
18
- cookieName: process.env.NEXT_PUBLIC_INTLAYER_COOKIE_NAME,
19
- prefixDefault: process.env.NEXT_PUBLIC_INTLAYER_PREFIX_DEFAULT,
20
- basePath: process.env.NEXT_PUBLIC_INTLAYER_BASE_PATH,
21
- serverSetCookie: process.env.NEXT_PUBLIC_INTLAYER_SERVER_SET_COOKIE,
22
- noPrefix: process.env.NEXT_PUBLIC_INTLAYER_NO_PREFIX,
23
- };
24
-
25
- const content: ReplaceValue<ContentConfig> = {
26
- fileExtensions: process.env.NEXT_PUBLIC_INTLAYER_FILE_EXTENSIONS,
27
- baseDir: process.env.NEXT_PUBLIC_INTLAYER_BASE_DIR,
28
- contentDirName: process.env.NEXT_PUBLIC_INTLAYER_CONTENT_DIR_NAME,
29
- contentDir: process.env.NEXT_PUBLIC_INTLAYER_CONTENT_DIR,
30
- excludedPath: process.env.NEXT_PUBLIC_INTLAYER_EXCLUDED_PATH,
31
- resultDirName: process.env.NEXT_PUBLIC_INTLAYER_RESULT_DIR_NAME,
32
- moduleAugmentationDirName:
33
- process.env.NEXT_PUBLIC_INTLAYER_MODULE_AUGMENTATION_DIR_NAME,
34
- dictionariesDirName: process.env.NEXT_PUBLIC_INTLAYER_DICTIONARIES_DIR_NAME,
35
- i18nDictionariesDir: process.env.NEXT_PUBLIC_INTLAYER_I18N_DICTIONARIES_DIR,
36
- typeDirName: process.env.NEXT_PUBLIC_INTLAYER_TYPE_DIR_NAME,
37
- mainDirName: process.env.NEXT_PUBLIC_INTLAYER_MAIN_DIR_NAME,
38
- resultDir: process.env.NEXT_PUBLIC_INTLAYER_RESULT_DIR,
39
- moduleAugmentationDir:
40
- process.env.NEXT_PUBLIC_INTLAYER_MODULE_AUGMENTATION_DIR,
41
- dictionariesDir: process.env.NEXT_PUBLIC_INTLAYER_DICTIONARIES_DIR,
42
- i18nDictionariesDirName:
43
- process.env.NEXT_PUBLIC_INTLAYER_I18N_DICTIONARIES_DIR_NAME,
44
- typesDir: process.env.NEXT_PUBLIC_INTLAYER_TYPE_DIR,
45
- mainDir: process.env.NEXT_PUBLIC_INTLAYER_MAIN_DIR,
46
- watchedFilesPattern: process.env.NEXT_PUBLIC_INTLAYER_WATCHED_FILES_PATTERN,
47
- watchedFilesPatternWithPath:
48
- process.env.NEXT_PUBLIC_INTLAYER_WATCHED_FILES_PATTERN_WITH_PATH,
49
- outputFilesPatternWithPath:
50
- process.env.NEXT_PUBLIC_INTLAYER_OUTPUT_FILES_PATTERN_WITH_PATH,
51
- dictionaryOutput: process.env.NEXT_PUBLIC_INTLAYER_DICTIONARY_OUTPUT,
52
- };
53
-
54
- const editor: ReplaceValue<EditorConfig> = {
55
- port: process.env.NEXT_PUBLIC_INTLAYER_PORT,
56
- };
57
-
58
- return {
59
- internationalization,
60
- middleware,
61
- content,
62
- editor,
63
- };
64
- };
@@ -1,64 +0,0 @@
1
- import type {
2
- InternationalizationConfig,
3
- MiddlewareConfig,
4
- ContentConfig,
5
- EditorConfig,
6
- } from '../../types/config';
7
- import type { IntlayerConfigEnvVariable, ReplaceValue } from './types';
8
-
9
- export const extractReactAppEnvVariable = (): IntlayerConfigEnvVariable => {
10
- const internationalization: ReplaceValue<InternationalizationConfig> = {
11
- locales: process.env.REACT_APP_INTLAYER_LOCALES,
12
- strictMode: process.env.REACT_APP_INTLAYER_STRICT_MODE,
13
- defaultLocale: process.env.REACT_APP_INTLAYER_DEFAULT_LOCALE,
14
- };
15
-
16
- const middleware: ReplaceValue<MiddlewareConfig> = {
17
- headerName: process.env.REACT_APP_INTLAYER_HEADER_NAME,
18
- cookieName: process.env.REACT_APP_INTLAYER_COOKIE_NAME,
19
- prefixDefault: process.env.REACT_APP_INTLAYER_PREFIX_DEFAULT,
20
- basePath: process.env.REACT_APP_INTLAYER_BASE_PATH,
21
- serverSetCookie: process.env.REACT_APP_INTLAYER_SERVER_SET_COOKIE,
22
- noPrefix: process.env.REACT_APP_INTLAYER_NO_PREFIX,
23
- };
24
-
25
- const content: ReplaceValue<ContentConfig> = {
26
- fileExtensions: process.env.REACT_APP_INTLAYER_FILE_EXTENSIONS,
27
- baseDir: process.env.REACT_APP_INTLAYER_BASE_DIR,
28
- contentDirName: process.env.REACT_APP_INTLAYER_CONTENT_DIR_NAME,
29
- contentDir: process.env.REACT_APP_INTLAYER_CONTENT_DIR,
30
- excludedPath: process.env.REACT_APP_INTLAYER_EXCLUDED_PATH,
31
- resultDirName: process.env.REACT_APP_INTLAYER_RESULT_DIR_NAME,
32
- moduleAugmentationDirName:
33
- process.env.REACT_APP_INTLAYER_MODULE_AUGMENTATION_DIR_NAME,
34
- dictionariesDirName: process.env.REACT_APP_INTLAYER_DICTIONARIES_DIR_NAME,
35
- i18nDictionariesDirName:
36
- process.env.REACT_APP_INTLAYER_I18N_DICTIONARIES_DIR_NAME,
37
- typeDirName: process.env.REACT_APP_INTLAYER_TYPE_DIR_NAME,
38
- mainDirName: process.env.REACT_APP_INTLAYER_MAIN_DIR_NAME,
39
- resultDir: process.env.REACT_APP_INTLAYER_RESULT_DIR,
40
- moduleAugmentationDir:
41
- process.env.REACT_APP_INTLAYER_MODULE_AUGMENTATION_DIR,
42
- dictionariesDir: process.env.REACT_APP_INTLAYER_DICTIONARIES_DIR,
43
- i18nDictionariesDir: process.env.REACT_APP_INTLAYER_I18N_DICTIONARIES_DIR,
44
- typesDir: process.env.REACT_APP_INTLAYER_TYPE_DIR,
45
- mainDir: process.env.REACT_APP_INTLAYER_MAIN_DIR,
46
- watchedFilesPattern: process.env.REACT_APP_INTLAYER_WATCHED_FILES_PATTERN,
47
- watchedFilesPatternWithPath:
48
- process.env.REACT_APP_INTLAYER_WATCHED_FILES_PATTERN_WITH_PATH,
49
- outputFilesPatternWithPath:
50
- process.env.REACT_APP_INTLAYER_OUTPUT_FILES_PATTERN_WITH_PATH,
51
- dictionaryOutput: process.env.REACT_APP_INTLAYER_DICTIONARY_OUTPUT,
52
- };
53
-
54
- const editor: ReplaceValue<EditorConfig> = {
55
- port: process.env.REACT_APP_INTLAYER_PORT,
56
- };
57
-
58
- return {
59
- internationalization,
60
- middleware,
61
- content,
62
- editor,
63
- };
64
- };
@@ -1,10 +0,0 @@
1
- import type { IntlayerConfig } from '../../client';
2
-
3
- // Utility type that replaces all values of a given type with another type
4
- export type ReplaceValue<T> = {
5
- [K in keyof T]: string | undefined;
6
- };
7
-
8
- export type IntlayerConfigEnvVariable = {
9
- [K in keyof IntlayerConfig]: ReplaceValue<IntlayerConfig[K]>;
10
- };
@@ -1,59 +0,0 @@
1
- import type {
2
- InternationalizationConfig,
3
- MiddlewareConfig,
4
- ContentConfig,
5
- EditorConfig,
6
- } from '../../types/config';
7
- import type { ReplaceValue, IntlayerConfigEnvVariable } from './types';
8
-
9
- export const extractEmptyEnvVariable = (): IntlayerConfigEnvVariable => {
10
- const internationalization: ReplaceValue<InternationalizationConfig> = {
11
- locales: undefined,
12
- strictMode: undefined,
13
- defaultLocale: undefined,
14
- };
15
-
16
- const middleware: ReplaceValue<MiddlewareConfig> = {
17
- headerName: undefined,
18
- cookieName: undefined,
19
- prefixDefault: undefined,
20
- basePath: undefined,
21
- serverSetCookie: undefined,
22
- noPrefix: undefined,
23
- };
24
-
25
- const content: ReplaceValue<ContentConfig> = {
26
- fileExtensions: undefined,
27
- baseDir: undefined,
28
- contentDirName: undefined,
29
- contentDir: undefined,
30
- excludedPath: undefined,
31
- resultDirName: undefined,
32
- moduleAugmentationDirName: undefined,
33
- dictionariesDirName: undefined,
34
- i18nDictionariesDirName: undefined,
35
- typeDirName: undefined,
36
- mainDirName: undefined,
37
- resultDir: undefined,
38
- moduleAugmentationDir: undefined,
39
- dictionariesDir: undefined,
40
- i18nDictionariesDir: undefined,
41
- typesDir: undefined,
42
- mainDir: undefined,
43
- watchedFilesPattern: undefined,
44
- watchedFilesPatternWithPath: undefined,
45
- outputFilesPatternWithPath: undefined,
46
- dictionaryOutput: undefined,
47
- };
48
-
49
- const editor: ReplaceValue<EditorConfig> = {
50
- port: undefined,
51
- };
52
-
53
- return {
54
- internationalization,
55
- middleware,
56
- content,
57
- editor,
58
- };
59
- };
@@ -1,72 +0,0 @@
1
- import type {
2
- InternationalizationConfig,
3
- MiddlewareConfig,
4
- ContentConfig,
5
- EditorConfig,
6
- } from '../../types/config';
7
- import type { IntlayerConfigEnvVariable, ReplaceValue } from './types';
8
- import { extractEmptyEnvVariable } from './undefined_platform';
9
-
10
- export const extractViteEnvVariable = (): IntlayerConfigEnvVariable => {
11
- if (!import.meta.env) {
12
- console.error(
13
- 'Vite env variables cannot be loaded on a commonjs environment.'
14
- );
15
- return extractEmptyEnvVariable();
16
- }
17
-
18
- const internationalization: ReplaceValue<InternationalizationConfig> = {
19
- locales: import.meta.env.VITE_INTLAYER_LOCALES,
20
- strictMode: import.meta.env.VITE_INTLAYER_STRICT_MODE,
21
- defaultLocale: import.meta.env.VITE_INTLAYER_DEFAULT_LOCALE,
22
- };
23
-
24
- const middleware: ReplaceValue<MiddlewareConfig> = {
25
- headerName: import.meta.env.VITE_INTLAYER_HEADER_NAME,
26
- cookieName: import.meta.env.VITE_INTLAYER_COOKIE_NAME,
27
- prefixDefault: import.meta.env.VITE_INTLAYER_PREFIX_DEFAULT,
28
- basePath: import.meta.env.VITE_INTLAYER_BASE_PATH,
29
- serverSetCookie: import.meta.env.VITE_INTLAYER_SERVER_SET_COOKIE,
30
- noPrefix: import.meta.env.VITE_INTLAYER_NO_PREFIX,
31
- };
32
-
33
- const content: ReplaceValue<ContentConfig> = {
34
- fileExtensions: import.meta.env.VITE_INTLAYER_FILE_EXTENSIONS,
35
- baseDir: import.meta.env.VITE_INTLAYER_BASE_DIR,
36
- contentDirName: import.meta.env.VITE_INTLAYER_CONTENT_DIR_NAME,
37
- contentDir: import.meta.env.VITE_INTLAYER_CONTENT_DIR,
38
- excludedPath: import.meta.env.VITE_INTLAYER_EXCLUDED_PATH,
39
- resultDirName: import.meta.env.VITE_INTLAYER_RESULT_DIR_NAME,
40
- moduleAugmentationDirName: import.meta.env
41
- .VITE_INTLAYER_MODULE_AUGMENTATION_DIR_NAME,
42
- dictionariesDirName: import.meta.env.VITE_INTLAYER_DICTIONARIES_DIR_NAME,
43
- i18nDictionariesDirName: import.meta.env
44
- .VITE_INTLAYER_I18N_DICTIONARIES_DIR_NAME,
45
- typeDirName: import.meta.env.VITE_INTLAYER_TYPE_DIR_NAME,
46
- mainDirName: import.meta.env.VITE_INTLAYER_MAIN_DIR_NAME,
47
- resultDir: import.meta.env.VITE_INTLAYER_RESULT_DIR,
48
- moduleAugmentationDir: import.meta.env
49
- .VITE_INTLAYER_MODULE_AUGMENTATION_DIR,
50
- dictionariesDir: import.meta.env.VITE_INTLAYER_DICTIONARIES_DIR,
51
- i18nDictionariesDir: import.meta.env.VITE_INTLAYER_I18N_DICTIONARIES_DIR,
52
- typesDir: import.meta.env.VITE_INTLAYER_TYPE_DIR,
53
- mainDir: import.meta.env.VITE_INTLAYER_MAIN_DIR,
54
- watchedFilesPattern: import.meta.env.VITE_INTLAYER_WATCHED_FILES_PATTERN,
55
- watchedFilesPatternWithPath: import.meta.env
56
- .VITE_INTLAYER_WATCHED_FILES_PATTERN_WITH_PATH,
57
- outputFilesPatternWithPath: import.meta.env
58
- .VITE_INTLAYER_OUTPUT_FILES_PATTERN_WITH_PATH,
59
- dictionaryOutput: import.meta.env.VITE_INTLAYER_DICTIONARY_OUTPUT,
60
- };
61
-
62
- const editor: ReplaceValue<EditorConfig> = {
63
- port: import.meta.env.VITE_INTLAYER_PORT,
64
- };
65
-
66
- return {
67
- internationalization,
68
- middleware,
69
- content,
70
- editor,
71
- };
72
- };
@@ -1,9 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
2
- /**
3
- * Module augmentation to add the `env` property to `import.meta`
4
- *
5
- * Simulate a vite environment
6
- */
7
- interface ImportMeta {
8
- env: Record<string, string | undefined>;
9
- }
@@ -1,39 +0,0 @@
1
- import { getConfiguration } from '../configFile/getConfiguration';
2
- import { getPrefix, type Platform } from './detectPlatform';
3
-
4
- /**
5
- * Format a key to corresponding environment variable name
6
- *
7
- * Example:
8
- * toEnvVariable('mainDir') => 'INTLAYER_MAIN_DIR'
9
- */
10
- const formatEnvName = (key: string, prefix: string): string =>
11
- prefix + key.replace(/([a-z0-9])([A-Z])/g, '$1_$2').toUpperCase();
12
-
13
- /**
14
- * Format all configuration values as environment variables
15
- */
16
- export const formatEnvVariable = (
17
- platform: Platform
18
- ): Record<string, string> => {
19
- const intlayerConfig = getConfiguration();
20
-
21
- const prefix = getPrefix(platform);
22
-
23
- // Set all configuration values as environment variables
24
- const env: Record<string, string> = {};
25
- for (const [key, value] of Object.entries({
26
- ...intlayerConfig.content,
27
- ...intlayerConfig.internationalization,
28
- ...intlayerConfig.middleware,
29
- ...intlayerConfig.editor,
30
- })) {
31
- if (typeof value === 'string') {
32
- env[formatEnvName(key, prefix)] = value;
33
- } else {
34
- env[formatEnvName(key, prefix)] = JSON.stringify(value);
35
- }
36
- }
37
-
38
- return env;
39
- };
@@ -1,109 +0,0 @@
1
- import type {
2
- ContentConfig,
3
- DictionaryOutput,
4
- InternationalizationConfig,
5
- IntlayerConfig,
6
- MiddlewareConfig,
7
- ServerSetCookieRule,
8
- StrictMode,
9
- } from '../types/config';
10
- import type { Locales } from '../types/locales';
11
- import { extractEnvVariable } from './extractEnvVariable/index';
12
- import { getEnvValue } from './utils';
13
-
14
- /**
15
- * Get all configuration values using environment variables
16
- * Can be used in the client side as the server side
17
- * To use it, be sure to have the environment variables set
18
- */
19
- export const getConfiguration = (): IntlayerConfig => {
20
- const env = extractEnvVariable();
21
-
22
- const intlayerIntlConfiguration: InternationalizationConfig = {
23
- locales: getEnvValue<Locales>(env.internationalization.locales, 'array')!,
24
- strictMode: getEnvValue<StrictMode>(
25
- env.internationalization.strictMode,
26
- 'string'
27
- )!,
28
- defaultLocale: getEnvValue<Locales>(
29
- env?.internationalization.defaultLocale,
30
- 'string'
31
- )!,
32
- };
33
-
34
- const intlayerMiddlewareConfiguration: MiddlewareConfig = {
35
- headerName: getEnvValue(env.middleware.headerName, 'string')!,
36
- cookieName: getEnvValue(env.middleware.cookieName, 'string')!,
37
- prefixDefault: getEnvValue(env.middleware.prefixDefault, 'boolean')!,
38
- basePath: getEnvValue(env.middleware.basePath, 'string')!,
39
- serverSetCookie: getEnvValue<ServerSetCookieRule>(
40
- env.middleware.serverSetCookie,
41
- 'string'
42
- )!,
43
- noPrefix: getEnvValue(env.middleware.noPrefix, 'boolean')!,
44
- };
45
-
46
- const intlayerContentConfiguration: ContentConfig = {
47
- fileExtensions: getEnvValue<string>(env.content.fileExtensions, 'array')!,
48
- baseDir: getEnvValue(env.content.baseDir, 'string')!,
49
- contentDirName: getEnvValue(env.content.contentDirName, 'string')!,
50
- contentDir: getEnvValue(env.content.contentDir, 'string')!,
51
- excludedPath: getEnvValue<string>(env.content.excludedPath, 'array')!,
52
- resultDirName: getEnvValue(env.content.resultDirName, 'string')!,
53
- resultDir: getEnvValue(env.content.resultDir, 'string')!,
54
- moduleAugmentationDirName: getEnvValue(
55
- env.content.moduleAugmentationDirName,
56
- 'string'
57
- )!,
58
- moduleAugmentationDir: getEnvValue(
59
- env.content.moduleAugmentationDir,
60
- 'string'
61
- )!,
62
- dictionaryOutput: getEnvValue<DictionaryOutput>(
63
- env.content.dictionaryOutput,
64
- 'array'
65
- )!,
66
- dictionariesDirName: getEnvValue(
67
- env.content.dictionariesDirName,
68
- 'string'
69
- )!,
70
- dictionariesDir: getEnvValue(env.content.dictionariesDir, 'string')!,
71
- i18nDictionariesDirName: getEnvValue(
72
- env.content.i18nDictionariesDirName,
73
- 'string'
74
- )!,
75
- i18nDictionariesDir: getEnvValue(
76
- env.content.i18nDictionariesDir,
77
- 'string'
78
- )!,
79
- typeDirName: getEnvValue(env.content.typeDirName, 'string')!,
80
- typesDir: getEnvValue(env.content.typesDir, 'string')!,
81
- mainDirName: getEnvValue(env.content.mainDirName, 'string')!,
82
- mainDir: getEnvValue(env.content.mainDir, 'string')!,
83
- watchedFilesPattern: getEnvValue<string>(
84
- env.content.watchedFilesPattern,
85
- 'array'
86
- )!,
87
- watchedFilesPatternWithPath: getEnvValue<string>(
88
- env.content.watchedFilesPatternWithPath,
89
- 'array'
90
- )!,
91
- outputFilesPatternWithPath: getEnvValue(
92
- env.content.outputFilesPatternWithPath,
93
- 'string'
94
- )!,
95
- };
96
-
97
- const intlayerEditorConfiguration = {
98
- port: getEnvValue(env.editor.port, 'number')!,
99
- };
100
-
101
- const intlayerConfiguration: IntlayerConfig = {
102
- internationalization: intlayerIntlConfiguration,
103
- middleware: intlayerMiddlewareConfiguration,
104
- content: intlayerContentConfiguration,
105
- editor: intlayerEditorConfiguration,
106
- };
107
-
108
- return intlayerConfiguration;
109
- };
@@ -1,2 +0,0 @@
1
- export { getConfiguration } from './getConfiguration';
2
- export { formatEnvVariable } from './formatEnvVariable';
@@ -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 };