Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit f11e78f

Browse files
committed
Improve CLI output
1 parent 40780bf commit f11e78f

5 files changed

Lines changed: 18 additions & 20 deletions

File tree

packages/cli/package.json

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,13 @@
88
"devDependencies": {
99
"@sindresorhus/tsconfig": "^3.0.1",
1010
"@types/node": "^18.8.0",
11-
"ava": "^4.3.3",
12-
"nyc": "^15.1.0",
1311
"pkg": "^5.8.0",
14-
"ts-node": "^10.9.1",
12+
"tsx": "^3.9.0",
1513
"typescript": "^4.8.4"
1614
},
1715
"dependencies": {
1816
"github-version-checker": "*",
17+
"pretty-error": "^4.0.0",
1918
"sade": "^1.8.1"
20-
},
21-
"ava": {
22-
"extensions": [
23-
"ts"
24-
],
25-
"require": [
26-
"ts-node/register/transpile-only"
27-
]
2819
}
2920
}

packages/cli/src/action.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import versionCheck from 'github-version-checker'
2-
import { CliArguments } from './types'
2+
import PrettyError from 'pretty-error'
3+
import { CliArguments, JsonOutput } from './types'
34
import { print, printError } from './util'
45

56
function printPretty(result: any, args: CliArguments) {
@@ -11,11 +12,6 @@ function printPretty(result: any, args: CliArguments) {
1112
}
1213
}
1314

14-
function printJson(result: any) {
15-
const json = JSON.stringify(result)
16-
print(json, false)
17-
}
18-
1915
export default async function action(args: CliArguments) {
2016
try {
2117
const result = await versionCheck({
@@ -28,12 +24,21 @@ export default async function action(args: CliArguments) {
2824
})
2925

3026
if (args.json) {
31-
printJson(result)
27+
const output: JsonOutput = {
28+
type: result === undefined ? 'notfound' : 'outdated',
29+
data: result
30+
}
31+
print(JSON.stringify(output), false)
3232
}
3333
else {
3434
printPretty(result, args)
3535
}
3636
} catch (error: any) {
37-
printError(error.message)
37+
if (args.verbose) {
38+
printError(new PrettyError().render(error))
39+
}
40+
else {
41+
printError(error.message)
42+
}
3843
}
3944
}

packages/cli/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ program
1212
.option('--no-pre-releases', 'Excludes pre-releases.', false)
1313
.option('--token', 'A PAT to use.')
1414
.option('--json', 'Outputs the raw result data as JSON.', false)
15+
.option('--verbose', 'Enables verbose logging.', false)
1516
.action(action)
1617

1718
program.parse(process.argv)

packages/cli/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export interface CliArguments {
66
'no-pre-releases': boolean
77
token?: string
88
json: boolean
9+
verbose: boolean
910
}

packages/cli/src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export function print(data: any, newline = true) {
1010
}
1111

1212
export function printError(data: any, newline = true) {
13-
write(process.stderr, data, newline)
13+
write(process.stdout, data, newline)
1414
}

0 commit comments

Comments
 (0)