@@ -12,7 +12,7 @@ import buildModule from './targets/module';
12
12
import buildTypescript from './targets/typescript' ;
13
13
import buildCodegen from './targets/codegen' ;
14
14
import customTarget from './targets/custom' ;
15
- import type { Options , Report , Target } from './types' ;
15
+ import type { Options , Target } from './types' ;
16
16
17
17
type ArgName = 'target' ;
18
18
58
58
}
59
59
60
60
if ( ! ( await fs . pathExists ( projectPackagePath ) ) ) {
61
- logger . exit (
61
+ logger . error (
62
62
`Couldn't find a 'package.json' file in '${ root } '.\n Are you in a project folder?`
63
63
) ;
64
+ process . exit ( 1 ) ;
64
65
}
65
66
66
67
const pkg = JSON . parse ( await fs . readFile ( projectPackagePath , 'utf-8' ) ) ;
@@ -98,10 +99,10 @@ yargs
98
99
}
99
100
100
101
if ( ! entryFile ) {
101
- logger . exit (
102
+ logger . error (
102
103
`Couldn't find a 'index.js'. 'index.ts' or 'index.tsx' file under '${ source } '.\n Please re-run the CLI after creating it.`
103
104
) ;
104
- return ;
105
+ process . exit ( 1 ) ;
105
106
}
106
107
107
108
pkg . devDependencies = Object . fromEntries (
@@ -463,71 +464,56 @@ yargs
463
464
const result = await explorer . search ( ) ;
464
465
465
466
if ( ! result ?. config ) {
466
- logger . exit (
467
+ logger . error (
467
468
`No configuration found. Run '${ argv . $0 } init' to create one automatically.`
468
469
) ;
470
+ process . exit ( 1 ) ;
469
471
}
470
472
471
473
const options : Options = result ! . config ;
472
474
473
475
if ( ! options . targets ?. length ) {
474
- logger . exit (
476
+ logger . error (
475
477
`No targets found in the configuration in '${ path . relative (
476
478
root ,
477
479
result ! . filepath
478
480
) } '.`
479
481
) ;
482
+ process . exit ( 1 ) ;
480
483
}
481
484
482
485
const source = options . source ;
483
486
484
487
if ( ! source ) {
485
- logger . exit (
488
+ logger . error (
486
489
`No source option found in the configuration in '${ path . relative (
487
490
root ,
488
491
result ! . filepath
489
492
) } '.`
490
493
) ;
494
+ process . exit ( 1 ) ;
491
495
}
492
496
493
497
const output = options . output ;
494
498
495
499
if ( ! output ) {
496
- logger . exit (
500
+ logger . error (
497
501
`No source option found in the configuration in '${ path . relative (
498
502
root ,
499
503
result ! . filepath
500
504
) } '.`
501
505
) ;
506
+ process . exit ( 1 ) ;
502
507
}
503
508
504
509
const exclude =
505
510
options . exclude ?? '**/{__tests__,__fixtures__,__mocks__}/**' ;
506
511
507
- const report = {
508
- info : logger . info ,
509
- warn : logger . warn ,
510
- error : logger . error ,
511
- success : logger . success ,
512
- } ;
513
-
514
512
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 ) ;
522
514
} else {
523
515
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 ) ;
531
517
}
532
518
}
533
519
} )
@@ -537,15 +523,14 @@ yargs
537
523
538
524
async function buildTarget (
539
525
target : Exclude < Options [ 'targets' ] , undefined > [ number ] ,
540
- report : Report ,
541
526
source : string ,
542
527
output : string ,
543
528
exclude : string
544
529
) {
545
530
const targetName = Array . isArray ( target ) ? target [ 0 ] : target ;
546
531
const targetOptions = Array . isArray ( target ) ? target [ 1 ] : undefined ;
547
532
548
- report . info ( `Building target ${ kleur . blue ( targetName ) } ` ) ;
533
+ const report = logger . grouped ( targetName ) ;
549
534
550
535
switch ( targetName ) {
551
536
case 'commonjs' :
@@ -594,6 +579,7 @@ async function buildTarget(
594
579
} ) ;
595
580
break ;
596
581
default :
597
- logger . exit ( `Invalid target ${ kleur . blue ( targetName ) } .` ) ;
582
+ logger . error ( `Invalid target ${ kleur . blue ( targetName ) } .` ) ;
583
+ process . exit ( 1 ) ;
598
584
}
599
585
}
0 commit comments