@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,81 @@
|
|
|
1
|
+
import { ChildProcessWithoutNullStreams } from "child_process";
|
|
2
|
+
import { Environment } from "./environment";
|
|
3
|
+
/**
|
|
4
|
+
* @description Defines the structure for promise resolution and rejection.
|
|
5
|
+
* @summary Provides methods to resolve or reject a promise.
|
|
6
|
+
* @template R - The type of the resolved value.
|
|
7
|
+
* @template E - The type of the error value, defaulting to Error.
|
|
8
|
+
* @typedef {Object} PromiseExecutor
|
|
9
|
+
* @property {function(R): void} resolve - Function to resolve the promise.
|
|
10
|
+
* @property {function(E): void} reject - Function to reject the promise.
|
|
11
|
+
* @memberOf @decaf-ts/utils
|
|
12
|
+
*/
|
|
13
|
+
export interface PromiseExecutor<R, E = Error> {
|
|
14
|
+
resolve: (value: R | PromiseLike<R>) => void;
|
|
15
|
+
reject: (error: E) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @description Represents the result of a command execution.
|
|
19
|
+
* @summary Extends Promise with additional properties related to the command execution.
|
|
20
|
+
* This interface provides a comprehensive way to handle and interact with the results
|
|
21
|
+
* of an asynchronous command execution, including access to the command details,
|
|
22
|
+
* output logs, and the ability to abort the execution.
|
|
23
|
+
*
|
|
24
|
+
* @template R - The type of the resolved value, defaulting to void.
|
|
25
|
+
* @interface CommandResult
|
|
26
|
+
* @extends Promise<R>
|
|
27
|
+
* @memberOf @decaf-ts/utils
|
|
28
|
+
*/
|
|
29
|
+
export interface CommandResult<R = void> {
|
|
30
|
+
promise: Promise<R>;
|
|
31
|
+
/**
|
|
32
|
+
* @description Controller to abort the command execution.
|
|
33
|
+
* @summary Provides a mechanism to cancel the ongoing command execution.
|
|
34
|
+
*/
|
|
35
|
+
abort: AbortController;
|
|
36
|
+
/**
|
|
37
|
+
* @description The executed command string.
|
|
38
|
+
* @summary Contains the actual command that was executed.
|
|
39
|
+
*/
|
|
40
|
+
command: string;
|
|
41
|
+
/**
|
|
42
|
+
* @description The child process object.
|
|
43
|
+
* @summary Represents the Node.js child process that was spawned to execute the command.
|
|
44
|
+
*/
|
|
45
|
+
cmd?: ChildProcessWithoutNullStreams;
|
|
46
|
+
/**
|
|
47
|
+
* @description Array of stdout logs.
|
|
48
|
+
* @summary Contains all the standard output messages produced during the command execution.
|
|
49
|
+
*/
|
|
50
|
+
logs: string[];
|
|
51
|
+
/**
|
|
52
|
+
* @description Array of stderr logs.
|
|
53
|
+
* @summary Contains all the standard error messages produced during the command execution.
|
|
54
|
+
*/
|
|
55
|
+
errs: string[];
|
|
56
|
+
/**
|
|
57
|
+
* @description allows chaining commands.
|
|
58
|
+
* @summary allows chaining commands (or piping).
|
|
59
|
+
*/
|
|
60
|
+
pipe: <E>(cb: (r: R) => E) => Promise<E>;
|
|
61
|
+
}
|
|
62
|
+
export type EnvironmentFactory<T extends object, E extends Environment<T>> = (...args: unknown[]) => E;
|
|
63
|
+
export type DependencyMap = {
|
|
64
|
+
prod: {
|
|
65
|
+
name: string;
|
|
66
|
+
version: string;
|
|
67
|
+
}[];
|
|
68
|
+
dev: {
|
|
69
|
+
name: string;
|
|
70
|
+
version: string;
|
|
71
|
+
}[];
|
|
72
|
+
peer: {
|
|
73
|
+
name: string;
|
|
74
|
+
version: string;
|
|
75
|
+
}[];
|
|
76
|
+
};
|
|
77
|
+
export type SimpleDependencyMap = {
|
|
78
|
+
prod?: string[];
|
|
79
|
+
dev?: string[];
|
|
80
|
+
peer?: string[];
|
|
81
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ChildProcessWithoutNullStreams, SpawnOptionsWithoutStdio } from "child_process";
|
|
2
|
+
import { StandardOutputWriter } from "../writers/StandardOutputWriter";
|
|
3
|
+
import { CommandResult } from "./types";
|
|
4
|
+
import { OutputWriterConstructor } from "../writers/types";
|
|
5
|
+
import { VerbosityLogger } from "../output/types";
|
|
6
|
+
/**
|
|
7
|
+
* @description Creates a locked version of a function.
|
|
8
|
+
* @summary This higher-order function takes a function and returns a new function that ensures
|
|
9
|
+
* sequential execution of the original function, even when called multiple times concurrently.
|
|
10
|
+
* It uses a Promise-based locking mechanism to queue function calls.
|
|
11
|
+
*
|
|
12
|
+
* @template R - The return type of the input function.
|
|
13
|
+
*
|
|
14
|
+
* @param f - The function to be locked. It can take any number of parameters and return a value of type R.
|
|
15
|
+
* @return A new function with the same signature as the input function, but with sequential execution guaranteed.
|
|
16
|
+
*
|
|
17
|
+
* @function lockify
|
|
18
|
+
*
|
|
19
|
+
* @mermaid
|
|
20
|
+
* sequenceDiagram
|
|
21
|
+
* participant Caller
|
|
22
|
+
* participant LockedFunction
|
|
23
|
+
* participant OriginalFunction
|
|
24
|
+
* Caller->>LockedFunction: Call with params
|
|
25
|
+
* LockedFunction->>LockedFunction: Check current lock
|
|
26
|
+
* alt Lock is resolved
|
|
27
|
+
* LockedFunction->>OriginalFunction: Execute with params
|
|
28
|
+
* OriginalFunction-->>LockedFunction: Return result
|
|
29
|
+
* LockedFunction-->>Caller: Return result
|
|
30
|
+
* else Lock is pending
|
|
31
|
+
* LockedFunction->>LockedFunction: Queue execution
|
|
32
|
+
* LockedFunction-->>Caller: Return promise
|
|
33
|
+
* Note over LockedFunction: Wait for previous execution
|
|
34
|
+
* LockedFunction->>OriginalFunction: Execute with params
|
|
35
|
+
* OriginalFunction-->>LockedFunction: Return result
|
|
36
|
+
* LockedFunction-->>Caller: Resolve promise with result
|
|
37
|
+
* end
|
|
38
|
+
* LockedFunction->>LockedFunction: Update lock
|
|
39
|
+
*
|
|
40
|
+
* @memberOf @decaf-ts/utils
|
|
41
|
+
*/
|
|
42
|
+
export declare function lockify<R>(f: (...params: unknown[]) => R): (...params: unknown[]) => Promise<R>;
|
|
43
|
+
export declare function chainAbortController(controller: AbortController, ...signals: AbortSignal[]): AbortController;
|
|
44
|
+
export declare function chainAbortController(...signals: AbortSignal[]): AbortController;
|
|
45
|
+
export declare function spawnCommand<R = string>(output: StandardOutputWriter<R>, command: string, opts: SpawnOptionsWithoutStdio, abort: AbortController, logger: VerbosityLogger): ChildProcessWithoutNullStreams;
|
|
46
|
+
/**
|
|
47
|
+
* @description Executes a command asynchronously with customizable output handling.
|
|
48
|
+
* @summary This function runs a shell command as a child process, providing fine-grained
|
|
49
|
+
* control over its execution and output handling. It supports custom output writers,
|
|
50
|
+
* allows for command abortion, and captures both stdout and stderr.
|
|
51
|
+
*
|
|
52
|
+
* @template R - The type of the resolved value from the command execution.
|
|
53
|
+
*
|
|
54
|
+
* @param command - The command to run, either as a string or an array of strings.
|
|
55
|
+
* @param opts - Spawn options for the child process. Defaults to an empty object.
|
|
56
|
+
* @param outputConstructor - Constructor for the output writer. Defaults to StandardOutputWriter.
|
|
57
|
+
* @param args - Additional arguments to pass to the output constructor.
|
|
58
|
+
* @return {CommandResult} A promise that resolves to the command result of type R.
|
|
59
|
+
*
|
|
60
|
+
* @function runCommand
|
|
61
|
+
*
|
|
62
|
+
* @mermaid
|
|
63
|
+
* sequenceDiagram
|
|
64
|
+
* participant Caller
|
|
65
|
+
* participant runCommand
|
|
66
|
+
* participant OutputWriter
|
|
67
|
+
* participant ChildProcess
|
|
68
|
+
* Caller->>runCommand: Call with command and options
|
|
69
|
+
* runCommand->>OutputWriter: Create new instance
|
|
70
|
+
* runCommand->>OutputWriter: Parse command
|
|
71
|
+
* runCommand->>ChildProcess: Spawn process
|
|
72
|
+
* ChildProcess-->>runCommand: Return process object
|
|
73
|
+
* runCommand->>ChildProcess: Set up event listeners
|
|
74
|
+
* loop For each stdout data
|
|
75
|
+
* ChildProcess->>runCommand: Emit stdout data
|
|
76
|
+
* runCommand->>OutputWriter: Handle stdout data
|
|
77
|
+
* end
|
|
78
|
+
* loop For each stderr data
|
|
79
|
+
* ChildProcess->>runCommand: Emit stderr data
|
|
80
|
+
* runCommand->>OutputWriter: Handle stderr data
|
|
81
|
+
* end
|
|
82
|
+
* ChildProcess->>runCommand: Emit error (if any)
|
|
83
|
+
* runCommand->>OutputWriter: Handle error
|
|
84
|
+
* ChildProcess->>runCommand: Emit exit
|
|
85
|
+
* runCommand->>OutputWriter: Handle exit
|
|
86
|
+
* OutputWriter-->>runCommand: Resolve or reject promise
|
|
87
|
+
* runCommand-->>Caller: Return CommandResult
|
|
88
|
+
*
|
|
89
|
+
* @memberOf @decaf-ts/utils
|
|
90
|
+
*/
|
|
91
|
+
export declare function runCommand<R = string>(command: string, opts?: SpawnOptionsWithoutStdio, outputConstructor?: OutputWriterConstructor<R, StandardOutputWriter<R>, Error>, ...args: unknown[]): CommandResult<R>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @function isBrowser
|
|
3
|
+
* @description Determines if the current environment is a browser by checking the prototype chain of the global object.
|
|
4
|
+
* @summary Checks if the code is running in a browser environment.
|
|
5
|
+
* @returns {boolean} True if the environment is a browser, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isBrowser(): boolean;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Defines the structure for output writing operations.
|
|
3
|
+
* @summary The OutputWriter interface provides a standardized set of methods for handling
|
|
4
|
+
* various types of output in a command-line interface (CLI) application. It includes
|
|
5
|
+
* methods for writing data, handling errors, and managing the program's exit process.
|
|
6
|
+
* This interface allows for consistent output handling across different parts of the application.
|
|
7
|
+
*
|
|
8
|
+
* @interface OutputWriter
|
|
9
|
+
* @memberOf @decaf-ts/utils
|
|
10
|
+
*/
|
|
11
|
+
export interface OutputWriter {
|
|
12
|
+
/**
|
|
13
|
+
* @description Handles the output of data chunks.
|
|
14
|
+
* @summary Processes and writes a chunk of data to the output stream.
|
|
15
|
+
* This method is typically used for standard output operations.
|
|
16
|
+
*
|
|
17
|
+
* @param chunk - The data to be written. Can be of any type.
|
|
18
|
+
* @return void
|
|
19
|
+
*/
|
|
20
|
+
data(chunk: any): void;
|
|
21
|
+
/**
|
|
22
|
+
* @description Handles error output.
|
|
23
|
+
* @summary Processes and writes error information to the error output stream.
|
|
24
|
+
* This method is used for non-critical errors or warnings.
|
|
25
|
+
*
|
|
26
|
+
* @param chunk - The error data to be written. Can be of any type.
|
|
27
|
+
* @return void
|
|
28
|
+
*/
|
|
29
|
+
error(chunk: any): void;
|
|
30
|
+
/**
|
|
31
|
+
* @description Handles critical errors.
|
|
32
|
+
* @summary Processes and writes critical error information.
|
|
33
|
+
* This method is used for handling and reporting Error objects.
|
|
34
|
+
*
|
|
35
|
+
* @param err - The Error object to be processed and written.
|
|
36
|
+
* @return void
|
|
37
|
+
*/
|
|
38
|
+
errors(err: Error): void;
|
|
39
|
+
/**
|
|
40
|
+
* @description Manages the program exit process.
|
|
41
|
+
* @summary Handles the termination of the program with a specified exit code.
|
|
42
|
+
* This method is called when the program needs to exit, either successfully or due to an error.
|
|
43
|
+
*
|
|
44
|
+
* @param code - The exit code to be used when terminating the program.
|
|
45
|
+
* @param logs
|
|
46
|
+
* @return void
|
|
47
|
+
*/
|
|
48
|
+
exit(code: number, logs: string[]): void;
|
|
49
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { StandardOutputWriter } from "./StandardOutputWriter";
|
|
2
|
+
import { PromiseExecutor } from "../utils/types";
|
|
3
|
+
/**
|
|
4
|
+
* @description A specialized output writer that uses regular expressions to process output.
|
|
5
|
+
* @summary This class extends StandardOutputWriter to provide regex-based output processing.
|
|
6
|
+
* It allows for pattern matching in the output stream and can trigger specific actions
|
|
7
|
+
* based on matched patterns.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of the resolved value, defaulting to string.
|
|
10
|
+
*
|
|
11
|
+
* @param lock - A PromiseExecutor to control the asynchronous flow.
|
|
12
|
+
* @param regexp - A string or RegExp to match against the output.
|
|
13
|
+
* @param flags - Optional flags for the RegExp constructor.
|
|
14
|
+
*
|
|
15
|
+
* @class
|
|
16
|
+
*/
|
|
17
|
+
export declare class RegexpOutputWriter extends StandardOutputWriter<string> {
|
|
18
|
+
/**
|
|
19
|
+
* @description The regular expression used for matching output.
|
|
20
|
+
* @summary This readonly property stores the compiled RegExp used for pattern matching.
|
|
21
|
+
*/
|
|
22
|
+
protected readonly regexp: RegExp;
|
|
23
|
+
/**
|
|
24
|
+
* @description Initializes a new instance of RegexpOutputWriter.
|
|
25
|
+
* @summary Constructs the RegexpOutputWriter with a lock mechanism and a regular expression.
|
|
26
|
+
*
|
|
27
|
+
* @param cmd
|
|
28
|
+
* @param lock - A PromiseExecutor to control the asynchronous flow.
|
|
29
|
+
* @param regexp - A string or RegExp to match against the output.
|
|
30
|
+
* @param flags - Optional flags for the RegExp constructor, defaults to "g".
|
|
31
|
+
*/
|
|
32
|
+
constructor(cmd: string, lock: PromiseExecutor<string, Error>, regexp: string | RegExp, flags?: string);
|
|
33
|
+
/**
|
|
34
|
+
* @description Tests the input data against the stored regular expression.
|
|
35
|
+
* @summary Executes the regular expression on the input data and returns the match result.
|
|
36
|
+
*
|
|
37
|
+
* @param data - The string to test against the regular expression.
|
|
38
|
+
* @return The result of the regular expression execution, or undefined if an error occurs.
|
|
39
|
+
*/
|
|
40
|
+
private test;
|
|
41
|
+
/**
|
|
42
|
+
* @description Tests the data and resolves the promise if a match is found.
|
|
43
|
+
* @summary Executes the test method and resolves the promise with the first match group if successful.
|
|
44
|
+
*
|
|
45
|
+
* @param data - The string to test against the regular expression.
|
|
46
|
+
*/
|
|
47
|
+
protected testAndResolve(data: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* @description Tests the data and rejects the promise if a match is found.
|
|
50
|
+
* @summary Executes the test method and rejects the promise with the first match group if successful.
|
|
51
|
+
*
|
|
52
|
+
* @param data - The string to test against the regular expression.
|
|
53
|
+
*/
|
|
54
|
+
protected testAndReject(data: string): void;
|
|
55
|
+
/**
|
|
56
|
+
* @description Processes incoming data chunks.
|
|
57
|
+
* @summary Calls the parent class data method and then tests the data for a match to potentially resolve the promise.
|
|
58
|
+
*
|
|
59
|
+
* @param chunk - The data chunk to process.
|
|
60
|
+
*/
|
|
61
|
+
data(chunk: any): void;
|
|
62
|
+
/**
|
|
63
|
+
* @description Processes incoming error chunks.
|
|
64
|
+
* @summary Calls the parent class error method and then tests the data for a match to potentially reject the promise.
|
|
65
|
+
*
|
|
66
|
+
* @param chunk - The error chunk to process.
|
|
67
|
+
*/
|
|
68
|
+
error(chunk: any): void;
|
|
69
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { OutputWriter } from "./OutputWriter";
|
|
2
|
+
import { PromiseExecutor } from "../utils/types";
|
|
3
|
+
import { OutputType } from "./types";
|
|
4
|
+
import { VerbosityLogger } from "../output/types";
|
|
5
|
+
/**
|
|
6
|
+
* @description A standard output writer for handling command execution output.
|
|
7
|
+
* @summary This class implements the OutputWriter interface and provides methods for
|
|
8
|
+
* handling various types of output from command execution, including standard output,
|
|
9
|
+
* error output, and exit codes. It also includes utility methods for parsing commands
|
|
10
|
+
* and resolving or rejecting promises based on execution results.
|
|
11
|
+
*
|
|
12
|
+
* @template R - The type of the resolved value, defaulting to number.
|
|
13
|
+
*
|
|
14
|
+
* @param lock - A PromiseExecutor to control the asynchronous flow.
|
|
15
|
+
* @param args - Additional arguments (unused in the current implementation).
|
|
16
|
+
*
|
|
17
|
+
* @class
|
|
18
|
+
*/
|
|
19
|
+
export declare class StandardOutputWriter<R = string> implements OutputWriter {
|
|
20
|
+
protected cmd: string;
|
|
21
|
+
protected lock: PromiseExecutor<R>;
|
|
22
|
+
protected logger: VerbosityLogger;
|
|
23
|
+
/**
|
|
24
|
+
* @description Initializes a new instance of StandardOutputWriter.
|
|
25
|
+
* @summary Constructs the StandardOutputWriter with a lock mechanism and optional arguments.
|
|
26
|
+
*
|
|
27
|
+
* @param cmd
|
|
28
|
+
* @param lock - A PromiseExecutor to control the asynchronous flow.
|
|
29
|
+
* @param args - Additional arguments (currently unused).
|
|
30
|
+
*/
|
|
31
|
+
constructor(cmd: string, lock: PromiseExecutor<R>, ...args: unknown[]);
|
|
32
|
+
/**
|
|
33
|
+
* @description Logs output to the console.
|
|
34
|
+
* @summary Formats and logs the given data with a timestamp and type indicator.
|
|
35
|
+
*
|
|
36
|
+
* @param type - The type of output (stdout or stderr).
|
|
37
|
+
* @param data - The data to be logged.
|
|
38
|
+
*/
|
|
39
|
+
protected log(type: OutputType, data: string | Buffer): void;
|
|
40
|
+
/**
|
|
41
|
+
* @description Handles standard output data.
|
|
42
|
+
* @summary Logs the given chunk as standard output.
|
|
43
|
+
*
|
|
44
|
+
* @param chunk - The data chunk to be logged.
|
|
45
|
+
*/
|
|
46
|
+
data(chunk: any): void;
|
|
47
|
+
/**
|
|
48
|
+
* @description Handles error output data.
|
|
49
|
+
* @summary Logs the given chunk as error output.
|
|
50
|
+
*
|
|
51
|
+
* @param chunk - The error data chunk to be logged.
|
|
52
|
+
*/
|
|
53
|
+
error(chunk: any): void;
|
|
54
|
+
/**
|
|
55
|
+
* @description Handles error objects.
|
|
56
|
+
* @summary Logs the error message from the given Error object.
|
|
57
|
+
*
|
|
58
|
+
* @param err - The Error object to be logged.
|
|
59
|
+
*/
|
|
60
|
+
errors(err: Error): void;
|
|
61
|
+
/**
|
|
62
|
+
* @description Handles the exit of a command.
|
|
63
|
+
* @summary Logs the exit code and resolves or rejects the promise based on the code.
|
|
64
|
+
*
|
|
65
|
+
* @param code - The exit code of the command.
|
|
66
|
+
* @param logs
|
|
67
|
+
*/
|
|
68
|
+
exit(code: number | string, logs: string[]): void;
|
|
69
|
+
/**
|
|
70
|
+
* @description Parses a command string or array into components.
|
|
71
|
+
* @summary Converts the command into a consistent format and stores it, then returns it split into command and arguments.
|
|
72
|
+
*
|
|
73
|
+
* @param command - The command as a string or array of strings.
|
|
74
|
+
* @return A tuple containing the command and its arguments as separate elements.
|
|
75
|
+
*/
|
|
76
|
+
parseCommand(command: string | string[]): [string, string[]];
|
|
77
|
+
/**
|
|
78
|
+
* @description Resolves the promise with a success message.
|
|
79
|
+
* @summary Logs a success message and resolves the promise with the given reason.
|
|
80
|
+
*
|
|
81
|
+
* @param reason - The reason for resolving the promise.
|
|
82
|
+
*/
|
|
83
|
+
protected resolve(reason: R): void;
|
|
84
|
+
/**
|
|
85
|
+
* @description Rejects the promise with an error message.
|
|
86
|
+
* @summary Logs an error message and rejects the promise with the given reason.
|
|
87
|
+
*
|
|
88
|
+
* @param reason - The reason for rejecting the promise, either a number (exit code) or a string.
|
|
89
|
+
*/
|
|
90
|
+
protected reject(reason: number | string | Error): void;
|
|
91
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { StandardOutputWriter } from "./StandardOutputWriter";
|
|
2
|
+
import { PromiseExecutor } from "../utils/types";
|
|
3
|
+
/**
|
|
4
|
+
* @description Represents the type of output stream.
|
|
5
|
+
* @summary A union type for standard output and standard error streams.
|
|
6
|
+
* @typedef {("stdout" | "stderr")} OutputType
|
|
7
|
+
* @memberOf @decaf-ts/utils
|
|
8
|
+
*/
|
|
9
|
+
export type OutputType = "stdout" | "stderr";
|
|
10
|
+
/**
|
|
11
|
+
* @description Constructor type for output writers.
|
|
12
|
+
* @summary Defines the structure for creating new output writer instances. This type represents
|
|
13
|
+
* a constructor function that takes a PromiseExecutor and additional arguments to create
|
|
14
|
+
* a new instance of an output writer. It allows for flexible creation of different types
|
|
15
|
+
* of output writers while maintaining a consistent interface.
|
|
16
|
+
*
|
|
17
|
+
* @template R - The type of the resolved value, defaulting to string.
|
|
18
|
+
* @template C - The type of the output writer, extending StandardOutputWriter<R>.
|
|
19
|
+
* @template E - The type of the error value, defaulting to number.
|
|
20
|
+
*
|
|
21
|
+
* @param {PromiseExecutor<R, E>} lock - The promise executor for managing asynchronous operations.
|
|
22
|
+
* @param {...unknown[]} args - Additional arguments passed to the constructor.
|
|
23
|
+
* @return {C} An instance of the output writer.
|
|
24
|
+
*
|
|
25
|
+
* @memberOf @decaf-ts/utils
|
|
26
|
+
*/
|
|
27
|
+
export type OutputWriterConstructor<R = string, C extends StandardOutputWriter<R> = StandardOutputWriter<R>, E = number> = {
|
|
28
|
+
new (cmd: string, lock: PromiseExecutor<R, E>, ...args: unknown[]): C;
|
|
29
|
+
};
|