UNPKG

910 BJavaScriptView Raw
1/* eslint no-console: 0 */
2const File = require('vinyl');
3const ansiHTML = require('ansi-html');
4
5const template =
6 '<head><style>' +
7 'body{padding:20px;font:18px monospace;background:#880000;color:#fff;}' +
8 '</style></head>';
9
10ansiHTML.setColors({
11 reset: ['fff', '800'],
12 black: 'aaa', // String
13 red: '9ff',
14 green: 'f9f',
15 yellow: '99f',
16 blue: 'ff9',
17 magenta: 'f99',
18 cyan: '9f9',
19 lightgrey: 'ccc',
20 darkgrey: 'aaa'
21});
22
23/**
24 * Given an error, generate an HTML page that represents the error.
25 * @param error parse or generation error
26 * @returns {Object} vinyl file object
27 */
28function errorPage(error) {
29 let errorText = error.toString();
30 console.error(error);
31 if (error.codeFrame) {
32 errorText += '<pre>' + ansiHTML(error.codeFrame) + '</pre>';
33 }
34 return new File({
35 path: 'index.html',
36 contents: new Buffer(template + errorText)
37 });
38}
39
40module.exports = errorPage;