@@ -12,7 +12,7 @@ import buildModule from './targets/module';
1212import buildTypescript from './targets/typescript' ;
1313import buildCodegen from './targets/codegen' ;
1414import customTarget from './targets/custom' ;
15- import type { Options , Report , Target } from './types' ;
15+ import type { Options , Target } from './types' ;
1616
1717type ArgName = 'target' ;
1818
5858 }
5959
6060 if ( ! ( await fs . pathExists ( projectPackagePath ) ) ) {
61- logger . exit (
61+ logger . error (
6262 `Couldn't find a 'package.json' file in '${ root } '.\n Are you in a project folder?`
6363 ) ;
64+ process . exit ( 1 ) ;
6465 }
6566
6667 const pkg = JSON . parse ( await fs . readFile ( projectPackagePath , 'utf-8' ) ) ;
@@ -98,10 +99,10 @@ yargs
9899 }
99100
100101 if ( ! entryFile ) {
101- logger . exit (
102+ logger . error (
102103 `Couldn't find a 'index.js'. 'index.ts' or 'index.tsx' file under '${ source } '.\n Please re-run the CLI after creating it.`
103104 ) ;
104- return ;
105+ process . exit ( 1 ) ;
105106 }
106107
107108 pkg . devDependencies = Object . fromEntries (
@@ -463,71 +464,56 @@ yargs
463464 const result = await explorer . search ( ) ;
464465
465466 if ( ! result ?. config ) {
466- logger . exit (
467+ logger . error (
467468 `No configuration found. Run '${ argv . $0 } init' to create one automatically.`
468469 ) ;
470+ process . exit ( 1 ) ;
469471 }
470472
471473 const options : Options = result ! . config ;
472474
473475 if ( ! options . targets ?. length ) {
474- logger . exit (
476+ logger . error (
475477 `No targets found in the configuration in '${ path . relative (
476478 root ,
477479 result ! . filepath
478480 ) } '.`
479481 ) ;
482+ process . exit ( 1 ) ;
480483 }
481484
482485 const source = options . source ;
483486
484487 if ( ! source ) {
485- logger . exit (
488+ logger . error (
486489 `No source option found in the configuration in '${ path . relative (
487490 root ,
488491 result ! . filepath
489492 ) } '.`
490493 ) ;
494+ process . exit ( 1 ) ;
491495 }
492496
493497 const output = options . output ;
494498
495499 if ( ! output ) {
496- logger . exit (
500+ logger . error (
497501 `No source option found in the configuration in '${ path . relative (
498502 root ,
499503 result ! . filepath
500504 ) } '.`
501505 ) ;
506+ process . exit ( 1 ) ;
502507 }
503508
504509 const exclude =
505510 options . exclude ?? '**/{__tests__,__fixtures__,__mocks__}/**' ;
506511
507- const report = {
508- info : logger . info ,
509- warn : logger . warn ,
510- error : logger . error ,
511- success : logger . success ,
512- } ;
513-
514512 if ( argv . target != null ) {
515- buildTarget (
516- argv . target ,
517- report ,
518- source as string ,
519- output as string ,
520- exclude
521- ) ;
513+ buildTarget ( argv . target , source as string , output as string , exclude ) ;
522514 } else {
523515 for ( const target of options . targets ! ) {
524- buildTarget (
525- target ,
526- report ,
527- source as string ,
528- output as string ,
529- exclude
530- ) ;
516+ buildTarget ( target , source as string , output as string , exclude ) ;
531517 }
532518 }
533519 } )
@@ -537,15 +523,14 @@ yargs
537523
538524async function buildTarget (
539525 target : Exclude < Options [ 'targets' ] , undefined > [ number ] ,
540- report : Report ,
541526 source : string ,
542527 output : string ,
543528 exclude : string
544529) {
545530 const targetName = Array . isArray ( target ) ? target [ 0 ] : target ;
546531 const targetOptions = Array . isArray ( target ) ? target [ 1 ] : undefined ;
547532
548- report . info ( `Building target ${ kleur . blue ( targetName ) } ` ) ;
533+ const report = logger . grouped ( targetName ) ;
549534
550535 switch ( targetName ) {
551536 case 'commonjs' :
@@ -594,6 +579,7 @@ async function buildTarget(
594579 } ) ;
595580 break ;
596581 default :
597- logger . exit ( `Invalid target ${ kleur . blue ( targetName ) } .` ) ;
582+ logger . error ( `Invalid target ${ kleur . blue ( targetName ) } .` ) ;
583+ process . exit ( 1 ) ;
598584 }
599585}
0 commit comments