1
0
Fork 0
freesewing/packages/plugin-debug/src/index.js

65 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-08-09 11:08:54 +02:00
import { version, name } from "../package.json";
2018-09-23 12:19:14 +02:00
const color = {
info: "#FFF",
warning: "#FFF",
error: "#FFF",
success: "#FFF"
};
const background = {
info: "#29ABE0",
warning: "#F47C3C",
error: "#d9534f",
success: "#4caf50"
};
/* Returns an object to style debug output */
function debugStyle(type, text) {
let style = `color: ${color[type]};`;
style += `background: ${background[type]};`;
style += "font-weight: 600;";
style += "padding: 0 5px;";
style += "border-radius: 3px;";
return style;
}
2018-08-09 11:08:54 +02:00
export default {
name: name,
version: version,
hooks: {
debug: function(next, d = "", e = "", b = "", u = "", g = "") {
if(typeof d === 'object' && d.debug === 'custom') {
console.log(
"%c"+d.text,
d.style,
e,
b,
u,
g
2018-08-09 11:08:54 +02:00
);
2018-09-23 12:19:14 +02:00
} else if(typeof d === 'object' && typeof d.style !== 'undefined') {
console.log(
"%c"+d.text,
debugStyle(d.style),
e,
b,
u,
g
);
} else {
console.log(
"%cDebug",
"color: #dd69dd; font-weight: bold",
d,
e,
b,
u,
g
);
}
2018-08-09 11:08:54 +02:00
next();
}
}
};