@j-o-r/sh 0.0.3 → 0.0.4
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/lib/sh.d.ts +164 -16
- package/lib/sh.js +873 -24
- package/package.json +4 -3
- package/lib/ProcessOutput.d.ts +0 -44
- package/lib/ProcessOutput.js +0 -113
- package/lib/ProcessPromise.d.ts +0 -147
- package/lib/ProcessPromise.js +0 -354
- package/lib/utils.d.ts +0 -20
- package/lib/utils.js +0 -422
- package/release/j-o-r-sh-0.0.3.tgz +0 -0
package/lib/sh.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
export type resolver = Function;
|
|
4
|
+
export type rejecter = Function;
|
|
5
|
+
export type PromiseConstruct = Function;
|
|
6
|
+
export type StdioOption = ('pipe' | 'ignore' | 'inherit' | number);
|
|
7
|
+
export type StdioOptions = Array<StdioOption> | StdioOption;
|
|
1
8
|
/**
|
|
2
9
|
* Creates a new ProcessPromise object that represents a command to be executed.
|
|
3
10
|
*/
|
|
@@ -18,25 +25,15 @@ export type Shell = Function;
|
|
|
18
25
|
* const command = await SH`echo 'Hello, world!'`;
|
|
19
26
|
*/
|
|
20
27
|
/** @type {Shell & { (pieces: TemplateStringsArray, ...args: any[]): ProcessPromise }} */
|
|
21
|
-
export const SH:
|
|
28
|
+
export const SH: Shell & {
|
|
29
|
+
(pieces: TemplateStringsArray, ...args: any[]): ProcessPromise;
|
|
30
|
+
};
|
|
22
31
|
/**
|
|
23
32
|
* Change working directory
|
|
24
33
|
* @param {string} dir
|
|
25
34
|
*/
|
|
26
35
|
export function cd(dir: string): void;
|
|
27
|
-
|
|
28
|
-
* This function pauses or "sleeps" code execution for a specified duration.
|
|
29
|
-
* @param {string|number} duration - The duration to pause execution for, e.g., '100ms' or '3s'.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
*
|
|
33
|
-
* const res = await Promise.all([
|
|
34
|
-
* SH`sleep 2; echo 2`, // Sleep for 2 seconds
|
|
35
|
-
* sleep(2), // Sleep for 2 seconds
|
|
36
|
-
* SH`sleep 3; echo 3` // Sleep for 3 seconds
|
|
37
|
-
* ]);
|
|
38
|
-
*/
|
|
39
|
-
export function sleep(duration: string | number): Promise<any>;
|
|
36
|
+
export function expBackoff(max?: string, rand?: string): Generator<number, void, unknown>;
|
|
40
37
|
/**
|
|
41
38
|
* This function retries a command a specified number of times.
|
|
42
39
|
* @example
|
|
@@ -51,6 +48,19 @@ export function sleep(duration: string | number): Promise<any>;
|
|
|
51
48
|
*/
|
|
52
49
|
export function retry(count: any, a: any, b: any): Promise<any>;
|
|
53
50
|
/**
|
|
51
|
+
* This function pauses or "sleeps" code execution for a specified duration.
|
|
52
|
+
* @param {string|number} duration - The duration to pause execution for, e.g., '100ms' or '3s'.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
*
|
|
56
|
+
* const res = await Promise.all([
|
|
57
|
+
* SH`sleep 2; echo 2`, // Sleep for 2 seconds
|
|
58
|
+
* sleep(2), // Sleep for 2 seconds
|
|
59
|
+
* SH`sleep 3; echo 3` // Sleep for 3 seconds
|
|
60
|
+
* ]);
|
|
61
|
+
*/
|
|
62
|
+
export function sleep(duration: string | number): Promise<any>;
|
|
63
|
+
/**
|
|
54
64
|
* This function reads the standard input (stdin) for the current process.
|
|
55
65
|
* It is used to get piped content into a script.
|
|
56
66
|
* @example
|
|
@@ -70,5 +80,143 @@ export function stdin(): Promise<string>;
|
|
|
70
80
|
* ]);
|
|
71
81
|
*/
|
|
72
82
|
export function within(callback: Function): any;
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
/**
|
|
84
|
+
* @typedef {Function} resolver
|
|
85
|
+
* @param {ProcessOutput} value
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* @typedef {Function} rejecter
|
|
89
|
+
* @param {ProcessOutput} value
|
|
90
|
+
*/
|
|
91
|
+
/**
|
|
92
|
+
* @typedef {Function} PromiseConstruct
|
|
93
|
+
* @param {resolver} resolve
|
|
94
|
+
* @param {rejecter} reject
|
|
95
|
+
*/
|
|
96
|
+
/**
|
|
97
|
+
* @typedef {('pipe' | 'ignore' | 'inherit' | number)} StdioOption
|
|
98
|
+
* @description Defines the stdio configuration for each of the standard streams.
|
|
99
|
+
*
|
|
100
|
+
* - 'pipe' creates a pipe between the child process and the parent process.
|
|
101
|
+
* The parent end of the pipe is exposed as a property on the `ChildProcess` object.
|
|
102
|
+
* - 'ignore' indicates that the child process's corresponding stdio file descriptor will be ignored.
|
|
103
|
+
* - 'inherit' passes the corresponding stdio stream to/from the child process.
|
|
104
|
+
* - Stream object to be used for the stdio stream.
|
|
105
|
+
* - Positive integer representing a file descriptor to be used for the stdio stream.
|
|
106
|
+
*/
|
|
107
|
+
/**
|
|
108
|
+
* @typedef {Array<StdioOption>|StdioOption} StdioOptions
|
|
109
|
+
* @description
|
|
110
|
+
* Configures the stdio streams for the child process. This can be an array or a single StdioOption.
|
|
111
|
+
*
|
|
112
|
+
* Array Form: Specify the configuration for [stdin, stdout, stderr].
|
|
113
|
+
* - If array length is more than 3, additional positions correspond to extra streams.
|
|
114
|
+
* Single Value: This value will be applied to stdin, stdout, and stderr.
|
|
115
|
+
*
|
|
116
|
+
* Examples:
|
|
117
|
+
* - ['pipe', 'pipe', 'ignore']: Pipe stdin and stdout, ignore stderr.
|
|
118
|
+
* - 'inherit': Inherit all stdio streams from the parent.
|
|
119
|
+
*/
|
|
120
|
+
/**
|
|
121
|
+
* class extends promise
|
|
122
|
+
*/
|
|
123
|
+
declare class ProcessPromise extends Promise<any> {
|
|
124
|
+
/**
|
|
125
|
+
* @param {PromiseConstruct} p - A function that takes two arguments, resolve and reject.
|
|
126
|
+
*/
|
|
127
|
+
constructor(p: PromiseConstruct);
|
|
128
|
+
/**
|
|
129
|
+
* Set the environment
|
|
130
|
+
* and the
|
|
131
|
+
* @param {string} cmd - Command to execute
|
|
132
|
+
* @param {string} from - Position in the codfe where this is triggred from
|
|
133
|
+
* @param {function} resolve - Promise resolve method
|
|
134
|
+
* @param {function} reject - Reject method
|
|
135
|
+
* @param {object} options - Settings (options default)
|
|
136
|
+
*/
|
|
137
|
+
_bind(cmd: string, from: string, resolve: Function, reject: Function, options: object): void;
|
|
138
|
+
/**
|
|
139
|
+
* Run the promise
|
|
140
|
+
*/
|
|
141
|
+
run(): this;
|
|
142
|
+
child: import("child_process").ChildProcessWithoutNullStreams & import("child_process").ChildProcessByStdio<import("stream").Writable, import("stream").Readable, import("stream").Readable> & import("child_process").ChildProcessByStdio<import("stream").Writable, import("stream").Readable, null> & import("child_process").ChildProcessByStdio<import("stream").Writable, null, import("stream").Readable> & import("child_process").ChildProcessByStdio<null, import("stream").Readable, import("stream").Readable> & import("child_process").ChildProcessByStdio<import("stream").Writable, null, null> & import("child_process").ChildProcessByStdio<null, import("stream").Readable, null> & import("child_process").ChildProcessByStdio<null, null, import("stream").Readable> & import("child_process").ChildProcessByStdio<null, null, null> & import("child_process").ChildProcess;
|
|
143
|
+
/**
|
|
144
|
+
* stdin child stream
|
|
145
|
+
* @retruns {Writeable}
|
|
146
|
+
*/
|
|
147
|
+
get stdin(): null;
|
|
148
|
+
/**
|
|
149
|
+
* stdout child stream
|
|
150
|
+
* @retruns {Readable}
|
|
151
|
+
*/
|
|
152
|
+
get stdout(): null;
|
|
153
|
+
/**
|
|
154
|
+
* stderr child stream
|
|
155
|
+
* @retruns {Readable}
|
|
156
|
+
*/
|
|
157
|
+
get stderr(): null;
|
|
158
|
+
/**
|
|
159
|
+
* process exit code
|
|
160
|
+
* @returns {Promise<number>}
|
|
161
|
+
*/
|
|
162
|
+
get exitCode(): Promise<number>;
|
|
163
|
+
catch(onrejected: any): Promise<any>;
|
|
164
|
+
/**
|
|
165
|
+
* Pipe the output to the input to the next Promise
|
|
166
|
+
* @example
|
|
167
|
+
* const res = await SH`ls -FLa`.pipe(SH`grep package.json`);
|
|
168
|
+
*/
|
|
169
|
+
pipe(dest: any): ProcessPromise;
|
|
170
|
+
/**
|
|
171
|
+
* @private
|
|
172
|
+
* Set a postrun action, internal use only
|
|
173
|
+
* @param {function} f
|
|
174
|
+
*/
|
|
175
|
+
private set _postrun(f);
|
|
176
|
+
/**
|
|
177
|
+
* Send a KILL signal to the child process
|
|
178
|
+
* @returns {Promise<number[]>} the pid numbers that has been killed
|
|
179
|
+
*/
|
|
180
|
+
kill(signal?: string): Promise<number[]>;
|
|
181
|
+
stdio(stdin: any, stdout?: string, stderr?: string): this;
|
|
182
|
+
/**
|
|
183
|
+
* Do not throw
|
|
184
|
+
*/
|
|
185
|
+
nothrow(): this;
|
|
186
|
+
/**
|
|
187
|
+
* supress log output
|
|
188
|
+
* SH.verbose = false; does the same
|
|
189
|
+
*/
|
|
190
|
+
quiet(): this;
|
|
191
|
+
/**
|
|
192
|
+
* Show log output in the console
|
|
193
|
+
*/
|
|
194
|
+
verbose(): this;
|
|
195
|
+
_quiet: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Set a timeout to kill a process
|
|
198
|
+
*
|
|
199
|
+
* @param {string} d - 10s, 1000ms
|
|
200
|
+
* @param {string} [signal] - default "SIGTERM" Signal to send to kill the proces
|
|
201
|
+
*/
|
|
202
|
+
timeout(d: string, signal?: string): this;
|
|
203
|
+
_timeout: number;
|
|
204
|
+
_timeoutSignal: string;
|
|
205
|
+
/**
|
|
206
|
+
* stop execution for the next step
|
|
207
|
+
*/
|
|
208
|
+
halt(): this;
|
|
209
|
+
/**
|
|
210
|
+
* @private
|
|
211
|
+
* Set a prerun action, internal use only
|
|
212
|
+
* @param {function} f
|
|
213
|
+
*/
|
|
214
|
+
private set _prerun(f);
|
|
215
|
+
/**
|
|
216
|
+
* Is this promise halted?
|
|
217
|
+
* @returns {boolean}
|
|
218
|
+
*/
|
|
219
|
+
get isHalted(): boolean;
|
|
220
|
+
#private;
|
|
221
|
+
}
|
|
222
|
+
export {};
|