@decaf-ts/utils 1.0.10 → 1.2.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/README.md +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/lib/cjs/assets/slogans.cjs +3 -2
- package/lib/cjs/assets/slogans.cjs.map +1 -0
- package/lib/cjs/bin/build-scripts.cjs +5 -4
- package/lib/cjs/bin/build-scripts.cjs.map +1 -0
- package/lib/cjs/bin/release-chain-dispatch.cjs +5 -4
- package/lib/cjs/bin/release-chain-dispatch.cjs.map +1 -0
- package/lib/cjs/bin/release-chain.cjs +5 -4
- package/lib/cjs/bin/release-chain.cjs.map +1 -0
- package/lib/cjs/bin/tag-release.cjs +5 -4
- package/lib/cjs/bin/tag-release.cjs.map +1 -0
- package/lib/cjs/cli/command.cjs +11 -10
- package/lib/cjs/cli/command.cjs.map +1 -0
- package/lib/cjs/cli/commands/build-scripts.cjs +163 -44
- package/lib/cjs/cli/commands/build-scripts.cjs.map +1 -0
- package/lib/cjs/cli/commands/index.cjs +1 -0
- package/lib/cjs/cli/commands/index.cjs.map +1 -0
- package/lib/cjs/cli/commands/release-chain.cjs +12 -11
- package/lib/cjs/cli/commands/release-chain.cjs.map +1 -0
- package/lib/cjs/cli/commands/tag-release.cjs +21 -20
- package/lib/cjs/cli/commands/tag-release.cjs.map +1 -0
- package/lib/cjs/cli/constants.cjs +1 -0
- package/lib/cjs/cli/constants.cjs.map +1 -0
- package/lib/cjs/cli/index.cjs +1 -0
- package/lib/cjs/cli/index.cjs.map +1 -0
- package/lib/cjs/cli/types.cjs +1 -0
- package/lib/cjs/cli/types.cjs.map +1 -0
- package/lib/cjs/index.cjs +2 -1
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/input/index.cjs +1 -0
- package/lib/cjs/input/index.cjs.map +1 -0
- package/lib/cjs/input/input.cjs +1 -0
- package/lib/cjs/input/input.cjs.map +1 -0
- package/lib/cjs/input/types.cjs +1 -0
- package/lib/cjs/input/types.cjs.map +1 -0
- package/lib/cjs/output/common.cjs +4 -3
- package/lib/cjs/output/common.cjs.map +1 -0
- package/lib/cjs/output/index.cjs +1 -0
- package/lib/cjs/output/index.cjs.map +1 -0
- package/lib/cjs/release-chain/index.cjs +1 -0
- package/lib/cjs/release-chain/index.cjs.map +1 -0
- package/lib/cjs/tests/Consumer.cjs +3 -2
- package/lib/cjs/tests/Consumer.cjs.map +1 -0
- package/lib/cjs/tests/ProducerChildProcess.cjs.map +1 -0
- package/lib/cjs/tests/TestReporter.cjs +5 -4
- package/lib/cjs/tests/TestReporter.cjs.map +1 -0
- package/lib/cjs/tests/index.cjs +1 -0
- package/lib/cjs/tests/index.cjs.map +1 -0
- package/lib/cjs/tests/jestPerformanceRunner.cjs +5 -4
- package/lib/cjs/tests/jestPerformanceRunner.cjs.map +1 -0
- package/lib/cjs/tests/utils.cjs +5 -4
- package/lib/cjs/tests/utils.cjs.map +1 -0
- package/lib/cjs/utils/constants.cjs +3 -16
- package/lib/cjs/utils/constants.cjs.map +1 -0
- package/lib/cjs/utils/fs.cjs +16 -15
- package/lib/cjs/utils/fs.cjs.map +1 -0
- package/lib/cjs/utils/http.cjs +1 -0
- package/lib/cjs/utils/http.cjs.map +1 -0
- package/lib/cjs/utils/index.cjs +1 -0
- package/lib/cjs/utils/index.cjs.map +1 -0
- package/lib/cjs/utils/md.cjs +1 -0
- package/lib/cjs/utils/md.cjs.map +1 -0
- package/lib/cjs/utils/performanceRunner.cjs +1 -0
- package/lib/cjs/utils/performanceRunner.cjs.map +1 -0
- package/lib/cjs/utils/timeout.cjs +1 -0
- package/lib/cjs/utils/timeout.cjs.map +1 -0
- package/lib/cjs/utils/types.cjs +1 -0
- package/lib/cjs/utils/types.cjs.map +1 -0
- package/lib/cjs/utils/utils.cjs +5 -4
- package/lib/cjs/utils/utils.cjs.map +1 -0
- package/lib/cjs/writers/OutputWriter.cjs +1 -0
- package/lib/cjs/writers/OutputWriter.cjs.map +1 -0
- package/lib/cjs/writers/RegexpOutputWriter.cjs +3 -2
- package/lib/cjs/writers/RegexpOutputWriter.cjs.map +1 -0
- package/lib/cjs/writers/StandardOutputWriter.cjs +3 -2
- package/lib/cjs/writers/StandardOutputWriter.cjs.map +1 -0
- package/lib/cjs/writers/index.cjs +1 -0
- package/lib/cjs/writers/index.cjs.map +1 -0
- package/lib/cjs/writers/types.cjs +1 -0
- package/lib/cjs/writers/types.cjs.map +1 -0
- package/lib/esm/cli/commands/build-scripts.js +142 -24
- package/lib/esm/cli/commands/build-scripts.js.map +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/types/assets/slogans.d.cts +19 -0
- package/lib/types/assets/slogans.d.mts +19 -0
- package/lib/types/bin/build-scripts.d.cts +1 -0
- package/lib/types/bin/build-scripts.d.mts +1 -0
- package/lib/types/bin/release-chain-dispatch.d.cts +1 -0
- package/lib/types/bin/release-chain-dispatch.d.mts +1 -0
- package/lib/types/bin/release-chain.d.cts +1 -0
- package/lib/types/bin/release-chain.d.mts +1 -0
- package/lib/types/bin/tag-release.d.cts +1 -0
- package/lib/types/bin/tag-release.d.mts +1 -0
- package/lib/types/cli/command.d.cts +104 -0
- package/lib/types/cli/command.d.mts +104 -0
- package/lib/types/cli/commands/build-scripts.d.cts +148 -0
- package/lib/types/cli/commands/build-scripts.d.mts +148 -0
- package/lib/types/cli/commands/build-scripts.d.ts +5 -0
- package/lib/types/cli/commands/index.d.cts +3 -0
- package/lib/types/cli/commands/index.d.mts +3 -0
- package/lib/types/cli/commands/release-chain.d.cts +62 -0
- package/lib/types/cli/commands/release-chain.d.mts +62 -0
- package/lib/types/cli/commands/tag-release.d.cts +105 -0
- package/lib/types/cli/commands/tag-release.d.mts +105 -0
- package/lib/types/cli/constants.d.cts +75 -0
- package/lib/types/cli/constants.d.mts +75 -0
- package/lib/types/cli/index.d.cts +4 -0
- package/lib/types/cli/index.d.mts +4 -0
- package/lib/types/cli/types.d.cts +30 -0
- package/lib/types/cli/types.d.mts +30 -0
- package/lib/types/index.d.cts +38 -0
- package/lib/types/index.d.mts +38 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/input/index.d.cts +2 -0
- package/lib/types/input/index.d.mts +2 -0
- package/lib/types/input/input.d.cts +517 -0
- package/lib/types/input/input.d.mts +517 -0
- package/lib/types/input/types.d.cts +159 -0
- package/lib/types/input/types.d.mts +159 -0
- package/lib/types/output/common.d.cts +53 -0
- package/lib/types/output/common.d.mts +53 -0
- package/lib/types/output/index.d.cts +1 -0
- package/lib/types/output/index.d.mts +1 -0
- package/lib/types/release-chain/index.d.cts +43 -0
- package/lib/types/release-chain/index.d.mts +43 -0
- package/lib/types/tests/Consumer.d.cts +151 -0
- package/lib/types/tests/Consumer.d.mts +151 -0
- package/lib/types/tests/ProducerChildProcess.d.cts +18 -0
- package/lib/types/tests/ProducerChildProcess.d.mts +18 -0
- package/lib/types/tests/TestReporter.d.cts +245 -0
- package/lib/types/tests/TestReporter.d.mts +245 -0
- package/lib/types/tests/index.d.cts +4 -0
- package/lib/types/tests/index.d.mts +4 -0
- package/lib/types/tests/jestPerformanceRunner.d.cts +37 -0
- package/lib/types/tests/jestPerformanceRunner.d.mts +37 -0
- package/lib/types/tests/utils.d.cts +5 -0
- package/lib/types/tests/utils.d.mts +5 -0
- package/lib/types/utils/constants.d.cts +65 -0
- package/lib/types/utils/constants.d.mts +65 -0
- package/lib/types/utils/fs.d.cts +259 -0
- package/lib/types/utils/fs.d.mts +259 -0
- package/lib/types/utils/http.d.cts +41 -0
- package/lib/types/utils/http.d.mts +41 -0
- package/lib/types/utils/index.d.cts +6 -0
- package/lib/types/utils/index.d.mts +6 -0
- package/lib/types/utils/md.d.cts +156 -0
- package/lib/types/utils/md.d.mts +156 -0
- package/lib/types/utils/performanceRunner.d.cts +129 -0
- package/lib/types/utils/performanceRunner.d.mts +129 -0
- package/lib/types/utils/timeout.d.cts +12 -0
- package/lib/types/utils/timeout.d.mts +12 -0
- package/lib/types/utils/types.d.cts +112 -0
- package/lib/types/utils/types.d.mts +112 -0
- package/lib/types/utils/utils.d.cts +133 -0
- package/lib/types/utils/utils.d.mts +133 -0
- package/lib/types/writers/OutputWriter.d.cts +49 -0
- package/lib/types/writers/OutputWriter.d.mts +49 -0
- package/lib/types/writers/RegexpOutputWriter.d.cts +110 -0
- package/lib/types/writers/RegexpOutputWriter.d.mts +110 -0
- package/lib/types/writers/StandardOutputWriter.d.cts +130 -0
- package/lib/types/writers/StandardOutputWriter.d.mts +130 -0
- package/lib/types/writers/index.d.cts +4 -0
- package/lib/types/writers/index.d.mts +4 -0
- package/lib/types/writers/types.d.cts +29 -0
- package/lib/types/writers/types.d.mts +29 -0
- package/package.json +14 -8
- package/lib/cjs/assets/slogans.js.map +0 -1
- package/lib/cjs/bin/build-scripts.js.map +0 -1
- package/lib/cjs/bin/release-chain-dispatch.js.map +0 -1
- package/lib/cjs/bin/release-chain.js.map +0 -1
- package/lib/cjs/bin/tag-release.js.map +0 -1
- package/lib/cjs/cli/command.js.map +0 -1
- package/lib/cjs/cli/commands/build-scripts.js.map +0 -1
- package/lib/cjs/cli/commands/index.js.map +0 -1
- package/lib/cjs/cli/commands/release-chain.js.map +0 -1
- package/lib/cjs/cli/commands/tag-release.js.map +0 -1
- package/lib/cjs/cli/constants.js.map +0 -1
- package/lib/cjs/cli/index.js.map +0 -1
- package/lib/cjs/cli/types.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/input/index.js.map +0 -1
- package/lib/cjs/input/input.js.map +0 -1
- package/lib/cjs/input/types.js.map +0 -1
- package/lib/cjs/output/common.js.map +0 -1
- package/lib/cjs/output/index.js.map +0 -1
- package/lib/cjs/release-chain/index.js.map +0 -1
- package/lib/cjs/tests/Consumer.js.map +0 -1
- package/lib/cjs/tests/ProducerChildProcess.js.map +0 -1
- package/lib/cjs/tests/TestReporter.js.map +0 -1
- package/lib/cjs/tests/index.js.map +0 -1
- package/lib/cjs/tests/jestPerformanceRunner.js.map +0 -1
- package/lib/cjs/tests/utils.js.map +0 -1
- package/lib/cjs/utils/constants.js.map +0 -1
- package/lib/cjs/utils/fs.js.map +0 -1
- package/lib/cjs/utils/http.js.map +0 -1
- package/lib/cjs/utils/index.js.map +0 -1
- package/lib/cjs/utils/md.js.map +0 -1
- package/lib/cjs/utils/performanceRunner.js.map +0 -1
- package/lib/cjs/utils/timeout.js.map +0 -1
- package/lib/cjs/utils/types.js.map +0 -1
- package/lib/cjs/utils/utils.js.map +0 -1
- package/lib/cjs/writers/OutputWriter.js.map +0 -1
- package/lib/cjs/writers/RegexpOutputWriter.js.map +0 -1
- package/lib/cjs/writers/StandardOutputWriter.js.map +0 -1
- package/lib/cjs/writers/index.js.map +0 -1
- package/lib/cjs/writers/types.js.map +0 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ChildProcessWithoutNullStreams } from "child_process";
|
|
2
|
+
import { Environment } from "@decaf-ts/logging";
|
|
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 module: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 module: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
|
+
/**
|
|
63
|
+
* @description Factory type for creating Environment instances.
|
|
64
|
+
* @summary Defines a function type that creates and returns Environment instances.
|
|
65
|
+
*
|
|
66
|
+
* @template T - The type of object the Environment will accumulate.
|
|
67
|
+
* @template E - The specific Environment type to be created, extending Environment<T>.
|
|
68
|
+
* @typedef {function(...unknown[]): E} EnvironmentFactory
|
|
69
|
+
* @memberOf module:utils
|
|
70
|
+
*/
|
|
71
|
+
export type EnvironmentFactory<T extends object, E extends Environment<T>> = (...args: unknown[]) => E;
|
|
72
|
+
/**
|
|
73
|
+
* @description Map of project dependencies with detailed information.
|
|
74
|
+
* @summary Represents the structure of project dependencies categorized by type (production, development, peer).
|
|
75
|
+
* Each category contains an array of objects with name and version information.
|
|
76
|
+
*
|
|
77
|
+
* @typedef {Object} DependencyMap
|
|
78
|
+
* @property {Array<{name: string, version: string}>} prod - Production dependencies with name and version.
|
|
79
|
+
* @property {Array<{name: string, version: string}>} dev - Development dependencies with name and version.
|
|
80
|
+
* @property {Array<{name: string, version: string}>} peer - Peer dependencies with name and version.
|
|
81
|
+
* @memberOf module:utils
|
|
82
|
+
*/
|
|
83
|
+
export type DependencyMap = {
|
|
84
|
+
prod: {
|
|
85
|
+
name: string;
|
|
86
|
+
version: string;
|
|
87
|
+
}[];
|
|
88
|
+
dev: {
|
|
89
|
+
name: string;
|
|
90
|
+
version: string;
|
|
91
|
+
}[];
|
|
92
|
+
peer: {
|
|
93
|
+
name: string;
|
|
94
|
+
version: string;
|
|
95
|
+
}[];
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* @description Simplified map of project dependencies.
|
|
99
|
+
* @summary Represents a simplified structure of project dependencies categorized by type.
|
|
100
|
+
* Each category contains an optional array of dependency names without version information.
|
|
101
|
+
*
|
|
102
|
+
* @typedef {Object} SimpleDependencyMap
|
|
103
|
+
* @property {string[]} [prod] - Optional array of production dependency names.
|
|
104
|
+
* @property {string[]} [dev] - Optional array of development dependency names.
|
|
105
|
+
* @property {string[]} [peer] - Optional array of peer dependency names.
|
|
106
|
+
* @memberOf module:utils
|
|
107
|
+
*/
|
|
108
|
+
export type SimpleDependencyMap = {
|
|
109
|
+
prod?: string[];
|
|
110
|
+
dev?: string[];
|
|
111
|
+
peer?: string[];
|
|
112
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ChildProcessWithoutNullStreams } from "child_process";
|
|
2
|
+
import { Environment } from "@decaf-ts/logging";
|
|
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 module: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 module: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
|
+
/**
|
|
63
|
+
* @description Factory type for creating Environment instances.
|
|
64
|
+
* @summary Defines a function type that creates and returns Environment instances.
|
|
65
|
+
*
|
|
66
|
+
* @template T - The type of object the Environment will accumulate.
|
|
67
|
+
* @template E - The specific Environment type to be created, extending Environment<T>.
|
|
68
|
+
* @typedef {function(...unknown[]): E} EnvironmentFactory
|
|
69
|
+
* @memberOf module:utils
|
|
70
|
+
*/
|
|
71
|
+
export type EnvironmentFactory<T extends object, E extends Environment<T>> = (...args: unknown[]) => E;
|
|
72
|
+
/**
|
|
73
|
+
* @description Map of project dependencies with detailed information.
|
|
74
|
+
* @summary Represents the structure of project dependencies categorized by type (production, development, peer).
|
|
75
|
+
* Each category contains an array of objects with name and version information.
|
|
76
|
+
*
|
|
77
|
+
* @typedef {Object} DependencyMap
|
|
78
|
+
* @property {Array<{name: string, version: string}>} prod - Production dependencies with name and version.
|
|
79
|
+
* @property {Array<{name: string, version: string}>} dev - Development dependencies with name and version.
|
|
80
|
+
* @property {Array<{name: string, version: string}>} peer - Peer dependencies with name and version.
|
|
81
|
+
* @memberOf module:utils
|
|
82
|
+
*/
|
|
83
|
+
export type DependencyMap = {
|
|
84
|
+
prod: {
|
|
85
|
+
name: string;
|
|
86
|
+
version: string;
|
|
87
|
+
}[];
|
|
88
|
+
dev: {
|
|
89
|
+
name: string;
|
|
90
|
+
version: string;
|
|
91
|
+
}[];
|
|
92
|
+
peer: {
|
|
93
|
+
name: string;
|
|
94
|
+
version: string;
|
|
95
|
+
}[];
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* @description Simplified map of project dependencies.
|
|
99
|
+
* @summary Represents a simplified structure of project dependencies categorized by type.
|
|
100
|
+
* Each category contains an optional array of dependency names without version information.
|
|
101
|
+
*
|
|
102
|
+
* @typedef {Object} SimpleDependencyMap
|
|
103
|
+
* @property {string[]} [prod] - Optional array of production dependency names.
|
|
104
|
+
* @property {string[]} [dev] - Optional array of development dependency names.
|
|
105
|
+
* @property {string[]} [peer] - Optional array of peer dependency names.
|
|
106
|
+
* @memberOf module:utils
|
|
107
|
+
*/
|
|
108
|
+
export type SimpleDependencyMap = {
|
|
109
|
+
prod?: string[];
|
|
110
|
+
dev?: string[];
|
|
111
|
+
peer?: string[];
|
|
112
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { ChildProcessWithoutNullStreams, SpawnOptionsWithoutStdio } from "child_process";
|
|
2
|
+
import { StandardOutputWriter } from "../writers/StandardOutputWriter.cjs";
|
|
3
|
+
import { CommandResult } from "./types.cjs";
|
|
4
|
+
import { OutputWriterConstructor } from "../writers/types.cjs";
|
|
5
|
+
import { Logger } from "@decaf-ts/logging";
|
|
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 module:utils
|
|
41
|
+
*/
|
|
42
|
+
export declare function lockify<R>(f: (...params: unknown[]) => R): (...params: unknown[]) => Promise<R>;
|
|
43
|
+
/**
|
|
44
|
+
* @description Chains multiple abort signals to a controller.
|
|
45
|
+
* @summary Creates a mechanism where multiple abort signals can trigger a single abort controller.
|
|
46
|
+
* This is useful for coordinating cancellation across multiple asynchronous operations.
|
|
47
|
+
*
|
|
48
|
+
* @param {AbortController} controller - The abort controller to be triggered by signals.
|
|
49
|
+
* @param {...AbortSignal} signals - One or more abort signals that can trigger the controller.
|
|
50
|
+
* @return {AbortController} The input controller, now connected to the signals.
|
|
51
|
+
*
|
|
52
|
+
* @function chainAbortController
|
|
53
|
+
*
|
|
54
|
+
* @memberOf module:utils
|
|
55
|
+
*/
|
|
56
|
+
export declare function chainAbortController(controller: AbortController, ...signals: AbortSignal[]): AbortController;
|
|
57
|
+
/**
|
|
58
|
+
* @description Creates a new controller chained to multiple abort signals.
|
|
59
|
+
* @summary Creates a new abort controller that will be triggered if any of the provided signals are aborted.
|
|
60
|
+
*
|
|
61
|
+
* @param {...AbortSignal} signals - One or more abort signals that can trigger the new controller.
|
|
62
|
+
* @return {AbortController} A new abort controller connected to the signals.
|
|
63
|
+
*
|
|
64
|
+
* @function chainAbortController
|
|
65
|
+
*
|
|
66
|
+
* @memberOf module:utils
|
|
67
|
+
*/
|
|
68
|
+
export declare function chainAbortController(...signals: AbortSignal[]): AbortController;
|
|
69
|
+
/**
|
|
70
|
+
* @description Spawns a command as a child process with output handling.
|
|
71
|
+
* @summary Creates a child process to execute a command with support for piping multiple commands,
|
|
72
|
+
* custom output handling, and abort control. This function handles the low-level details of
|
|
73
|
+
* spawning processes and connecting their inputs/outputs when piping is used.
|
|
74
|
+
*
|
|
75
|
+
* @template R - The type of the processed output, defaulting to string.
|
|
76
|
+
* @param {StandardOutputWriter<R>} output - The output writer to handle command output.
|
|
77
|
+
* @param {string} command - The command to execute, can include pipe operators.
|
|
78
|
+
* @param {SpawnOptionsWithoutStdio} opts - Options for the spawned process.
|
|
79
|
+
* @param {AbortController} abort - Controller to abort the command execution.
|
|
80
|
+
* @param {Logger} logger - Logger for recording command execution details.
|
|
81
|
+
* @return {ChildProcessWithoutNullStreams} The spawned child process.
|
|
82
|
+
*
|
|
83
|
+
* @function spawnCommand
|
|
84
|
+
*
|
|
85
|
+
* @memberOf module:utils
|
|
86
|
+
*/
|
|
87
|
+
export declare function spawnCommand<R = string>(output: StandardOutputWriter<R>, command: string, opts: SpawnOptionsWithoutStdio, abort: AbortController, logger: Logger): ChildProcessWithoutNullStreams;
|
|
88
|
+
/**
|
|
89
|
+
* @description Executes a command asynchronously with customizable output handling.
|
|
90
|
+
* @summary This function runs a shell command as a child process, providing fine-grained
|
|
91
|
+
* control over its execution and output handling. It supports custom output writers,
|
|
92
|
+
* allows for command abortion, and captures both stdout and stderr.
|
|
93
|
+
*
|
|
94
|
+
* @template R - The type of the resolved value from the command execution.
|
|
95
|
+
*
|
|
96
|
+
* @param command - The command to run, either as a string or an array of strings.
|
|
97
|
+
* @param opts - Spawn options for the child process. Defaults to an empty object.
|
|
98
|
+
* @param outputConstructor - Constructor for the output writer. Defaults to StandardOutputWriter.
|
|
99
|
+
* @param args - Additional arguments to pass to the output constructor.
|
|
100
|
+
* @return {CommandResult} A promise that resolves to the command result of type R.
|
|
101
|
+
*
|
|
102
|
+
* @function runCommand
|
|
103
|
+
*
|
|
104
|
+
* @mermaid
|
|
105
|
+
* sequenceDiagram
|
|
106
|
+
* participant Caller
|
|
107
|
+
* participant runCommand
|
|
108
|
+
* participant OutputWriter
|
|
109
|
+
* participant ChildProcess
|
|
110
|
+
* Caller->>runCommand: Call with command and options
|
|
111
|
+
* runCommand->>OutputWriter: Create new instance
|
|
112
|
+
* runCommand->>OutputWriter: Parse command
|
|
113
|
+
* runCommand->>ChildProcess: Spawn process
|
|
114
|
+
* ChildProcess-->>runCommand: Return process object
|
|
115
|
+
* runCommand->>ChildProcess: Set up event listeners
|
|
116
|
+
* loop For each stdout data
|
|
117
|
+
* ChildProcess->>runCommand: Emit stdout data
|
|
118
|
+
* runCommand->>OutputWriter: Handle stdout data
|
|
119
|
+
* end
|
|
120
|
+
* loop For each stderr data
|
|
121
|
+
* ChildProcess->>runCommand: Emit stderr data
|
|
122
|
+
* runCommand->>OutputWriter: Handle stderr data
|
|
123
|
+
* end
|
|
124
|
+
* ChildProcess->>runCommand: Emit error (if any)
|
|
125
|
+
* runCommand->>OutputWriter: Handle error
|
|
126
|
+
* ChildProcess->>runCommand: Emit exit
|
|
127
|
+
* runCommand->>OutputWriter: Handle exit
|
|
128
|
+
* OutputWriter-->>runCommand: Resolve or reject promise
|
|
129
|
+
* runCommand-->>Caller: Return CommandResult
|
|
130
|
+
*
|
|
131
|
+
* @memberOf module:utils
|
|
132
|
+
*/
|
|
133
|
+
export declare function runCommand<R = string>(command: string, opts?: SpawnOptionsWithoutStdio, outputConstructor?: OutputWriterConstructor<R, StandardOutputWriter<R>, Error>, ...args: unknown[]): CommandResult<R>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { ChildProcessWithoutNullStreams, SpawnOptionsWithoutStdio } from "child_process";
|
|
2
|
+
import { StandardOutputWriter } from "../writers/StandardOutputWriter.js";
|
|
3
|
+
import { CommandResult } from "./types.js";
|
|
4
|
+
import { OutputWriterConstructor } from "../writers/types.js";
|
|
5
|
+
import { Logger } from "@decaf-ts/logging";
|
|
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 module:utils
|
|
41
|
+
*/
|
|
42
|
+
export declare function lockify<R>(f: (...params: unknown[]) => R): (...params: unknown[]) => Promise<R>;
|
|
43
|
+
/**
|
|
44
|
+
* @description Chains multiple abort signals to a controller.
|
|
45
|
+
* @summary Creates a mechanism where multiple abort signals can trigger a single abort controller.
|
|
46
|
+
* This is useful for coordinating cancellation across multiple asynchronous operations.
|
|
47
|
+
*
|
|
48
|
+
* @param {AbortController} controller - The abort controller to be triggered by signals.
|
|
49
|
+
* @param {...AbortSignal} signals - One or more abort signals that can trigger the controller.
|
|
50
|
+
* @return {AbortController} The input controller, now connected to the signals.
|
|
51
|
+
*
|
|
52
|
+
* @function chainAbortController
|
|
53
|
+
*
|
|
54
|
+
* @memberOf module:utils
|
|
55
|
+
*/
|
|
56
|
+
export declare function chainAbortController(controller: AbortController, ...signals: AbortSignal[]): AbortController;
|
|
57
|
+
/**
|
|
58
|
+
* @description Creates a new controller chained to multiple abort signals.
|
|
59
|
+
* @summary Creates a new abort controller that will be triggered if any of the provided signals are aborted.
|
|
60
|
+
*
|
|
61
|
+
* @param {...AbortSignal} signals - One or more abort signals that can trigger the new controller.
|
|
62
|
+
* @return {AbortController} A new abort controller connected to the signals.
|
|
63
|
+
*
|
|
64
|
+
* @function chainAbortController
|
|
65
|
+
*
|
|
66
|
+
* @memberOf module:utils
|
|
67
|
+
*/
|
|
68
|
+
export declare function chainAbortController(...signals: AbortSignal[]): AbortController;
|
|
69
|
+
/**
|
|
70
|
+
* @description Spawns a command as a child process with output handling.
|
|
71
|
+
* @summary Creates a child process to execute a command with support for piping multiple commands,
|
|
72
|
+
* custom output handling, and abort control. This function handles the low-level details of
|
|
73
|
+
* spawning processes and connecting their inputs/outputs when piping is used.
|
|
74
|
+
*
|
|
75
|
+
* @template R - The type of the processed output, defaulting to string.
|
|
76
|
+
* @param {StandardOutputWriter<R>} output - The output writer to handle command output.
|
|
77
|
+
* @param {string} command - The command to execute, can include pipe operators.
|
|
78
|
+
* @param {SpawnOptionsWithoutStdio} opts - Options for the spawned process.
|
|
79
|
+
* @param {AbortController} abort - Controller to abort the command execution.
|
|
80
|
+
* @param {Logger} logger - Logger for recording command execution details.
|
|
81
|
+
* @return {ChildProcessWithoutNullStreams} The spawned child process.
|
|
82
|
+
*
|
|
83
|
+
* @function spawnCommand
|
|
84
|
+
*
|
|
85
|
+
* @memberOf module:utils
|
|
86
|
+
*/
|
|
87
|
+
export declare function spawnCommand<R = string>(output: StandardOutputWriter<R>, command: string, opts: SpawnOptionsWithoutStdio, abort: AbortController, logger: Logger): ChildProcessWithoutNullStreams;
|
|
88
|
+
/**
|
|
89
|
+
* @description Executes a command asynchronously with customizable output handling.
|
|
90
|
+
* @summary This function runs a shell command as a child process, providing fine-grained
|
|
91
|
+
* control over its execution and output handling. It supports custom output writers,
|
|
92
|
+
* allows for command abortion, and captures both stdout and stderr.
|
|
93
|
+
*
|
|
94
|
+
* @template R - The type of the resolved value from the command execution.
|
|
95
|
+
*
|
|
96
|
+
* @param command - The command to run, either as a string or an array of strings.
|
|
97
|
+
* @param opts - Spawn options for the child process. Defaults to an empty object.
|
|
98
|
+
* @param outputConstructor - Constructor for the output writer. Defaults to StandardOutputWriter.
|
|
99
|
+
* @param args - Additional arguments to pass to the output constructor.
|
|
100
|
+
* @return {CommandResult} A promise that resolves to the command result of type R.
|
|
101
|
+
*
|
|
102
|
+
* @function runCommand
|
|
103
|
+
*
|
|
104
|
+
* @mermaid
|
|
105
|
+
* sequenceDiagram
|
|
106
|
+
* participant Caller
|
|
107
|
+
* participant runCommand
|
|
108
|
+
* participant OutputWriter
|
|
109
|
+
* participant ChildProcess
|
|
110
|
+
* Caller->>runCommand: Call with command and options
|
|
111
|
+
* runCommand->>OutputWriter: Create new instance
|
|
112
|
+
* runCommand->>OutputWriter: Parse command
|
|
113
|
+
* runCommand->>ChildProcess: Spawn process
|
|
114
|
+
* ChildProcess-->>runCommand: Return process object
|
|
115
|
+
* runCommand->>ChildProcess: Set up event listeners
|
|
116
|
+
* loop For each stdout data
|
|
117
|
+
* ChildProcess->>runCommand: Emit stdout data
|
|
118
|
+
* runCommand->>OutputWriter: Handle stdout data
|
|
119
|
+
* end
|
|
120
|
+
* loop For each stderr data
|
|
121
|
+
* ChildProcess->>runCommand: Emit stderr data
|
|
122
|
+
* runCommand->>OutputWriter: Handle stderr data
|
|
123
|
+
* end
|
|
124
|
+
* ChildProcess->>runCommand: Emit error (if any)
|
|
125
|
+
* runCommand->>OutputWriter: Handle error
|
|
126
|
+
* ChildProcess->>runCommand: Emit exit
|
|
127
|
+
* runCommand->>OutputWriter: Handle exit
|
|
128
|
+
* OutputWriter-->>runCommand: Resolve or reject promise
|
|
129
|
+
* runCommand-->>Caller: Return CommandResult
|
|
130
|
+
*
|
|
131
|
+
* @memberOf module:utils
|
|
132
|
+
*/
|
|
133
|
+
export declare function runCommand<R = string>(command: string, opts?: SpawnOptionsWithoutStdio, outputConstructor?: OutputWriterConstructor<R, StandardOutputWriter<R>, Error>, ...args: unknown[]): CommandResult<R>;
|
|
@@ -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 module: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 - Array of log messages to be processed before exiting.
|
|
46
|
+
* @return void
|
|
47
|
+
*/
|
|
48
|
+
exit(code: number, logs: string[]): void;
|
|
49
|
+
}
|
|
@@ -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 module: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 - Array of log messages to be processed before exiting.
|
|
46
|
+
* @return void
|
|
47
|
+
*/
|
|
48
|
+
exit(code: number, logs: string[]): void;
|
|
49
|
+
}
|