1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.output = void 0;
|
4 | const chalk = require("chalk");
|
5 |
|
6 |
|
7 |
|
8 | if (process.env.CI === 'true') {
|
9 | chalk.level = 0;
|
10 | }
|
11 | class CLIOutput {
|
12 | constructor() {
|
13 | this.NX_PREFIX = `${chalk.cyan('>')} ${chalk.reset.inverse.bold.cyan(' NX ')}`;
|
14 | |
15 |
|
16 |
|
17 |
|
18 | this.VERTICAL_SEPARATOR = '———————————————————————————————————————————————';
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 | this.colors = {
|
25 | gray: chalk.gray,
|
26 | };
|
27 | this.bold = chalk.bold;
|
28 | this.underline = chalk.underline;
|
29 | }
|
30 | writeToStdOut(str) {
|
31 | process.stdout.write(str);
|
32 | }
|
33 | writeOutputTitle({ label, title, }) {
|
34 | let outputTitle;
|
35 | if (label) {
|
36 | outputTitle = `${this.NX_PREFIX} ${label} ${title}\n`;
|
37 | }
|
38 | else {
|
39 | outputTitle = `${this.NX_PREFIX} ${title}\n`;
|
40 | }
|
41 | this.writeToStdOut(outputTitle);
|
42 | }
|
43 | writeOptionalOutputBody(bodyLines) {
|
44 | if (!bodyLines) {
|
45 | return;
|
46 | }
|
47 | this.addNewline();
|
48 | bodyLines.forEach((bodyLine) => this.writeToStdOut(` ${bodyLine}\n`));
|
49 | }
|
50 | addNewline() {
|
51 | this.writeToStdOut('\n');
|
52 | }
|
53 | addVerticalSeparator() {
|
54 | this.writeToStdOut(`\n${chalk.gray(this.VERTICAL_SEPARATOR)}\n\n`);
|
55 | }
|
56 | addVerticalSeparatorWithoutNewLines() {
|
57 | this.writeToStdOut(`${chalk.gray(this.VERTICAL_SEPARATOR)}\n`);
|
58 | }
|
59 | error({ title, slug, bodyLines }) {
|
60 | this.addNewline();
|
61 | this.writeOutputTitle({
|
62 | label: chalk.reset.inverse.bold.red(' ERROR '),
|
63 | title: chalk.bold.red(title),
|
64 | });
|
65 | this.writeOptionalOutputBody(bodyLines);
|
66 | |
67 |
|
68 |
|
69 | if (slug && typeof slug === 'string') {
|
70 | this.addNewline();
|
71 | this.writeToStdOut(`${chalk.grey(' Learn more about this error: ')}https://errors.nx.dev/${slug}\n`);
|
72 | }
|
73 | this.addNewline();
|
74 | }
|
75 | warn({ title, slug, bodyLines }) {
|
76 | this.addNewline();
|
77 | this.writeOutputTitle({
|
78 | label: chalk.reset.inverse.bold.yellow(' WARNING '),
|
79 | title: chalk.bold.yellow(title),
|
80 | });
|
81 | this.writeOptionalOutputBody(bodyLines);
|
82 | |
83 |
|
84 |
|
85 | if (slug && typeof slug === 'string') {
|
86 | this.addNewline();
|
87 | this.writeToStdOut(`${chalk.grey(' Learn more about this warning: ')}https://errors.nx.dev/${slug}\n`);
|
88 | }
|
89 | this.addNewline();
|
90 | }
|
91 | note({ title, bodyLines }) {
|
92 | this.addNewline();
|
93 | this.writeOutputTitle({
|
94 | label: chalk.reset.inverse.bold.keyword('orange')(' NOTE '),
|
95 | title: chalk.bold.keyword('orange')(title),
|
96 | });
|
97 | this.writeOptionalOutputBody(bodyLines);
|
98 | this.addNewline();
|
99 | }
|
100 | success({ title, bodyLines }) {
|
101 | this.addNewline();
|
102 | this.writeOutputTitle({
|
103 | label: chalk.reset.inverse.bold.green(' SUCCESS '),
|
104 | title: chalk.bold.green(title),
|
105 | });
|
106 | this.writeOptionalOutputBody(bodyLines);
|
107 | this.addNewline();
|
108 | }
|
109 | logSingleLine(message) {
|
110 | this.addNewline();
|
111 | this.writeOutputTitle({
|
112 | title: message,
|
113 | });
|
114 | this.addNewline();
|
115 | }
|
116 | logCommand(message, isCached = false) {
|
117 | this.addNewline();
|
118 | this.writeToStdOut(chalk.bold(`> ${message} `));
|
119 | if (isCached) {
|
120 | this.writeToStdOut(chalk.bold.grey(`[retrieved from cache]`));
|
121 | }
|
122 | this.addNewline();
|
123 | }
|
124 | log({ title, bodyLines }) {
|
125 | this.addNewline();
|
126 | this.writeOutputTitle({
|
127 | title: chalk.white(title),
|
128 | });
|
129 | this.writeOptionalOutputBody(bodyLines);
|
130 | this.addNewline();
|
131 | }
|
132 | }
|
133 | exports.output = new CLIOutput();
|
134 |
|
\ | No newline at end of file |