Skip to content

Commit 86a9eeb

Browse files
committed
feat(ui): add ability to output to stderr
closes #218 - add stderr option to log method - change error method to output most things to stderr rather than stdout
1 parent f052df6 commit 86a9eeb

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/ui/index.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ class UI {
122122
});
123123
}
124124

125-
log(message, color) {
125+
log(message, color, stderr) {
126126
if (color) {
127127
message = chalk[color](message);
128128
}
129129

130-
this.stdout.write(`${this.spinner ? '\r' : ''}${message}\n`);
130+
let stream = stderr ? 'stderr' : 'stdout';
131+
132+
this[stream].write(`${this.spinner ? '\r' : ''}${message}\n`);
131133
}
132134

133135
success(message) {
@@ -157,7 +159,7 @@ class UI {
157159
let verboseOutput = error.toString(true);
158160

159161
// Log the verbose error if verbose is set, otherwise log the non-verbose error output
160-
this.log(this.verbose ? verboseOutput : error.toString(false));
162+
this.log(this.verbose ? verboseOutput : error.toString(false), null, true);
161163
this.log(debugInfo, 'yellow');
162164

163165
if (error.logToFile()) {
@@ -168,7 +170,7 @@ class UI {
168170
let output = `An error occurred.\n${chalk.yellow('Message:')} '${error.message}'\n\n`;
169171

170172
if (!this.verbose) {
171-
this.log(output, 'red');
173+
this.log(output, 'red', true);
172174
}
173175

174176
if (error.stack) {
@@ -184,17 +186,17 @@ class UI {
184186
}
185187

186188
if (this.verbose) {
187-
this.log(output, 'red');
189+
this.log(output, 'red', true);
188190
}
189191

190192
this.log(debugInfo, 'yellow');
191193
this._logErrorToFile(`${debugInfo}\n${output}`);
192194
} else if (isObject(error)) {
193195
// TODO: find better way to handle object errors?
194-
this.log(JSON.stringify(error));
196+
this.log(JSON.stringify(error), null, true);
195197
} else if (error !== false) {
196198
// If the error is false, we're just exiting (makes the promise chains easier)
197-
this.log('An unknown error occured.');
199+
this.log('An unknown error occured.', null, true);
198200
}
199201
}
200202

0 commit comments

Comments
 (0)