-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
69 lines (60 loc) · 1.74 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import * as actionsExec from '@actions/exec'
import { ExecOptions } from '@actions/exec/lib/interfaces'
export const exec = async (command: string, args?: string[], options?: ExecOptions) => {
const originalListeners = options?.listeners
let stdout = Buffer.concat([], 0)
let stderr = Buffer.concat([], 0)
let stdline = ''
let errline = ''
let debug = ''
const listeners: ExecOptions['listeners'] = {
stdout: (data: Buffer): void => {
const concatData = [stdout, data]
const concatLength = stdout.length + data.length
stdout = Buffer.concat(concatData, concatLength)
if (originalListeners?.stdout != null) {
originalListeners.stdout(data)
}
},
stderr: (data: Buffer): void => {
const concatData = [stderr, data]
const concatLength = stderr.length + data.length
stderr = Buffer.concat(concatData, concatLength)
if (originalListeners?.stderr != null) {
originalListeners.stderr(data)
}
},
stdline: (data: string): void => {
stdline += data.toString()
if (originalListeners?.stdline != null) {
originalListeners.stdline(data)
}
},
errline: (data: string): void => {
stdline += data.toString()
if (originalListeners?.errline != null) {
originalListeners.errline(data)
}
},
debug: (data: string): void => {
stdline += data.toString()
if (originalListeners?.debug != null) {
originalListeners.debug(data)
}
}
}
const exitCode = await actionsExec.exec(command, args, {
...options,
listeners,
})
return {
exitCode,
stdout,
stdoutStr: stdout.toString(),
stderr,
stderrStr: stderr.toString(),
stdline,
errline,
debug,
}
}