feat(agents): json-viewer use jq cli other than node-jq module (#163)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"@inquirer/input": "^4.0.2",
|
||||
"json-schema-generator": "^2.0.6",
|
||||
"node-jq": "^6.0.1"
|
||||
"json-schema-generator": "^2.0.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
const fs = require("node:fs/promises");
|
||||
const { exec } = require("node:child_process");
|
||||
const { exec, spawn } = require("node:child_process");
|
||||
const { promisify } = require("node:util");
|
||||
const path = require("node:path");
|
||||
const { tmpdir } = require("node:os");
|
||||
|
||||
const jq = require("node-jq");
|
||||
const jsonSchemaGenerator = require("json-schema-generator");
|
||||
const input = require("@inquirer/input").default;
|
||||
|
||||
@@ -44,6 +43,19 @@ json_schema: ${JSON.stringify(json_schema, null, 2)}
|
||||
*/
|
||||
exports.print_json = async function (args) {
|
||||
const { json_file_path, jq_expr } = args;
|
||||
const result = await jq.run(jq_expr, json_file_path, { raw: true });
|
||||
console.log(result);
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn("jq", ["-r", jq_expr, json_file_path], { stdio: "inherit" });
|
||||
|
||||
child.on('close', code => {
|
||||
if (code === 0) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error(`jq exited with code ${code}`));
|
||||
}
|
||||
});
|
||||
|
||||
child.on('error', err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user