From 4619f9706d97919991231ec17c7ec953d7911c42 Mon Sep 17 00:00:00 2001 From: Tianyu Yao Date: Fri, 19 Jan 2024 14:40:11 -0800 Subject: [PATCH] Add a json output option Reviewed By: voideanvalue Differential Revision: D52855914 fbshipit-source-id: 5345a12c851d9dabc2ae291c2e4c6adcd4f0c9bb --- .../relay-compiler/src/status_reporter.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/compiler/crates/relay-compiler/src/status_reporter.rs b/compiler/crates/relay-compiler/src/status_reporter.rs index e22389f861cf1..9d96b01999198 100644 --- a/compiler/crates/relay-compiler/src/status_reporter.rs +++ b/compiler/crates/relay-compiler/src/status_reporter.rs @@ -151,3 +151,23 @@ impl StatusReporter for ConsoleStatusReporter { } } } + +pub struct JSONStatusReporter; + +impl StatusReporter for JSONStatusReporter { + fn build_starts(&self) {} + + fn build_completes(&self, diagnostics: &[Diagnostic]) { + println!( + "{{\"completed\":true,\"diagnostics\":{}}}", + serde_json::to_string(diagnostics).unwrap() + ); + } + + fn build_errors(&self, error: &Error) { + println!( + "{{\"completed\":false,\"error\":{}}}", + serde_json::to_string(error).unwrap() + ); + } +}