feat: deprecate logStream, add logger
Signed-off-by: ElaineDeMattosSilvaB <elaine.de-mattos-silva-bezerra@deutschebahn.com>
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
import { spawn, SpawnOptionsWithoutStdio } from 'child_process';
|
||||
import { PassThrough, Writable } from 'stream';
|
||||
import { Logger } from 'winston';
|
||||
|
||||
/**
|
||||
* Options for {@link executeShellCommand}.
|
||||
@@ -29,7 +30,12 @@ export type ExecuteShellCommandOptions = {
|
||||
args: string[];
|
||||
/** options to pass to spawn */
|
||||
options?: SpawnOptionsWithoutStdio;
|
||||
/** stream to capture stdout and stderr output */
|
||||
/** logger to capture stdout and stderr output */
|
||||
logger?: Logger;
|
||||
/**
|
||||
* stream to capture stdout and stderr output
|
||||
* @deprecated please provide a logger instead.
|
||||
*/
|
||||
logStream?: Writable;
|
||||
};
|
||||
|
||||
@@ -45,20 +51,27 @@ export async function executeShellCommand(
|
||||
command,
|
||||
args,
|
||||
options: spawnOptions,
|
||||
logger,
|
||||
logStream = new PassThrough(),
|
||||
} = options;
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const process = spawn(command, args, spawnOptions);
|
||||
|
||||
process.stdout.on('data', stream => {
|
||||
logStream.write(stream);
|
||||
process.stdout.on('data', chunk => {
|
||||
logStream?.write(chunk);
|
||||
logger?.log(
|
||||
'info',
|
||||
Buffer.isBuffer(chunk) ? chunk.toString('utf8').trim() : chunk.trim(),
|
||||
);
|
||||
});
|
||||
|
||||
process.stderr.on('data', stream => {
|
||||
logStream.write(stream);
|
||||
process.stderr.on('data', chunk => {
|
||||
logStream?.write(chunk);
|
||||
logger?.log(
|
||||
'error',
|
||||
Buffer.isBuffer(chunk) ? chunk.toString('utf8').trim() : chunk.trim(),
|
||||
);
|
||||
});
|
||||
|
||||
process.on('error', error => {
|
||||
return reject(error);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user