@sap/cds-dk
Version:
Command line client and development toolkit for the SAP Cloud Application Programming Model
25 lines (23 loc) • 1.2 kB
JavaScript
// sorts, filters, and writes compilation messages to console
module.exports = (messages, options={}) => {
const { format } = require('../../lib/util/term')
const logLevel = options && options['log-level'] || require('../../lib').env.log.levels.cli || ''
const levels = {
debug: { Error:4, undefined:4, Warning:3, Info:2, Debug:1 },
info: { Error:4, undefined:4, Warning:3, Info:2 },
warn: { Error:4, undefined:4, Warning:3 },
error: { Error:4, undefined:4 },
} [logLevel.toLowerCase()] || { Error:4, undefined:4, Warning:3 }
const log = options.log || console.error
if (!Array.isArray (messages)) messages = [messages]
for (let m of messages.filter (m => m.severity in levels)) {
// show stack for resolution issues since there the requiring code location is in the stack
// check for standard Error classes, but not Error itself
const internalError = m.name === 'EvalError' || m.name === 'InternalError' || m.name === 'RangeError'
|| m.name === 'ReferenceError' || m.name === 'SyntaxError' || m.name === 'TypeError'
|| m.name === 'URIError'
const mf = format (m, m.severity, internalError, true)
log (mf)
}
}
/* eslint no-console:off */