handle npx elm compile error messages

This commit is contained in:
Ryan Haskell-Glatz 2021-02-08 21:54:57 -06:00
parent 0f8cc59757
commit 8b7e741e50
2 changed files with 20 additions and 2 deletions

View File

@ -137,8 +137,23 @@ const compileMainElm = (env : Environment) => async () => {
.catch(colorElmError)
}
const red = colors.RED
const green = colors.green
const colorElmError = (err : string) => {
const errors = JSON.parse(err).errors as Error[] || []
let errors = []
try {
errors = JSON.parse(err).errors as Error[] || []
} catch (e) {
return Promise.reject([
`${red}Something went wrong with elm-spa.${reset}`,
`Please report this entire error to ${green}https://github.com/ryannhg/elm-spa/issues${reset}`,
`-----`,
err,
`-----`
].join('\n\n'))
}
const strIf = (str : string) => (cond : boolean) : string => cond ? str : ''
const boldIf = strIf(bold)

View File

@ -2,5 +2,8 @@ import { exec } from 'child_process'
export const run = (cmd : string) : Promise<unknown> =>
new Promise((resolve, reject) =>
exec(cmd, (err, stdout, stderr) => err ? reject(stderr) : resolve(stdout))
exec(cmd, (err, stdout, stderr) => err
? reject(stderr.split('npm ERR!')[0] || stderr)
: resolve(stdout)
)
)