@storm-software/config-tools 1.37.0 → 1.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -24
- package/LICENSE +201 -0
- package/README.md +43 -7
- package/declarations.d.ts +26 -23
- package/index.cjs +72683 -0
- package/index.js +72641 -0
- package/meta.cjs.json +1 -0
- package/meta.esm.json +1 -0
- package/package.json +3 -2
- package/utilities/chalk.cjs +1610 -0
- package/utilities/chalk.js +1606 -0
- package/utilities/find-workspace-root.cjs +111 -0
- package/utilities/find-workspace-root.js +84 -0
- package/utilities/logger.cjs +1785 -0
- package/utilities/logger.js +1770 -0
- package/.eslintrc.json +0 -37
- package/jest.config.ts +0 -3
- package/project.json +0 -67
- package/src/config-file/get-config-file.ts +0 -69
- package/src/config-file/index.ts +0 -1
- package/src/create-storm-config.ts +0 -134
- package/src/env/get-env.ts +0 -141
- package/src/env/index.ts +0 -2
- package/src/env/set-env.ts +0 -207
- package/src/index.ts +0 -14
- package/src/types.ts +0 -45
- package/src/utilities/apply-workspace-tokens.ts +0 -83
- package/src/utilities/chalk.ts +0 -53
- package/src/utilities/correct-paths.ts +0 -12
- package/src/utilities/file-path-utils.ts +0 -26
- package/src/utilities/find-up.ts +0 -21
- package/src/utilities/find-workspace-root.ts +0 -68
- package/src/utilities/get-default-config.ts +0 -106
- package/src/utilities/get-log-level.ts +0 -64
- package/src/utilities/index.ts +0 -10
- package/src/utilities/logger.ts +0 -239
- package/src/utilities/process-handler.ts +0 -44
- package/src/utilities/run.ts +0 -37
- package/tsconfig.json +0 -15
- package/tsconfig.spec.json +0 -16
package/.eslintrc.json
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": ["../../.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/jest.config.ts
DELETED
package/project.json
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
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": ["{options.outputPath}"],
|
|
10
|
-
"options": {
|
|
11
|
-
"main": "packages/config-tools/src/index.ts",
|
|
12
|
-
"additionalEntryPoints": [
|
|
13
|
-
"packages/config-tools/src/utilities/find-workspace-root.ts",
|
|
14
|
-
"packages/config-tools/src/utilities/chalk.ts",
|
|
15
|
-
"packages/config-tools/src/utilities/logger.ts"
|
|
16
|
-
],
|
|
17
|
-
"outputPath": "dist/packages/config-tools",
|
|
18
|
-
"tsConfig": "packages/config-tools/tsconfig.json",
|
|
19
|
-
"project": "packages/config-tools/package.json",
|
|
20
|
-
"defaultConfiguration": "production",
|
|
21
|
-
"platform": "node",
|
|
22
|
-
"deleteOutputPath": true,
|
|
23
|
-
"bundle": true,
|
|
24
|
-
"thirdParty": true,
|
|
25
|
-
"skipTypeCheck": false,
|
|
26
|
-
"metafile": true,
|
|
27
|
-
"minify": false,
|
|
28
|
-
"format": ["cjs"],
|
|
29
|
-
"esbuildOptions": {
|
|
30
|
-
"outExtension": {
|
|
31
|
-
".js": ".js"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"assets": [
|
|
35
|
-
{
|
|
36
|
-
"input": "./packages/config-tools",
|
|
37
|
-
"glob": "*.md",
|
|
38
|
-
"output": "."
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"input": "",
|
|
42
|
-
"glob": "LICENSE",
|
|
43
|
-
"output": "."
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"input": "./packages/config-tools",
|
|
47
|
-
"glob": "declarations.d.ts",
|
|
48
|
-
"output": "."
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
"configurations": {
|
|
52
|
-
"production": {
|
|
53
|
-
"debug": false,
|
|
54
|
-
"verbose": false
|
|
55
|
-
},
|
|
56
|
-
"development": {
|
|
57
|
-
"debug": true,
|
|
58
|
-
"verbose": true
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
"nx-release-publish": {
|
|
63
|
-
"executor": "@storm-software/workspace-tools:npm-publish"
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { StormConfigInput } from "@storm-software/config";
|
|
2
|
-
import { findWorkspaceRoot } from "../utilities/find-workspace-root";
|
|
3
|
-
import { loadConfig } from "c12";
|
|
4
|
-
import merge from "deepmerge";
|
|
5
|
-
|
|
6
|
-
// let _cosmiconfig: any = undefined;
|
|
7
|
-
// let defaultExplorer: PublicExplorer | undefined;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Get the config file for the current Storm workspace
|
|
11
|
-
*
|
|
12
|
-
* @param fileName - The name of the config file to search for
|
|
13
|
-
* @param filePath - The path to search for the config file in
|
|
14
|
-
* @returns The config file for the current Storm workspace
|
|
15
|
-
*/
|
|
16
|
-
export const getConfigFileByName = async (
|
|
17
|
-
fileName: string,
|
|
18
|
-
filePath?: string
|
|
19
|
-
): Promise<Partial<StormConfigInput> | undefined> => {
|
|
20
|
-
const workspacePath = filePath ? filePath : findWorkspaceRoot(filePath);
|
|
21
|
-
|
|
22
|
-
return loadConfig<Partial<StormConfigInput>>({
|
|
23
|
-
cwd: workspacePath,
|
|
24
|
-
name: fileName
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Get the config file for the current Storm workspace
|
|
30
|
-
*
|
|
31
|
-
* @returns The config file for the current Storm workspace
|
|
32
|
-
*/
|
|
33
|
-
export const getConfigFile = async (
|
|
34
|
-
filePath?: string,
|
|
35
|
-
additionalFileNames: string[] = []
|
|
36
|
-
): Promise<Partial<StormConfigInput> | undefined> => {
|
|
37
|
-
const workspacePath = filePath ? filePath : findWorkspaceRoot(filePath);
|
|
38
|
-
|
|
39
|
-
let { config, configFile } = await loadConfig<Partial<StormConfigInput>>({
|
|
40
|
-
cwd: workspacePath,
|
|
41
|
-
name: "storm"
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
if (additionalFileNames) {
|
|
45
|
-
const results = await Promise.all(
|
|
46
|
-
additionalFileNames.map(fileName =>
|
|
47
|
-
loadConfig({
|
|
48
|
-
cwd: workspacePath,
|
|
49
|
-
name: fileName
|
|
50
|
-
})
|
|
51
|
-
)
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
for (const result of results) {
|
|
55
|
-
if (result) {
|
|
56
|
-
config = merge(config ?? {}, result.config ?? {});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (!config) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
config.configFile = configFile;
|
|
66
|
-
config.runtimeVersion = "0.0.1";
|
|
67
|
-
|
|
68
|
-
return config;
|
|
69
|
-
};
|
package/src/config-file/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./get-config-file";
|
|
@@ -1,134 +0,0 @@
|
|
|
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
|
|
29
|
-
keyof StormConfig["extensions"] = keyof StormConfig["extensions"],
|
|
30
|
-
TExtensionConfig = any,
|
|
31
|
-
TExtensionSchema extends ZodTypeAny = ZodTypeAny
|
|
32
|
-
>(
|
|
33
|
-
extensionName?: TExtensionName,
|
|
34
|
-
schema?: TExtensionSchema,
|
|
35
|
-
workspaceRoot?: string
|
|
36
|
-
): StormConfig<TExtensionName, TExtensionConfig> => {
|
|
37
|
-
let result!: StormConfig<TExtensionName, TExtensionConfig>;
|
|
38
|
-
if (!_static_cache) {
|
|
39
|
-
const config = getConfigEnv() as StormConfig & {
|
|
40
|
-
[extensionName in TExtensionName]: TExtensionConfig;
|
|
41
|
-
};
|
|
42
|
-
const defaultConfig = getDefaultConfig(config, workspaceRoot);
|
|
43
|
-
|
|
44
|
-
result = StormConfigSchema.parse({
|
|
45
|
-
...defaultConfig,
|
|
46
|
-
...config,
|
|
47
|
-
colors: {
|
|
48
|
-
...defaultConfig?.colors,
|
|
49
|
-
...config.colors
|
|
50
|
-
}
|
|
51
|
-
}) as StormConfig<TExtensionName, TExtensionConfig>;
|
|
52
|
-
} else {
|
|
53
|
-
result = _static_cache as StormConfig<TExtensionName, TExtensionConfig>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (schema && extensionName) {
|
|
57
|
-
result.extensions = {
|
|
58
|
-
...result.extensions,
|
|
59
|
-
[extensionName]: createConfigExtension<
|
|
60
|
-
TExtensionName,
|
|
61
|
-
TExtensionConfig,
|
|
62
|
-
TExtensionSchema
|
|
63
|
-
>(extensionName, schema)
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
_static_cache = result;
|
|
68
|
-
return result;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Get the config for a specific Storm config Extension
|
|
73
|
-
*
|
|
74
|
-
* @param extensionName - The name of the config extension
|
|
75
|
-
* @param options - The options for the config extension
|
|
76
|
-
* @returns The config for the specified Storm config extension. If the extension does not exist, `undefined` is returned.
|
|
77
|
-
*/
|
|
78
|
-
export const createConfigExtension = <
|
|
79
|
-
TExtensionName extends
|
|
80
|
-
keyof StormConfig["extensions"] = keyof StormConfig["extensions"],
|
|
81
|
-
TExtensionConfig = any,
|
|
82
|
-
TExtensionSchema extends ZodTypeAny = ZodTypeAny
|
|
83
|
-
>(
|
|
84
|
-
extensionName: TExtensionName,
|
|
85
|
-
schema: TExtensionSchema
|
|
86
|
-
): TExtensionConfig => {
|
|
87
|
-
const extension_cache_key = { extensionName };
|
|
88
|
-
if (_extension_cache.has(extension_cache_key)) {
|
|
89
|
-
return _extension_cache.get(extension_cache_key) as TExtensionConfig;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
let extension = getExtensionEnv(extensionName);
|
|
93
|
-
if (schema) {
|
|
94
|
-
extension = schema.parse(extension);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
_extension_cache.set(extension_cache_key, extension);
|
|
98
|
-
return extension as TExtensionConfig;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Load the config file values for the current Storm workspace into environment variables
|
|
103
|
-
*/
|
|
104
|
-
export const loadStormConfig = async (
|
|
105
|
-
workspaceRoot?: string
|
|
106
|
-
): Promise<StormConfig> => {
|
|
107
|
-
let config = {} as StormConfig;
|
|
108
|
-
|
|
109
|
-
let _workspaceRoot = workspaceRoot;
|
|
110
|
-
if (!_workspaceRoot) {
|
|
111
|
-
_workspaceRoot = findWorkspaceRoot();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const configFile = await getConfigFile(_workspaceRoot);
|
|
115
|
-
if (!configFile) {
|
|
116
|
-
writeWarning(
|
|
117
|
-
{ logLevel: "all" },
|
|
118
|
-
"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"
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
config = StormConfigSchema.parse(
|
|
123
|
-
await getDefaultConfig(
|
|
124
|
-
{
|
|
125
|
-
...getConfigEnv(),
|
|
126
|
-
...configFile
|
|
127
|
-
} as Partial<StormConfig>,
|
|
128
|
-
_workspaceRoot
|
|
129
|
-
)
|
|
130
|
-
);
|
|
131
|
-
setConfigEnv(config);
|
|
132
|
-
|
|
133
|
-
return config;
|
|
134
|
-
};
|
package/src/env/get-env.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
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 = <
|
|
14
|
-
TConfig extends Record<string, any> = Record<string, any>
|
|
15
|
-
>(
|
|
16
|
-
extensionName: string
|
|
17
|
-
): TConfig | undefined => {
|
|
18
|
-
const prefix = `STORM_EXTENSION_${extensionName.toUpperCase()}_`;
|
|
19
|
-
return Object.keys(process.env)
|
|
20
|
-
.filter(key => key.startsWith(prefix))
|
|
21
|
-
.reduce((ret: Record<string, any>, key: string) => {
|
|
22
|
-
const name = key
|
|
23
|
-
.replace(prefix, "")
|
|
24
|
-
.split("_")
|
|
25
|
-
.map(i =>
|
|
26
|
-
i.length > 0
|
|
27
|
-
? i.trim().charAt(0).toUpperCase() + i.trim().slice(1)
|
|
28
|
-
: ""
|
|
29
|
-
)
|
|
30
|
-
.join("");
|
|
31
|
-
if (name) {
|
|
32
|
-
ret[name] = process.env[key];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return ret;
|
|
36
|
-
}, {}) as TConfig;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Get the config for the current Storm workspace
|
|
41
|
-
*
|
|
42
|
-
* @returns The config for the current Storm workspace from environment variables
|
|
43
|
-
*/
|
|
44
|
-
export const getConfigEnv = (): DeepPartial<StormConfig> => {
|
|
45
|
-
const prefix = "STORM_";
|
|
46
|
-
|
|
47
|
-
let config: DeepPartial<StormConfig> = {
|
|
48
|
-
extends: process.env[`${prefix}EXTENDS`],
|
|
49
|
-
name: process.env[`${prefix}NAME`],
|
|
50
|
-
namespace: process.env[`${prefix}NAMESPACE`],
|
|
51
|
-
owner: process.env[`${prefix}OWNER`],
|
|
52
|
-
worker: process.env[`${prefix}WORKER`],
|
|
53
|
-
organization: process.env[`${prefix}ORGANIZATION`],
|
|
54
|
-
packageManager: process.env[
|
|
55
|
-
`${prefix}PACKAGE_MANAGER`
|
|
56
|
-
] as StormConfig["packageManager"],
|
|
57
|
-
license: process.env[`${prefix}LICENSE`],
|
|
58
|
-
homepage: process.env[`${prefix}HOMEPAGE`],
|
|
59
|
-
timezone: process.env[`${prefix}TIMEZONE`] ?? process.env.TZ,
|
|
60
|
-
locale: process.env[`${prefix}LOCALE`] ?? process.env.LOCALE,
|
|
61
|
-
configFile: correctPaths(process.env[`${prefix}CONFIG_FILE`]),
|
|
62
|
-
workspaceRoot: correctPaths(process.env[`${prefix}WORKSPACE_ROOT`]),
|
|
63
|
-
packageDirectory: correctPaths(process.env[`${prefix}PACKAGE_DIRECTORY`]),
|
|
64
|
-
buildDirectory: correctPaths(process.env[`${prefix}BUILD_DIRECTORY`]),
|
|
65
|
-
skipCache:
|
|
66
|
-
process.env[`${prefix}SKIP_CACHE`] !== undefined
|
|
67
|
-
? Boolean(process.env[`${prefix}SKIP_CACHE`])
|
|
68
|
-
: undefined,
|
|
69
|
-
cacheDirectory: correctPaths(process.env[`${prefix}CACHE_DIRECTORY`]),
|
|
70
|
-
runtimeVersion: process.env[`${prefix}RUNTIME_VERSION`],
|
|
71
|
-
outputDirectory: correctPaths(process.env[`${prefix}OUTPUT_DIRECTORY`]),
|
|
72
|
-
env: (process.env[`${prefix}ENV`] ??
|
|
73
|
-
process.env.NODE_ENV ??
|
|
74
|
-
process.env.ENVIRONMENT) as StormConfig["env"],
|
|
75
|
-
ci:
|
|
76
|
-
process.env[`${prefix}CI`] !== undefined
|
|
77
|
-
? Boolean(
|
|
78
|
-
process.env[`${prefix}CI`] ??
|
|
79
|
-
process.env.CI ??
|
|
80
|
-
process.env.CONTINUOUS_INTEGRATION
|
|
81
|
-
)
|
|
82
|
-
: undefined,
|
|
83
|
-
colors: {
|
|
84
|
-
primary: process.env[`${prefix}COLOR_PRIMARY`],
|
|
85
|
-
dark: process.env[`${prefix}COLOR_DARK`],
|
|
86
|
-
light: process.env[`${prefix}COLOR_LIGHT`],
|
|
87
|
-
success: process.env[`${prefix}COLOR_SUCCESS`],
|
|
88
|
-
info: process.env[`${prefix}COLOR_INFO`],
|
|
89
|
-
warning: process.env[`${prefix}COLOR_WARNING`],
|
|
90
|
-
error: process.env[`${prefix}COLOR_ERROR`],
|
|
91
|
-
fatal: process.env[`${prefix}COLOR_FATAL`]
|
|
92
|
-
},
|
|
93
|
-
repository: process.env[`${prefix}REPOSITORY`],
|
|
94
|
-
branch: process.env[`${prefix}BRANCH`],
|
|
95
|
-
preid: process.env[`${prefix}PRE_ID`],
|
|
96
|
-
externalPackagePatterns: process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`]
|
|
97
|
-
? JSON.parse(process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] as string)
|
|
98
|
-
: [],
|
|
99
|
-
logLevel:
|
|
100
|
-
process.env[`${prefix}LOG_LEVEL`] !== null &&
|
|
101
|
-
process.env[`${prefix}LOG_LEVEL`] !== undefined
|
|
102
|
-
? process.env[`${prefix}LOG_LEVEL`] &&
|
|
103
|
-
Number.isSafeInteger(
|
|
104
|
-
Number.parseInt(process.env[`${prefix}LOG_LEVEL`] as string)
|
|
105
|
-
)
|
|
106
|
-
? getLogLevelLabel(
|
|
107
|
-
Number.parseInt(process.env[`${prefix}LOG_LEVEL`] as string)
|
|
108
|
-
)
|
|
109
|
-
: (process.env[`${prefix}LOG_LEVEL`] as LogLevelLabel)
|
|
110
|
-
: undefined
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const serializedConfig = process.env[`${prefix}CONFIG`];
|
|
114
|
-
if (serializedConfig) {
|
|
115
|
-
const parsed = JSON.parse(serializedConfig);
|
|
116
|
-
config = {
|
|
117
|
-
...config,
|
|
118
|
-
...parsed,
|
|
119
|
-
colors: { ...config.colors, ...parsed.colors },
|
|
120
|
-
extensions: { ...config.extensions, ...parsed.extensions }
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return config;
|
|
125
|
-
|
|
126
|
-
/*const extensionPrefix = `${prefix}EXTENSION_`;
|
|
127
|
-
return Object.keys(process.env)
|
|
128
|
-
.filter((key) => key.startsWith(extensionPrefix))
|
|
129
|
-
.reduce((ret: StormConfig, key: string) => {
|
|
130
|
-
const extensionName = key
|
|
131
|
-
.substring(prefix.length, key.indexOf("_", prefix.length))
|
|
132
|
-
.split("_")
|
|
133
|
-
.map((i) => (i.length > 0 ? i.trim().charAt(0).toUpperCase() + i.trim().slice(1) : ""))
|
|
134
|
-
.join("");
|
|
135
|
-
if (extensionName) {
|
|
136
|
-
ret.extensions[extensionName] = getExtensionEnv(extensionName);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return ret;
|
|
140
|
-
}, config);*/
|
|
141
|
-
};
|
package/src/env/index.ts
DELETED
package/src/env/set-env.ts
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { LogLevel } from "../types";
|
|
2
|
-
import type { StormConfig } from "@storm-software/config";
|
|
3
|
-
import { getLogLevel } from "../utilities/get-log-level";
|
|
4
|
-
import { correctPaths } from "../utilities/correct-paths";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Get the config for an extension module of Storm workspace from environment variables
|
|
8
|
-
*
|
|
9
|
-
* @param extensionName - The name of the extension module
|
|
10
|
-
* @returns The config for the specified Storm extension module. If the module does not exist, `undefined` is returned.
|
|
11
|
-
*/
|
|
12
|
-
export const setExtensionEnv = <
|
|
13
|
-
TConfig extends Record<string, any> = Record<string, any>
|
|
14
|
-
>(
|
|
15
|
-
extensionName: string,
|
|
16
|
-
extension: TConfig
|
|
17
|
-
) => {
|
|
18
|
-
for (const key of Object.keys(extension ?? {})) {
|
|
19
|
-
if (extension[key]) {
|
|
20
|
-
const result =
|
|
21
|
-
key
|
|
22
|
-
?.replace(/([A-Z])+/g, (input?: string) =>
|
|
23
|
-
input ? input[0]?.toUpperCase() + input.slice(1) : ""
|
|
24
|
-
)
|
|
25
|
-
.split(/(?=[A-Z])|[.\-\s_]/)
|
|
26
|
-
.map((x: string) => x.toLowerCase()) ?? [];
|
|
27
|
-
|
|
28
|
-
let extensionKey: string;
|
|
29
|
-
if (result.length === 0) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (result.length === 1) {
|
|
33
|
-
extensionKey = result[0]?.toUpperCase() ?? "";
|
|
34
|
-
} else {
|
|
35
|
-
extensionKey = result.reduce((ret: string, part: string) => {
|
|
36
|
-
return `${ret}_${part.toLowerCase()}`;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
process.env[
|
|
41
|
-
`STORM_EXTENSION_${extensionName.toUpperCase()}_${extensionKey.toUpperCase()}`
|
|
42
|
-
] = extension[key];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Get the config for the current Storm workspace
|
|
49
|
-
*
|
|
50
|
-
* @returns The config for the current Storm workspace from environment variables
|
|
51
|
-
*/
|
|
52
|
-
export const setConfigEnv = (config: StormConfig) => {
|
|
53
|
-
const prefix = "STORM_";
|
|
54
|
-
|
|
55
|
-
if (config.extends) {
|
|
56
|
-
process.env[`${prefix}EXTENDS`] = config.extends;
|
|
57
|
-
}
|
|
58
|
-
if (config.name) {
|
|
59
|
-
process.env[`${prefix}NAME`] = config.name;
|
|
60
|
-
}
|
|
61
|
-
if (config.namespace) {
|
|
62
|
-
process.env[`${prefix}NAMESPACE`] = config.namespace;
|
|
63
|
-
}
|
|
64
|
-
if (config.owner) {
|
|
65
|
-
process.env[`${prefix}OWNER`] = config.owner;
|
|
66
|
-
}
|
|
67
|
-
if (config.worker) {
|
|
68
|
-
process.env[`${prefix}WORKER`] = config.worker;
|
|
69
|
-
}
|
|
70
|
-
if (config.organization) {
|
|
71
|
-
process.env[`${prefix}ORGANIZATION`] = config.organization;
|
|
72
|
-
}
|
|
73
|
-
if (config.packageManager) {
|
|
74
|
-
process.env[`${prefix}PACKAGE_MANAGER`] = config.packageManager;
|
|
75
|
-
}
|
|
76
|
-
if (config.license) {
|
|
77
|
-
process.env[`${prefix}LICENSE`] = config.license;
|
|
78
|
-
}
|
|
79
|
-
if (config.homepage) {
|
|
80
|
-
process.env[`${prefix}HOMEPAGE`] = config.homepage;
|
|
81
|
-
}
|
|
82
|
-
if (config.timezone) {
|
|
83
|
-
process.env[`${prefix}TIMEZONE`] = config.timezone;
|
|
84
|
-
process.env.TZ = config.timezone;
|
|
85
|
-
process.env.DEFAULT_TIMEZONE = config.timezone;
|
|
86
|
-
}
|
|
87
|
-
if (config.locale) {
|
|
88
|
-
process.env[`${prefix}LOCALE`] = config.locale;
|
|
89
|
-
process.env.LOCALE = config.locale;
|
|
90
|
-
process.env.DEFAULT_LOCALE = config.locale;
|
|
91
|
-
process.env.LANG = config.locale
|
|
92
|
-
? `${config.locale.replaceAll("-", "_")}.UTF-8`
|
|
93
|
-
: "en_US.UTF-8";
|
|
94
|
-
}
|
|
95
|
-
if (config.configFile) {
|
|
96
|
-
process.env[`${prefix}CONFIG_FILE`] = correctPaths(config.configFile);
|
|
97
|
-
}
|
|
98
|
-
if (config.workspaceRoot) {
|
|
99
|
-
process.env[`${prefix}WORKSPACE_ROOT`] = correctPaths(config.workspaceRoot);
|
|
100
|
-
process.env.NX_WORKSPACE_ROOT = correctPaths(config.workspaceRoot);
|
|
101
|
-
process.env.NX_WORKSPACE_ROOT_PATH = correctPaths(config.workspaceRoot);
|
|
102
|
-
}
|
|
103
|
-
if (config.packageDirectory) {
|
|
104
|
-
process.env[`${prefix}PACKAGE_DIRECTORY`] = correctPaths(
|
|
105
|
-
config.packageDirectory
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
if (config.buildDirectory) {
|
|
109
|
-
process.env[`${prefix}BUILD_DIRECTORY`] = correctPaths(
|
|
110
|
-
config.buildDirectory
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
if (config.skipCache !== undefined) {
|
|
114
|
-
process.env[`${prefix}SKIP_CACHE`] = String(config.skipCache);
|
|
115
|
-
if (config.skipCache) {
|
|
116
|
-
process.env.NX_SKIP_NX_CACHE ??= String(config.skipCache);
|
|
117
|
-
process.env.NX_CACHE_PROJECT_GRAPH ??= String(config.skipCache);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (!config.skipCache && config.cacheDirectory) {
|
|
121
|
-
process.env[`${prefix}CACHE_DIRECTORY`] = correctPaths(
|
|
122
|
-
config.cacheDirectory
|
|
123
|
-
);
|
|
124
|
-
// if (config.cacheDirectory.includes("/storm") || config.cacheDirectory.includes("\\storm")) {
|
|
125
|
-
// const nxCacheDirectory = join(
|
|
126
|
-
// config.cacheDirectory.includes("/storm")
|
|
127
|
-
// ? config.cacheDirectory.split("/storm")[0]
|
|
128
|
-
// : config.cacheDirectory.split("\\storm")[0],
|
|
129
|
-
// "nx"
|
|
130
|
-
// );
|
|
131
|
-
// process.env.NX_CACHE_DIRECTORY ??= nxCacheDirectory;
|
|
132
|
-
// process.env.NX_PROJECT_GRAPH_CACHE_DIRECTORY ??= nxCacheDirectory;
|
|
133
|
-
// }
|
|
134
|
-
}
|
|
135
|
-
if (config.runtimeVersion) {
|
|
136
|
-
process.env[`${prefix}RUNTIME_VERSION`] = config.runtimeVersion;
|
|
137
|
-
}
|
|
138
|
-
if (config.outputDirectory) {
|
|
139
|
-
process.env[`${prefix}OUTPUT_DIRECTORY`] = correctPaths(
|
|
140
|
-
config.outputDirectory
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
if (config.env) {
|
|
144
|
-
process.env[`${prefix}ENV`] = config.env;
|
|
145
|
-
process.env.NODE_ENV = config.env;
|
|
146
|
-
process.env.ENVIRONMENT = config.env;
|
|
147
|
-
}
|
|
148
|
-
if (config.ci) {
|
|
149
|
-
process.env[`${prefix}CI`] = String(config.ci);
|
|
150
|
-
process.env.CI = String(config.ci);
|
|
151
|
-
process.env.CONTINUOUS_INTEGRATION = String(config.ci);
|
|
152
|
-
}
|
|
153
|
-
if (config.colors.primary) {
|
|
154
|
-
process.env[`${prefix}COLOR_PRIMARY`] = config.colors.primary;
|
|
155
|
-
}
|
|
156
|
-
if (config.colors.dark) {
|
|
157
|
-
process.env[`${prefix}COLOR_DARK`] = config.colors.dark;
|
|
158
|
-
}
|
|
159
|
-
if (config.colors.light) {
|
|
160
|
-
process.env[`${prefix}COLOR_LIGHT`] = config.colors.light;
|
|
161
|
-
}
|
|
162
|
-
if (config.colors.success) {
|
|
163
|
-
process.env[`${prefix}COLOR_SUCCESS`] = config.colors.success;
|
|
164
|
-
}
|
|
165
|
-
if (config.colors.info) {
|
|
166
|
-
process.env[`${prefix}COLOR_INFO`] = config.colors.info;
|
|
167
|
-
}
|
|
168
|
-
if (config.colors.warning) {
|
|
169
|
-
process.env[`${prefix}COLOR_WARNING`] = config.colors.warning;
|
|
170
|
-
}
|
|
171
|
-
if (config.colors.error) {
|
|
172
|
-
process.env[`${prefix}COLOR_ERROR`] = config.colors.error;
|
|
173
|
-
}
|
|
174
|
-
if (config.colors.fatal) {
|
|
175
|
-
process.env[`${prefix}COLOR_FATAL`] = config.colors.fatal;
|
|
176
|
-
}
|
|
177
|
-
if (config.repository) {
|
|
178
|
-
process.env[`${prefix}REPOSITORY`] = config.repository;
|
|
179
|
-
}
|
|
180
|
-
if (config.branch) {
|
|
181
|
-
process.env[`${prefix}BRANCH`] = config.branch;
|
|
182
|
-
}
|
|
183
|
-
if (config.preid) {
|
|
184
|
-
process.env[`${prefix}PRE_ID`] = String(config.preid);
|
|
185
|
-
}
|
|
186
|
-
if (config.externalPackagePatterns) {
|
|
187
|
-
process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] = JSON.stringify(
|
|
188
|
-
config.externalPackagePatterns
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
if (config.logLevel) {
|
|
192
|
-
process.env[`${prefix}LOG_LEVEL`] = String(config.logLevel);
|
|
193
|
-
process.env.LOG_LEVEL = String(config.logLevel);
|
|
194
|
-
process.env.NX_VERBOSE_LOGGING = String(
|
|
195
|
-
getLogLevel(config.logLevel) >= LogLevel.DEBUG ? true : false
|
|
196
|
-
);
|
|
197
|
-
process.env.RUST_BACKTRACE =
|
|
198
|
-
getLogLevel(config.logLevel) >= LogLevel.DEBUG ? "full" : "none";
|
|
199
|
-
}
|
|
200
|
-
process.env[`${prefix}CONFIG`] = JSON.stringify(config);
|
|
201
|
-
|
|
202
|
-
for (const key of Object.keys(config.extensions ?? {})) {
|
|
203
|
-
config.extensions[key] &&
|
|
204
|
-
Object.keys(config.extensions[key]) &&
|
|
205
|
-
setExtensionEnv(key, config.extensions[key]);
|
|
206
|
-
}
|
|
207
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The config-tools library used by Storm Software for building TypeScript applications.
|
|
3
|
-
*
|
|
4
|
-
* @remarks
|
|
5
|
-
* A package containing various utilities to support custom workspace configurations
|
|
6
|
-
*
|
|
7
|
-
* @packageDocumentation
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export * from "./config-file";
|
|
11
|
-
export * from "./create-storm-config";
|
|
12
|
-
export * from "./env";
|
|
13
|
-
export * from "./types";
|
|
14
|
-
export * from "./utilities";
|