@storm-software/config-tools 1.32.3 → 1.33.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/.eslintrc.json +37 -0
- package/CHANGELOG.md +26 -0
- package/README.md +1 -1
- package/jest.config.ts +3 -0
- package/package.json +5 -5
- package/project.json +69 -0
- package/src/config-file/get-config-file.ts +129 -0
- package/src/config-file/index.ts +1 -0
- package/src/create-storm-config.ts +129 -0
- package/src/env/get-env.ts +125 -0
- package/src/env/index.ts +2 -0
- package/src/env/set-env.ts +192 -0
- package/src/index.ts +14 -0
- package/src/types.ts +45 -0
- package/src/utilities/apply-workspace-tokens.ts +83 -0
- package/src/utilities/correct-paths.ts +12 -0
- package/src/utilities/file-path-utils.ts +26 -0
- package/src/utilities/find-up.ts +21 -0
- package/src/utilities/find-workspace-root.ts +68 -0
- package/src/utilities/get-default-config.ts +98 -0
- package/src/utilities/get-log-level.ts +64 -0
- package/src/utilities/index.ts +9 -0
- package/src/utilities/logger.ts +257 -0
- package/src/utilities/process-handler.ts +44 -0
- package/src/utilities/run.ts +32 -0
- package/tsconfig.json +15 -0
- package/tsconfig.spec.json +16 -0
- package/LICENSE +0 -201
- package/index.js +0 -216120
- package/meta.json +0 -1
- package/utilities/find-workspace-root.js +0 -111
- package/utilities/logger.js +0 -1779
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["../../.eslintrc.json", "../../.eslintrc.base.json"],
|
|
3
|
+
"ignorePatterns": ["!**/*", "node_modules/*"],
|
|
4
|
+
"overrides": [
|
|
5
|
+
{
|
|
6
|
+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
|
7
|
+
"rules": {}
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"files": ["*.ts", "*.tsx"],
|
|
11
|
+
"rules": {}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"files": ["*.js", "*.jsx"],
|
|
15
|
+
"rules": {}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"files": ["*.json"],
|
|
19
|
+
"parser": "jsonc-eslint-parser",
|
|
20
|
+
"rules": {
|
|
21
|
+
"@nx/dependency-checks": [
|
|
22
|
+
"error",
|
|
23
|
+
{
|
|
24
|
+
"buildTargets": ["build"],
|
|
25
|
+
"ignoredFiles": [
|
|
26
|
+
"{projectRoot}/esbuild.config.{js,ts,mjs,mts}",
|
|
27
|
+
"{projectRoot}/jest.config.ts"
|
|
28
|
+
],
|
|
29
|
+
"checkMissingDependencies": true,
|
|
30
|
+
"checkObsoleteDependencies": true,
|
|
31
|
+
"checkVersionMismatches": false
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
## 1.33.0 (2024-03-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 🚀 Features
|
|
5
|
+
|
|
6
|
+
- **workspace-tools:** Added Nx plugin to apply rust and typescript targets ([5738161f](https://github.com/storm-software/storm-ops/commit/5738161f))
|
|
7
|
+
|
|
8
|
+
- **workspace-tools:** Major updates to base nx.json configuration ([06ec9a6a](https://github.com/storm-software/storm-ops/commit/06ec9a6a))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### ❤️ Thank You
|
|
12
|
+
|
|
13
|
+
- Patrick Sullivan
|
|
14
|
+
|
|
15
|
+
## 1.32.4 (2024-03-15)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### 🩹 Fixes
|
|
19
|
+
|
|
20
|
+
- **build-tools:** Resolved issue with improper token application ([53398629](https://github.com/storm-software/storm-ops/commit/53398629))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### ❤️ Thank You
|
|
24
|
+
|
|
25
|
+
- Patrick Sullivan
|
|
26
|
+
|
|
1
27
|
## 1.32.3 (2024-03-06)
|
|
2
28
|
|
|
3
29
|
|
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ This package is part of the <b>⚡Storm-Ops</b> monorepo. The Storm-Ops packages
|
|
|
16
16
|
|
|
17
17
|
<h3 align="center">💻 Visit <a href="https://stormsoftware.org" target="_blank">stormsoftware.org</a> to stay up to date with this developer</h3><br />
|
|
18
18
|
|
|
19
|
-
[](https://prettier.io/)
|
|
20
20
|
[](http://nx.dev/) [](https://nextjs.org/) [](http://commitizen.github.io/cz-cli/)  [](https://docusaurus.io/) 
|
|
21
21
|
|
|
22
22
|
> [!IMPORTANT]
|
package/jest.config.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storm-software/config-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.33.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "⚡The Storm-Ops monorepo contains utility applications, tools, and various libraries to create modern and scalable web applications.",
|
|
6
6
|
"repository": {
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"chalk": "4.1.2",
|
|
15
15
|
"cosmiconfig": "9.0.0",
|
|
16
|
-
"find-up": "7.0.0",
|
|
17
|
-
"fs-extra": "11.2.0",
|
|
18
|
-
"locate-path": "7.2.0",
|
|
19
16
|
"zod": "3.22.4"
|
|
20
17
|
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@storm-software/config": "workspace:*"
|
|
20
|
+
},
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@
|
|
25
|
+
"@storm-software/config": "1.7.0"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/project.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "config-tools",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"projectType": "library",
|
|
5
|
+
"sourceRoot": "packages/config-tools/src",
|
|
6
|
+
"targets": {
|
|
7
|
+
"build": {
|
|
8
|
+
"executor": "@nx/esbuild:esbuild",
|
|
9
|
+
"outputs": [
|
|
10
|
+
"{options.outputPath}"
|
|
11
|
+
],
|
|
12
|
+
"options": {
|
|
13
|
+
"main": "packages/config-tools/src/index.ts",
|
|
14
|
+
"additionalEntryPoints": [
|
|
15
|
+
"packages/config-tools/src/utilities/find-workspace-root.ts",
|
|
16
|
+
"packages/config-tools/src/utilities/logger.ts"
|
|
17
|
+
],
|
|
18
|
+
"outputPath": "dist/packages/config-tools",
|
|
19
|
+
"tsConfig": "packages/config-tools/tsconfig.json",
|
|
20
|
+
"project": "packages/config-tools/package.json",
|
|
21
|
+
"defaultConfiguration": "production",
|
|
22
|
+
"platform": "node",
|
|
23
|
+
"deleteOutputPath": true,
|
|
24
|
+
"bundle": true,
|
|
25
|
+
"thirdParty": true,
|
|
26
|
+
"skipTypeCheck": false,
|
|
27
|
+
"metafile": true,
|
|
28
|
+
"minify": false,
|
|
29
|
+
"format": [
|
|
30
|
+
"cjs"
|
|
31
|
+
],
|
|
32
|
+
"esbuildOptions": {
|
|
33
|
+
"outExtension": {
|
|
34
|
+
".js": ".js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"assets": [
|
|
38
|
+
{
|
|
39
|
+
"input": "./packages/config-tools",
|
|
40
|
+
"glob": "*.md",
|
|
41
|
+
"output": "."
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"input": "",
|
|
45
|
+
"glob": "LICENSE",
|
|
46
|
+
"output": "."
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"input": "./packages/config-tools",
|
|
50
|
+
"glob": "declarations.d.ts",
|
|
51
|
+
"output": "."
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"configurations": {
|
|
55
|
+
"production": {
|
|
56
|
+
"debug": false,
|
|
57
|
+
"verbose": false
|
|
58
|
+
},
|
|
59
|
+
"development": {
|
|
60
|
+
"debug": true,
|
|
61
|
+
"verbose": true
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"lint": {},
|
|
67
|
+
"test": {}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { CosmiconfigResult, PublicExplorer, Config } from "cosmiconfig";
|
|
2
|
+
import type { StormConfigInput } from "@storm-software/config";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { findWorkspaceRoot } from "../utilities/find-workspace-root";
|
|
5
|
+
import { readFile, stat } from "node:fs/promises";
|
|
6
|
+
|
|
7
|
+
let _cosmiconfig: any = undefined;
|
|
8
|
+
let defaultExplorer: PublicExplorer | undefined;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get the config file for the current Storm workspace
|
|
12
|
+
*
|
|
13
|
+
* @param fileName - The name of the config file to search for
|
|
14
|
+
* @param filePath - The path to search for the config file in
|
|
15
|
+
* @returns The config file for the current Storm workspace
|
|
16
|
+
*/
|
|
17
|
+
export const getConfigFileExplorer = async (
|
|
18
|
+
fileName: string
|
|
19
|
+
): Promise<PublicExplorer | undefined> => {
|
|
20
|
+
if (!_cosmiconfig) {
|
|
21
|
+
const mod = await import("cosmiconfig");
|
|
22
|
+
if (mod?.cosmiconfig) {
|
|
23
|
+
_cosmiconfig = mod.cosmiconfig;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!_cosmiconfig) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return _cosmiconfig(fileName, { cache: true });
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the config file for the current Storm workspace
|
|
36
|
+
*
|
|
37
|
+
* @param fileName - The name of the config file to search for
|
|
38
|
+
* @param filePath - The path to search for the config file in
|
|
39
|
+
* @returns The config file for the current Storm workspace
|
|
40
|
+
*/
|
|
41
|
+
export const getConfigFileByName = async (
|
|
42
|
+
fileName: string,
|
|
43
|
+
filePath?: string
|
|
44
|
+
): Promise<CosmiconfigResult | undefined> => {
|
|
45
|
+
return (await getConfigFileExplorer(fileName))?.search(filePath);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the config file for the current Storm workspace
|
|
50
|
+
*
|
|
51
|
+
* @param fileName - The name of the config file to search for
|
|
52
|
+
* @param filePath - The path to search for the config file in
|
|
53
|
+
* @returns The config file for the current Storm workspace
|
|
54
|
+
*/
|
|
55
|
+
export const getJsonConfigFile = async (
|
|
56
|
+
fileName: string,
|
|
57
|
+
filePath?: string
|
|
58
|
+
): Promise<CosmiconfigResult | undefined> => {
|
|
59
|
+
// const fse = await import("fs-extra/esm");
|
|
60
|
+
|
|
61
|
+
const jsonPath = join(
|
|
62
|
+
filePath ?? process.cwd(),
|
|
63
|
+
fileName.endsWith(".json") ? fileName : `${fileName}.json`
|
|
64
|
+
);
|
|
65
|
+
const isEmpty = !!(await stat(jsonPath).catch((_) => false));
|
|
66
|
+
|
|
67
|
+
return isEmpty
|
|
68
|
+
? {
|
|
69
|
+
config: JSON.parse(await readFile(jsonPath, "utf-8")),
|
|
70
|
+
filepath: jsonPath,
|
|
71
|
+
isEmpty
|
|
72
|
+
}
|
|
73
|
+
: { config: {} as Config, filepath: jsonPath, isEmpty };
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get the config file for the current Storm workspace
|
|
78
|
+
*
|
|
79
|
+
* @returns The config file for the current Storm workspace
|
|
80
|
+
*/
|
|
81
|
+
export const getConfigFile = async (
|
|
82
|
+
filePath?: string,
|
|
83
|
+
additionalFileNames: string[] = []
|
|
84
|
+
): Promise<Partial<StormConfigInput> | undefined> => {
|
|
85
|
+
const workspacePath = filePath ? filePath : findWorkspaceRoot(filePath);
|
|
86
|
+
|
|
87
|
+
// let cosmiconfigResult = await getJsonConfigFile("storm", workspacePath);
|
|
88
|
+
// if (!cosmiconfigResult || cosmiconfigResult.isEmpty) {
|
|
89
|
+
if (!defaultExplorer) {
|
|
90
|
+
defaultExplorer = await getConfigFileExplorer("storm");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let cosmiconfigResult: any = null;
|
|
94
|
+
if (defaultExplorer) {
|
|
95
|
+
cosmiconfigResult = await defaultExplorer.search(workspacePath);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if ((!cosmiconfigResult || cosmiconfigResult.isEmpty) && additionalFileNames.length > 0) {
|
|
99
|
+
for (const additionalFileName of additionalFileNames) {
|
|
100
|
+
cosmiconfigResult = await getJsonConfigFile(additionalFileName, workspacePath);
|
|
101
|
+
if (cosmiconfigResult && !cosmiconfigResult.isEmpty) {
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
cosmiconfigResult = await getConfigFileByName(additionalFileName, workspacePath);
|
|
106
|
+
if (cosmiconfigResult && !cosmiconfigResult.isEmpty) {
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// }
|
|
112
|
+
|
|
113
|
+
if (
|
|
114
|
+
!cosmiconfigResult ||
|
|
115
|
+
Object.keys(cosmiconfigResult).length === 0 ||
|
|
116
|
+
cosmiconfigResult.isEmpty ||
|
|
117
|
+
!cosmiconfigResult.filepath
|
|
118
|
+
) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const config: Partial<StormConfigInput> = cosmiconfigResult.config ?? {};
|
|
123
|
+
if (cosmiconfigResult.filepath) {
|
|
124
|
+
config.configFile = cosmiconfigResult.filepath;
|
|
125
|
+
}
|
|
126
|
+
config.runtimeVersion = "0.0.1";
|
|
127
|
+
|
|
128
|
+
return config;
|
|
129
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./get-config-file";
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { ZodTypeAny } from "zod";
|
|
2
|
+
import { getConfigFile } from "./config-file/get-config-file";
|
|
3
|
+
import { getConfigEnv, getExtensionEnv } from "./env/get-env";
|
|
4
|
+
import { setConfigEnv } from "./env/set-env";
|
|
5
|
+
import type { StormConfig } from "@storm-software/config";
|
|
6
|
+
import { StormConfigSchema } from "@storm-software/config/schema";
|
|
7
|
+
import { findWorkspaceRoot, writeWarning } from "./utilities";
|
|
8
|
+
import { getDefaultConfig } from "./utilities/get-default-config";
|
|
9
|
+
|
|
10
|
+
const _extension_cache = new WeakMap<{ extensionName: string }, any>();
|
|
11
|
+
let _static_cache: StormConfig | undefined = undefined;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Get the config for the current Storm workspace
|
|
15
|
+
*
|
|
16
|
+
* @returns The config for the current Storm workspace
|
|
17
|
+
*/
|
|
18
|
+
export const createConfig = (workspaceRoot?: string): StormConfig => {
|
|
19
|
+
return createStormConfig(undefined, undefined, workspaceRoot);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get the config for the current Storm workspace
|
|
24
|
+
*
|
|
25
|
+
* @returns The config for the current Storm workspace
|
|
26
|
+
*/
|
|
27
|
+
export const createStormConfig = <
|
|
28
|
+
TExtensionName extends keyof StormConfig["extensions"] = keyof StormConfig["extensions"],
|
|
29
|
+
TExtensionConfig = any,
|
|
30
|
+
TExtensionSchema extends ZodTypeAny = ZodTypeAny
|
|
31
|
+
>(
|
|
32
|
+
extensionName?: TExtensionName,
|
|
33
|
+
schema?: TExtensionSchema,
|
|
34
|
+
workspaceRoot?: string
|
|
35
|
+
): StormConfig<TExtensionName, TExtensionConfig> => {
|
|
36
|
+
let result!: StormConfig<TExtensionName, TExtensionConfig>;
|
|
37
|
+
if (!_static_cache) {
|
|
38
|
+
const config = getConfigEnv() as StormConfig & {
|
|
39
|
+
[extensionName in TExtensionName]: TExtensionConfig;
|
|
40
|
+
};
|
|
41
|
+
const defaultConfig = getDefaultConfig(config, workspaceRoot);
|
|
42
|
+
|
|
43
|
+
result = StormConfigSchema.parse({
|
|
44
|
+
...defaultConfig,
|
|
45
|
+
...config,
|
|
46
|
+
colors: {
|
|
47
|
+
...defaultConfig?.colors,
|
|
48
|
+
...config.colors
|
|
49
|
+
}
|
|
50
|
+
}) as StormConfig<TExtensionName, TExtensionConfig>;
|
|
51
|
+
} else {
|
|
52
|
+
result = _static_cache as StormConfig<TExtensionName, TExtensionConfig>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (schema && extensionName) {
|
|
56
|
+
result.extensions = {
|
|
57
|
+
...result.extensions,
|
|
58
|
+
[extensionName]: createConfigExtension<TExtensionName, TExtensionConfig, TExtensionSchema>(
|
|
59
|
+
extensionName,
|
|
60
|
+
schema
|
|
61
|
+
)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
_static_cache = result;
|
|
66
|
+
return result;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get the config for a specific Storm config Extension
|
|
71
|
+
*
|
|
72
|
+
* @param extensionName - The name of the config extension
|
|
73
|
+
* @param options - The options for the config extension
|
|
74
|
+
* @returns The config for the specified Storm config extension. If the extension does not exist, `undefined` is returned.
|
|
75
|
+
*/
|
|
76
|
+
export const createConfigExtension = <
|
|
77
|
+
TExtensionName extends keyof StormConfig["extensions"] = keyof StormConfig["extensions"],
|
|
78
|
+
TExtensionConfig = any,
|
|
79
|
+
TExtensionSchema extends ZodTypeAny = ZodTypeAny
|
|
80
|
+
>(
|
|
81
|
+
extensionName: TExtensionName,
|
|
82
|
+
schema: TExtensionSchema
|
|
83
|
+
): TExtensionConfig => {
|
|
84
|
+
const extension_cache_key = { extensionName };
|
|
85
|
+
if (_extension_cache.has(extension_cache_key)) {
|
|
86
|
+
return _extension_cache.get(extension_cache_key) as TExtensionConfig;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let extension = getExtensionEnv(extensionName);
|
|
90
|
+
if (schema) {
|
|
91
|
+
extension = schema.parse(extension);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
_extension_cache.set(extension_cache_key, extension);
|
|
95
|
+
return extension as TExtensionConfig;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Load the config file values for the current Storm workspace into environment variables
|
|
100
|
+
*/
|
|
101
|
+
export const loadStormConfig = async (workspaceRoot?: string): Promise<StormConfig> => {
|
|
102
|
+
let config = {} as StormConfig;
|
|
103
|
+
|
|
104
|
+
let _workspaceRoot = workspaceRoot;
|
|
105
|
+
if (!_workspaceRoot) {
|
|
106
|
+
_workspaceRoot = findWorkspaceRoot();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const configFile = await getConfigFile(_workspaceRoot);
|
|
110
|
+
if (!configFile) {
|
|
111
|
+
writeWarning(
|
|
112
|
+
{ logLevel: "all" },
|
|
113
|
+
"No Storm config file found in the current workspace. Please ensure this is the expected behavior - you can add a `storm.config.js` file to the root of your workspace if it is not.\n"
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
config = StormConfigSchema.parse(
|
|
118
|
+
await getDefaultConfig(
|
|
119
|
+
{
|
|
120
|
+
...getConfigEnv(),
|
|
121
|
+
...configFile
|
|
122
|
+
} as Partial<StormConfig>,
|
|
123
|
+
_workspaceRoot
|
|
124
|
+
)
|
|
125
|
+
);
|
|
126
|
+
setConfigEnv(config);
|
|
127
|
+
|
|
128
|
+
return config;
|
|
129
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { LogLevelLabel } from "../types";
|
|
2
|
+
import type { StormConfig } from "@storm-software/config";
|
|
3
|
+
import { getLogLevelLabel } from "../utilities";
|
|
4
|
+
import type { DeepPartial } from "../../declarations.d";
|
|
5
|
+
import { correctPaths } from "../utilities/correct-paths";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get the config for an extension module of Storm workspace from environment variables
|
|
9
|
+
*
|
|
10
|
+
* @param extensionName - The name of the extension module
|
|
11
|
+
* @returns The config for the specified Storm extension module. If the module does not exist, `undefined` is returned.
|
|
12
|
+
*/
|
|
13
|
+
export const getExtensionEnv = <TConfig extends Record<string, any> = Record<string, any>>(
|
|
14
|
+
extensionName: string
|
|
15
|
+
): TConfig | undefined => {
|
|
16
|
+
const prefix = `STORM_EXTENSION_${extensionName.toUpperCase()}_`;
|
|
17
|
+
return Object.keys(process.env)
|
|
18
|
+
.filter((key) => key.startsWith(prefix))
|
|
19
|
+
.reduce((ret: Record<string, any>, key: string) => {
|
|
20
|
+
const name = key
|
|
21
|
+
.replace(prefix, "")
|
|
22
|
+
.split("_")
|
|
23
|
+
.map((i) => (i.length > 0 ? i.trim().charAt(0).toUpperCase() + i.trim().slice(1) : ""))
|
|
24
|
+
.join("");
|
|
25
|
+
if (name) {
|
|
26
|
+
ret[name] = process.env[key];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return ret;
|
|
30
|
+
}, {}) as TConfig;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get the config for the current Storm workspace
|
|
35
|
+
*
|
|
36
|
+
* @returns The config for the current Storm workspace from environment variables
|
|
37
|
+
*/
|
|
38
|
+
export const getConfigEnv = (): DeepPartial<StormConfig> => {
|
|
39
|
+
const prefix = "STORM_";
|
|
40
|
+
|
|
41
|
+
let config: DeepPartial<StormConfig> = {
|
|
42
|
+
extends: process.env[`${prefix}EXTENDS`],
|
|
43
|
+
name: process.env[`${prefix}NAME`],
|
|
44
|
+
namespace: process.env[`${prefix}NAMESPACE`],
|
|
45
|
+
owner: process.env[`${prefix}OWNER`],
|
|
46
|
+
worker: process.env[`${prefix}WORKER`],
|
|
47
|
+
organization: process.env[`${prefix}ORGANIZATION`],
|
|
48
|
+
packageManager: process.env[`${prefix}PACKAGE_MANAGER`] as StormConfig["packageManager"],
|
|
49
|
+
license: process.env[`${prefix}LICENSE`],
|
|
50
|
+
homepage: process.env[`${prefix}HOMEPAGE`],
|
|
51
|
+
timezone: process.env[`${prefix}TIMEZONE`] ?? process.env.TZ,
|
|
52
|
+
locale: process.env[`${prefix}LOCALE`] ?? process.env.LOCALE,
|
|
53
|
+
configFile: correctPaths(process.env[`${prefix}CONFIG_FILE`]),
|
|
54
|
+
workspaceRoot: correctPaths(process.env[`${prefix}WORKSPACE_ROOT`]),
|
|
55
|
+
packageDirectory: correctPaths(process.env[`${prefix}PACKAGE_DIRECTORY`]),
|
|
56
|
+
buildDirectory: correctPaths(process.env[`${prefix}BUILD_DIRECTORY`]),
|
|
57
|
+
skipCache:
|
|
58
|
+
process.env[`${prefix}SKIP_CACHE`] !== undefined
|
|
59
|
+
? Boolean(process.env[`${prefix}SKIP_CACHE`])
|
|
60
|
+
: undefined,
|
|
61
|
+
cacheDirectory: correctPaths(process.env[`${prefix}CACHE_DIRECTORY`]),
|
|
62
|
+
runtimeVersion: process.env[`${prefix}RUNTIME_VERSION`],
|
|
63
|
+
runtimeDirectory: correctPaths(process.env[`${prefix}RUNTIME_DIRECTORY`]),
|
|
64
|
+
env: (process.env[`${prefix}ENV`] ??
|
|
65
|
+
process.env.NODE_ENV ??
|
|
66
|
+
process.env.ENVIRONMENT) as StormConfig["env"],
|
|
67
|
+
ci:
|
|
68
|
+
process.env[`${prefix}CI`] !== undefined
|
|
69
|
+
? Boolean(
|
|
70
|
+
process.env[`${prefix}CI`] ?? process.env.CI ?? process.env.CONTINUOUS_INTEGRATION
|
|
71
|
+
)
|
|
72
|
+
: undefined,
|
|
73
|
+
colors: {
|
|
74
|
+
primary: process.env[`${prefix}COLOR_PRIMARY`],
|
|
75
|
+
background: process.env[`${prefix}COLOR_BACKGROUND`],
|
|
76
|
+
success: process.env[`${prefix}COLOR_SUCCESS`],
|
|
77
|
+
info: process.env[`${prefix}COLOR_INFO`],
|
|
78
|
+
warning: process.env[`${prefix}COLOR_WARNING`],
|
|
79
|
+
error: process.env[`${prefix}COLOR_ERROR`],
|
|
80
|
+
fatal: process.env[`${prefix}COLOR_FATAL`]
|
|
81
|
+
},
|
|
82
|
+
repository: process.env[`${prefix}REPOSITORY`],
|
|
83
|
+
branch: process.env[`${prefix}BRANCH`],
|
|
84
|
+
preid: process.env[`${prefix}PRE_ID`],
|
|
85
|
+
externalPackagePatterns: process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`]
|
|
86
|
+
? JSON.parse(process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] as string)
|
|
87
|
+
: [],
|
|
88
|
+
logLevel:
|
|
89
|
+
process.env[`${prefix}LOG_LEVEL`] !== null && process.env[`${prefix}LOG_LEVEL`] !== undefined
|
|
90
|
+
? process.env[`${prefix}LOG_LEVEL`] &&
|
|
91
|
+
Number.isSafeInteger(Number.parseInt(process.env[`${prefix}LOG_LEVEL`] as string))
|
|
92
|
+
? getLogLevelLabel(Number.parseInt(process.env[`${prefix}LOG_LEVEL`] as string))
|
|
93
|
+
: (process.env[`${prefix}LOG_LEVEL`] as LogLevelLabel)
|
|
94
|
+
: undefined
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const serializedConfig = process.env[`${prefix}CONFIG`];
|
|
98
|
+
if (serializedConfig) {
|
|
99
|
+
const parsed = JSON.parse(serializedConfig);
|
|
100
|
+
config = {
|
|
101
|
+
...config,
|
|
102
|
+
...parsed,
|
|
103
|
+
colors: { ...config.colors, ...parsed.colors },
|
|
104
|
+
extensions: { ...config.extensions, ...parsed.extensions }
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return config;
|
|
109
|
+
|
|
110
|
+
/*const extensionPrefix = `${prefix}EXTENSION_`;
|
|
111
|
+
return Object.keys(process.env)
|
|
112
|
+
.filter((key) => key.startsWith(extensionPrefix))
|
|
113
|
+
.reduce((ret: StormConfig, key: string) => {
|
|
114
|
+
const extensionName = key
|
|
115
|
+
.substring(prefix.length, key.indexOf("_", prefix.length))
|
|
116
|
+
.split("_")
|
|
117
|
+
.map((i) => (i.length > 0 ? i.trim().charAt(0).toUpperCase() + i.trim().slice(1) : ""))
|
|
118
|
+
.join("");
|
|
119
|
+
if (extensionName) {
|
|
120
|
+
ret.extensions[extensionName] = getExtensionEnv(extensionName);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return ret;
|
|
124
|
+
}, config);*/
|
|
125
|
+
};
|
package/src/env/index.ts
ADDED