1
1
#!/usr/bin/env node
2
2
3
- const fs = require ( "fs" ) ;
4
3
const path = require ( "path" ) ;
5
4
const readline = require ( "readline" ) ;
6
5
@@ -37,31 +36,21 @@ async function main() {
37
36
const [ node , dispatcher , ...rest ] = argv ;
38
37
const flags = rest . filter ( ( f ) => f . startsWith ( "--" ) ) ;
39
38
const options = {
40
- dry : flags . includes ( "--dry" ) ,
41
39
help : flags . includes ( "--help" ) || rest . length === 0 ,
42
- confirm : flags . includes ( "--c" ) ,
43
40
} ;
44
41
45
42
if ( options . help ) {
46
43
console . info ( `
47
44
Usage:
48
45
b [package query words] - [command query words]
49
- b c s3 c - b t
46
+ b c s3 c - b t, b cjs
50
47
51
48
matches to:
52
- (cd clients/client-s3-control && yarn build:types)
49
+ (cd clients/client-s3-control && yarn build:types && yarn build:cjs )
53
50
54
51
Query words are substrings that match against the package name and npm scripts.
55
52
The substrings must appear in order for a match.
56
53
Match priority goes to whole-word matching and initial matching.
57
-
58
- Options:
59
- --dry
60
- dry run with no command execution.
61
- --help
62
- show this message.
63
- --c
64
- ask for confirmation before executing command.
65
54
` ) ;
66
55
return 0 ;
67
56
}
@@ -70,6 +59,10 @@ async function main() {
70
59
const separatorIndex = rest . indexOf ( "-" ) !== - 1 ? rest . indexOf ( "-" ) : rest . length ;
71
60
const query = nonFlags . slice ( 0 , separatorIndex ) ;
72
61
const commands = nonFlags . slice ( separatorIndex + 1 ) ;
62
+ const multiCommands = commands
63
+ . join ( " " )
64
+ . split ( / , \s ? / )
65
+ . map ( ( c ) => c . split ( " " ) ) ;
73
66
74
67
const matchedPackages = findFolders ( allPackages , ...query ) ;
75
68
@@ -85,59 +78,42 @@ async function main() {
85
78
) ;
86
79
87
80
const [ target ] = matchedPackages ;
88
-
89
81
const targetPkgJson = require ( path . join ( target . location , "package.json" ) ) ;
90
- const matchedScripts = findScripts ( Object . keys ( targetPkgJson . scripts || { } ) , ...commands ) ;
91
- const [ script ] = matchedScripts ;
92
-
93
- if ( commands . length === 0 ) {
94
- console . info ( "No commands entered" ) ;
95
- return 0 ;
96
- }
97
82
98
- if ( matchedScripts . length === 0 ) {
99
- console . error ( "No matching scripts for command query:" , commands ) ;
100
- return 0 ;
101
- }
83
+ for ( const commands of multiCommands ) {
84
+ const matchedScripts = findScripts ( Object . keys ( targetPkgJson . scripts || { } ) , ...commands ) ;
102
85
103
- console . log ( "commands:" , ...commands ) ;
104
- console . log ( "matched commands:" , matchedScripts ) ;
86
+ if ( commands . length === 0 ) {
87
+ console . info ( "No commands entered" ) ;
88
+ return 0 ;
89
+ }
105
90
106
- const command = `yarn ${ script } in ${ target . location } ` ;
91
+ if ( matchedScripts . length === 0 ) {
92
+ console . error ( "No matching scripts for command query:" , commands ) ;
93
+ return 0 ;
94
+ }
107
95
108
- if ( options . dry ) {
109
- console . log ( "DRYRUN:" , command ) ;
110
- return 0 ;
96
+ console . log ( "commands:" , ...commands ) ;
97
+ console . log ( "matched commands:" , matchedScripts ) ;
111
98
}
112
99
113
- const execute = async ( ) => {
114
- const { spawnProcess } = require ( "../utils/spawn-process" ) ;
115
- console . info ( "Running:" , "yarn" , script ) ;
116
- console . info ( "Location:" , target . location ) ;
117
- await spawnProcess ( "yarn" , [ script ] , {
118
- cwd : target . location ,
119
- stdio : "inherit" ,
120
- } ) ;
121
- return ;
122
- } ;
123
-
124
- if ( options . confirm ) {
125
- const rl = readline . createInterface ( {
126
- input : process . stdin ,
127
- output : process . stdout ,
128
- } ) ;
129
-
130
- rl . question ( `run script "${ script } " in ${ target . location } (y)/n?:` , async ( confirm ) => {
131
- if ( confirm . toLowerCase ( ) . trim ( ) === "y" || confirm === "" ) {
132
- await execute ( ) ;
133
- }
134
- rl . close ( ) ;
135
- } ) ;
136
- return 0 ;
100
+ for ( const commands of multiCommands ) {
101
+ const matchedScripts = findScripts ( Object . keys ( targetPkgJson . scripts || { } ) , ...commands ) ;
102
+ const [ script ] = matchedScripts ;
103
+
104
+ const execute = async ( ) => {
105
+ const { spawnProcess } = require ( "../utils/spawn-process" ) ;
106
+ console . info ( "Running:" , "yarn" , script ) ;
107
+ console . info ( "Location:" , target . location ) ;
108
+ await spawnProcess ( "yarn" , [ script ] , {
109
+ cwd : target . location ,
110
+ stdio : "inherit" ,
111
+ } ) ;
112
+ } ;
113
+
114
+ await execute ( ) ;
137
115
}
138
116
139
- await execute ( ) ;
140
-
141
117
return 0 ;
142
118
}
143
119
0 commit comments