-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreporter.ts
35 lines (28 loc) · 910 Bytes
/
reporter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import chalk from 'chalk';
export function log(text: string) {
console.log(text);
}
export function info(text: string) {
console.log(chalk.blue('info'), text);
}
export function success(text: string) {
console.log(chalk.green('success'), text);
}
export function warn(text: string) {
console.log(chalk.yellow('warn'), text);
}
export function error(text: string) {
console.log(chalk.red('error'), text);
}
export function tree(text: string, children) {
function recursiveTree(name = '', nodes = [], prefix = '') {
nodes.sort((a, b) => a.name.localeCompare(b.name));
return `${name}\n${nodes
.map((node, index) => {
const last = index === nodes.length - 1;
return `${prefix}${last ? '└' : '├'}─ ${recursiveTree(node.name, node.children, `${prefix}${last ? ' ' : '│'} `)}`;
})
.join('')}`;
}
console.log(recursiveTree(text, children));
}