@@ -28,12 +28,16 @@ const access = async (path) => {
2828 }
2929} ;
3030
31- const exit = ( error ) => {
31+ const error = ( e ) => {
3232 /* eslint-disable no-console */
33- console . error ( `${ error . name } : ${ error . message } ` ) ;
34- if ( error . cause ) {
35- console . error ( ` ${ error . cause . name } : ${ error . cause . message } ` ) ;
33+ console . error ( `${ e . name } : ${ e . message } ` ) ;
34+ if ( e . cause ) {
35+ console . error ( ` ${ e . cause . name } : ${ e . cause . message } ` ) ;
3636 }
37+ } ;
38+
39+ const exit = ( e ) => {
40+ error ( e ) ;
3741 /* eslint-enable no-console */
3842 process . exit ( 1 ) ;
3943} ;
@@ -265,13 +269,26 @@ class Worker {
265269
266270const main = async ( ) => {
267271 try {
268- const args = { inputs : [ ] , measure : false , profile : false } ;
272+ const args = { inputs : [ ] , measure : false , profile : false , continue : false , serial : false } ;
269273 if ( process . argv . length > 2 ) {
270274 for ( const arg of process . argv . slice ( 2 ) ) {
271275 switch ( arg ) {
272- case 'measure' : args . measure = true ; break ;
273- case 'profile' : args . profile = true ; break ;
274- default : args . inputs . push ( arg ) ; break ;
276+ case 'measure' : args . measure = true ; args . serial = true ; break ;
277+ case 'profile' : args . profile = true ; args . serial = true ; break ;
278+ case 'continue' : args . continue = true ; args . serial = true ; break ;
279+ default : {
280+ // eslint-disable-next-line no-await-in-loop
281+ const exists = await access ( arg ) ;
282+ if ( exists || ! / [ * ? [ \] ] / . test ( arg ) ) {
283+ args . inputs . push ( arg ) ;
284+ } else {
285+ const iterator = fs . glob ( arg , { cwd : process . cwd ( ) } ) ;
286+ // eslint-disable-next-line no-await-in-loop
287+ const files = await Array . fromAsync ( iterator ) ;
288+ args . inputs . push ( ...files ) ;
289+ }
290+ break ;
291+ }
275292 }
276293 }
277294 }
@@ -280,7 +297,7 @@ const main = async () => {
280297 const patterns = paths ? [ ] : args . inputs ;
281298 const targets = paths ? args . inputs . map ( ( path ) => ( { target : path , tags : 'quantization,validation' } ) ) : await configuration ( ) ;
282299 const queue = new Queue ( targets , patterns ) ;
283- const threads = args . measure || inspector . url ( ) ? 1 : undefined ;
300+ const threads = args . serial || inspector . url ( ) ? 1 : undefined ;
284301 const logger = new Logger ( threads ) ;
285302 let measures = null ;
286303 if ( args . measure ) {
@@ -303,17 +320,32 @@ const main = async () => {
303320 }
304321 if ( threads === 1 ) {
305322 const worker = await import ( './worker.js' ) ;
323+ const total = queue . length ;
324+ let success = 0 ;
306325 for ( let item = queue . pop ( ) ; item ; item = queue . pop ( ) ) {
307326 const target = new worker . Target ( item ) ;
308327 target . measures = measures ? new Map ( ) : null ;
328+ target . serial = args . serial ;
309329 target . on ( 'status' , ( sender , message ) => logger . update ( '' , message ) ) ;
310330 /* eslint-disable no-await-in-loop */
311- await target . execute ( ) ;
331+ try {
332+ await target . execute ( ) ;
333+ success += 1 ;
334+ } catch ( e ) {
335+ if ( args . continue ) {
336+ error ( e ) ;
337+ } else {
338+ exit ( e ) ;
339+ }
340+ }
312341 if ( target . measures ) {
313342 await measures . add ( target . measures ) ;
314343 }
315344 /* eslint-enable no-await-in-loop */
316345 }
346+ if ( args . continue ) {
347+ write ( ` ${ success } / ${ total } = ${ success * 100 / total } %\n` ) ;
348+ }
317349 } else {
318350 const threads = Math . min ( 10 , Math . round ( 0.7 * os . cpus ( ) . length ) , queue . length ) ;
319351 const identifiers = [ ...new Array ( threads ) . keys ( ) ] . map ( ( value ) => value . toString ( ) ) ;
0 commit comments