File size: 881 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env node
const path = require( 'path' );
const yargs = require( 'yargs' );
const { getEffectiveTreeAsTree, getEffectiveTreeAsList } = require( './index.js' );

const args = yargs
	.usage( 'Usage: $0' )
	.options( {
		root: {
			alias: 'r',
			describe: 'Path of the root package.json. Defaults to ./package.json',
			default: path.join( process.cwd(), 'package.json' ),
		},
		output: {
			alias: 'o',
			describe: 'Output to generate',
			choices: [ 'tree', 'list' ],
			default: 'tree',
		},
	} )
	.example( '$0', 'generate the tree for the project in the current directory' )
	.example( '$0 --root "./src"', 'generate the tree for the project inside ./src' )
	.help( 'h' )
	.alias( 'h', 'help' ).argv;

let tree;
if ( args.output === 'tree' ) {
	tree = getEffectiveTreeAsTree( args.root );
} else {
	tree = getEffectiveTreeAsList( args.root );
}
console.log( tree );