Skip to content

Commit 281c8ec

Browse files
authored
feat: use log sysmbols for easier to read output (#21) (#104)
1 parent 6f8e5a0 commit 281c8ec

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

packages/lockfile-lint/__tests__/cli.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('CLI tests', () => {
5959
expect(output).toContain(
6060
'detected invalid protocol for package: ms@^2.1.1\n expected: https:\n actual: http:\n'
6161
)
62-
expect(output).toContain('error: command failed with exit code 1')
62+
expect(output).toContain('Error: security issues detected!')
6363
done()
6464
})
6565
})

packages/lockfile-lint/bin/lockfile-lint.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44
const debug = require('debug')('lockfile-lint')
55
const main = require('../src/main')
66

7+
const isSupported =
8+
process.platform !== 'win32' || process.env.CI || process.env.TERM === 'xterm-256color'
9+
10+
const symbolsDefault = {
11+
info: 'ℹ',
12+
success: '✔',
13+
error: '✖'
14+
}
15+
16+
const symbolsFallback = {
17+
info: 'i',
18+
success: '√',
19+
error: '×'
20+
}
21+
22+
const symbols = isSupported ? symbolsDefault : symbolsFallback
23+
24+
const RESET = '\x1b[0m'
25+
const RED = '\x1b[31m'
26+
const GREEN = '\x1b[32m'
27+
const YELLOW = '\x1b[33m'
28+
729
let config
830

931
try {
@@ -57,10 +79,15 @@ try {
5779
validators
5880
})
5981
} catch (error) {
60-
console.error('ABORTING lockfile lint process due to error exceptions', '\n')
82+
console.error(
83+
YELLOW,
84+
`${symbols.info} ABORTING lockfile lint process due to error exceptions`,
85+
'\n',
86+
RESET
87+
)
6188
console.error(error.message, '\n')
6289
console.error(error.stack, '\n')
63-
console.error('error: command failed with exit code 1', '\n')
90+
console.error(RED, `${symbols.error} Error: command failed with exit code 1`, '\n', RESET)
6491
process.exit(1)
6592
}
6693

@@ -71,10 +98,8 @@ debug(`total validator failures: ${validatorFailures}`)
7198
debug(`total validator successes: ${validatorSuccesses}`)
7299

73100
if (validatorFailures !== 0) {
74-
console.error('error: command failed with exit code 1', '\n')
101+
console.error(RED, `${symbols.error} Error: security issues detected!`, '\n', RESET)
75102
process.exit(1)
76103
} else {
77-
const GREEN = '\x1b[32m'
78-
const RESET = '\x1b[0m'
79-
console.info(GREEN, 'No issues detected', '\n', RESET)
104+
console.info(GREEN, `${symbols.success} No issues detected`, '\n', RESET)
80105
}

0 commit comments

Comments
 (0)