-
-
Notifications
You must be signed in to change notification settings - Fork 217
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
Showing
18 changed files
with
246 additions
and
157 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
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
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
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
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
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 |
---|---|---|
@@ -1,58 +1,38 @@ | ||
import prettyMs from 'pretty-ms'; | ||
import {gray} from 'yoctocolors'; | ||
import {escapeLines} from '../arguments/escape.js'; | ||
import {getDurationMs} from '../return/duration.js'; | ||
import {isVerbose} from './info.js'; | ||
import {verboseLog} from './log.js'; | ||
import {logError} from './error.js'; | ||
|
||
// When `verbose` is `short|full`, print each command's completion, duration and error | ||
export const logFinalResult = ({shortMessage, failed, durationMs}, reject, verboseInfo) => { | ||
logResult({ | ||
message: shortMessage, | ||
failed, | ||
reject, | ||
durationMs, | ||
verboseInfo, | ||
}); | ||
export const logFinalResult = ({shortMessage, durationMs, failed}, verboseInfo) => { | ||
logResult(shortMessage, durationMs, verboseInfo, failed); | ||
}; | ||
|
||
// Same but for early validation errors | ||
export const logEarlyResult = (error, startTime, verboseInfo) => { | ||
logResult({ | ||
message: escapeLines(String(error)), | ||
failed: true, | ||
reject: true, | ||
durationMs: getDurationMs(startTime), | ||
verboseInfo, | ||
}); | ||
export const logEarlyResult = (error, startTime, {rawOptions, ...verboseInfo}) => { | ||
const shortMessage = escapeLines(String(error)); | ||
const durationMs = getDurationMs(startTime); | ||
const earlyVerboseInfo = {...verboseInfo, rawOptions: {...rawOptions, reject: true}}; | ||
logResult(shortMessage, durationMs, earlyVerboseInfo, true); | ||
}; | ||
|
||
const logResult = ({message, failed, reject, durationMs, verboseInfo: {verbose, verboseId}}) => { | ||
if (!isVerbose(verbose)) { | ||
const logResult = (shortMessage, durationMs, verboseInfo, failed) => { | ||
if (!isVerbose(verboseInfo)) { | ||
return; | ||
} | ||
|
||
const icon = getIcon(failed, reject); | ||
logError({ | ||
message, | ||
failed, | ||
reject, | ||
verboseId, | ||
icon, | ||
}); | ||
logDuration(durationMs, verboseId, icon); | ||
}; | ||
|
||
const logDuration = (durationMs, verboseId, icon) => { | ||
const durationMessage = `(done in ${prettyMs(durationMs)})`; | ||
verboseLog(durationMessage, verboseId, icon, gray); | ||
logError(shortMessage, verboseInfo, failed); | ||
logDuration(durationMs, verboseInfo, failed); | ||
}; | ||
|
||
const getIcon = (failed, reject) => { | ||
if (!failed) { | ||
return 'success'; | ||
} | ||
|
||
return reject ? 'error' : 'warning'; | ||
const logDuration = (durationMs, verboseInfo, failed) => { | ||
const logMessage = `(done in ${prettyMs(durationMs)})`; | ||
verboseLog({ | ||
type: 'duration', | ||
logMessage, | ||
verboseInfo, | ||
failed, | ||
}); | ||
}; |
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,46 @@ | ||
import figures from 'figures'; | ||
import { | ||
gray, | ||
bold, | ||
redBright, | ||
yellowBright, | ||
} from 'yoctocolors'; | ||
|
||
// Default logger for the `verbose` option | ||
export const defaultLogger = ({type, message, timestamp, failed, piped, commandId, options: {reject = true}}) => { | ||
const timestampString = serializeTimestamp(timestamp); | ||
const icon = ICONS[type]({failed, reject, piped}); | ||
const color = COLORS[type]({reject}); | ||
return `${gray(`[${timestampString}]`)} ${gray(`[${commandId}]`)} ${color(icon)} ${color(message)}`; | ||
}; | ||
|
||
// Prepending the timestamp allows debugging the slow paths of a subprocess | ||
const serializeTimestamp = timestamp => `${padField(timestamp.getHours(), 2)}:${padField(timestamp.getMinutes(), 2)}:${padField(timestamp.getSeconds(), 2)}.${padField(timestamp.getMilliseconds(), 3)}`; | ||
|
||
const padField = (field, padding) => String(field).padStart(padding, '0'); | ||
|
||
const getFinalIcon = ({failed, reject}) => { | ||
if (!failed) { | ||
return figures.tick; | ||
} | ||
|
||
return reject ? figures.cross : figures.warning; | ||
}; | ||
|
||
const ICONS = { | ||
command: ({piped}) => piped ? '|' : '$', | ||
output: () => ' ', | ||
ipc: () => '*', | ||
error: getFinalIcon, | ||
duration: getFinalIcon, | ||
}; | ||
|
||
const identity = string => string; | ||
|
||
const COLORS = { | ||
command: () => bold, | ||
output: () => identity, | ||
ipc: () => identity, | ||
error: ({reject}) => reject ? redBright : yellowBright, | ||
duration: () => gray, | ||
}; |
Oops, something went wrong.