Skip to content

Commit 0d0307e

Browse files
committed
feat: add a strict json formatting option
1 parent fd2a638 commit 0d0307e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

bin/detect-node-support

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
'use strict';
44

55
const Minimist = require('minimist');
6+
const Util = require('util');
67

78
const NodeSupport = require('..');
89

@@ -11,17 +12,18 @@ const internals = {};
1112
internals.help = () => {
1213

1314
return `
14-
Usage: detect-node-support [--deps] <what>
15+
Usage: detect-node-support [--deps] [--json] <what>
1516
1617
<what> can be an npm package name, or a Github URL, or a path
1718
with a package.json.
1819
1920
Options:
2021
--deps Include the support information of all dependencies
22+
--json Print JSON formatted output
2123
`;
2224
};
2325

24-
exports.main = async ({ _: [what], deps }) => {
26+
exports.main = async ({ _: [what], deps, json }) => {
2527

2628
if (!what) {
2729
console.log(internals.help());
@@ -30,10 +32,15 @@ exports.main = async ({ _: [what], deps }) => {
3032

3133
const result = await NodeSupport.detect(what, { deps });
3234

33-
console.log(result);
35+
if (json) {
36+
console.log(JSON.stringify(result, null, ' '));
37+
}
38+
else {
39+
console.log(Util.inspect(result, false, null, true));
40+
}
3441
};
3542

36-
exports.main(Minimist(process.argv.slice(2), { boolean: 'deps' }))
43+
exports.main(Minimist(process.argv.slice(2), { boolean: ['deps', 'json'] }))
3744
.catch((err) => {
3845

3946
console.error(err);

0 commit comments

Comments
 (0)