diff --git a/README.md b/README.md index 27a9dbd..8cfafe5 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/bin/vta.mjs b/bin/vta.mjs index 6b216d7..f9ad0d1 100755 --- a/bin/vta.mjs +++ b/bin/vta.mjs @@ -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 }) { @@ -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)