From 6ae40688887ea721e7c2ea2b8c2b9c8bc766cd98 Mon Sep 17 00:00:00 2001 From: Ey Pacha! Date: Fri, 14 Jun 2024 12:03:22 -0300 Subject: [PATCH 1/2] feat: add JSON output option --- bin/vta.mjs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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) From 326a420a7d19b904727d87dc352f76e958f11574 Mon Sep 17 00:00:00 2001 From: Ey Pacha! Date: Fri, 14 Jun 2024 12:15:26 -0300 Subject: [PATCH 2/2] docs: add example for valid JSON output to README --- README.md | 3 +++ 1 file changed, 3 insertions(+) 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)