11import kleur from 'kleur' ;
22import path from 'path' ;
3+ import fs from 'fs-extra' ;
34import type { Input } from '../types' ;
45import { spawn } from '../utils/spawn' ;
56import dedent from 'dedent' ;
@@ -23,14 +24,14 @@ export default async function customTarget({ options, root, report }: Options) {
2324 process . exit ( 1 ) ;
2425 }
2526
26- if ( options . clean ) {
27- report . info (
28- `Cleaning up ${ kleur . blue (
29- path . relative ( root , options . clean )
30- ) } `
31- ) ;
27+ const pathToClean = options . clean
28+ ? path . relative ( root , options . clean )
29+ : undefined ;
30+
31+ if ( pathToClean ) {
32+ report . info ( `Cleaning up ${ kleur . blue ( pathToClean ) } ` ) ;
3233
33- await del ( [ path . resolve ( root , options . clean ) ] ) ;
34+ await del ( [ path . resolve ( root , pathToClean ) ] ) ;
3435 }
3536
3637 const packageManager = process . env . npm_execpath ?? 'npm' ;
@@ -49,9 +50,23 @@ export default async function customTarget({ options, root, report }: Options) {
4950 stdio : [ 'ignore' , 'ignore' , 'inherit' ] ,
5051 } ) ;
5152 } catch ( e ) {
52- report . error ( `An error occurred when running ${ kleur . blue ( options . script ) } ` ) ;
53+ report . error (
54+ `An error occurred when running ${ kleur . blue ( options . script ) } `
55+ ) ;
5356 process . exit ( 1 ) ;
5457 }
5558
5659 report . success ( `Ran the ${ kleur . blue ( options . script ) } script succesfully` ) ;
60+
61+ if ( options . clean && pathToClean && ! ( await fs . pathExists ( pathToClean ) ) ) {
62+ report . warn (
63+ `Custom target with the ${ kleur . blue (
64+ options . script
65+ ) } script has ${ kleur . blue ( options . clean ) } as the ${ kleur . bold (
66+ 'clean'
67+ ) } option but this path wasn't created after running the script. Are you sure you've defined the ${ kleur . bold (
68+ 'clean'
69+ ) } path correctly?`
70+ ) ;
71+ }
5772}
0 commit comments