Skip to content

Commit 85cd836

Browse files
committed
Print results as JSON
1 parent 932dd86 commit 85cd836

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

resolver/src/bin/format.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import parseArgs from "minimist";
44
import {Resource as ResourceParser} from "../lib/parser";
55
import {Resource} from "../ast";
66
import {Bundle} from "../bundle";
7+
import {ErrorKind} from "../error";
78

89
const argv = parseArgs(process.argv.slice(2), {
910
boolean: ["help"],
@@ -57,14 +58,22 @@ function format(resource: Resource) {
5758
let bundle = new Bundle();
5859
bundle.addResource(resource);
5960

61+
let results = [];
6062
for (let entry of resource.body) {
6163
let message = bundle.getMessage(entry.id.name);
6264
if (message) {
6365
let {value, errors} = bundle.formatValue(message, new Map());
64-
console.log(value);
65-
console.log(errors);
66+
results.push({
67+
value,
68+
errors: errors.map(error => ({
69+
kind: ErrorKind[error.kind],
70+
arg: error.arg,
71+
})),
72+
});
6673
}
6774
}
75+
76+
console.log(JSON.stringify(results, null, 4));
6877
}
6978

7079
function parseStdin() {

0 commit comments

Comments
 (0)