forked from nodejs/core-validate-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
59 lines (52 loc) · 1.48 KB
/
utils.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
'use strict'
const chalk = require('chalk')
const CHECK = chalk.green('✔')
const X = chalk.red('✖')
const WARN = chalk.yellow('⚠')
exports.CHECK = CHECK
exports.X = X
exports.WARN = WARN
exports.rightPad = function rightPad(str, max) {
const diff = max - str.length + 1
if (diff > 0) {
return `${str}${' '.repeat(diff)}`
}
return str
}
exports.leftPad = function leftPad(str, max) {
const diff = max - str.length + 1
if (diff > 0) {
return `${' '.repeat(diff)}${str}`
}
return str
}
exports.header = (sha, status) => {
switch (status) {
case 'skip':
case 'pass':
const suffix = status === 'skip'
? ' # SKIPPED'
: ''
return `${CHECK} ${chalk.underline(sha)}${suffix}`
case 'fail':
return `${X} ${chalk.underline(sha)}`
}
}
exports.describeRule = function describeRule(rule, max = 20) {
if (rule.meta && rule.meta.description) {
const desc = rule.meta.description
const title = exports.leftPad(rule.id, max)
console.log(' %s %s', chalk.red(title), chalk.dim(desc))
}
}
exports.describeSubsystem = function describeSubsystem(subsystems, max = 20) {
if (subsystems) {
for (let sub = 0; sub < subsystems.length; sub = sub + 3) {
console.log('%s %s %s',
chalk.green(exports.leftPad(subsystems[sub] || '', max)),
chalk.green(exports.leftPad(subsystems[sub + 1] || '', max)),
chalk.green(exports.leftPad(subsystems[sub + 2] || '', max))
)
}
}
}