@intlayer/config 1.2.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/cjs/client.cjs.map +1 -1
  2. package/dist/cjs/client.d.ts +1 -1
  3. package/dist/cjs/configFile/buildConfigurationFields.cjs +40 -1
  4. package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
  5. package/dist/cjs/defaultValues/editor.cjs +32 -0
  6. package/dist/cjs/defaultValues/editor.cjs.map +1 -0
  7. package/dist/cjs/defaultValues/editor.d.ts +4 -0
  8. package/dist/cjs/defaultValues/internationalization.cjs +5 -2
  9. package/dist/cjs/defaultValues/internationalization.cjs.map +1 -1
  10. package/dist/cjs/defaultValues/internationalization.d.ts +3 -1
  11. package/dist/cjs/envVariables/extractEnvVariable/next.cjs +7 -1
  12. package/dist/cjs/envVariables/extractEnvVariable/next.cjs.map +1 -1
  13. package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs +7 -1
  14. package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs.map +1 -1
  15. package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs +7 -1
  16. package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs.map +1 -1
  17. package/dist/cjs/envVariables/extractEnvVariable/vite.cjs +7 -1
  18. package/dist/cjs/envVariables/extractEnvVariable/vite.cjs.map +1 -1
  19. package/dist/cjs/envVariables/formatEnvVariable.cjs +2 -1
  20. package/dist/cjs/envVariables/formatEnvVariable.cjs.map +1 -1
  21. package/dist/cjs/envVariables/getConfiguration.cjs +10 -1
  22. package/dist/cjs/envVariables/getConfiguration.cjs.map +1 -1
  23. package/dist/cjs/index.cjs.map +1 -1
  24. package/dist/cjs/index.d.ts +1 -1
  25. package/dist/cjs/types/config.cjs.map +1 -1
  26. package/dist/cjs/types/config.d.ts +52 -1
  27. package/dist/esm/client.d.mts +1 -1
  28. package/dist/esm/client.mjs.map +1 -1
  29. package/dist/esm/configFile/buildConfigurationFields.mjs +45 -2
  30. package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
  31. package/dist/esm/defaultValues/editor.d.mts +4 -0
  32. package/dist/esm/defaultValues/editor.mjs +7 -0
  33. package/dist/esm/defaultValues/editor.mjs.map +1 -0
  34. package/dist/esm/defaultValues/internationalization.d.mts +3 -1
  35. package/dist/esm/defaultValues/internationalization.mjs +3 -1
  36. package/dist/esm/defaultValues/internationalization.mjs.map +1 -1
  37. package/dist/esm/envVariables/extractEnvVariable/next.mjs +7 -1
  38. package/dist/esm/envVariables/extractEnvVariable/next.mjs.map +1 -1
  39. package/dist/esm/envVariables/extractEnvVariable/react_app.mjs +7 -1
  40. package/dist/esm/envVariables/extractEnvVariable/react_app.mjs.map +1 -1
  41. package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs +7 -1
  42. package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs.map +1 -1
  43. package/dist/esm/envVariables/extractEnvVariable/vite.mjs +7 -1
  44. package/dist/esm/envVariables/extractEnvVariable/vite.mjs.map +1 -1
  45. package/dist/esm/envVariables/formatEnvVariable.mjs +2 -1
  46. package/dist/esm/envVariables/formatEnvVariable.mjs.map +1 -1
  47. package/dist/esm/envVariables/getConfiguration.mjs +10 -1
  48. package/dist/esm/envVariables/getConfiguration.mjs.map +1 -1
  49. package/dist/esm/index.d.mts +1 -1
  50. package/dist/esm/index.mjs.map +1 -1
  51. package/dist/esm/types/config.d.mts +52 -1
  52. package/package.json +2 -3
  53. package/src/index.ts +1 -0
  54. package/src/client.ts +0 -11
  55. package/src/configFile/buildConfigurationFields.ts +0 -474
  56. package/src/configFile/getConfiguration.ts +0 -78
  57. package/src/configFile/index.ts +0 -2
  58. package/src/configFile/loadConfigurationFile.ts +0 -115
  59. package/src/configFile/searchConfigurationFile.ts +0 -59
  60. package/src/defaultValues/internationalization.ts +0 -5
  61. package/src/defaultValues/middleware.ts +0 -11
  62. package/src/defaultValues/server.ts +0 -28
  63. package/src/envVariables/detectPlatform.ts +0 -41
  64. package/src/envVariables/extractEnvVariable/index.ts +0 -20
  65. package/src/envVariables/extractEnvVariable/next.ts +0 -57
  66. package/src/envVariables/extractEnvVariable/react_app.ts +0 -57
  67. package/src/envVariables/extractEnvVariable/types.ts +0 -10
  68. package/src/envVariables/extractEnvVariable/undefined_platform.ts +0 -52
  69. package/src/envVariables/extractEnvVariable/vite.ts +0 -65
  70. package/src/envVariables/extractEnvVariable/vite_env.d.ts +0 -9
  71. package/src/envVariables/formatEnvVariable.ts +0 -38
  72. package/src/envVariables/getConfiguration.ts +0 -99
  73. package/src/envVariables/index.ts +0 -2
  74. package/src/envVariables/utils.ts +0 -64
  75. package/src/types/config.ts +0 -360
  76. package/src/types/locales.ts +0 -469
@@ -1,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
- };
@@ -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,5 +0,0 @@
1
- import { Locales } from '../types/locales';
2
-
3
- export const LOCALES: Locales[] = [Locales.ENGLISH];
4
-
5
- export const DEFAULT_LOCALE: Locales = Locales.ENGLISH;
@@ -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,57 +0,0 @@
1
- import type {
2
- InternationalizationConfig,
3
- MiddlewareConfig,
4
- ContentConfig,
5
- } from '../../types/config';
6
- import type { IntlayerConfigEnvVariable, ReplaceValue } from './types';
7
-
8
- export const extractNextEnvVariable = (): IntlayerConfigEnvVariable => {
9
- const internationalization: ReplaceValue<InternationalizationConfig> = {
10
- locales: process.env.NEXT_PUBLIC_INTLAYER_LOCALES,
11
- defaultLocale: process.env.NEXT_PUBLIC_INTLAYER_DEFAULT_LOCALE,
12
- };
13
-
14
- const middleware: ReplaceValue<MiddlewareConfig> = {
15
- headerName: process.env.NEXT_PUBLIC_INTLAYER_HEADER_NAME,
16
- cookieName: process.env.NEXT_PUBLIC_INTLAYER_COOKIE_NAME,
17
- prefixDefault: process.env.NEXT_PUBLIC_INTLAYER_PREFIX_DEFAULT,
18
- basePath: process.env.NEXT_PUBLIC_INTLAYER_BASE_PATH,
19
- serverSetCookie: process.env.NEXT_PUBLIC_INTLAYER_SERVER_SET_COOKIE,
20
- noPrefix: process.env.NEXT_PUBLIC_INTLAYER_NO_PREFIX,
21
- };
22
-
23
- const content: ReplaceValue<ContentConfig> = {
24
- fileExtensions: process.env.NEXT_PUBLIC_INTLAYER_FILE_EXTENSIONS,
25
- baseDir: process.env.NEXT_PUBLIC_INTLAYER_BASE_DIR,
26
- contentDirName: process.env.NEXT_PUBLIC_INTLAYER_CONTENT_DIR_NAME,
27
- contentDir: process.env.NEXT_PUBLIC_INTLAYER_CONTENT_DIR,
28
- excludedPath: process.env.NEXT_PUBLIC_INTLAYER_EXCLUDED_PATH,
29
- resultDirName: process.env.NEXT_PUBLIC_INTLAYER_RESULT_DIR_NAME,
30
- moduleAugmentationDirName:
31
- process.env.NEXT_PUBLIC_INTLAYER_MODULE_AUGMENTATION_DIR_NAME,
32
- dictionariesDirName: process.env.NEXT_PUBLIC_INTLAYER_DICTIONARIES_DIR_NAME,
33
- i18nDictionariesDir: process.env.NEXT_PUBLIC_INTLAYER_I18N_DICTIONARIES_DIR,
34
- typeDirName: process.env.NEXT_PUBLIC_INTLAYER_TYPE_DIR_NAME,
35
- mainDirName: process.env.NEXT_PUBLIC_INTLAYER_MAIN_DIR_NAME,
36
- resultDir: process.env.NEXT_PUBLIC_INTLAYER_RESULT_DIR,
37
- moduleAugmentationDir:
38
- process.env.NEXT_PUBLIC_INTLAYER_MODULE_AUGMENTATION_DIR,
39
- dictionariesDir: process.env.NEXT_PUBLIC_INTLAYER_DICTIONARIES_DIR,
40
- i18nDictionariesDirName:
41
- process.env.NEXT_PUBLIC_INTLAYER_I18N_DICTIONARIES_DIR_NAME,
42
- typesDir: process.env.NEXT_PUBLIC_INTLAYER_TYPE_DIR,
43
- mainDir: process.env.NEXT_PUBLIC_INTLAYER_MAIN_DIR,
44
- watchedFilesPattern: process.env.NEXT_PUBLIC_INTLAYER_WATCHED_FILES_PATTERN,
45
- watchedFilesPatternWithPath:
46
- process.env.NEXT_PUBLIC_INTLAYER_WATCHED_FILES_PATTERN_WITH_PATH,
47
- outputFilesPatternWithPath:
48
- process.env.NEXT_PUBLIC_INTLAYER_OUTPUT_FILES_PATTERN_WITH_PATH,
49
- dictionaryOutput: process.env.NEXT_PUBLIC_INTLAYER_DICTIONARY_OUTPUT,
50
- };
51
-
52
- return {
53
- internationalization,
54
- middleware,
55
- content,
56
- };
57
- };
@@ -1,57 +0,0 @@
1
- import type {
2
- InternationalizationConfig,
3
- MiddlewareConfig,
4
- ContentConfig,
5
- } from '../../types/config';
6
- import type { IntlayerConfigEnvVariable, ReplaceValue } from './types';
7
-
8
- export const extractReactAppEnvVariable = (): IntlayerConfigEnvVariable => {
9
- const internationalization: ReplaceValue<InternationalizationConfig> = {
10
- locales: process.env.REACT_APP_INTLAYER_LOCALES,
11
- defaultLocale: process.env.REACT_APP_INTLAYER_DEFAULT_LOCALE,
12
- };
13
-
14
- const middleware: ReplaceValue<MiddlewareConfig> = {
15
- headerName: process.env.REACT_APP_INTLAYER_HEADER_NAME,
16
- cookieName: process.env.REACT_APP_INTLAYER_COOKIE_NAME,
17
- prefixDefault: process.env.REACT_APP_INTLAYER_PREFIX_DEFAULT,
18
- basePath: process.env.REACT_APP_INTLAYER_BASE_PATH,
19
- serverSetCookie: process.env.REACT_APP_INTLAYER_SERVER_SET_COOKIE,
20
- noPrefix: process.env.REACT_APP_INTLAYER_NO_PREFIX,
21
- };
22
-
23
- const content: ReplaceValue<ContentConfig> = {
24
- fileExtensions: process.env.REACT_APP_INTLAYER_FILE_EXTENSIONS,
25
- baseDir: process.env.REACT_APP_INTLAYER_BASE_DIR,
26
- contentDirName: process.env.REACT_APP_INTLAYER_CONTENT_DIR_NAME,
27
- contentDir: process.env.REACT_APP_INTLAYER_CONTENT_DIR,
28
- excludedPath: process.env.REACT_APP_INTLAYER_EXCLUDED_PATH,
29
- resultDirName: process.env.REACT_APP_INTLAYER_RESULT_DIR_NAME,
30
- moduleAugmentationDirName:
31
- process.env.REACT_APP_INTLAYER_MODULE_AUGMENTATION_DIR_NAME,
32
- dictionariesDirName: process.env.REACT_APP_INTLAYER_DICTIONARIES_DIR_NAME,
33
- i18nDictionariesDirName:
34
- process.env.REACT_APP_INTLAYER_I18N_DICTIONARIES_DIR_NAME,
35
- typeDirName: process.env.REACT_APP_INTLAYER_TYPE_DIR_NAME,
36
- mainDirName: process.env.REACT_APP_INTLAYER_MAIN_DIR_NAME,
37
- resultDir: process.env.REACT_APP_INTLAYER_RESULT_DIR,
38
- moduleAugmentationDir:
39
- process.env.REACT_APP_INTLAYER_MODULE_AUGMENTATION_DIR,
40
- dictionariesDir: process.env.REACT_APP_INTLAYER_DICTIONARIES_DIR,
41
- i18nDictionariesDir: process.env.REACT_APP_INTLAYER_I18N_DICTIONARIES_DIR,
42
- typesDir: process.env.REACT_APP_INTLAYER_TYPE_DIR,
43
- mainDir: process.env.REACT_APP_INTLAYER_MAIN_DIR,
44
- watchedFilesPattern: process.env.REACT_APP_INTLAYER_WATCHED_FILES_PATTERN,
45
- watchedFilesPatternWithPath:
46
- process.env.REACT_APP_INTLAYER_WATCHED_FILES_PATTERN_WITH_PATH,
47
- outputFilesPatternWithPath:
48
- process.env.REACT_APP_INTLAYER_OUTPUT_FILES_PATTERN_WITH_PATH,
49
- dictionaryOutput: process.env.REACT_APP_INTLAYER_DICTIONARY_OUTPUT,
50
- };
51
-
52
- return {
53
- internationalization,
54
- middleware,
55
- content,
56
- };
57
- };
@@ -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,52 +0,0 @@
1
- import type {
2
- InternationalizationConfig,
3
- MiddlewareConfig,
4
- ContentConfig,
5
- } from '../../types/config';
6
- import type { ReplaceValue, IntlayerConfigEnvVariable } from './types';
7
-
8
- export const extractEmptyEnvVariable = (): IntlayerConfigEnvVariable => {
9
- const internationalization: ReplaceValue<InternationalizationConfig> = {
10
- locales: undefined,
11
- defaultLocale: undefined,
12
- };
13
-
14
- const middleware: ReplaceValue<MiddlewareConfig> = {
15
- headerName: undefined,
16
- cookieName: undefined,
17
- prefixDefault: undefined,
18
- basePath: undefined,
19
- serverSetCookie: undefined,
20
- noPrefix: undefined,
21
- };
22
-
23
- const content: ReplaceValue<ContentConfig> = {
24
- fileExtensions: undefined,
25
- baseDir: undefined,
26
- contentDirName: undefined,
27
- contentDir: undefined,
28
- excludedPath: undefined,
29
- resultDirName: undefined,
30
- moduleAugmentationDirName: undefined,
31
- dictionariesDirName: undefined,
32
- i18nDictionariesDirName: undefined,
33
- typeDirName: undefined,
34
- mainDirName: undefined,
35
- resultDir: undefined,
36
- moduleAugmentationDir: undefined,
37
- dictionariesDir: undefined,
38
- i18nDictionariesDir: undefined,
39
- typesDir: undefined,
40
- mainDir: undefined,
41
- watchedFilesPattern: undefined,
42
- watchedFilesPatternWithPath: undefined,
43
- outputFilesPatternWithPath: undefined,
44
- dictionaryOutput: undefined,
45
- };
46
-
47
- return {
48
- internationalization,
49
- middleware,
50
- content,
51
- };
52
- };
@@ -1,65 +0,0 @@
1
- import type {
2
- InternationalizationConfig,
3
- MiddlewareConfig,
4
- ContentConfig,
5
- } from '../../types/config';
6
- import type { IntlayerConfigEnvVariable, ReplaceValue } from './types';
7
- import { extractEmptyEnvVariable } from './undefined_platform';
8
-
9
- export const extractViteEnvVariable = (): IntlayerConfigEnvVariable => {
10
- if (!import.meta.env) {
11
- console.error(
12
- 'Vite env variables cannot be loaded on a commonjs environment.'
13
- );
14
- return extractEmptyEnvVariable();
15
- }
16
-
17
- const internationalization: ReplaceValue<InternationalizationConfig> = {
18
- locales: import.meta.env.VITE_INTLAYER_LOCALES,
19
- defaultLocale: import.meta.env.VITE_INTLAYER_DEFAULT_LOCALE,
20
- };
21
-
22
- const middleware: ReplaceValue<MiddlewareConfig> = {
23
- headerName: import.meta.env.VITE_INTLAYER_HEADER_NAME,
24
- cookieName: import.meta.env.VITE_INTLAYER_COOKIE_NAME,
25
- prefixDefault: import.meta.env.VITE_INTLAYER_PREFIX_DEFAULT,
26
- basePath: import.meta.env.VITE_INTLAYER_BASE_PATH,
27
- serverSetCookie: import.meta.env.VITE_INTLAYER_SERVER_SET_COOKIE,
28
- noPrefix: import.meta.env.VITE_INTLAYER_NO_PREFIX,
29
- };
30
-
31
- const content: ReplaceValue<ContentConfig> = {
32
- fileExtensions: import.meta.env.VITE_INTLAYER_FILE_EXTENSIONS,
33
- baseDir: import.meta.env.VITE_INTLAYER_BASE_DIR,
34
- contentDirName: import.meta.env.VITE_INTLAYER_CONTENT_DIR_NAME,
35
- contentDir: import.meta.env.VITE_INTLAYER_CONTENT_DIR,
36
- excludedPath: import.meta.env.VITE_INTLAYER_EXCLUDED_PATH,
37
- resultDirName: import.meta.env.VITE_INTLAYER_RESULT_DIR_NAME,
38
- moduleAugmentationDirName: import.meta.env
39
- .VITE_INTLAYER_MODULE_AUGMENTATION_DIR_NAME,
40
- dictionariesDirName: import.meta.env.VITE_INTLAYER_DICTIONARIES_DIR_NAME,
41
- i18nDictionariesDirName: import.meta.env
42
- .VITE_INTLAYER_I18N_DICTIONARIES_DIR_NAME,
43
- typeDirName: import.meta.env.VITE_INTLAYER_TYPE_DIR_NAME,
44
- mainDirName: import.meta.env.VITE_INTLAYER_MAIN_DIR_NAME,
45
- resultDir: import.meta.env.VITE_INTLAYER_RESULT_DIR,
46
- moduleAugmentationDir: import.meta.env
47
- .VITE_INTLAYER_MODULE_AUGMENTATION_DIR,
48
- dictionariesDir: import.meta.env.VITE_INTLAYER_DICTIONARIES_DIR,
49
- i18nDictionariesDir: import.meta.env.VITE_INTLAYER_I18N_DICTIONARIES_DIR,
50
- typesDir: import.meta.env.VITE_INTLAYER_TYPE_DIR,
51
- mainDir: import.meta.env.VITE_INTLAYER_MAIN_DIR,
52
- watchedFilesPattern: import.meta.env.VITE_INTLAYER_WATCHED_FILES_PATTERN,
53
- watchedFilesPatternWithPath: import.meta.env
54
- .VITE_INTLAYER_WATCHED_FILES_PATTERN_WITH_PATH,
55
- outputFilesPatternWithPath: import.meta.env
56
- .VITE_INTLAYER_OUTPUT_FILES_PATTERN_WITH_PATH,
57
- dictionaryOutput: import.meta.env.VITE_INTLAYER_DICTIONARY_OUTPUT,
58
- };
59
-
60
- return {
61
- internationalization,
62
- middleware,
63
- content,
64
- };
65
- };
@@ -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,38 +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
- })) {
30
- if (typeof value === 'string') {
31
- env[formatEnvName(key, prefix)] = value;
32
- } else {
33
- env[formatEnvName(key, prefix)] = JSON.stringify(value);
34
- }
35
- }
36
-
37
- return env;
38
- };
@@ -1,99 +0,0 @@
1
- import type {
2
- ContentConfig,
3
- DictionaryOutput,
4
- InternationalizationConfig,
5
- IntlayerConfig,
6
- MiddlewareConfig,
7
- ServerSetCookieRule,
8
- } from '../types/config';
9
- import type { Locales } from '../types/locales';
10
- import { extractEnvVariable } from './extractEnvVariable/index';
11
- import { getEnvValue } from './utils';
12
-
13
- /**
14
- * Get all configuration values using environment variables
15
- * Can be used in the client side as the server side
16
- * To use it, be sure to have the environment variables set
17
- */
18
- export const getConfiguration = (): IntlayerConfig => {
19
- const env = extractEnvVariable();
20
-
21
- const intlayerIntlConfiguration: InternationalizationConfig = {
22
- locales: getEnvValue<Locales>(env.internationalization.locales, 'array')!,
23
- defaultLocale: getEnvValue<Locales>(
24
- env?.internationalization.defaultLocale,
25
- 'string'
26
- )!,
27
- };
28
-
29
- const intlayerMiddlewareConfiguration: MiddlewareConfig = {
30
- headerName: getEnvValue(env.middleware.headerName, 'string')!,
31
- cookieName: getEnvValue(env.middleware.cookieName, 'string')!,
32
- prefixDefault: getEnvValue(env.middleware.prefixDefault, 'boolean')!,
33
- basePath: getEnvValue(env.middleware.basePath, 'string')!,
34
- serverSetCookie: getEnvValue<ServerSetCookieRule>(
35
- env.middleware.serverSetCookie,
36
- 'string'
37
- )!,
38
- noPrefix: getEnvValue(env.middleware.noPrefix, 'boolean')!,
39
- };
40
-
41
- const intlayerContentConfiguration: ContentConfig = {
42
- fileExtensions: getEnvValue<string>(env.content.fileExtensions, 'array')!,
43
- baseDir: getEnvValue(env.content.baseDir, 'string')!,
44
- contentDirName: getEnvValue(env.content.contentDirName, 'string')!,
45
- contentDir: getEnvValue(env.content.contentDir, 'string')!,
46
- excludedPath: getEnvValue<string>(env.content.excludedPath, 'array')!,
47
- resultDirName: getEnvValue(env.content.resultDirName, 'string')!,
48
- resultDir: getEnvValue(env.content.resultDir, 'string')!,
49
- moduleAugmentationDirName: getEnvValue(
50
- env.content.moduleAugmentationDirName,
51
- 'string'
52
- )!,
53
- moduleAugmentationDir: getEnvValue(
54
- env.content.moduleAugmentationDir,
55
- 'string'
56
- )!,
57
- dictionaryOutput: getEnvValue<DictionaryOutput>(
58
- env.content.dictionaryOutput,
59
- 'array'
60
- )!,
61
- dictionariesDirName: getEnvValue(
62
- env.content.dictionariesDirName,
63
- 'string'
64
- )!,
65
- dictionariesDir: getEnvValue(env.content.dictionariesDir, 'string')!,
66
- i18nDictionariesDirName: getEnvValue(
67
- env.content.i18nDictionariesDirName,
68
- 'string'
69
- )!,
70
- i18nDictionariesDir: getEnvValue(
71
- env.content.i18nDictionariesDir,
72
- 'string'
73
- )!,
74
- typeDirName: getEnvValue(env.content.typeDirName, 'string')!,
75
- typesDir: getEnvValue(env.content.typesDir, 'string')!,
76
- mainDirName: getEnvValue(env.content.mainDirName, 'string')!,
77
- mainDir: getEnvValue(env.content.mainDir, 'string')!,
78
- watchedFilesPattern: getEnvValue<string>(
79
- env.content.watchedFilesPattern,
80
- 'array'
81
- )!,
82
- watchedFilesPatternWithPath: getEnvValue<string>(
83
- env.content.watchedFilesPatternWithPath,
84
- 'array'
85
- )!,
86
- outputFilesPatternWithPath: getEnvValue(
87
- env.content.outputFilesPatternWithPath,
88
- 'string'
89
- )!,
90
- };
91
-
92
- const intlayerConfiguration: IntlayerConfig = {
93
- internationalization: intlayerIntlConfiguration,
94
- middleware: intlayerMiddlewareConfiguration,
95
- content: intlayerContentConfiguration,
96
- };
97
-
98
- return intlayerConfiguration;
99
- };
@@ -1,2 +0,0 @@
1
- export { getConfiguration } from './getConfiguration';
2
- export { formatEnvVariable } from './formatEnvVariable';