@@ -6,15 +6,9 @@ const glob = require('glob');
6
6
const { hideBin } = require ( 'yargs/helpers' ) ;
7
7
const yargs = require ( 'yargs/yargs' ) ;
8
8
9
- const packageNames = require ( './util /packageNames' ) ;
9
+ const packageNames = require ( 'vx /packageNames' ) ;
10
10
const vxPath = require ( 'vx/vxPath' ) ;
11
11
12
- require ( './scripts/genTsConfig' ) ;
13
-
14
- const { _ : args , ...options } = yargs ( hideBin ( process . argv ) ) . argv ;
15
-
16
- const [ command , target = insidePackageDir ( ) ] = args ;
17
-
18
12
const commands = glob
19
13
. sync ( `./commands/*.js` , {
20
14
cwd : vxPath . VX_ROOT_PATH ,
@@ -27,11 +21,36 @@ const commands = glob
27
21
{ }
28
22
) ;
29
23
24
+ require ( './scripts/genTsConfig' ) ;
25
+
26
+ const argv = hideBin ( process . argv ) ;
27
+
28
+ const cli = yargs ( argv )
29
+ . command ( '$0 <command> [options..]' , 'Run vx monorepo utility' , yargs => {
30
+ yargs . positional ( 'command' , {
31
+ describe : 'Command to run' ,
32
+ choices : Object . keys ( commands ) ,
33
+ demandOption : true ,
34
+ } ) ;
35
+ } )
36
+ . option ( 'packageName' , {
37
+ alias : 'p' ,
38
+ choices : packageNames . list ,
39
+ demandOption : false ,
40
+ describe : 'Optional. Package to run the command on.' ,
41
+ } )
42
+ . help ( ) . argv ;
43
+
44
+ // is there a better way of doing this?
45
+ const options = argv . slice ( cli . packageName ? 3 : 1 ) . join ( ' ' ) ;
46
+
47
+ const { packageName = insidePackageDir ( ) , command } = cli ;
48
+
30
49
if ( ! commands [ command ] ) {
31
50
throw new Error ( `Command ${ command } not found.` ) ;
32
51
}
33
52
34
- commands [ command ] ( target , options ) ;
53
+ commands [ command ] ( packageName , options ) ;
35
54
36
55
function insidePackageDir ( ) {
37
56
if ( ! process . cwd ( ) . includes ( vxPath . PACKAGES_PATH ) ) {
0 commit comments