1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var formatWebpackMessages = require("react-dev-utils/formatWebpackMessages");
|
4 | var chalk = require("chalk");
|
5 | var RED = chalk.red.bind(chalk);
|
6 | var DIM = chalk.dim.bind(chalk);
|
7 | var GREEN = chalk.green.bind(chalk);
|
8 | var WHITE = chalk.white.bind(chalk);
|
9 | var YELLOW = chalk.yellow.bind(chalk);
|
10 | var colorsForLevel = {
|
11 | info: DIM,
|
12 | error: RED,
|
13 | success: GREEN,
|
14 | warning: YELLOW,
|
15 | };
|
16 | function notify(_a) {
|
17 | var title = _a.title, level = _a.level, message = _a.message;
|
18 | var levelColor = colorsForLevel[level] || WHITE;
|
19 | var flag = levelColor("[" + level + "]");
|
20 |
|
21 | console.log(chalk.bold(flag) + " " + chalk.bold(title + " ->") + " " + message);
|
22 | }
|
23 | exports.notify = notify;
|
24 | function logStats(stats, _a) {
|
25 | var name = _a.name, onlyErrors = _a.onlyErrors, matchingStats = _a.matchingStats;
|
26 | var statsObject = stats.toJson();
|
27 | var messages = formatWebpackMessages(statsObject);
|
28 | var matchingMessages = matchingStats
|
29 | ? formatWebpackMessages(matchingStats.toJson())
|
30 | : { errors: [], warnings: [] };
|
31 |
|
32 |
|
33 | var finalMessages = { errors: [], warnings: [] };
|
34 | ['warnings', 'errors'].forEach(function (messageType) {
|
35 | var matchingMessagesOfType = matchingMessages[messageType];
|
36 | finalMessages[messageType] = matchingMessagesOfType.length
|
37 | ? messages[messageType].filter(function (message) { return !matchingMessagesOfType.includes(message); })
|
38 | : messages[messageType];
|
39 | });
|
40 | if (messages.errors.length) {
|
41 | notify({
|
42 | title: name,
|
43 | level: 'error',
|
44 | message: "Build failed." + (finalMessages.errors.length ? '' : ' See errors noted above.'),
|
45 | });
|
46 | }
|
47 | else if (messages.warnings.length) {
|
48 | notify({
|
49 | title: name,
|
50 | level: 'warning',
|
51 | message: "Build had warnings." + (finalMessages.warnings.length ? '' : ' See warnings noted above.'),
|
52 | });
|
53 | }
|
54 | else if (!onlyErrors) {
|
55 | notify({
|
56 | title: name,
|
57 | level: 'success',
|
58 | message: "Compiled with latest changes (" + statsObject.time + "ms)",
|
59 | });
|
60 | }
|
61 | if (finalMessages.errors.length) {
|
62 |
|
63 | console.log();
|
64 | finalMessages.errors.forEach(function (error) {
|
65 |
|
66 | console.log(error + "\n");
|
67 | });
|
68 | }
|
69 | if (finalMessages.warnings.length) {
|
70 |
|
71 | console.log();
|
72 | finalMessages.warnings.forEach(function (warning) {
|
73 |
|
74 | console.log(warning + "\n");
|
75 | });
|
76 | }
|
77 | }
|
78 | exports.logStats = logStats;
|