@@ -22,6 +22,8 @@ program
22
22
. option ( '--trailing-comma <none|es5|all>' , 'Print trailing commas wherever possible when multi-line.' , 'none' )
23
23
. option ( '--use-tabs' , 'Indent with tabs instead of spaces.' , false )
24
24
. option ( '--ignore-prettier-errors' , 'Ignore (but warn about) errors in Prettier' , false )
25
+ . option ( '--keep-original-files' , 'Keep original files' , false )
26
+ . option ( '--keep-temporary-files' , 'Keep temporary files' , false )
25
27
. usage ( '[options] <filename or glob>' )
26
28
. command ( '* <glob>' )
27
29
. action ( globPattern => {
@@ -52,12 +54,18 @@ program
52
54
fs . copyFileSync ( filePath , temporaryPath ) ;
53
55
const result = run ( temporaryPath , prettierOptions , compilationOptions ) ;
54
56
fs . writeFileSync ( newPath , result ) ;
55
- fs . unlinkSync ( filePath ) ;
56
- fs . unlinkSync ( temporaryPath ) ;
57
+ if ( ! program . keepOriginalFiles ) {
58
+ fs . unlinkSync ( filePath ) ;
59
+ }
57
60
} catch ( error ) {
58
61
console . warn ( `Failed to convert ${ file } ` ) ;
59
62
console . warn ( error ) ;
60
63
}
64
+ if ( ! program . keepTemporaryFiles ) {
65
+ if ( fs . existsSync ( temporaryPath ) ) {
66
+ fs . unlinkSync ( temporaryPath ) ;
67
+ }
68
+ }
61
69
}
62
70
} ) ;
63
71
0 commit comments