Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import chalk from 'chalk';
import signale from 'signale';
import marked from 'marked';
import TerminalRenderer from 'marked-terminal';
import { existsSync, writeFileSync } from 'fs';
marked.setOptions({
renderer: new TerminalRenderer(),
});
// 支持内部框架扩展 error code map
const ERROR_CODE_MAP = require(process.env.ERROR_CODE_MAP_PATH || '@umijs/error-code-map');
export class UmiError extends Error {
constructor(opts, ...params) {
const { message, code, context } = opts;
super(message, ...params);
this.code = code;
this.context = context || {};
this.test();
}
test() {
export default function(callback) {
// Display formatted readme.md
marked.setOptions({
renderer: new markedTerminal()
})
log.info(marked(fs.readFileSync('./README.md', 'UTF-8')))
callback()
}
});
body = setLineSameWidth(body.trim());
var quote = "";
body.split('\n').forEach(line => {
if (line.trim() === "") {
quote += '\n';
return;
}
quote += ('> ' + line + '\n');
});
return '\n' + this.o.blockquote(indentify(quote)) + '\n\n';
});
};
TerminalRenderer.prototype.html = function(html) {
var out = "";
if (html instanceof Array) {
html.forEach(block => {
out += block;
});
} else {
out = html;
}
out = out.replace(/<[^>\)\(]+>/g,'');
return this.o.html(setLineSameWidth(out));
};
/**
* Read slide content.
var hasText = text && text !== href;
var out = '';
if (hasText) out += this.emoji(text) + ' (';
out += this.o.href(href);
if (hasText) out += ')';
return this.o.link(out);
};
TerminalRenderer.prototype.hr = function() {
return '\n\n' + '-'.repeat(this.o.width) + '\n';
};
TerminalRenderer.prototype.blockquote = function(quoteBlocks) {
return Promise.all(quoteBlocks).then(quotes => {
var body = "";
quotes.forEach(quote => {
body += quote;
});
body = setLineSameWidth(body.trim());
var quote = "";
body.split('\n').forEach(line => {
if (line.trim() === "") {
quote += '\n';
return;
}
quote += ('> ' + line + '\n');
});
return '\n' + this.o.blockquote(indentify(quote)) + '\n\n';
if (prot.indexOf('javascript:') === 0) {
return '';
}
}
var hasText = text && text !== href;
var out = '';
if (hasText) out += this.emoji(text) + ' (';
out += this.o.href(href);
if (hasText) out += ')';
return this.o.link(out);
};
TerminalRenderer.prototype.hr = function() {
return '\n\n' + '-'.repeat(this.o.width) + '\n';
};
TerminalRenderer.prototype.blockquote = function(quoteBlocks) {
return Promise.all(quoteBlocks).then(quotes => {
var body = "";
quotes.forEach(quote => {
body += quote;
});
body = setLineSameWidth(body.trim());
var quote = "";
body.split('\n').forEach(line => {
if (line.trim() === "") {
quote += '\n';
return;
if (Object.prototype.hasOwnProperty.call(target, key)) {
obj[key] = target[key];
}
}
}
return obj;
}
TerminalRenderer.prototype.code = function(code, lang, escaped) {
code = setLineSameWidth(code);
return '\n' + indentify(highlight(code, lang, this.o, this.highlightOptions)) + '\n';
};
TerminalRenderer.prototype.list = function(body, ordered) {
body = setLineSameWidth(body);
body = indentLines(this.o.listitem(body));
body = body + '\n';
if (!ordered) return body;
return changeToOrdered(body);
};
TerminalRenderer.prototype.image = function(href, title, text) {
return new Promise((resolve, reject) => {
imageToAscii(href,
{ size: { height: "60%" }
}, (err, converted) => {
if (err) reject(err);
else resolve(converted + "\n");
});
});
return changeToOrdered(body);
};
TerminalRenderer.prototype.image = function(href, title, text) {
return new Promise((resolve, reject) => {
imageToAscii(href,
{ size: { height: "60%" }
}, (err, converted) => {
if (err) reject(err);
else resolve(converted + "\n");
});
});
};
TerminalRenderer.prototype.heading = function(text, level, raw) {
text = this.transform(text.join(''));
var prefix = this.o.showSectionPrefix ?
(new Array(level + 1)).join('#')+' ' : '';
text = prefix + text;
if (this.o.reflowText) {
text = reflowText(text, this.o.width, this.options.gfm);
}
if (level === 1) {
return this.o.firstHeading(text) + '\n';
}
return '\n' + this.o.heading(text) + '\n';
};
TerminalRenderer.prototype.paragraph = function(texts) {
return Promise.all(texts).then(data => {
TerminalRenderer.prototype.code = function(code, lang, escaped) {
code = setLineSameWidth(code);
return '\n' + indentify(highlight(code, lang, this.o, this.highlightOptions)) + '\n';
};
TerminalRenderer.prototype.list = function(body, ordered) {
body = setLineSameWidth(body);
body = indentLines(this.o.listitem(body));
body = body + '\n';
if (!ordered) return body;
return changeToOrdered(body);
};
TerminalRenderer.prototype.image = function(href, title, text) {
return new Promise((resolve, reject) => {
imageToAscii(href,
{ size: { height: "60%" }
}, (err, converted) => {
if (err) reject(err);
else resolve(converted + "\n");
});
});
};
TerminalRenderer.prototype.heading = function(text, level, raw) {
text = this.transform(text.join(''));
var prefix = this.o.showSectionPrefix ?
(new Array(level + 1)).join('#')+' ' : '';
TerminalRenderer.prototype.heading = function(text, level, raw) {
text = this.transform(text.join(''));
var prefix = this.o.showSectionPrefix ?
(new Array(level + 1)).join('#')+' ' : '';
text = prefix + text;
if (this.o.reflowText) {
text = reflowText(text, this.o.width, this.options.gfm);
}
if (level === 1) {
return this.o.firstHeading(text) + '\n';
}
return '\n' + this.o.heading(text) + '\n';
};
TerminalRenderer.prototype.paragraph = function(texts) {
return Promise.all(texts).then(data => {
var res = '';
data.forEach(i => {
res += i;
});
return '\n' + res + '\n';
});
};
TerminalRenderer.prototype.link = function(href, title, text) {
text = text.join('');
var prot = "";
if (this.options.sanitize) {
try {
prot = decodeURIComponent(unescape(href))
.replace(/[^\w:]/g, '')
return this.o.firstHeading(text) + '\n';
}
return '\n' + this.o.heading(text) + '\n';
};
TerminalRenderer.prototype.paragraph = function(texts) {
return Promise.all(texts).then(data => {
var res = '';
data.forEach(i => {
res += i;
});
return '\n' + res + '\n';
});
};
TerminalRenderer.prototype.link = function(href, title, text) {
text = text.join('');
var prot = "";
if (this.options.sanitize) {
try {
prot = decodeURIComponent(unescape(href))
.replace(/[^\w:]/g, '')
.toLowerCase();
} catch (e) {
return '';
}
if (prot.indexOf('javascript:') === 0) {
return '';
}
}
var hasText = text && text !== href;