@storm-software/config-tools 1.32.4 → 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 +14 -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 -216122
- package/meta.json +0 -1
- package/utilities/find-workspace-root.js +0 -111
- package/utilities/logger.js +0 -1779
|
@@ -0,0 +1,192 @@
|
|
|
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 = <TConfig extends Record<string, any> = Record<string, any>>(
|
|
13
|
+
extensionName: string,
|
|
14
|
+
extension: TConfig
|
|
15
|
+
) => {
|
|
16
|
+
for (const key of Object.keys(extension ?? {})) {
|
|
17
|
+
if (extension[key]) {
|
|
18
|
+
const result =
|
|
19
|
+
key
|
|
20
|
+
?.replace(/([A-Z])+/g, (input?: string) =>
|
|
21
|
+
input ? input[0]?.toUpperCase() + input.slice(1) : ""
|
|
22
|
+
)
|
|
23
|
+
.split(/(?=[A-Z])|[.\-\s_]/)
|
|
24
|
+
.map((x: string) => x.toLowerCase()) ?? [];
|
|
25
|
+
|
|
26
|
+
let extensionKey: string;
|
|
27
|
+
if (result.length === 0) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (result.length === 1) {
|
|
31
|
+
extensionKey = result[0]?.toUpperCase() ?? "";
|
|
32
|
+
} else {
|
|
33
|
+
extensionKey = result.reduce((ret: string, part: string) => {
|
|
34
|
+
return `${ret}_${part.toLowerCase()}`;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
process.env[`STORM_EXTENSION_${extensionName.toUpperCase()}_${extensionKey.toUpperCase()}`] =
|
|
39
|
+
extension[key];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get the config for the current Storm workspace
|
|
46
|
+
*
|
|
47
|
+
* @returns The config for the current Storm workspace from environment variables
|
|
48
|
+
*/
|
|
49
|
+
export const setConfigEnv = (config: StormConfig) => {
|
|
50
|
+
const prefix = "STORM_";
|
|
51
|
+
|
|
52
|
+
if (config.extends) {
|
|
53
|
+
process.env[`${prefix}EXTENDS`] = config.extends;
|
|
54
|
+
}
|
|
55
|
+
if (config.name) {
|
|
56
|
+
process.env[`${prefix}NAME`] = config.name;
|
|
57
|
+
}
|
|
58
|
+
if (config.namespace) {
|
|
59
|
+
process.env[`${prefix}NAMESPACE`] = config.namespace;
|
|
60
|
+
}
|
|
61
|
+
if (config.owner) {
|
|
62
|
+
process.env[`${prefix}OWNER`] = config.owner;
|
|
63
|
+
}
|
|
64
|
+
if (config.worker) {
|
|
65
|
+
process.env[`${prefix}WORKER`] = config.worker;
|
|
66
|
+
}
|
|
67
|
+
if (config.organization) {
|
|
68
|
+
process.env[`${prefix}ORGANIZATION`] = config.organization;
|
|
69
|
+
}
|
|
70
|
+
if (config.packageManager) {
|
|
71
|
+
process.env[`${prefix}PACKAGE_MANAGER`] = config.packageManager;
|
|
72
|
+
}
|
|
73
|
+
if (config.license) {
|
|
74
|
+
process.env[`${prefix}LICENSE`] = config.license;
|
|
75
|
+
}
|
|
76
|
+
if (config.homepage) {
|
|
77
|
+
process.env[`${prefix}HOMEPAGE`] = config.homepage;
|
|
78
|
+
}
|
|
79
|
+
if (config.timezone) {
|
|
80
|
+
process.env[`${prefix}TIMEZONE`] = config.timezone;
|
|
81
|
+
process.env.TZ = config.timezone;
|
|
82
|
+
process.env.DEFAULT_TIMEZONE = config.timezone;
|
|
83
|
+
}
|
|
84
|
+
if (config.locale) {
|
|
85
|
+
process.env[`${prefix}LOCALE`] = config.locale;
|
|
86
|
+
process.env.LOCALE = config.locale;
|
|
87
|
+
process.env.DEFAULT_LOCALE = config.locale;
|
|
88
|
+
process.env.LANG = config.locale
|
|
89
|
+
? `${config.locale.replaceAll("-", "_")}.UTF-8`
|
|
90
|
+
: "en_US.UTF-8";
|
|
91
|
+
}
|
|
92
|
+
if (config.configFile) {
|
|
93
|
+
process.env[`${prefix}CONFIG_FILE`] = correctPaths(config.configFile);
|
|
94
|
+
}
|
|
95
|
+
if (config.workspaceRoot) {
|
|
96
|
+
process.env[`${prefix}WORKSPACE_ROOT`] = correctPaths(config.workspaceRoot);
|
|
97
|
+
process.env.NX_WORKSPACE_ROOT = correctPaths(config.workspaceRoot);
|
|
98
|
+
process.env.NX_WORKSPACE_ROOT_PATH = correctPaths(config.workspaceRoot);
|
|
99
|
+
}
|
|
100
|
+
if (config.packageDirectory) {
|
|
101
|
+
process.env[`${prefix}PACKAGE_DIRECTORY`] = correctPaths(config.packageDirectory);
|
|
102
|
+
}
|
|
103
|
+
if (config.buildDirectory) {
|
|
104
|
+
process.env[`${prefix}BUILD_DIRECTORY`] = correctPaths(config.buildDirectory);
|
|
105
|
+
}
|
|
106
|
+
if (config.skipCache !== undefined) {
|
|
107
|
+
process.env[`${prefix}SKIP_CACHE`] = String(config.skipCache);
|
|
108
|
+
if (config.skipCache) {
|
|
109
|
+
process.env.NX_SKIP_NX_CACHE ??= String(config.skipCache);
|
|
110
|
+
process.env.NX_CACHE_PROJECT_GRAPH ??= String(config.skipCache);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!config.skipCache && config.cacheDirectory) {
|
|
114
|
+
process.env[`${prefix}CACHE_DIRECTORY`] = correctPaths(config.cacheDirectory);
|
|
115
|
+
// if (config.cacheDirectory.includes("/storm") || config.cacheDirectory.includes("\\storm")) {
|
|
116
|
+
// const nxCacheDirectory = join(
|
|
117
|
+
// config.cacheDirectory.includes("/storm")
|
|
118
|
+
// ? config.cacheDirectory.split("/storm")[0]
|
|
119
|
+
// : config.cacheDirectory.split("\\storm")[0],
|
|
120
|
+
// "nx"
|
|
121
|
+
// );
|
|
122
|
+
// process.env.NX_CACHE_DIRECTORY ??= nxCacheDirectory;
|
|
123
|
+
// process.env.NX_PROJECT_GRAPH_CACHE_DIRECTORY ??= nxCacheDirectory;
|
|
124
|
+
// }
|
|
125
|
+
}
|
|
126
|
+
if (config.runtimeVersion) {
|
|
127
|
+
process.env[`${prefix}RUNTIME_VERSION`] = config.runtimeVersion;
|
|
128
|
+
}
|
|
129
|
+
if (config.runtimeDirectory) {
|
|
130
|
+
process.env[`${prefix}RUNTIME_DIRECTORY`] = correctPaths(config.runtimeDirectory);
|
|
131
|
+
}
|
|
132
|
+
if (config.env) {
|
|
133
|
+
process.env[`${prefix}ENV`] = config.env;
|
|
134
|
+
process.env.NODE_ENV = config.env;
|
|
135
|
+
process.env.ENVIRONMENT = config.env;
|
|
136
|
+
}
|
|
137
|
+
if (config.ci) {
|
|
138
|
+
process.env[`${prefix}CI`] = String(config.ci);
|
|
139
|
+
process.env.CI = String(config.ci);
|
|
140
|
+
process.env.CONTINUOUS_INTEGRATION = String(config.ci);
|
|
141
|
+
}
|
|
142
|
+
if (config.colors.primary) {
|
|
143
|
+
process.env[`${prefix}COLOR_PRIMARY`] = config.colors.primary;
|
|
144
|
+
}
|
|
145
|
+
if (config.colors.background) {
|
|
146
|
+
process.env[`${prefix}COLOR_BACKGROUND`] = config.colors.background;
|
|
147
|
+
}
|
|
148
|
+
if (config.colors.success) {
|
|
149
|
+
process.env[`${prefix}COLOR_SUCCESS`] = config.colors.success;
|
|
150
|
+
}
|
|
151
|
+
if (config.colors.info) {
|
|
152
|
+
process.env[`${prefix}COLOR_INFO`] = config.colors.info;
|
|
153
|
+
}
|
|
154
|
+
if (config.colors.warning) {
|
|
155
|
+
process.env[`${prefix}COLOR_WARNING`] = config.colors.warning;
|
|
156
|
+
}
|
|
157
|
+
if (config.colors.error) {
|
|
158
|
+
process.env[`${prefix}COLOR_ERROR`] = config.colors.error;
|
|
159
|
+
}
|
|
160
|
+
if (config.colors.fatal) {
|
|
161
|
+
process.env[`${prefix}COLOR_FATAL`] = config.colors.fatal;
|
|
162
|
+
}
|
|
163
|
+
if (config.repository) {
|
|
164
|
+
process.env[`${prefix}REPOSITORY`] = config.repository;
|
|
165
|
+
}
|
|
166
|
+
if (config.branch) {
|
|
167
|
+
process.env[`${prefix}BRANCH`] = config.branch;
|
|
168
|
+
}
|
|
169
|
+
if (config.preid) {
|
|
170
|
+
process.env[`${prefix}PRE_ID`] = String(config.preid);
|
|
171
|
+
}
|
|
172
|
+
if (config.externalPackagePatterns) {
|
|
173
|
+
process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] = JSON.stringify(
|
|
174
|
+
config.externalPackagePatterns
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
if (config.logLevel) {
|
|
178
|
+
process.env[`${prefix}LOG_LEVEL`] = String(config.logLevel);
|
|
179
|
+
process.env.LOG_LEVEL = String(config.logLevel);
|
|
180
|
+
process.env.NX_VERBOSE_LOGGING = String(
|
|
181
|
+
getLogLevel(config.logLevel) >= LogLevel.DEBUG ? true : false
|
|
182
|
+
);
|
|
183
|
+
process.env.RUST_BACKTRACE = getLogLevel(config.logLevel) >= LogLevel.DEBUG ? "full" : "none";
|
|
184
|
+
}
|
|
185
|
+
process.env[`${prefix}CONFIG`] = JSON.stringify(config);
|
|
186
|
+
|
|
187
|
+
for (const key of Object.keys(config.extensions ?? {})) {
|
|
188
|
+
config.extensions[key] &&
|
|
189
|
+
Object.keys(config.extensions[key]) &&
|
|
190
|
+
setExtensionEnv(key, config.extensions[key]);
|
|
191
|
+
}
|
|
192
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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";
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { StormConfig } from "@storm-software/config";
|
|
2
|
+
|
|
3
|
+
export type LogLevel = 0 | 10 | 20 | 30 | 35 | 40 | 60 | 70 | 100;
|
|
4
|
+
export const LogLevel = {
|
|
5
|
+
SILENT: 0 as LogLevel,
|
|
6
|
+
FATAL: 10 as LogLevel,
|
|
7
|
+
ERROR: 20 as LogLevel,
|
|
8
|
+
WARN: 30 as LogLevel,
|
|
9
|
+
SUCCESS: 35 as LogLevel,
|
|
10
|
+
INFO: 40 as LogLevel,
|
|
11
|
+
DEBUG: 60 as LogLevel,
|
|
12
|
+
TRACE: 70 as LogLevel,
|
|
13
|
+
ALL: 100 as LogLevel
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
export type LogLevelLabel =
|
|
17
|
+
| "silent"
|
|
18
|
+
| "fatal"
|
|
19
|
+
| "error"
|
|
20
|
+
| "warn"
|
|
21
|
+
| "info"
|
|
22
|
+
| "debug"
|
|
23
|
+
| "trace"
|
|
24
|
+
| "all";
|
|
25
|
+
export const LogLevelLabel = {
|
|
26
|
+
SILENT: "silent" as LogLevelLabel,
|
|
27
|
+
FATAL: "fatal" as LogLevelLabel,
|
|
28
|
+
ERROR: "error" as LogLevelLabel,
|
|
29
|
+
WARN: "warn" as LogLevelLabel,
|
|
30
|
+
INFO: "info" as LogLevelLabel,
|
|
31
|
+
DEBUG: "debug" as LogLevelLabel,
|
|
32
|
+
TRACE: "trace" as LogLevelLabel,
|
|
33
|
+
ALL: "all" as LogLevelLabel
|
|
34
|
+
} as const;
|
|
35
|
+
|
|
36
|
+
export interface BaseTokenizerOptions {
|
|
37
|
+
workspaceRoot?: string;
|
|
38
|
+
config?: StormConfig;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ProjectTokenizerOptions extends BaseTokenizerOptions {
|
|
42
|
+
projectRoot?: string;
|
|
43
|
+
projectName?: string;
|
|
44
|
+
sourceRoot?: string;
|
|
45
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { BaseTokenizerOptions, ProjectTokenizerOptions } from "../../declarations";
|
|
2
|
+
import { findWorkspaceRoot } from "./find-workspace-root";
|
|
3
|
+
|
|
4
|
+
export const applyWorkspaceBaseTokens = async (
|
|
5
|
+
option: string,
|
|
6
|
+
tokenizerOptions: BaseTokenizerOptions
|
|
7
|
+
): Promise<string> => {
|
|
8
|
+
let result = option;
|
|
9
|
+
if (!result) {
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (tokenizerOptions) {
|
|
14
|
+
const optionKeys = Object.keys(tokenizerOptions);
|
|
15
|
+
if (optionKeys.some((optionKey) => result.includes(`{${optionKey}}`))) {
|
|
16
|
+
for (const optionKey of optionKeys) {
|
|
17
|
+
if (result.includes(`{${optionKey}}`)) {
|
|
18
|
+
result = result.replaceAll(`{${optionKey}}`, tokenizerOptions.config?.[optionKey] ?? "");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (tokenizerOptions.config) {
|
|
24
|
+
const configKeys = Object.keys(tokenizerOptions.config);
|
|
25
|
+
if (configKeys.some((configKey) => result.includes(`{${configKey}}`))) {
|
|
26
|
+
for (const configKey of configKeys) {
|
|
27
|
+
if (result.includes(`{${configKey}}`)) {
|
|
28
|
+
result = result.replaceAll(`{${configKey}}`, tokenizerOptions.config[configKey]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (result.includes("{workspaceRoot}")) {
|
|
35
|
+
result = result.replaceAll(
|
|
36
|
+
"{workspaceRoot}",
|
|
37
|
+
tokenizerOptions.workspaceRoot ??
|
|
38
|
+
tokenizerOptions.config?.workspaceRoot ??
|
|
39
|
+
findWorkspaceRoot()
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const applyWorkspaceProjectTokens = (
|
|
47
|
+
option: string,
|
|
48
|
+
tokenizerOptions: ProjectTokenizerOptions
|
|
49
|
+
): Promise<string> => {
|
|
50
|
+
return applyWorkspaceBaseTokens(option, tokenizerOptions);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const applyWorkspaceTokens = async <
|
|
54
|
+
TConfig extends BaseTokenizerOptions = BaseTokenizerOptions
|
|
55
|
+
>(
|
|
56
|
+
options: Record<string, any>,
|
|
57
|
+
config: TConfig,
|
|
58
|
+
tokenizerFn: (option: string, config: TConfig) => string | Promise<string>
|
|
59
|
+
): Promise<Record<string, any>> => {
|
|
60
|
+
if (!options) {
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const result: Record<string, any> = {};
|
|
65
|
+
|
|
66
|
+
for (const option of Object.keys(options)) {
|
|
67
|
+
if (typeof options[option] === "string") {
|
|
68
|
+
result[option] = await Promise.resolve(tokenizerFn(options[option], config));
|
|
69
|
+
} else if (Array.isArray(options[option])) {
|
|
70
|
+
result[option] = await Promise.all(
|
|
71
|
+
options[option].map(async (item: any) =>
|
|
72
|
+
typeof item === "string" ? await Promise.resolve(tokenizerFn(item, config)) : item
|
|
73
|
+
)
|
|
74
|
+
);
|
|
75
|
+
} else if (typeof options[option] === "object") {
|
|
76
|
+
result[option] = await applyWorkspaceTokens(options[option], config, tokenizerFn);
|
|
77
|
+
} else {
|
|
78
|
+
result[option] = options[option];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const correctPaths = (path?: string): string => {
|
|
2
|
+
if (!path) {
|
|
3
|
+
return "";
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// Handle Windows absolute paths
|
|
7
|
+
if (path?.toUpperCase()?.startsWith("C:")) {
|
|
8
|
+
return path.replaceAll("/", "\\");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return path.replaceAll("\\", "/");
|
|
12
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { sep } from "node:path";
|
|
2
|
+
|
|
3
|
+
export const removeExtension = (filePath?: string): string => {
|
|
4
|
+
const result =
|
|
5
|
+
!filePath || (filePath.match(/./g) || []).length <= 1
|
|
6
|
+
? "."
|
|
7
|
+
: filePath.lastIndexOf(".")
|
|
8
|
+
? filePath.substring(0, filePath.lastIndexOf("."))
|
|
9
|
+
: filePath;
|
|
10
|
+
|
|
11
|
+
if (result.startsWith("./")) {
|
|
12
|
+
return result.substring(2);
|
|
13
|
+
}
|
|
14
|
+
if (result.startsWith(".") || result.startsWith("/")) {
|
|
15
|
+
return result.substring(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function findFileName(filePath: string): string {
|
|
22
|
+
return (
|
|
23
|
+
filePath?.split(filePath?.includes(sep) ? sep : filePath?.includes("/") ? "/" : "\\")?.pop() ??
|
|
24
|
+
""
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
const MAX_PATH_SEARCH_DEPTH = 30;
|
|
5
|
+
let depth = 0;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Gets the nearest "node_modules" folder by walking up from start path.
|
|
9
|
+
*/
|
|
10
|
+
export function findFolderUp(startPath: string, endFileNames: string[]): string | undefined {
|
|
11
|
+
const _startPath = startPath ?? process.cwd();
|
|
12
|
+
|
|
13
|
+
if (endFileNames.some((endFileName) => existsSync(join(_startPath, endFileName)))) {
|
|
14
|
+
return _startPath;
|
|
15
|
+
}
|
|
16
|
+
if (_startPath !== "/" && depth++ < MAX_PATH_SEARCH_DEPTH) {
|
|
17
|
+
const parent = join(_startPath, "..");
|
|
18
|
+
return findFolderUp(parent, endFileNames);
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { correctPaths } from "./correct-paths";
|
|
2
|
+
import { findFolderUp } from "./find-up";
|
|
3
|
+
|
|
4
|
+
const rootFiles = [
|
|
5
|
+
"storm.json",
|
|
6
|
+
"storm.config.js",
|
|
7
|
+
"storm.config.ts",
|
|
8
|
+
".storm.json",
|
|
9
|
+
".storm.yaml",
|
|
10
|
+
".storm.yml",
|
|
11
|
+
".storm.js",
|
|
12
|
+
".storm.ts",
|
|
13
|
+
"lerna.json",
|
|
14
|
+
"nx.json",
|
|
15
|
+
"turbo.json",
|
|
16
|
+
"npm-workspace.json",
|
|
17
|
+
"yarn-workspace.json",
|
|
18
|
+
"pnpm-workspace.json",
|
|
19
|
+
"npm-workspace.yaml",
|
|
20
|
+
"yarn-workspace.yaml",
|
|
21
|
+
"pnpm-workspace.yaml",
|
|
22
|
+
"npm-workspace.yml",
|
|
23
|
+
"yarn-workspace.yml",
|
|
24
|
+
"pnpm-workspace.yml",
|
|
25
|
+
"npm-lock.json",
|
|
26
|
+
"yarn-lock.json",
|
|
27
|
+
"pnpm-lock.json",
|
|
28
|
+
"npm-lock.yaml",
|
|
29
|
+
"yarn-lock.yaml",
|
|
30
|
+
"pnpm-lock.yaml",
|
|
31
|
+
"npm-lock.yml",
|
|
32
|
+
"yarn-lock.yml",
|
|
33
|
+
"pnpm-lock.yml",
|
|
34
|
+
"bun.lockb"
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Find the monorepo root directory, searching upwards from `path`.
|
|
39
|
+
*
|
|
40
|
+
* @param pathInsideMonorepo - The path inside the monorepo to start searching from
|
|
41
|
+
* @returns The monorepo root directory
|
|
42
|
+
*/
|
|
43
|
+
export function findWorkspaceRootSafe(pathInsideMonorepo?: string): string | undefined {
|
|
44
|
+
if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {
|
|
45
|
+
return correctPaths(process.env.STORM_WORKSPACE_ROOT ?? process.env.NX_WORKSPACE_ROOT_PATH);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return correctPaths(findFolderUp(pathInsideMonorepo ?? process.cwd(), rootFiles));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Find the monorepo root directory, searching upwards from `path`.
|
|
53
|
+
*
|
|
54
|
+
* @param pathInsideMonorepo - The path inside the monorepo to start searching from
|
|
55
|
+
* @returns The monorepo root directory
|
|
56
|
+
*/
|
|
57
|
+
export function findWorkspaceRoot(pathInsideMonorepo?: string): string {
|
|
58
|
+
const result = findWorkspaceRootSafe(pathInsideMonorepo);
|
|
59
|
+
if (!result) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`Cannot find workspace root upwards from known path. Files search list includes: \n${rootFiles.join(
|
|
62
|
+
"\n"
|
|
63
|
+
)}\nPath: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { type StormConfig, type ColorConfig, StormConfigSchema } from "@storm-software/config";
|
|
4
|
+
import { findWorkspaceRoot } from "./find-workspace-root";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Storm theme config values used for styling various workspace elements
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_COLOR_CONFIG: ColorConfig = {
|
|
10
|
+
primary: "#1fb2a6",
|
|
11
|
+
background: "#1d232a",
|
|
12
|
+
success: "#087f5b",
|
|
13
|
+
info: "#0ea5e9",
|
|
14
|
+
warning: "#fcc419",
|
|
15
|
+
error: "#990000",
|
|
16
|
+
fatal: "#7d1a1a"
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Storm Workspace config values used during various dev-ops processes
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_STORM_CONFIG: any = {
|
|
23
|
+
name: "storm",
|
|
24
|
+
namespace: "storm-software",
|
|
25
|
+
license: "Apache License 2.0",
|
|
26
|
+
homepage: "https://stormsoftware.org",
|
|
27
|
+
owner: "@storm-software/development",
|
|
28
|
+
worker: "stormie-bot",
|
|
29
|
+
runtimeDirectory: "node_modules/.storm",
|
|
30
|
+
cacheDirectory: "node_modules/.cache/storm",
|
|
31
|
+
skipCache: false,
|
|
32
|
+
packageManager: "npm",
|
|
33
|
+
timezone: "America/New_York",
|
|
34
|
+
locale: "en-US",
|
|
35
|
+
env: "production",
|
|
36
|
+
branch: "main",
|
|
37
|
+
organization: "storm-software",
|
|
38
|
+
ci: true,
|
|
39
|
+
configFile: null,
|
|
40
|
+
runtimeVersion: "1.0.0",
|
|
41
|
+
colors: { ...DEFAULT_COLOR_CONFIG },
|
|
42
|
+
extensions: {}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get the default Storm config values used during various dev-ops processes
|
|
47
|
+
*
|
|
48
|
+
* @returns The default Storm config values
|
|
49
|
+
*/
|
|
50
|
+
export const getDefaultConfig = (config: Partial<StormConfig> = {}, root?: string): StormConfig => {
|
|
51
|
+
let name = "storm-workspace";
|
|
52
|
+
let namespace = "storm-software";
|
|
53
|
+
let repository = "https://github.com/storm-software/storm-ops";
|
|
54
|
+
|
|
55
|
+
let license = DEFAULT_STORM_CONFIG.license;
|
|
56
|
+
let homepage = DEFAULT_STORM_CONFIG.homepage;
|
|
57
|
+
|
|
58
|
+
const workspaceRoot = findWorkspaceRoot(root);
|
|
59
|
+
if (existsSync(join(workspaceRoot, "package.json"))) {
|
|
60
|
+
const file = readFileSync(join(workspaceRoot, "package.json"), {
|
|
61
|
+
encoding: "utf-8"
|
|
62
|
+
});
|
|
63
|
+
if (file) {
|
|
64
|
+
const packageJson = JSON.parse(file);
|
|
65
|
+
|
|
66
|
+
if (packageJson.name) {
|
|
67
|
+
name = packageJson.name;
|
|
68
|
+
}
|
|
69
|
+
if (packageJson.namespace) {
|
|
70
|
+
namespace = packageJson.namespace;
|
|
71
|
+
}
|
|
72
|
+
if (packageJson.repository?.url) {
|
|
73
|
+
repository = packageJson.repository?.url;
|
|
74
|
+
}
|
|
75
|
+
if (packageJson.license) {
|
|
76
|
+
license = packageJson.license;
|
|
77
|
+
}
|
|
78
|
+
if (packageJson.homepage) {
|
|
79
|
+
homepage = packageJson.homepage;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return StormConfigSchema.parse({
|
|
85
|
+
...(DEFAULT_STORM_CONFIG as Required<StormConfig>),
|
|
86
|
+
...config,
|
|
87
|
+
colors: { ...DEFAULT_COLOR_CONFIG, ...config.colors },
|
|
88
|
+
workspaceRoot,
|
|
89
|
+
name,
|
|
90
|
+
namespace,
|
|
91
|
+
repository,
|
|
92
|
+
license: license ?? DEFAULT_STORM_CONFIG.license,
|
|
93
|
+
homepage: homepage ?? DEFAULT_STORM_CONFIG.homepage,
|
|
94
|
+
extensions: {
|
|
95
|
+
...config.extensions
|
|
96
|
+
}
|
|
97
|
+
}) as StormConfig;
|
|
98
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { LogLevel, LogLevelLabel } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Convert the log level label to a log level
|
|
5
|
+
*
|
|
6
|
+
* @param label - The log level label to convert
|
|
7
|
+
* @returns The log level
|
|
8
|
+
*/
|
|
9
|
+
export const getLogLevel = (label?: string): LogLevel => {
|
|
10
|
+
switch (label) {
|
|
11
|
+
case "all":
|
|
12
|
+
return LogLevel.ALL;
|
|
13
|
+
case "trace":
|
|
14
|
+
return LogLevel.TRACE;
|
|
15
|
+
case "debug":
|
|
16
|
+
return LogLevel.DEBUG;
|
|
17
|
+
case "info":
|
|
18
|
+
return LogLevel.INFO;
|
|
19
|
+
case "warn":
|
|
20
|
+
return LogLevel.WARN;
|
|
21
|
+
case "error":
|
|
22
|
+
return LogLevel.ERROR;
|
|
23
|
+
case "fatal":
|
|
24
|
+
return LogLevel.FATAL;
|
|
25
|
+
case "silent":
|
|
26
|
+
return LogLevel.SILENT;
|
|
27
|
+
default:
|
|
28
|
+
return LogLevel.INFO;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Convert the log level to a log level label
|
|
34
|
+
*
|
|
35
|
+
* @param logLevel - The log level to convert
|
|
36
|
+
* @returns The log level label
|
|
37
|
+
*/
|
|
38
|
+
export const getLogLevelLabel = (logLevel: number = LogLevel.INFO): LogLevelLabel => {
|
|
39
|
+
if (logLevel >= LogLevel.ALL) {
|
|
40
|
+
return LogLevelLabel.ALL;
|
|
41
|
+
}
|
|
42
|
+
if (logLevel >= LogLevel.TRACE) {
|
|
43
|
+
return LogLevelLabel.TRACE;
|
|
44
|
+
}
|
|
45
|
+
if (logLevel >= LogLevel.DEBUG) {
|
|
46
|
+
return LogLevelLabel.DEBUG;
|
|
47
|
+
}
|
|
48
|
+
if (logLevel >= LogLevel.INFO) {
|
|
49
|
+
return LogLevelLabel.INFO;
|
|
50
|
+
}
|
|
51
|
+
if (logLevel >= LogLevel.WARN) {
|
|
52
|
+
return LogLevelLabel.WARN;
|
|
53
|
+
}
|
|
54
|
+
if (logLevel >= LogLevel.ERROR) {
|
|
55
|
+
return LogLevelLabel.ERROR;
|
|
56
|
+
}
|
|
57
|
+
if (logLevel >= LogLevel.FATAL) {
|
|
58
|
+
return LogLevelLabel.FATAL;
|
|
59
|
+
}
|
|
60
|
+
if (logLevel <= LogLevel.SILENT) {
|
|
61
|
+
return LogLevelLabel.SILENT;
|
|
62
|
+
}
|
|
63
|
+
return LogLevelLabel.INFO;
|
|
64
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./find-workspace-root";
|
|
2
|
+
export * from "./get-default-config";
|
|
3
|
+
export * from "./get-log-level";
|
|
4
|
+
export * from "./logger";
|
|
5
|
+
export * from "./process-handler";
|
|
6
|
+
export * from "./run";
|
|
7
|
+
export * from "./correct-paths";
|
|
8
|
+
export * from "./file-path-utils";
|
|
9
|
+
export * from "./apply-workspace-tokens";
|