1 | /// <reference types="node" />
|
2 | import { HandlerResult } from "@atomist/automation-client/lib/HandlerResult";
|
3 | import { execPromise, ExecPromiseError, ExecPromiseResult, killProcess, spawn, spawnPromise, SpawnPromiseOptions, SpawnPromiseReturns, WritableLog } from "@atomist/automation-client/lib/util/child_process";
|
4 | import { ChildProcess } from "child_process";
|
5 | import { ProgressLog } from "../../spi/log/ProgressLog";
|
6 | /** Re-export child process objects from automation-client. */
|
7 | export { execPromise, ExecPromiseError, ExecPromiseResult, killProcess, spawn, spawnPromise, SpawnPromiseOptions, SpawnPromiseReturns, WritableLog, };
|
8 | /**
|
9 | * Type that can react to the exit of a spawned child process, after
|
10 | * Node has terminated without reporting an error. This is necessary
|
11 | * only for commands that can return a zero exit status on failure or
|
12 | * non-zero exit code on success. Implementations should return
|
13 | * `true` if an error is found, `false` otherwise.
|
14 | */
|
15 | export declare type ErrorFinder = (code: number, signal: string, log: WritableLog) => boolean;
|
16 | /**
|
17 | * Default ErrorFinder that regards everything but a return code of 0
|
18 | * as failure.
|
19 | *
|
20 | * @param code process exit status
|
21 | * @return true if exit status is not zero
|
22 | */
|
23 | export declare const SuccessIsReturn0ErrorFinder: ErrorFinder;
|
24 | /**
|
25 | * Add an error finder to SpawnPromietOptions to allow for
|
26 | * poorly-behaved command-line tools that do not properly reflect
|
27 | * their status in their return code.
|
28 | */
|
29 | export interface SpawnLogOptions extends SpawnPromiseOptions {
|
30 | /**
|
31 | * If your command can return zero on failure or non-zero on
|
32 | * success, you can override the default behavior of determining
|
33 | * success or failure using this option. For example, if your
|
34 | * command returns zero for certain types of errors, you can scan
|
35 | * the log content from the command to determine if an error
|
36 | * occurs. If this function finds an error, the `error` property
|
37 | * will be populated with an `Error`.
|
38 | */
|
39 | errorFinder?: ErrorFinder;
|
40 | /**
|
41 | * Make SpawnPromiseOptions log mandatory and a ProgressLog.
|
42 | */
|
43 | log: ProgressLog;
|
44 | }
|
45 | /**
|
46 | * Interface containing the arguments to spawnAndLog.
|
47 | */
|
48 | export interface SpawnLogCommand {
|
49 | /** Executable able to be run by cross-spawn. */
|
50 | command: string;
|
51 | /** Arguments to command */
|
52 | args?: string[];
|
53 | /** Options to customize how command is run. */
|
54 | options?: SpawnLogOptions;
|
55 | }
|
56 | /**
|
57 | * Interface similar to [[SpawnLogCommand]] but making the log
|
58 | * property optional since that can typically be obtained other ways
|
59 | * when commands are invoked from within goals.
|
60 | */
|
61 | export interface SpawnLogInvocation {
|
62 | /** Executable able to be run by cross-spawn. */
|
63 | command: string;
|
64 | /** Arguments to command */
|
65 | args?: string[];
|
66 | /** Options to customize how command is run. */
|
67 | options?: Partial<SpawnLogOptions>;
|
68 | }
|
69 | /**
|
70 | * Result returned by spawnAndLog after running a child process. It
|
71 | * is compatible with handler results. To support both HandlerResult
|
72 | * and SpawnPromiseReturns, the value of code and status are
|
73 | * identical.
|
74 | */
|
75 | export declare type SpawnLogResult = HandlerResult & SpawnPromiseReturns;
|
76 | /**
|
77 | * Spawn a process, logging its standard output and standard error,
|
78 | * and return a Promise of its results. The command is spawned using
|
79 | * cross-spawn. A DelimitedWriteProgressLogDecorator, using newlines
|
80 | * as delimiters, is created from the provided `opts.log`. The default
|
81 | * command timeout is 10 minutes. The default
|
82 | * [[SpawnLogOptions#errorFinder]] sets the `error` property if the
|
83 | * command exits with a non-zero status or is killed by a signal. If
|
84 | * the process is killed due to a signal or the `errorFinder` returns
|
85 | * `true`, the returned `code` property will be non-zero.
|
86 | *
|
87 | * @param cmd Command to run.
|
88 | * @param args Arguments to command.
|
89 | * @param opts Options for spawn, spawnPromise, and spawnLog.
|
90 | * @return A promise that provides information on the child process and
|
91 | * its execution result, including if the exit status was non-zero
|
92 | * or the process was killed by a signal. The promise is only
|
93 | * rejected with an `ExecPromiseError` if there is an error
|
94 | * spawning the process.
|
95 | */
|
96 | export declare function spawnLog(cmd: string, args: string[], opts: SpawnLogOptions): Promise<SpawnLogResult>;
|
97 | /**
|
98 | * Kill the process and wait for it to shut down. This can take a
|
99 | * while as processes may have shut down hooks. On win32, the process
|
100 | * is killed and the Promise is rejected if the process does not exit
|
101 | * within `wait` milliseconds. On other platforms, first the process
|
102 | * is sent the default signal, SIGTERM. After `wait` milliseconds, it
|
103 | * is sent SIGKILL. After another `wait` milliseconds, an error is
|
104 | * thrown.
|
105 | *
|
106 | * @param childProcess Child process to kill
|
107 | * @param wait Number of milliseconds to wait before sending SIGKILL and
|
108 | * then erroring, default is 30000 ms
|
109 | */
|
110 | export declare function killAndWait(childProcess: ChildProcess, wait?: number): Promise<void>;
|
111 | //# sourceMappingURL=child_process.d.ts.map |
\ | No newline at end of file |