This repository has been archived by the owner on Oct 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
format.js
111 lines (88 loc) · 2.36 KB
/
format.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var path = require('path')
var filesize = require('filesize')
var ProgressBar = require('./bar')
require('colour')
function countEmittedAssets (assets) {
return assets.filter(function (asset) { return asset.emitted }).length
}
function singlespace () {
console.log()
}
function doublespace () {
console.log('\n')
}
function indentLine (n, line) {
return Array(n).join(' ') + line
}
function indentLines (n, lines) {
return lines.split('\n').map(function (line) {
return indentLine(n, line)
}).join('\n')
}
function formatMsgs (msgs) {
if (msgs.length > 0) {
console.error(indentLine(2, 'Messages:'.bold.blue))
msgs.forEach(function (msg, i) {
console.log(indentLines(4, msg))
})
doublespace()
}
}
function formatErrors (errors) {
if (errors.length > 0) {
console.error(indentLine(2, 'Errors:'.bold.red))
errors.forEach(function (error, i) {
console.error(indentLines(4, error))
if (i !== errors.length - 1) { singlespace() }
})
doublespace()
}
}
function formatWarnings (warnings) {
if (warnings.length > 0) {
console.log(indentLine(2, 'Warnings:'.bold.yellow))
warnings.forEach(function (warning, i) {
console.log(indentLines(4, warning))
if (i !== warnings.length - 1) { singlespace() }
})
doublespace()
}
}
function formatStats (config, stats) {
if (countEmittedAssets(stats.assets) > 0) {
console.log(indentLine(2, 'Files:'.bold.green))
stats.assets.forEach(function (asset) {
var pathToAsset = path.relative(process.cwd(), path.join(config.output.path, asset.name))
var sizeOfAsset = filesize(asset.size)
if (asset.emitted) {
console.log(indentLines(4, pathToAsset + ' (' + sizeOfAsset + ')'))
}
})
doublespace()
}
}
exports.pre = function (config) {
if (config._msgs.length > 0) {
doublespace()
}
formatMsgs(config._msgs)
}
exports.done = function (err, config, errors, warnings, stats) {
if (err) {
return console.error(err)
}
if ((errors.length > 0 || warnings.length > 0 || countEmittedAssets(stats.assets) > 0) && config._msgs.length === 0) {
doublespace()
}
formatErrors(errors)
formatWarnings(warnings)
formatStats(config, stats)
}
var bar = new ProgressBar()
exports.progress = function (percent, msg) {
if (percent === 1) {
bar.hide()
} else {
bar.show(msg, percent)
}
}