@db-lyon/flowkit 0.5.2 → 0.6.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 +55 -0
- package/dist/config/schema.d.ts +247 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +9 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/flow/runner.d.ts +55 -0
- package/dist/flow/runner.d.ts.map +1 -1
- package/dist/flow/runner.js +169 -33
- package/dist/flow/runner.js.map +1 -1
- package/dist/task/shell-task.d.ts +11 -1
- package/dist/task/shell-task.d.ts.map +1 -1
- package/dist/task/shell-task.js +103 -16
- package/dist/task/shell-task.js.map +1 -1
- package/package.json +1 -1
package/dist/task/shell-task.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
2
|
import { BaseTask } from './base-task.js';
|
|
3
3
|
/**
|
|
4
|
-
* Task that executes a shell command
|
|
4
|
+
* Task that executes a shell command.
|
|
5
|
+
*
|
|
6
|
+
* Stdout and stderr stream line-by-line through `this.logger` as they
|
|
7
|
+
* arrive, so observers (per-step hooks, log-shipping clients, live UIs)
|
|
8
|
+
* see output in real time instead of waiting for the command to finish:
|
|
9
|
+
*
|
|
10
|
+
* logger.info({ stream: 'stdout' }, line)
|
|
11
|
+
* logger.warn({ stream: 'stderr' }, line)
|
|
12
|
+
*
|
|
13
|
+
* The final `TaskResult.data.output` / `stderr` still contains the full
|
|
14
|
+
* captured text for callers that just want the end result.
|
|
5
15
|
*
|
|
6
16
|
* Usage in YAML:
|
|
7
17
|
* steps:
|
|
@@ -23,23 +33,100 @@ export class ShellTask extends BaseTask {
|
|
|
23
33
|
}
|
|
24
34
|
async execute() {
|
|
25
35
|
const { command, cwd, timeout = 300_000 } = this.options;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
return new Promise((resolve) => {
|
|
37
|
+
// Cross-platform: route through the platform shell so command strings
|
|
38
|
+
// like "npm run build" or "echo $HOME && ls" work the same way they
|
|
39
|
+
// did under execSync.
|
|
40
|
+
const child = spawn(command, {
|
|
30
41
|
cwd,
|
|
31
|
-
|
|
42
|
+
shell: true,
|
|
43
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
32
44
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
let stdoutBuf = '';
|
|
46
|
+
let stderrBuf = '';
|
|
47
|
+
let stdoutTail = '';
|
|
48
|
+
let stderrTail = '';
|
|
49
|
+
let timedOut = false;
|
|
50
|
+
const emitLines = (chunk, tailRef, emit) => {
|
|
51
|
+
// Maintain a small tail buffer so we never emit a partial line.
|
|
52
|
+
// Each newline we see flushes everything before it as one line;
|
|
53
|
+
// the remainder carries over to the next chunk.
|
|
54
|
+
const combined = (tailRef === 'stdout' ? stdoutTail : stderrTail) + chunk;
|
|
55
|
+
const parts = combined.split(/\r?\n/);
|
|
56
|
+
const remainder = parts.pop() ?? '';
|
|
57
|
+
if (tailRef === 'stdout')
|
|
58
|
+
stdoutTail = remainder;
|
|
59
|
+
else
|
|
60
|
+
stderrTail = remainder;
|
|
61
|
+
for (const line of parts) {
|
|
62
|
+
if (line.length > 0)
|
|
63
|
+
emit(line);
|
|
64
|
+
}
|
|
41
65
|
};
|
|
42
|
-
|
|
66
|
+
child.stdout?.setEncoding('utf-8');
|
|
67
|
+
child.stderr?.setEncoding('utf-8');
|
|
68
|
+
child.stdout?.on('data', (chunk) => {
|
|
69
|
+
stdoutBuf += chunk;
|
|
70
|
+
emitLines(chunk, 'stdout', (line) => {
|
|
71
|
+
this.logger.info({ stream: 'stdout' }, line);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
child.stderr?.on('data', (chunk) => {
|
|
75
|
+
stderrBuf += chunk;
|
|
76
|
+
emitLines(chunk, 'stderr', (line) => {
|
|
77
|
+
this.logger.warn({ stream: 'stderr' }, line);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
const timer = setTimeout(() => {
|
|
81
|
+
timedOut = true;
|
|
82
|
+
// SIGKILL on Windows is mapped to TerminateProcess by libuv.
|
|
83
|
+
child.kill('SIGKILL');
|
|
84
|
+
}, timeout);
|
|
85
|
+
const flushTails = () => {
|
|
86
|
+
if (stdoutTail.length > 0) {
|
|
87
|
+
this.logger.info({ stream: 'stdout' }, stdoutTail);
|
|
88
|
+
stdoutBuf += stdoutTail;
|
|
89
|
+
stdoutTail = '';
|
|
90
|
+
}
|
|
91
|
+
if (stderrTail.length > 0) {
|
|
92
|
+
this.logger.warn({ stream: 'stderr' }, stderrTail);
|
|
93
|
+
stderrBuf += stderrTail;
|
|
94
|
+
stderrTail = '';
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
child.on('error', (err) => {
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
flushTails();
|
|
100
|
+
resolve({
|
|
101
|
+
success: false,
|
|
102
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
103
|
+
data: { exitCode: null, stderr: stderrBuf.trimEnd(), stdout: stdoutBuf.trimEnd() },
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
child.on('close', (code, signal) => {
|
|
107
|
+
clearTimeout(timer);
|
|
108
|
+
flushTails();
|
|
109
|
+
const trimmedOut = stdoutBuf.trimEnd();
|
|
110
|
+
const trimmedErr = stderrBuf.trimEnd();
|
|
111
|
+
if (timedOut) {
|
|
112
|
+
resolve({
|
|
113
|
+
success: false,
|
|
114
|
+
error: new Error(`Shell command timed out after ${timeout}ms`),
|
|
115
|
+
data: { exitCode: code, signal, stderr: trimmedErr, stdout: trimmedOut },
|
|
116
|
+
});
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (code === 0) {
|
|
120
|
+
resolve({ success: true, data: { output: trimmedOut } });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
resolve({
|
|
124
|
+
success: false,
|
|
125
|
+
error: new Error(`Shell command failed (exit ${code}): ${(trimmedErr || trimmedOut).trimEnd()}`),
|
|
126
|
+
data: { exitCode: code, signal, stderr: trimmedErr, stdout: trimmedOut },
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
43
130
|
}
|
|
44
131
|
}
|
|
45
132
|
//# sourceMappingURL=shell-task.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-task.js","sourceRoot":"","sources":["../../src/task/shell-task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"shell-task.js","sourceRoot":"","sources":["../../src/task/shell-task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAmB,MAAM,gBAAgB,CAAC;AAQ3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,SAAU,SAAQ,QAA0B;IACvD,IAAI,QAAQ;QACV,OAAO,SAAS,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IACzC,CAAC;IAES,QAAQ;QAChB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACtE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAEzD,OAAO,IAAI,OAAO,CAAa,CAAC,OAAO,EAAE,EAAE;YACzC,sEAAsE;YACtE,oEAAoE;YACpE,sBAAsB;YACtB,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE;gBAC3B,G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