11#!/usr/bin/env node
22
3- const fs = require ( "fs" ) ;
43const path = require ( "path" ) ;
54const readline = require ( "readline" ) ;
65
@@ -37,31 +36,21 @@ async function main() {
3736 const [ node , dispatcher , ...rest ] = argv ;
3837 const flags = rest . filter ( ( f ) => f . startsWith ( "--" ) ) ;
3938 const options = {
40- dry : flags . includes ( "--dry" ) ,
4139 help : flags . includes ( "--help" ) || rest . length === 0 ,
42- confirm : flags . includes ( "--c" ) ,
4340 } ;
4441
4542 if ( options . help ) {
4643 console . info ( `
4744 Usage:
4845 b [package query words] - [command query words]
49- b c s3 c - b t
46+ b c s3 c - b t, b cjs
5047
5148 matches to:
52- (cd clients/client-s3-control && yarn build:types)
49+ (cd clients/client-s3-control && yarn build:types && yarn build:cjs )
5350
5451 Query words are substrings that match against the package name and npm scripts.
5552 The substrings must appear in order for a match.
5653 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.
6554` ) ;
6655 return 0 ;
6756 }
@@ -70,6 +59,10 @@ async function main() {
7059 const separatorIndex = rest . indexOf ( "-" ) !== - 1 ? rest . indexOf ( "-" ) : rest . length ;
7160 const query = nonFlags . slice ( 0 , separatorIndex ) ;
7261 const commands = nonFlags . slice ( separatorIndex + 1 ) ;
62+ const multiCommands = commands
63+ . join ( " " )
64+ . split ( / , \s ? / )
65+ . map ( ( c ) => c . split ( " " ) ) ;
7366
7467 const matchedPackages = findFolders ( allPackages , ...query ) ;
7568
@@ -85,59 +78,42 @@ async function main() {
8578 ) ;
8679
8780 const [ target ] = matchedPackages ;
88-
8981 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- }
9782
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 ) ;
10285
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+ }
10590
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+ }
10795
108- if ( options . dry ) {
109- console . log ( "DRYRUN:" , command ) ;
110- return 0 ;
96+ console . log ( "commands:" , ...commands ) ;
97+ console . log ( "matched commands:" , matchedScripts ) ;
11198 }
11299
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 ( ) ;
137115 }
138116
139- await execute ( ) ;
140-
141117 return 0 ;
142118}
143119
0 commit comments