1 | let { log, warn, error, info, time, timeEnd } = console;
|
2 | let { color } = new (require('./string'))();
|
3 | let { NODE_ENV } = process.env;
|
4 | let testing = (NODE_ENV === 'test') || (NODE_ENV === 'testing');
|
5 | let anon = () => {};
|
6 | let config;
|
7 | let disabled;
|
8 | let enabled;
|
9 |
|
10 | try {
|
11 | config = require(path.join(process.cwd(), 'config'));
|
12 | } catch (err) {
|
13 | config = {};
|
14 | }
|
15 |
|
16 | disabled = testing && !config.enableConsoleMethodsWhenTesting;
|
17 | enabled = !disabled;
|
18 |
|
19 | exports.log = disabled ? anon : log;
|
20 | exports.warn = disabled ? anon : warn;
|
21 | exports.error = disabled ? anon : error;
|
22 | exports.info = disabled ? anon : info;
|
23 | exports.time = disabled ? anon : time;
|
24 | exports.timeEnd = disabled ? anon : timeEnd;
|
25 |
|
26 | exports.verbose = function (...args) {
|
27 | if (disabled) return;
|
28 | if (process.verbose) {
|
29 | log(args);
|
30 | }
|
31 | }
|
32 |
|
33 | exports.chalk = {
|
34 |
|
35 | ok (...args) {
|
36 | if (disabled) return;
|
37 | log(color(args.map(a => {
|
38 | return (typeof a === typeof {}) ? JSON.stringify(a, null, 2) : a;
|
39 | }).join('\n'), 'green'));
|
40 | },
|
41 |
|
42 | warn (...args) {
|
43 | if (disabled) return;
|
44 | log(color(args.map(a => {
|
45 | return (typeof a === typeof {}) ? JSON.stringify(a, null, 2) : a;
|
46 | }).join('\n'), 'yellow'));
|
47 | },
|
48 |
|
49 | error (...args) {
|
50 | if (disabled) return;
|
51 | error(color(args.map(a => {
|
52 | return (typeof a === typeof {}) ? JSON.stringify(a, null, 2) : a;
|
53 | }).join('\n'), 'red'));
|
54 | },
|
55 |
|
56 | info (...args) {
|
57 | if (disabled) return;
|
58 | info(color(args.map(a => {
|
59 | return (typeof a === typeof {}) ? JSON.stringify(a, null, 2) : a;
|
60 | }).join('\n'), 'grey'));
|
61 | },
|
62 |
|
63 | verbose (information, _color = 'grey') {
|
64 | if (disabled) return;
|
65 | if (process.verbose) {
|
66 | info(color(information, _color));
|
67 | }
|
68 | }
|
69 |
|
70 | }
|