1 | // https://gist.github.com/pguillory/729616
|
2 |
|
3 | function hookStdout(callback: Function) {
|
4 | let old_write = process.stdout.write;
|
5 |
|
6 | // @ts-ignore
|
7 | process.stdout.write = ((write: any) =>
|
8 | function (str: string) {
|
9 | write.apply(process.stdout, arguments);
|
10 | callback(str);
|
11 | })(process.stdout.write);
|
12 |
|
13 | return () => {
|
14 | process.stdout.write = old_write;
|
15 | };
|
16 | }
|
17 |
|
18 | export default hookStdout;
|