Skip to content

Commit

Permalink
STY: Prettify logging; make it verbose
Browse files Browse the repository at this point in the history
In brief:
- Use bold font for "titles".
- Use Dim magenta, and icons, for verbose logs.
- Use an italic font for data logs.
- Add command args to verbose logs.

Update src/lib/log.js:
- Use bold font for info logs.
- Use italic font for data logs.
- Use dim magenta font for verbose logs.

Update bin/bli:
- Remove ellipsis from log.

Update src/handle-event.js:
- Make status log verbose by printing the cmd and its args.
- Show status log as verbose/error log.
- Simplify status log: use ticks and cross icons for status log.

Update src/lib/run-cmd.js:
- Add newline before each info log.
- Print cmd and its args as a verbose log.

Update src/stop.js:
- Add newline before end log.
- Remove ellipsis from end log.

Update test/integration/cli.test.js:
- Remove ellipsis from commands.
- Add newlines on end commands.
  • Loading branch information
AlexisPuga committed Sep 11, 2021
1 parent 949528c commit 1b337d7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const { argv } = yargs(hideBin(process.argv))
}, async (argv) => {
process.on('exit', shutdown)

log('info', 'Starting precise-watcher...')
log('info', 'Starting precise-watcher')
await start(argv)
})
.command('stop', 'Stop watching files.', {}, () => stop())
2 changes: 1 addition & 1 deletion src/handle-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ module.exports = (eventName, commands, {

debug(`Running ${cmd}, args: ${JSON.stringify(cmdArgs)}, options: ${JSON.stringify(cmdOptions)}.`)
runCmd(cmd, cmdArgs, cmdOptions).then(async (status) => {
log('info', `${cmd} exited with status ${status}`)
log(`${status > 0 ? 'error' : 'verbose'}`, `${status > 0 ? '✕' : '✓'} ${cmd} ${cmdArgs.join(' ')}`)

if (serial) {
debug('Calling next command in serial...')
Expand Down
6 changes: 3 additions & 3 deletions src/lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const colors = require('colors/safe')
colors.setTheme({
silly: 'rainbow',
input: 'grey',
verbose: 'cyan',
verbose: ['dim', 'magenta'],
prompt: 'grey',
info: 'green',
data: 'grey',
info: 'bold',
data: 'italic',
help: 'cyan',
warn: 'yellow',
debug: 'blue',
Expand Down
3 changes: 2 additions & 1 deletion src/lib/run-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = async (cmd, args, options) => await new Promise((resolve, rejec
const child = spawn(cmd, args, options)
const { stdout, stderr } = child

log('info', `Running ${cmd}`)
log('info', `\nRunning ${cmd}`)
log('verbose', `▸ ${cmd} ${args.join(' ')}`)

stdout.on('data', (data) => {
log('data', data.toString())
Expand Down
2 changes: 1 addition & 1 deletion src/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const removeAllWatchers = async (watchers) => await Promise.all(
)

module.exports = async (watchers) => {
log('info', 'Stopping precise-watcher...')
log('info', '\nStopping precise-watcher')

if (!watchers) {
debug('Removing all watchers.')
Expand Down
10 changes: 5 additions & 5 deletions test/integration/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ describe('precise-watcher', () => {

expect(stderr).toBe('')
expect(stdout).toBe([
'Starting precise-watcher...',
'Stopping precise-watcher...'
'Starting precise-watcher',
'\nStopping precise-watcher'
].join('\n') + '\n')
})

Expand Down Expand Up @@ -52,8 +52,8 @@ describe('precise-watcher', () => {
expect(stderr).toMatch(`Setting config to ${config}`)
expect(stderr).toMatch(`Reading ${path.join(cwd, config)}`)
expect(stdout).toBe([
'Starting precise-watcher...',
'Stopping precise-watcher...'
'Starting precise-watcher',
'\nStopping precise-watcher'
].join('\n') + '\n')
})

Expand All @@ -63,6 +63,6 @@ describe('precise-watcher', () => {
})

expect(stderr).toBe('')
expect(stdout).toBe('Stopping precise-watcher...\n')
expect(stdout).toBe('\nStopping precise-watcher\n')
})
})

0 comments on commit 1b337d7

Please sign in to comment.