@decaf-ts/utils 0.1.6
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/LICENSE.md +157 -0
- package/README.md +95 -0
- package/dist/esm/utils.js +1 -0
- package/dist/types/bin/tag-release.d.ts +1 -0
- package/dist/types/bin/update-scripts.d.ts +1 -0
- package/dist/types/cli/command.d.ts +110 -0
- package/dist/types/cli/commands/index.d.ts +2 -0
- package/dist/types/cli/commands/tag-release.d.ts +105 -0
- package/dist/types/cli/commands/update-scripts.d.ts +211 -0
- package/dist/types/cli/constants.d.ts +73 -0
- package/dist/types/cli/index.d.ts +4 -0
- package/dist/types/cli/types.d.ts +28 -0
- package/dist/types/index.d.ts +39 -0
- package/dist/types/input/index.d.ts +2 -0
- package/dist/types/input/input.d.ts +472 -0
- package/dist/types/input/types.d.ts +76 -0
- package/dist/types/output/common.d.ts +51 -0
- package/dist/types/output/index.d.ts +3 -0
- package/dist/types/output/logging.d.ts +177 -0
- package/dist/types/output/types.d.ts +203 -0
- package/dist/types/utils/accumulator.d.ts +105 -0
- package/dist/types/utils/constants.d.ts +136 -0
- package/dist/types/utils/environment.d.ts +57 -0
- package/dist/types/utils/fs.d.ts +133 -0
- package/dist/types/utils/http.d.ts +41 -0
- package/dist/types/utils/index.d.ts +7 -0
- package/dist/types/utils/md.d.ts +156 -0
- package/dist/types/utils/tests.d.ts +170 -0
- package/dist/types/utils/text.d.ts +106 -0
- package/dist/types/utils/timeout.d.ts +1 -0
- package/dist/types/utils/types.d.ts +81 -0
- package/dist/types/utils/utils.d.ts +91 -0
- package/dist/types/utils/web.d.ts +7 -0
- package/dist/types/writers/OutputWriter.d.ts +49 -0
- package/dist/types/writers/RegexpOutputWriter.d.ts +69 -0
- package/dist/types/writers/StandardOutputWriter.d.ts +91 -0
- package/dist/types/writers/index.d.ts +4 -0
- package/dist/types/writers/types.d.ts +29 -0
- package/dist/utils.js +1 -0
- package/lib/assets/slogans.json +802 -0
- package/lib/bin/tag-release.cjs +12 -0
- package/lib/bin/update-scripts.cjs +12 -0
- package/lib/cli/command.cjs +153 -0
- package/lib/cli/commands/index.cjs +20 -0
- package/lib/cli/commands/tag-release.cjs +168 -0
- package/lib/cli/commands/update-scripts.cjs +511 -0
- package/lib/cli/constants.cjs +80 -0
- package/lib/cli/index.cjs +22 -0
- package/lib/cli/types.cjs +4 -0
- package/lib/esm/assets/slogans.json +802 -0
- package/lib/esm/bin/tag-release.js +10 -0
- package/lib/esm/bin/update-scripts.js +10 -0
- package/lib/esm/cli/command.js +149 -0
- package/lib/esm/cli/commands/index.js +4 -0
- package/lib/esm/cli/commands/tag-release.js +164 -0
- package/lib/esm/cli/commands/update-scripts.js +504 -0
- package/lib/esm/cli/constants.js +77 -0
- package/lib/esm/cli/index.js +6 -0
- package/lib/esm/cli/types.js +3 -0
- package/lib/esm/index.js +41 -0
- package/lib/esm/input/index.js +4 -0
- package/lib/esm/input/input.js +570 -0
- package/lib/esm/input/types.js +3 -0
- package/lib/esm/output/common.js +93 -0
- package/lib/esm/output/index.js +5 -0
- package/lib/esm/output/logging.js +350 -0
- package/lib/esm/output/types.js +3 -0
- package/lib/esm/utils/accumulator.js +145 -0
- package/lib/esm/utils/constants.js +176 -0
- package/lib/esm/utils/environment.js +91 -0
- package/lib/esm/utils/fs.js +271 -0
- package/lib/esm/utils/http.js +70 -0
- package/lib/esm/utils/index.js +9 -0
- package/lib/esm/utils/md.js +3 -0
- package/lib/esm/utils/tests.js +223 -0
- package/lib/esm/utils/text.js +142 -0
- package/lib/esm/utils/timeout.js +5 -0
- package/lib/esm/utils/types.js +3 -0
- package/lib/esm/utils/utils.js +220 -0
- package/lib/esm/utils/web.js +12 -0
- package/lib/esm/writers/OutputWriter.js +3 -0
- package/lib/esm/writers/RegexpOutputWriter.js +98 -0
- package/lib/esm/writers/StandardOutputWriter.js +127 -0
- package/lib/esm/writers/index.js +6 -0
- package/lib/esm/writers/types.js +3 -0
- package/lib/index.cjs +58 -0
- package/lib/input/index.cjs +20 -0
- package/lib/input/input.cjs +577 -0
- package/lib/input/types.cjs +4 -0
- package/lib/output/common.cjs +100 -0
- package/lib/output/index.cjs +21 -0
- package/lib/output/logging.cjs +355 -0
- package/lib/output/types.cjs +4 -0
- package/lib/utils/accumulator.cjs +149 -0
- package/lib/utils/constants.cjs +179 -0
- package/lib/utils/environment.cjs +95 -0
- package/lib/utils/fs.cjs +288 -0
- package/lib/utils/http.cjs +77 -0
- package/lib/utils/index.cjs +25 -0
- package/lib/utils/md.cjs +4 -0
- package/lib/utils/tests.cjs +263 -0
- package/lib/utils/text.cjs +153 -0
- package/lib/utils/timeout.cjs +8 -0
- package/lib/utils/types.cjs +4 -0
- package/lib/utils/utils.cjs +226 -0
- package/lib/utils/web.cjs +15 -0
- package/lib/writers/OutputWriter.cjs +4 -0
- package/lib/writers/RegexpOutputWriter.cjs +102 -0
- package/lib/writers/StandardOutputWriter.cjs +131 -0
- package/lib/writers/index.cjs +22 -0
- package/lib/writers/types.cjs +4 -0
- package/package.json +121 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { LogLevel } from "../utils/constants";
|
|
2
|
+
import { LoggingConfig, LoggingContext, StringLike, Theme, VerbosityLogger } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* @description A minimal logger implementation.
|
|
5
|
+
* @summary MiniLogger is a lightweight logging class that implements the VerbosityLogger interface.
|
|
6
|
+
* It provides basic logging functionality with support for different log levels and verbosity.
|
|
7
|
+
*
|
|
8
|
+
* @class
|
|
9
|
+
*/
|
|
10
|
+
export declare class MiniLogger implements VerbosityLogger {
|
|
11
|
+
protected context: string;
|
|
12
|
+
protected conf?: Partial<LoggingConfig> | undefined;
|
|
13
|
+
protected id?: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* @description Creates a new MiniLogger instance.
|
|
16
|
+
* @summary Initializes a MiniLogger with the given class name, optional configuration, and method name.
|
|
17
|
+
*
|
|
18
|
+
* @param context - The name of the class using this logger.
|
|
19
|
+
* @param [conf] - Optional logging configuration. Defaults to Info level and verbosity 0.
|
|
20
|
+
* @param [id] - Optional unique identifier for the logger instance.
|
|
21
|
+
*/
|
|
22
|
+
constructor(context: string, conf?: Partial<LoggingConfig> | undefined, id?: string | undefined);
|
|
23
|
+
protected config(key: keyof LoggingConfig): LoggingConfig[keyof LoggingConfig];
|
|
24
|
+
for(method?: string | ((...args: any[]) => any), config?: Partial<LoggingConfig>): VerbosityLogger;
|
|
25
|
+
/**
|
|
26
|
+
* @description Creates a formatted log string.
|
|
27
|
+
* @summary Generates a log string with timestamp, colored log level, and message.
|
|
28
|
+
*
|
|
29
|
+
* @param level - The log level as a string.
|
|
30
|
+
* @param message
|
|
31
|
+
* @param stack
|
|
32
|
+
* @return A formatted log string.
|
|
33
|
+
*/
|
|
34
|
+
protected createLog(level: LogLevel, message: StringLike | Error, stack?: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* @description Logs a message with the specified log level.
|
|
37
|
+
* @summary Checks if the message should be logged based on the current log level,
|
|
38
|
+
* then uses the appropriate console method to output the log.
|
|
39
|
+
*
|
|
40
|
+
* @param level - The log level of the message.
|
|
41
|
+
* @param msg - The message to be logged.
|
|
42
|
+
* @param stack
|
|
43
|
+
*/
|
|
44
|
+
protected log(level: LogLevel, msg: StringLike | Error, stack?: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* @description LLogs a `way too verbose` or a silly message.
|
|
47
|
+
* @summary Logs a message at the Silly level if the current verbosity allows it.
|
|
48
|
+
*
|
|
49
|
+
* @param msg - The message to be logged.
|
|
50
|
+
* @param verbosity - The verbosity level of the message (default: 0).
|
|
51
|
+
*/
|
|
52
|
+
silly(msg: StringLike, verbosity?: number): void;
|
|
53
|
+
/**
|
|
54
|
+
* @description Logs a verbose message.
|
|
55
|
+
* @summary Logs a message at the Verbose level if the current verbosity allows it.
|
|
56
|
+
*
|
|
57
|
+
* @param msg - The message to be logged.
|
|
58
|
+
* @param verbosity - The verbosity level of the message (default: 0).
|
|
59
|
+
*/
|
|
60
|
+
verbose(msg: StringLike, verbosity?: number): void;
|
|
61
|
+
/**
|
|
62
|
+
* @description Logs an info message.
|
|
63
|
+
* @summary Logs a message at the Info level.
|
|
64
|
+
*
|
|
65
|
+
* @param msg - The message to be logged.
|
|
66
|
+
*/
|
|
67
|
+
info(msg: StringLike): void;
|
|
68
|
+
/**
|
|
69
|
+
* @description Logs a debug message.
|
|
70
|
+
* @summary Logs a message at the Debug level.
|
|
71
|
+
*
|
|
72
|
+
* @param msg - The message to be logged.
|
|
73
|
+
*/
|
|
74
|
+
debug(msg: StringLike): void;
|
|
75
|
+
/**
|
|
76
|
+
* @description Logs an error message.
|
|
77
|
+
* @summary Logs a message at the Error level.
|
|
78
|
+
*
|
|
79
|
+
* @param msg - The message to be logged.
|
|
80
|
+
*/
|
|
81
|
+
error(msg: StringLike | Error): void;
|
|
82
|
+
setConfig(config: Partial<LoggingConfig>): void;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @description A static class for managing logging operations.
|
|
86
|
+
* @summary The Logging class provides a centralized logging mechanism with support for
|
|
87
|
+
* different log levels and verbosity. It uses a singleton pattern to maintain a global
|
|
88
|
+
* logger instance and allows creating specific loggers for different classes and methods.
|
|
89
|
+
*
|
|
90
|
+
* @class
|
|
91
|
+
*/
|
|
92
|
+
export declare class Logging {
|
|
93
|
+
/**
|
|
94
|
+
* @description The global logger instance.
|
|
95
|
+
* @summary A singleton instance of VerbosityLogger used for global logging.
|
|
96
|
+
*/
|
|
97
|
+
private static global?;
|
|
98
|
+
/**
|
|
99
|
+
* @description Factory function for creating logger instances.
|
|
100
|
+
* @summary A function that creates new VerbosityLogger instances. By default, it creates a MiniLogger.
|
|
101
|
+
*/
|
|
102
|
+
private static _factory;
|
|
103
|
+
/**
|
|
104
|
+
* @description Configuration for the logging system.
|
|
105
|
+
* @summary Stores the global verbosity level and log level settings.
|
|
106
|
+
*/
|
|
107
|
+
private static _config;
|
|
108
|
+
/**
|
|
109
|
+
* @description Private constructor to prevent instantiation.
|
|
110
|
+
* @summary Ensures that the Logging class cannot be instantiated as it's designed to be used statically.
|
|
111
|
+
*/
|
|
112
|
+
private constructor();
|
|
113
|
+
/**
|
|
114
|
+
* @description Setter for the logging configuration.
|
|
115
|
+
* @summary Allows updating the global logging configuration.
|
|
116
|
+
*
|
|
117
|
+
* @param config - An object containing verbosity and log level settings.
|
|
118
|
+
*/
|
|
119
|
+
static setConfig(config: Partial<LoggingConfig>): void;
|
|
120
|
+
static getConfig(): LoggingConfig;
|
|
121
|
+
/**
|
|
122
|
+
* @description Retrieves or creates the global logger instance.
|
|
123
|
+
* @summary Returns the existing global logger or creates a new one if it doesn't exist.
|
|
124
|
+
*
|
|
125
|
+
* @return The global VerbosityLogger instance.
|
|
126
|
+
*/
|
|
127
|
+
static get(): VerbosityLogger;
|
|
128
|
+
/**
|
|
129
|
+
* @description Logs a verbose message.
|
|
130
|
+
* @summary Delegates the verbose logging to the global logger instance.
|
|
131
|
+
*
|
|
132
|
+
* @param msg - The message to be logged.
|
|
133
|
+
* @param verbosity - The verbosity level of the message (default: 0).
|
|
134
|
+
*/
|
|
135
|
+
static verbose(msg: StringLike, verbosity?: number): void;
|
|
136
|
+
/**
|
|
137
|
+
* @description Logs an info message.
|
|
138
|
+
* @summary Delegates the info logging to the global logger instance.
|
|
139
|
+
*
|
|
140
|
+
* @param msg - The message to be logged.
|
|
141
|
+
*/
|
|
142
|
+
static info(msg: StringLike): void;
|
|
143
|
+
/**
|
|
144
|
+
* @description Logs a debug message.
|
|
145
|
+
* @summary Delegates the debug logging to the global logger instance.
|
|
146
|
+
*
|
|
147
|
+
* @param msg - The message to be logged.
|
|
148
|
+
*/
|
|
149
|
+
static debug(msg: StringLike): void;
|
|
150
|
+
/**
|
|
151
|
+
* @description Logs a silly message.
|
|
152
|
+
* @summary Delegates the debug logging to the global logger instance.
|
|
153
|
+
*
|
|
154
|
+
* @param msg - The message to be logged.
|
|
155
|
+
*/
|
|
156
|
+
static silly(msg: StringLike): void;
|
|
157
|
+
/**
|
|
158
|
+
* @description Logs an error message.
|
|
159
|
+
* @summary Delegates the error logging to the global logger instance.
|
|
160
|
+
*
|
|
161
|
+
* @param msg - The message to be logged.
|
|
162
|
+
*/
|
|
163
|
+
static error(msg: StringLike): void;
|
|
164
|
+
static for(object: LoggingContext, id?: string | Partial<LoggingConfig>, config?: Partial<LoggingConfig>): VerbosityLogger;
|
|
165
|
+
/**
|
|
166
|
+
* @description Creates a logger for a specific reason or context.
|
|
167
|
+
*
|
|
168
|
+
* @summary This static method creates a new logger instance using the factory function,
|
|
169
|
+
* based on a given reason or context.
|
|
170
|
+
*
|
|
171
|
+
* @param reason - A string describing the reason or context for creating this logger.
|
|
172
|
+
* @param id
|
|
173
|
+
* @returns A new VerbosityLogger or ClassLogger instance.
|
|
174
|
+
*/
|
|
175
|
+
static because(reason: string, id?: string): VerbosityLogger;
|
|
176
|
+
static theme(text: string, type: keyof Theme | keyof LogLevel, loggerLevel: LogLevel, template?: Theme): string;
|
|
177
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { LogLevel } from "../utils/constants";
|
|
2
|
+
import { styles } from "styled-string-builder";
|
|
3
|
+
export type StringLike = string | {
|
|
4
|
+
toString: () => string;
|
|
5
|
+
};
|
|
6
|
+
export type LoggingContext = string | {
|
|
7
|
+
new (...args: any[]): any;
|
|
8
|
+
} | ((...args: any[]) => any);
|
|
9
|
+
/**
|
|
10
|
+
* @description Interface for a logger with verbosity levels.
|
|
11
|
+
* @summary Defines methods for logging at different verbosity levels.
|
|
12
|
+
* @interface VerbosityLogger
|
|
13
|
+
* @memberOf @decaf-ts/utils
|
|
14
|
+
*/
|
|
15
|
+
export interface VerbosityLogger {
|
|
16
|
+
/**
|
|
17
|
+
* @description Logs a `way too verbose` or a silly message.
|
|
18
|
+
* @param {StringLike} msg - The message to log.
|
|
19
|
+
*/
|
|
20
|
+
silly(msg: StringLike): void;
|
|
21
|
+
/**
|
|
22
|
+
* @description Logs a verbose message.
|
|
23
|
+
* @param {StringLike} msg - The message to log.
|
|
24
|
+
* @param {number} verbosity - The verbosity level of the message.
|
|
25
|
+
*/
|
|
26
|
+
verbose(msg: StringLike, verbosity?: number): void;
|
|
27
|
+
/**
|
|
28
|
+
* @description Logs an info message.
|
|
29
|
+
* @param {StringLike} msg - The message to log.
|
|
30
|
+
*/
|
|
31
|
+
info(msg: StringLike): void;
|
|
32
|
+
/**
|
|
33
|
+
* @description Logs an error message.
|
|
34
|
+
* @param {StringLike | Error} msg - The message to log.
|
|
35
|
+
*/
|
|
36
|
+
error(msg: StringLike | Error): void;
|
|
37
|
+
/**
|
|
38
|
+
* @description Logs a debug message.
|
|
39
|
+
* @param {string} msg - The message to log.
|
|
40
|
+
*/
|
|
41
|
+
debug(msg: StringLike): void;
|
|
42
|
+
for(method?: string | ((...args: any[]) => any), config?: Partial<LoggingConfig>): VerbosityLogger;
|
|
43
|
+
setConfig(config: Partial<LoggingConfig>): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @description Configuration for logging.
|
|
47
|
+
* @summary Defines the log level and verbosity for logging.
|
|
48
|
+
* @typedef {Object} LoggingConfig
|
|
49
|
+
* @property {LogLevel} level - The logging level.
|
|
50
|
+
* @property {number} verbose - The verbosity level.
|
|
51
|
+
* @memberOf @decaf-ts/utils
|
|
52
|
+
*/
|
|
53
|
+
export type LoggingConfig = {
|
|
54
|
+
level: LogLevel;
|
|
55
|
+
logLevel?: boolean;
|
|
56
|
+
verbose: number;
|
|
57
|
+
separator: string;
|
|
58
|
+
style?: boolean;
|
|
59
|
+
timestamp?: boolean;
|
|
60
|
+
timestampFormat?: string;
|
|
61
|
+
context?: boolean;
|
|
62
|
+
theme?: Theme;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
/**
|
|
66
|
+
* @description Represents a theme option for console output styling.
|
|
67
|
+
* @summary Defines the structure for styling a specific element in the console output.
|
|
68
|
+
* It allows for customization of foreground color, background color, and additional styles.
|
|
69
|
+
* Colors can be specified as a single number, an RGB array, or left undefined for default.
|
|
70
|
+
*
|
|
71
|
+
* @interface ThemeOption
|
|
72
|
+
* @memberOf @decaf-ts/utils
|
|
73
|
+
*/
|
|
74
|
+
export interface ThemeOption {
|
|
75
|
+
fg?: number | [number] | [number, number, number];
|
|
76
|
+
bg?: number | [number] | [number, number, number];
|
|
77
|
+
style?: number[] | [keyof typeof styles];
|
|
78
|
+
}
|
|
79
|
+
export type ThemeOptionByLogLevel = Partial<Record<LogLevel, ThemeOption>>;
|
|
80
|
+
/**
|
|
81
|
+
/**
|
|
82
|
+
* @description Defines the color theme for console output.
|
|
83
|
+
* @summary This interface specifies the color scheme for various elements of console output,
|
|
84
|
+
* including styling for different log levels and components. It uses ThemeOption to
|
|
85
|
+
* define the styling for each element, allowing for customization of colors and styles
|
|
86
|
+
* for different parts of the log output.
|
|
87
|
+
*
|
|
88
|
+
* @interface Theme
|
|
89
|
+
* @memberOf @decaf-ts/utils
|
|
90
|
+
*/
|
|
91
|
+
export interface Theme {
|
|
92
|
+
/**
|
|
93
|
+
* @description Styling for class names in the output.
|
|
94
|
+
*/
|
|
95
|
+
class: ThemeOption | ThemeOptionByLogLevel;
|
|
96
|
+
/**
|
|
97
|
+
* @description Styling for timestamps in the output.
|
|
98
|
+
*/
|
|
99
|
+
timestamp: ThemeOption | ThemeOptionByLogLevel;
|
|
100
|
+
/**
|
|
101
|
+
* @description Styling for the main message text in the output.
|
|
102
|
+
*/
|
|
103
|
+
message: ThemeOption | ThemeOptionByLogLevel;
|
|
104
|
+
/**
|
|
105
|
+
* @description Styling for method names in the output.
|
|
106
|
+
*/
|
|
107
|
+
method: ThemeOption | ThemeOptionByLogLevel;
|
|
108
|
+
/**
|
|
109
|
+
* @description Styling for identifier elements in the output.
|
|
110
|
+
*/
|
|
111
|
+
id: ThemeOption | ThemeOptionByLogLevel;
|
|
112
|
+
/**
|
|
113
|
+
* @description Styling for identifier elements in the output.
|
|
114
|
+
*/
|
|
115
|
+
stack: ThemeOption;
|
|
116
|
+
/**
|
|
117
|
+
* @description Styling for different log levels in the output.
|
|
118
|
+
*/
|
|
119
|
+
logLevel: ThemeOptionByLogLevel;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @description Represents a color function in the Kleur library.
|
|
123
|
+
* @summary The Color interface defines a function that can be called with or without arguments
|
|
124
|
+
* to apply color styling to text or chain multiple color operations.
|
|
125
|
+
*
|
|
126
|
+
* @interface Color
|
|
127
|
+
* @memberOf module:@decaf-ts/utils
|
|
128
|
+
* */
|
|
129
|
+
export interface Color {
|
|
130
|
+
/**
|
|
131
|
+
* @description Applies the color to the given text.
|
|
132
|
+
* @param {string | number} x - The text or number to be colored.
|
|
133
|
+
* @return {string} The colored text.
|
|
134
|
+
*/
|
|
135
|
+
(x: string | number): string;
|
|
136
|
+
/**
|
|
137
|
+
* @description Allows chaining of multiple color operations.
|
|
138
|
+
* @return {Kleur} The Kleur instance for method chaining.
|
|
139
|
+
*/
|
|
140
|
+
(): Kleur;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* @description Represents the main Kleur interface with all available color and style methods.
|
|
144
|
+
* @summary The Kleur interface provides methods for applying various colors, background colors,
|
|
145
|
+
* and text styles to strings in terminal output.
|
|
146
|
+
*
|
|
147
|
+
* @interface Kleur
|
|
148
|
+
* @memberOf module:@decaf-ts/utils
|
|
149
|
+
*/
|
|
150
|
+
export interface Kleur {
|
|
151
|
+
/** @description Applies black color to the text. */
|
|
152
|
+
black: Color;
|
|
153
|
+
/** @description Applies red color to the text. */
|
|
154
|
+
red: Color;
|
|
155
|
+
/** @description Applies green color to the text. */
|
|
156
|
+
green: Color;
|
|
157
|
+
/** @description Applies yellow color to the text. */
|
|
158
|
+
yellow: Color;
|
|
159
|
+
/** @description Applies blue color to the text. */
|
|
160
|
+
blue: Color;
|
|
161
|
+
/** @description Applies magenta color to the text. */
|
|
162
|
+
magenta: Color;
|
|
163
|
+
/** @description Applies cyan color to the text. */
|
|
164
|
+
cyan: Color;
|
|
165
|
+
/** @description Applies white color to the text. */
|
|
166
|
+
white: Color;
|
|
167
|
+
/** @description Applies gray color to the text. */
|
|
168
|
+
gray: Color;
|
|
169
|
+
/** @description Alias for gray color. */
|
|
170
|
+
grey: Color;
|
|
171
|
+
/** @description Applies black background to the text. */
|
|
172
|
+
bgBlack: Color;
|
|
173
|
+
/** @description Applies red background to the text. */
|
|
174
|
+
bgRed: Color;
|
|
175
|
+
/** @description Applies green background to the text. */
|
|
176
|
+
bgGreen: Color;
|
|
177
|
+
/** @description Applies yellow background to the text. */
|
|
178
|
+
bgYellow: Color;
|
|
179
|
+
/** @description Applies blue background to the text. */
|
|
180
|
+
bgBlue: Color;
|
|
181
|
+
/** @description Applies magenta background to the text. */
|
|
182
|
+
bgMagenta: Color;
|
|
183
|
+
/** @description Applies cyan background to the text. */
|
|
184
|
+
bgCyan: Color;
|
|
185
|
+
/** @description Applies white background to the text. */
|
|
186
|
+
bgWhite: Color;
|
|
187
|
+
/** @description Resets all applied styles. */
|
|
188
|
+
reset: Color;
|
|
189
|
+
/** @description Applies bold style to the text. */
|
|
190
|
+
bold: Color;
|
|
191
|
+
/** @description Applies dim (decreased intensity) style to the text. */
|
|
192
|
+
dim: Color;
|
|
193
|
+
/** @description Applies italic style to the text. */
|
|
194
|
+
italic: Color;
|
|
195
|
+
/** @description Applies underline style to the text. */
|
|
196
|
+
underline: Color;
|
|
197
|
+
/** @description Inverts the foreground and background colors. */
|
|
198
|
+
inverse: Color;
|
|
199
|
+
/** @description Hides the text (same color as background). */
|
|
200
|
+
hidden: Color;
|
|
201
|
+
/** @description Applies strikethrough style to the text. */
|
|
202
|
+
strikethrough: Color;
|
|
203
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class ObjectAccumulator
|
|
3
|
+
* @template T - The type of the accumulated object, extends object
|
|
4
|
+
* @description A class that accumulates objects and provides type-safe access to their properties.
|
|
5
|
+
* It allows for dynamic addition of properties while maintaining type information.
|
|
6
|
+
* @summary Accumulates objects and maintains type information for accumulated properties
|
|
7
|
+
* @memberOf utils
|
|
8
|
+
*/
|
|
9
|
+
export declare class ObjectAccumulator<T extends object> {
|
|
10
|
+
/**
|
|
11
|
+
* @private
|
|
12
|
+
* @description The size of the accumulated object
|
|
13
|
+
* @type {number}
|
|
14
|
+
*/
|
|
15
|
+
private __size;
|
|
16
|
+
constructor();
|
|
17
|
+
/**
|
|
18
|
+
* @protected
|
|
19
|
+
* @description Expands the accumulator with properties from a new object
|
|
20
|
+
* @summary Adds new properties to the accumulator
|
|
21
|
+
* @template V - The type of the object being expanded
|
|
22
|
+
* @param {V} value - The object to expand with
|
|
23
|
+
* @returns {void}
|
|
24
|
+
*/
|
|
25
|
+
protected expand<V extends object>(value: V): void;
|
|
26
|
+
/**
|
|
27
|
+
* @description Accumulates a new object into the accumulator
|
|
28
|
+
* @summary Adds properties from a new object to the accumulator, maintaining type information
|
|
29
|
+
* @template V - The type of the object being accumulated
|
|
30
|
+
* @param {V} value - The object to accumulate
|
|
31
|
+
* @returns A new ObjectAccumulator instance with updated type information
|
|
32
|
+
* @mermaid
|
|
33
|
+
* sequenceDiagram
|
|
34
|
+
* participant A as Accumulator
|
|
35
|
+
* participant O as Object
|
|
36
|
+
* A->>O: Get entries
|
|
37
|
+
* loop For each entry
|
|
38
|
+
* A->>A: Define property
|
|
39
|
+
* end
|
|
40
|
+
* A->>A: Update size
|
|
41
|
+
* A->>A: Return updated accumulator
|
|
42
|
+
*/
|
|
43
|
+
accumulate<V extends object>(value: V): T & V & ObjectAccumulator<T & V>;
|
|
44
|
+
/**
|
|
45
|
+
* @description Retrieves a value from the accumulator by its key
|
|
46
|
+
* @summary Gets a value from the accumulated object using a type-safe key
|
|
47
|
+
* @template K - The key type, must be a key of this
|
|
48
|
+
* @param {K} key - The key of the value to retrieve
|
|
49
|
+
* @returns {any | undefined} The value associated with the key, or undefined if not found
|
|
50
|
+
*/
|
|
51
|
+
get<K extends keyof this>(key: K): this[K] | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* @description Checks if a key exists in the accumulator
|
|
54
|
+
* @summary Determines whether the accumulator contains a specific key
|
|
55
|
+
* @param {string} key - The key to check for existence
|
|
56
|
+
* @returns {boolean} True if the key exists, false otherwise
|
|
57
|
+
*/
|
|
58
|
+
has(key: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* @description Removes a key-value pair from the accumulator
|
|
61
|
+
* @summary Deletes a property from the accumulated object
|
|
62
|
+
* @param {string} key - The key of the property to remove
|
|
63
|
+
* @returns {} The accumulator instance with the specified property removed
|
|
64
|
+
*/
|
|
65
|
+
remove(key: keyof this | string): (Omit<this, typeof key> & ObjectAccumulator<Omit<this, typeof key>>) | this;
|
|
66
|
+
/**
|
|
67
|
+
* @description Retrieves all keys from the accumulator
|
|
68
|
+
* @summary Gets an array of all accumulated property keys
|
|
69
|
+
* @returns {string[]} An array of keys as strings
|
|
70
|
+
*/
|
|
71
|
+
keys(): string[];
|
|
72
|
+
/**
|
|
73
|
+
* @description Retrieves all values from the accumulator
|
|
74
|
+
* @summary Gets an array of all accumulated property values
|
|
75
|
+
* @returns An array of values
|
|
76
|
+
*/
|
|
77
|
+
values(): T[keyof T][];
|
|
78
|
+
/**
|
|
79
|
+
* @description Gets the number of key-value pairs in the accumulator
|
|
80
|
+
* @summary Returns the count of accumulated properties
|
|
81
|
+
* @returns {number} The number of key-value pairs
|
|
82
|
+
*/
|
|
83
|
+
size(): number;
|
|
84
|
+
/**
|
|
85
|
+
* @description Clears all accumulated key-value pairs
|
|
86
|
+
* @summary Removes all properties from the accumulator and returns a new empty instance
|
|
87
|
+
* @returns {ObjectAccumulator<never>} A new empty ObjectAccumulator instance
|
|
88
|
+
*/
|
|
89
|
+
clear(): ObjectAccumulator<never>;
|
|
90
|
+
/**
|
|
91
|
+
* @description Executes a callback for each key-value pair in the accumulator
|
|
92
|
+
* @summary Iterates over all accumulated properties, calling a function for each
|
|
93
|
+
* @param {function(any, string, number): void} callback - The function to execute for each entry
|
|
94
|
+
* @returns {void}
|
|
95
|
+
*/
|
|
96
|
+
forEach(callback: (value: this[keyof this], key: keyof this, i: number) => void): void;
|
|
97
|
+
/**
|
|
98
|
+
* @description Creates a new array with the results of calling a provided function on every element in the accumulator
|
|
99
|
+
* @summary Maps each accumulated property to a new value using a callback function
|
|
100
|
+
* @template R - The type of the mapped values
|
|
101
|
+
* @param {function(any, string,number): R} callback - Function that produces an element of the new array
|
|
102
|
+
* @returns {R[]} A new array with each element being the result of the callback function
|
|
103
|
+
*/
|
|
104
|
+
map<R>(callback: (value: this[keyof this], key: keyof this, i: number) => R): R[];
|
|
105
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { LoggingConfig, Theme } from "../output/types";
|
|
2
|
+
/**
|
|
3
|
+
* @description Default encoding for text operations.
|
|
4
|
+
* @summary The standard UTF-8 encoding used for text processing.
|
|
5
|
+
* @const {string} Encoding
|
|
6
|
+
* @memberOf @decaf-ts/utils
|
|
7
|
+
*/
|
|
8
|
+
export declare const Encoding = "utf-8";
|
|
9
|
+
/**
|
|
10
|
+
* @description Regular expression for semantic versioning.
|
|
11
|
+
* @summary A regex pattern to match and parse semantic version strings.
|
|
12
|
+
* @const {RegExp} SemVersionRegex
|
|
13
|
+
* @memberOf @decaf-ts/utils
|
|
14
|
+
*/
|
|
15
|
+
export declare const SemVersionRegex: RegExp;
|
|
16
|
+
/**
|
|
17
|
+
* @description Enum for semantic version components.
|
|
18
|
+
* @summary Defines the three levels of semantic versioning: PATCH, MINOR, and MAJOR.
|
|
19
|
+
* @enum {string}
|
|
20
|
+
* @memberOf @decaf-ts/utils
|
|
21
|
+
*/
|
|
22
|
+
export declare enum SemVersion {
|
|
23
|
+
/** Patch version for backwards-compatible bug fixes. */
|
|
24
|
+
PATCH = "patch",
|
|
25
|
+
/** Minor version for backwards-compatible new features. */
|
|
26
|
+
MINOR = "minor",
|
|
27
|
+
/** Major version for changes that break backwards compatibility. */
|
|
28
|
+
MAJOR = "major"
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @description Flag to indicate non-CI environment.
|
|
32
|
+
* @summary Used to specify that a command should run outside of a Continuous Integration environment.
|
|
33
|
+
* @const {string} NoCIFLag
|
|
34
|
+
* @memberOf @decaf-ts/utils
|
|
35
|
+
*/
|
|
36
|
+
export declare const NoCIFLag = "-no-ci";
|
|
37
|
+
/**
|
|
38
|
+
* @description Key for the setup script in package.json.
|
|
39
|
+
* @summary Identifies the script that runs after package installation.
|
|
40
|
+
* @const {string} SetupScriptKey
|
|
41
|
+
* @memberOf @decaf-ts/utils
|
|
42
|
+
*/
|
|
43
|
+
export declare const SetupScriptKey = "postinstall";
|
|
44
|
+
/**
|
|
45
|
+
* @description Enum for various authentication tokens.
|
|
46
|
+
* @summary Defines the file names for storing different types of authentication tokens.
|
|
47
|
+
* @enum {string}
|
|
48
|
+
* @memberOf @decaf-ts/utils
|
|
49
|
+
*/
|
|
50
|
+
export declare enum Tokens {
|
|
51
|
+
/** Git authentication token file name. */
|
|
52
|
+
GIT = ".token",
|
|
53
|
+
/** NPM authentication token file name. */
|
|
54
|
+
NPM = ".npmtoken",
|
|
55
|
+
/** Docker authentication token file name. */
|
|
56
|
+
DOCKER = ".dockertoken",
|
|
57
|
+
/** Confluence authentication token file name. */
|
|
58
|
+
CONFLUENCE = ".confluence-token"
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @description Enum for log levels.
|
|
62
|
+
* @summary Defines different levels of logging for the application.
|
|
63
|
+
* @enum {string}
|
|
64
|
+
* @memberOf @decaf-ts/utils
|
|
65
|
+
*/
|
|
66
|
+
export declare enum LogLevel {
|
|
67
|
+
/** Error events that are likely to cause problems. */
|
|
68
|
+
error = "error",
|
|
69
|
+
/** Routine information, such as ongoing status or performance. */
|
|
70
|
+
info = "info",
|
|
71
|
+
/** Additional relevant information. */
|
|
72
|
+
verbose = "verbose",
|
|
73
|
+
/** Debug or trace information. */
|
|
74
|
+
debug = "debug",
|
|
75
|
+
/** way too verbose or silly information. */
|
|
76
|
+
silly = "silly"
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @description Numeric values associated with log levels.
|
|
80
|
+
* @summary Provides a numeric representation of log levels for comparison and filtering.
|
|
81
|
+
* @const {Object} NumericLogLevels
|
|
82
|
+
* @property {number} error - Numeric value for error level (0).
|
|
83
|
+
* @property {number} info - Numeric value for info level (2).
|
|
84
|
+
* @property {number} verbose - Numeric value for verbose level (4).
|
|
85
|
+
* @property {number} debug - Numeric value for debug level (5).
|
|
86
|
+
* @property {number} silly - Numeric value for silly level (8).
|
|
87
|
+
* @memberOf @decaf-ts/utils
|
|
88
|
+
*/
|
|
89
|
+
export declare const NumericLogLevels: {
|
|
90
|
+
error: number;
|
|
91
|
+
info: number;
|
|
92
|
+
verbose: number;
|
|
93
|
+
debug: number;
|
|
94
|
+
silly: number;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* @description Default theme for styling log output.
|
|
98
|
+
* @summary Defines the default color and style settings for various components of log messages.
|
|
99
|
+
* @const DefaultTheme
|
|
100
|
+
* @typedef {Theme} DefaultTheme
|
|
101
|
+
* @property {Object} class - Styling for class names.
|
|
102
|
+
* @property {number} class.fg - Foreground color code for class names (4).
|
|
103
|
+
* @property {Object} id - Styling for identifiers.
|
|
104
|
+
* @property {number} id.fg - Foreground color code for identifiers (36).
|
|
105
|
+
* @property {Object} stack - Styling for stack traces (empty object).
|
|
106
|
+
* @property {Object} timestamp - Styling for timestamps (empty object).
|
|
107
|
+
* @property {Object} message - Styling for different types of messages.
|
|
108
|
+
* @property {Object} message.error - Styling for error messages.
|
|
109
|
+
* @property {number} message.error.fg - Foreground color code for error messages (34).
|
|
110
|
+
* @property {Object} method - Styling for method names (empty object).
|
|
111
|
+
* @property {Object} logLevel - Styling for different log levels.
|
|
112
|
+
* @property {Object} logLevel.error - Styling for error level logs.
|
|
113
|
+
* @property {number} logLevel.error.fg - Foreground color code for error level logs (6).
|
|
114
|
+
* @property {Object} logLevel.info - Styling for info level logs (empty object).
|
|
115
|
+
* @property {Object} logLevel.verbose - Styling for verbose level logs (empty object).
|
|
116
|
+
* @property {Object} logLevel.debug - Styling for debug level logs.
|
|
117
|
+
* @property {number} logLevel.debug.fg - Foreground color code for debug level logs (7).
|
|
118
|
+
* @memberOf @decaf-ts/utils
|
|
119
|
+
*/
|
|
120
|
+
export declare const DefaultTheme: Theme;
|
|
121
|
+
/**
|
|
122
|
+
* @description Default configuration for logging.
|
|
123
|
+
* @summary Defines the default settings for the logging system, including verbosity, log level, styling, and timestamp format.
|
|
124
|
+
* @const DefaultLoggingConfig
|
|
125
|
+
* @typedef {LoggingConfig} DefaultLoggingConfig
|
|
126
|
+
* @property {number} verbose - Verbosity level (0).
|
|
127
|
+
* @property {LogLevel} level - Default log level (LogLevel.info).
|
|
128
|
+
* @property {boolean} style - Whether to apply styling to log output (false).
|
|
129
|
+
* @property {boolean} timestamp - Whether to include timestamps in log messages (true).
|
|
130
|
+
* @property {string} timestampFormat - Format for timestamps ("HH:mm:ss.SSS").
|
|
131
|
+
* @property {boolean} context - Whether to include context information in log messages (true).
|
|
132
|
+
* @property {Theme} theme - The theme to use for styling log messages (DefaultTheme).
|
|
133
|
+
* @memberOf @decaf-ts/utils
|
|
134
|
+
*/
|
|
135
|
+
export declare const DefaultLoggingConfig: LoggingConfig;
|
|
136
|
+
export declare const AbortCode = "Aborted";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ObjectAccumulator } from "./accumulator";
|
|
2
|
+
import { EnvironmentFactory } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* @class Environment
|
|
5
|
+
* @extends {ObjectAccumulator<T>}
|
|
6
|
+
* @template T
|
|
7
|
+
* @description A class representing an environment with accumulation capabilities.
|
|
8
|
+
* @summary Manages environment-related data and provides methods for accumulation and key retrieval.
|
|
9
|
+
* @param {T} [initialData] - The initial data to populate the environment with.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Environment<T extends object> extends ObjectAccumulator<T> {
|
|
12
|
+
/**
|
|
13
|
+
* @static
|
|
14
|
+
* @protected
|
|
15
|
+
* @description A factory function for creating Environment instances.
|
|
16
|
+
* @summary Defines how new instances of the Environment class should be created.
|
|
17
|
+
* @return {Environment<any>} A new instance of the Environment class.
|
|
18
|
+
*/
|
|
19
|
+
protected static factory: EnvironmentFactory<any, any>;
|
|
20
|
+
/**
|
|
21
|
+
* @static
|
|
22
|
+
* @private
|
|
23
|
+
* @description The singleton instance of the Environment class.
|
|
24
|
+
* @type {Environment<any>}
|
|
25
|
+
*/
|
|
26
|
+
private static _instance;
|
|
27
|
+
protected constructor();
|
|
28
|
+
protected fromEnv(k: string): unknown;
|
|
29
|
+
protected expand<V extends object>(value: V): void;
|
|
30
|
+
/**
|
|
31
|
+
* @protected
|
|
32
|
+
* @static
|
|
33
|
+
* @description Retrieves or creates the singleton instance of the Environment class.
|
|
34
|
+
* @summary Ensures only one instance of the Environment class exists.
|
|
35
|
+
* @template E
|
|
36
|
+
* @param {...unknown[]} args - Arguments to pass to the factory function if a new instance is created.
|
|
37
|
+
* @return {E} The singleton instance of the Environment class.
|
|
38
|
+
*/
|
|
39
|
+
protected static instance<E extends Environment<any>>(...args: unknown[]): E;
|
|
40
|
+
/**
|
|
41
|
+
* @static
|
|
42
|
+
* @description Accumulates the given value into the environment.
|
|
43
|
+
* @summary Adds new properties to the environment from the provided object.
|
|
44
|
+
* @template V
|
|
45
|
+
* @param {V} value - The object to accumulate into the environment.
|
|
46
|
+
* @return {V} The updated environment instance.
|
|
47
|
+
*/
|
|
48
|
+
static accumulate<V extends object>(value: V): typeof Environment._instance & V & ObjectAccumulator<typeof Environment._instance & V>;
|
|
49
|
+
/**
|
|
50
|
+
* @static
|
|
51
|
+
* @description Retrieves the keys of the environment, optionally converting them to ENV format.
|
|
52
|
+
* @summary Gets all keys in the environment, with an option to format them for environment variables.
|
|
53
|
+
* @param {boolean} [toEnv=true] - Whether to convert the keys to ENV format.
|
|
54
|
+
* @return {string[]} An array of keys from the environment.
|
|
55
|
+
*/
|
|
56
|
+
static keys(toEnv?: boolean): string[];
|
|
57
|
+
}
|