3
3
'use strict' ;
4
4
5
5
const Minimist = require ( 'minimist' ) ;
6
+ const Util = require ( 'util' ) ;
6
7
7
8
const NodeSupport = require ( '..' ) ;
8
9
@@ -11,17 +12,18 @@ const internals = {};
11
12
internals . help = ( ) => {
12
13
13
14
return `
14
- Usage: detect-node-support [--deps] <what>
15
+ Usage: detect-node-support [--deps] [--json] <what>
15
16
16
17
<what> can be an npm package name, or a Github URL, or a path
17
18
with a package.json.
18
19
19
20
Options:
20
21
--deps Include the support information of all dependencies
22
+ --json Print JSON formatted output
21
23
` ;
22
24
} ;
23
25
24
- exports . main = async ( { _ : [ what ] , deps } ) => {
26
+ exports . main = async ( { _ : [ what ] , deps, json } ) => {
25
27
26
28
if ( ! what ) {
27
29
console . log ( internals . help ( ) ) ;
@@ -30,10 +32,15 @@ exports.main = async ({ _: [what], deps }) => {
30
32
31
33
const result = await NodeSupport . detect ( what , { deps } ) ;
32
34
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
+ }
34
41
} ;
35
42
36
- exports . main ( Minimist ( process . argv . slice ( 2 ) , { boolean : 'deps' } ) )
43
+ exports . main ( Minimist ( process . argv . slice ( 2 ) , { boolean : [ 'deps' , 'json' ] } ) )
37
44
. catch ( ( err ) => {
38
45
39
46
console . error ( err ) ;
0 commit comments