Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/json output #110

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ vta [url]

# Example
vta https://nuxt.com

# Example for valid JSON output
vta https://nuxt.com --json
```

[![render1585566509798](https://user-images.githubusercontent.com/904724/77906279-fb455d80-7287-11ea-86f2-d7eca773ba56.gif)](https://terminalizer.com/view/a30a95523602)
Expand Down
16 changes: 13 additions & 3 deletions bin/vta.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const main = defineCommand({
type: 'string',
description: 'Browser WS endpoint to use',
required: false
},
json: {
type: 'boolean',
description: 'Output results in JSON format',
required: false
}
},
async setup ({ args }) {
Expand All @@ -39,10 +44,15 @@ const main = defineCommand({
try {
const result = await analyze(args.url, { browserWSEndpoint: args.browser })
spinner.stop()
consola.log(result)

const hrend = process.hrtime(hrstart)
consola.info('Execution time (hr): %ds %dms', hrend[0], hrend[1] / 1000000)
if (args.json) {
console.log(JSON.stringify(result, null, 2))
} else {
consola.log(result)
const hrend = process.hrtime(hrstart)
consola.info('Execution time (hr): %ds %dms', hrend[0], hrend[1] / 1000000)
}

process.exit(0)
} catch (err) {
consola.error(err.message)
Expand Down