Skip to content

Commit

Permalink
feat(dependencies): update [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Jul 16, 2023
1 parent 26dea68 commit 09844ca
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 410 deletions.
61 changes: 47 additions & 14 deletions lib/getRenderer.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,61 @@
const getMainRendererOptions = ({ debug, quiet }, env) => {
if (quiet) return { renderer: 'silent' }
import { EOL } from 'node:os'
import { Writable } from 'node:stream'

import { ListrLogger, ProcessOutput } from 'listr2'

const EOLRegex = new RegExp(EOL + '$')

const bindLogger = (consoleLogMethod) =>
new Writable({
write: function (chunk, encoding, next) {
consoleLogMethod(chunk.toString().replace(EOLRegex, ''))
next()
},
})

const getMainRendererOptions = ({ debug, quiet }, logger, env) => {
if (quiet) {
return {
renderer: 'silent',
}
}

if (env.NODE_ENV === 'test') {
return {
renderer: 'test',
rendererOptions: {
logger: new ListrLogger({
processOutput: new ProcessOutput(bindLogger(logger.log), bindLogger(logger.error)),
}),
},
}
}

// Better support for dumb terminals: https://en.wikipedia.org/wiki/Computer_terminal#Dumb_terminals
const isDumbTerminal = env.TERM === 'dumb'
if (debug || isDumbTerminal || env.NODE_ENV === 'test') return { renderer: 'verbose' }
return { renderer: 'update', rendererOptions: { dateFormat: false } }
}
if (debug || env.TERM === 'dumb') {
return {
renderer: 'verbose',
}
}

const getFallbackRenderer = ({ renderer }, { FORCE_COLOR }) => {
if (renderer === 'silent') {
return 'silent'
return {
renderer: 'update',
}
}

// If colors are being forced, then also force non-fallback rendering
if (Number(FORCE_COLOR) > 0) {
const getFallbackRenderer = ({ renderer }, { FORCE_COLOR }) => {
if (renderer === 'silent' || renderer === 'test' || Number(FORCE_COLOR) > 0) {
return renderer
}

return 'verbose'
}

export const getRenderer = (options, env = process.env) => {
const mainRendererOptions = getMainRendererOptions(options, env)
export const getRenderer = (options, logger, env = process.env) => {
const mainRendererOptions = getMainRendererOptions(options, logger, env)

return {
...mainRendererOptions,
nonTTYRenderer: getFallbackRenderer(mainRendererOptions, env),
fallbackRenderer: getFallbackRenderer(mainRendererOptions, env),
}
}
2 changes: 1 addition & 1 deletion lib/runAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const runAll = async (
ctx,
exitOnError: false,
registerSignalListeners: false,
...getRenderer({ debug, quiet }),
...getRenderer({ debug, quiet }, logger),
}

const listrTasks = []
Expand Down
Loading

0 comments on commit 09844ca

Please sign in to comment.