@storm-software/config-tools 1.23.6 → 1.23.10

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.
@@ -1,234 +0,0 @@
1
- import * as chalk from "chalk";
2
- import { LogLevel, type StormConfig } from "../types";
3
- import { getLogLevel } from "./get-log-level";
4
-
5
- /**
6
- * Get the log function for a log level
7
- *
8
- * @param config - The Storm configuration
9
- * @param logLevel - The log level
10
- * @returns The log function
11
- */
12
- export const getLogFn = (
13
- config: Partial<StormConfig> = {},
14
- logLevel: number | LogLevel = LogLevel.INFO
15
- ): ((message: string) => void) => {
16
- if (
17
- (typeof logLevel === "number" &&
18
- (logLevel >= getLogLevel(config.logLevel ?? process.env?.STORM_LOG_LEVEL) ||
19
- logLevel <= LogLevel.SILENT)) ||
20
- (typeof logLevel === "string" &&
21
- getLogLevel(logLevel) >= getLogLevel(config.logLevel ?? process.env?.STORM_LOG_LEVEL))
22
- ) {
23
- return (_: string) => {
24
- /* noop */
25
- };
26
- }
27
-
28
- if (
29
- (typeof logLevel === "number" && LogLevel.FATAL >= logLevel) ||
30
- (typeof logLevel === "string" && LogLevel.FATAL >= getLogLevel(logLevel))
31
- ) {
32
- return (message: string) => {
33
- console.error(
34
- `
35
- ${chalk.bold.hex(config?.colors?.fatal ? config.colors.fatal : "#1fb2a6")(">")} ${chalk.bold
36
- .bgHex(config?.colors?.fatal ? config.colors.fatal : "#1fb2a6")
37
- .white(" šŸ’€ Fatal ")} ${chalk.hex(
38
- config?.colors?.fatal ? config.colors.fatal : "#1fb2a6"
39
- )(message)}
40
-
41
- `
42
- );
43
- };
44
- }
45
-
46
- if (
47
- (typeof logLevel === "number" && LogLevel.ERROR >= logLevel) ||
48
- (typeof logLevel === "string" && LogLevel.ERROR >= getLogLevel(logLevel))
49
- ) {
50
- return (message: string) => {
51
- console.error(
52
- `
53
- ${chalk.bold.hex(config?.colors?.error ? config.colors.error : "#7d1a1a")(">")} ${chalk.bold
54
- .bgHex(config?.colors?.error ? config.colors.error : "#7d1a1a")
55
- .white(" ✘ Error ")} ${chalk.hex(
56
- config?.colors?.error ? config.colors.error : "#7d1a1a"
57
- )(message)}
58
- `
59
- );
60
- };
61
- }
62
-
63
- if (
64
- (typeof logLevel === "number" && LogLevel.WARN >= logLevel) ||
65
- (typeof logLevel === "string" && LogLevel.WARN >= getLogLevel(logLevel))
66
- ) {
67
- return (message: string) => {
68
- console.warn(
69
- `
70
- ${chalk.bold.hex(config?.colors?.warning ? config.colors.warning : "#fcc419")(">")} ${chalk.bold
71
- .bgHex(config?.colors?.warning ? config.colors.warning : "#fcc419")
72
- .white(" ⚠ Warn ")} ${chalk.hex(
73
- config?.colors?.warning ? config.colors.warning : "#fcc419"
74
- )(message)}
75
- `
76
- );
77
- };
78
- }
79
-
80
- if (
81
- (typeof logLevel === "number" && LogLevel.INFO >= logLevel) ||
82
- (typeof logLevel === "string" && LogLevel.INFO >= getLogLevel(logLevel))
83
- ) {
84
- return (message: string) => {
85
- console.info(
86
- `
87
- ${chalk.bold.hex(config?.colors?.info ? config.colors.info : "#0ea5e9")(">")} ${chalk.bold
88
- .bgHex(config?.colors?.info ? config.colors.info : "#0ea5e9")
89
- .white(" ℹ Info ")} ${chalk.hex(config?.colors?.info ? config.colors.info : "#0ea5e9")(
90
- message
91
- )}
92
- `
93
- );
94
- };
95
- }
96
-
97
- if (
98
- (typeof logLevel === "number" && LogLevel.INFO >= logLevel) ||
99
- (typeof logLevel === "string" && LogLevel.INFO >= getLogLevel(logLevel))
100
- ) {
101
- return (message: string) => {
102
- console.info(
103
- `
104
- ${chalk.bold.hex(config?.colors?.success ? config.colors.success : "#087f5b")(">")} ${chalk.bold
105
- .bgHex(config?.colors?.success ? config.colors.success : "#087f5b")
106
- .white(" āœ“ Success ")} ${chalk.hex(
107
- config?.colors?.success ? config.colors.success : "#087f5b"
108
- )(message)}
109
- `
110
- );
111
- };
112
- }
113
-
114
- if (
115
- (typeof logLevel === "number" && LogLevel.DEBUG >= logLevel) ||
116
- (typeof logLevel === "string" && LogLevel.DEBUG >= getLogLevel(logLevel))
117
- ) {
118
- return (message: string) => {
119
- console.debug(
120
- `
121
- ${chalk.bold.hex(config?.colors?.primary ? config.colors.primary : "#1fb2a6")(">")} ${chalk.bold
122
- .bgHex(config?.colors?.primary ? config.colors.primary : "#1fb2a6")
123
- .white(" šŸ›  Debug ")} ${chalk.hex(
124
- config?.colors?.primary ? config.colors.primary : "#1fb2a6"
125
- )(message)}
126
- `
127
- );
128
- };
129
- }
130
-
131
- return (message: string) => {
132
- console.log(
133
- `
134
- ${chalk.bold.hex(config?.colors?.primary ? config.colors.primary : "#1fb2a6")(">")} ${chalk.bold
135
- .bgHex(config?.colors?.primary ? config.colors.primary : "#1fb2a6")
136
- .white(" āœ‰ System ")} ${chalk.hex(
137
- config?.colors?.primary ? config.colors.primary : "#1fb2a6"
138
- )(message)}
139
- `
140
- );
141
- };
142
- };
143
-
144
- /**
145
- * Write a message to the console at the `fatal` log level
146
- *
147
- * @param config - The Storm configuration
148
- * @param message - The message to write
149
- */
150
- export const writeFatal = (config: Partial<StormConfig>, message: string) =>
151
- getLogFn(config, LogLevel.FATAL)(message);
152
-
153
- /**
154
- * Write a message to the console at the `error` log level
155
- *
156
- * @param config - The Storm configuration
157
- * @param message - The message to write
158
- */
159
- export const writeError = (config: Partial<StormConfig>, message: string) =>
160
- getLogFn(config, LogLevel.ERROR)(message);
161
-
162
- /**
163
- * Write a message to the console at the `warning` log level
164
- *
165
- * @param config - The Storm configuration
166
- * @param message - The message to write
167
- */
168
- export const writeWarning = (config: Partial<StormConfig>, message: string) =>
169
- getLogFn(config, LogLevel.WARN)(message);
170
-
171
- /**
172
- * Write a message to the console at the `info` log level
173
- *
174
- * @param config - The Storm configuration
175
- * @param message - The message to write
176
- */
177
- export const writeInfo = (config: Partial<StormConfig>, message: string) =>
178
- getLogFn(config, LogLevel.INFO)(message);
179
-
180
- /**
181
- * Write a message to the console at the `success` log level
182
- *
183
- * @param config - The Storm configuration
184
- * @param message - The message to write
185
- */
186
- export const writeSuccess = (config: Partial<StormConfig>, message: string) =>
187
- getLogFn(config, LogLevel.SUCCESS)(message);
188
-
189
- /**
190
- * Write a message to the console at the `debug` log level
191
- *
192
- * @param config - The Storm configuration
193
- * @param message - The message to write
194
- */
195
- export const writeDebug = (config: Partial<StormConfig>, message: string) =>
196
- getLogFn(config, LogLevel.DEBUG)(message);
197
-
198
- /**
199
- * Write a message to the console at the `trace` log level
200
- *
201
- * @param config - The Storm configuration
202
- * @param message - The message to write
203
- */
204
- export const writeTrace = (config: Partial<StormConfig>, message: string) =>
205
- getLogFn(config, LogLevel.TRACE)(message);
206
-
207
- /**
208
- * Write a message to the console at the `all` log level
209
- *
210
- * @param config - The Storm configuration
211
- * @param message - The message to write
212
- */
213
- export const writeSystem = (config: Partial<StormConfig>, message: string) =>
214
- getLogFn(config, LogLevel.ALL)(message);
215
-
216
- /**
217
- * Get a stopwatch function
218
- *
219
- * @param name - The name of the process
220
- * @returns The stopwatch function
221
- */
222
- export const getStopwatch = (name: string) => {
223
- const start = process.hrtime();
224
- return () => {
225
- const end = process.hrtime(start);
226
- console.info(
227
- chalk.dim(
228
- `\nā±ļø The${name ? ` ${name}` : ""} process took ${Math.round(
229
- end[0] * 1000 + end[1] / 1000000
230
- )}ms to complete\n\n`
231
- )
232
- );
233
- };
234
- };
@@ -1,44 +0,0 @@
1
- import type { StormConfig } from "../types";
2
- import { writeError, writeFatal, writeSuccess, writeTrace } from "./logger";
3
-
4
- export const exitWithError = (config: StormConfig) => {
5
- writeFatal(config, "Exiting script with an error status...");
6
- process.exit(1);
7
- };
8
-
9
- export const exitWithSuccess = (config: StormConfig) => {
10
- writeSuccess(config, "Script completed successfully. Exiting...");
11
- process.exit(0);
12
- };
13
-
14
- export const handleProcess = (config: StormConfig) => {
15
- writeTrace(
16
- config,
17
- `Using the following arguments to process the script: ${process.argv.join(", ")}`
18
- );
19
-
20
- process.on("unhandledRejection", (error) => {
21
- writeError(config, `An Unhandled Rejection occurred while running the program: ${error}`);
22
- exitWithError(config);
23
- });
24
- process.on("uncaughtException", (error) => {
25
- writeError(
26
- config,
27
- `An Uncaught Exception occurred while running the program: ${error.message} \nStacktrace: ${error.stack}`
28
- );
29
- exitWithError(config);
30
- });
31
-
32
- process.on("SIGTERM", (signal: NodeJS.Signals) => {
33
- writeError(config, `The program terminated with signal code: ${signal}`);
34
- exitWithError(config);
35
- });
36
- process.on("SIGINT", (signal: NodeJS.Signals) => {
37
- writeError(config, `The program terminated with signal code: ${signal}`);
38
- exitWithError(config);
39
- });
40
- process.on("SIGHUP", (signal: NodeJS.Signals) => {
41
- writeError(config, `The program terminated with signal code: ${signal}`);
42
- exitWithError(config);
43
- });
44
- };
@@ -1,30 +0,0 @@
1
- import { execaCommandSync } from "execa";
2
- import type { StormConfig } from "../types";
3
-
4
- export const LARGE_BUFFER = 1024 * 1000000;
5
-
6
- /**
7
- * Run a command line process
8
- *
9
- * @remarks
10
- * A wrapper around execa to run our command line processes
11
- *
12
- * @param config - The Storm configuration object
13
- * @param command - The command to run
14
- * @param cwd - The current working directory
15
- * @returns The result of the command
16
- */
17
- export const run = (config: StormConfig, command: string, cwd: string = config.workspaceRoot) => {
18
- return execaCommandSync(command, {
19
- preferLocal: true,
20
- shell: true,
21
- cwd,
22
- env: {
23
- ...process.env,
24
- FORCE_COLOR: "true"
25
- },
26
- stdio: "inherit",
27
- maxBuffer: LARGE_BUFFER,
28
- killSignal: "SIGTERM"
29
- });
30
- };
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "allowSyntheticDefaultImports": true,
6
- "esModuleInterop": true
7
- },
8
- "files": [],
9
- "include": ["src/**/*.ts", "src/**/*.js", "bin/**/*", "declarations.d.ts"],
10
- "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
11
- }
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "types": ["jest", "node"]
6
- },
7
- "include": [
8
- "jest.config.ts",
9
- "src/**/*.test.ts",
10
- "src/**/*.spec.ts",
11
- "src/**/*.d.ts"
12
- ]
13
- }