|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import { logging, terminal } from '@angular-devkit/core'; |
| 9 | +import { createConsoleLogger } from '@angular-devkit/core/node'; |
10 | 10 | import { runCommand } from '../../models/command-runner'; |
11 | 11 | import { getWorkspaceRaw } from '../../utilities/config'; |
12 | 12 | import { getWorkspaceDetails } from '../../utilities/project'; |
13 | 13 |
|
14 | 14 |
|
15 | 15 | export default async function(options: { testing?: boolean, cliArgs: string[] }) { |
16 | | - const logger = new logging.IndentLogger('cling'); |
17 | | - let loggingSubscription; |
18 | | - if (!options.testing) { |
19 | | - loggingSubscription = initializeLogging(logger); |
20 | | - } |
| 16 | + const logger = createConsoleLogger(); |
21 | 17 |
|
22 | 18 | let projectDetails = getWorkspaceDetails(); |
23 | 19 | if (projectDetails === null) { |
@@ -60,64 +56,6 @@ export default async function(options: { testing?: boolean, cliArgs: string[] }) |
60 | 56 | throw err; |
61 | 57 | } |
62 | 58 |
|
63 | | - if (loggingSubscription) { |
64 | | - loggingSubscription.unsubscribe(); |
65 | | - } |
66 | | - |
67 | 59 | return 1; |
68 | 60 | } |
69 | 61 | } |
70 | | - |
71 | | -// Initialize logging. |
72 | | -function initializeLogging(logger: logging.Logger) { |
73 | | - return logger |
74 | | - .subscribe(entry => { |
75 | | - let color = (x: string) => terminal.dim(terminal.white(x)); |
76 | | - let output = process.stdout; |
77 | | - switch (entry.level) { |
78 | | - case 'debug': |
79 | | - return; |
80 | | - case 'info': |
81 | | - color = terminal.white; |
82 | | - break; |
83 | | - case 'warn': |
84 | | - color = (x: string) => terminal.bold(terminal.yellow(x)); |
85 | | - output = process.stderr; |
86 | | - break; |
87 | | - case 'fatal': |
88 | | - case 'error': |
89 | | - color = (x: string) => terminal.bold(terminal.red(x)); |
90 | | - output = process.stderr; |
91 | | - break; |
92 | | - } |
93 | | - |
94 | | - |
95 | | - // If we do console.log(message) or process.stdout.write(message + '\n'), the process might |
96 | | - // stop before the whole message is written and the stream is flushed. This happens when |
97 | | - // streams are asynchronous. |
98 | | - // |
99 | | - // NodeJS IO streams are different depending on platform and usage. In POSIX environment, |
100 | | - // for example, they're asynchronous when writing to a pipe, but synchronous when writing |
101 | | - // to a TTY. In windows, it's the other way around. You can verify which is which with |
102 | | - // stream.isTTY and platform, but this is not good enough. |
103 | | - // In the async case, one should wait for the callback before sending more data or |
104 | | - // continuing the process. In our case it would be rather hard to do (but not impossible). |
105 | | - // |
106 | | - // Instead we take the easy way out and simply chunk the message and call the write |
107 | | - // function while the buffer drain itself asynchronously. With a smaller chunk size than |
108 | | - // the buffer, we are mostly certain that it works. In this case, the chunk has been picked |
109 | | - // as half a page size (4096/2 = 2048), minus some bytes for the color formatting. |
110 | | - // On POSIX it seems the buffer is 2 pages (8192), but just to be sure (could be different |
111 | | - // by platform). |
112 | | - // |
113 | | - // For more details, see https://nodejs.org/api/process.html#process_a_note_on_process_i_o |
114 | | - const chunkSize = 2000; // Small chunk. |
115 | | - let message = entry.message; |
116 | | - while (message) { |
117 | | - const chunk = message.slice(0, chunkSize); |
118 | | - message = message.slice(chunkSize); |
119 | | - output.write(color(chunk)); |
120 | | - } |
121 | | - output.write('\n'); |
122 | | - }); |
123 | | -} |
0 commit comments