-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
131aad6
commit 425cfdb
Showing
3 changed files
with
120 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Acts as a listener for @actions/exec, by capturing STDOUT and STDERR | ||
* streams, and exposing them via a contents attribute. | ||
* | ||
* @example | ||
* // Instantiate a new listener | ||
* const listener = new OutputListener(); | ||
* // Register listener against STDOUT stream | ||
* await exec.exec('ls', ['-ltr'], { | ||
* listeners: { | ||
* stdout: listener.listener | ||
* } | ||
* }); | ||
* // Log out STDOUT contents | ||
* console.log(listener.contents); | ||
*/ | ||
class OutputListener { | ||
constructor() { | ||
this._buff = []; | ||
} | ||
|
||
get listener() { | ||
const listen = function listen(data) { | ||
this._buff.push(data); | ||
}; | ||
return listen.bind(this); | ||
} | ||
|
||
get contents() { | ||
return this._buff | ||
.map(chunk => chunk.toString()) | ||
.join(''); | ||
} | ||
} | ||
|
||
module.exports = OutputListener; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters