documentation/lib/serve/error_page.js
Tom MacWright 25152edeb9 style(prettier): Use prettier for code formatting (#710)
* style(prettier): Use prettier for code formatting

This saves us style issues. Also adds husky and lint-staged for pre-commit testing

Refs https://github.com/documentationjs/documentation/issues/709
2017-04-10 14:25:45 -04:00

42 lines
940 B
JavaScript

/* @flow */
/* eslint no-console: 0 */
'use strict';
var File = require('vinyl');
var ansiHTML = require('ansi-html');
var template = '<head><style>' +
'body{padding:20px;font:18px monospace;background:#880000;color:#fff;}' +
'</style></head>';
ansiHTML.setColors({
reset: ['fff', '800'],
black: 'aaa', // String
red: '9ff',
green: 'f9f',
yellow: '99f',
blue: 'ff9',
magenta: 'f99',
cyan: '9f9',
lightgrey: 'ccc',
darkgrey: 'aaa'
});
/**
* Given an error, generate an HTML page that represents the error.
* @param error parse or generation error
* @returns {Object} vinyl file object
*/
function errorPage(error /*: Error*/) {
var errorText = error.toString();
console.error(error);
if (error.codeFrame) {
errorText += '<pre>' + ansiHTML(error.codeFrame) + '</pre>';
}
return new File({
path: 'index.html',
contents: new Buffer(template + errorText)
});
}
module.exports = errorPage;