33'use strict' ;
44
55const Minimist = require ( 'minimist' ) ;
6+ const Util = require ( 'util' ) ;
67
78const NodeSupport = require ( '..' ) ;
89
@@ -11,17 +12,18 @@ const internals = {};
1112internals . 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
1920Options:
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