@@ -182,7 +182,30 @@ function run(root, appName, version, verbose, originalDirectory, template) {
182
182
183
183
install ( allDependencies , verbose , function ( code , command , args ) {
184
184
if ( code !== 0 ) {
185
- console . error ( chalk . cyan ( command + ' ' + args . join ( ' ' ) ) + ' failed' ) ;
185
+ console . log ( ) ;
186
+ console . error ( 'Aborting installation.' , chalk . cyan ( command + ' ' + args . join ( ' ' ) ) , 'has failed.' ) ;
187
+ // On 'exit' we will delete these files from target directory.
188
+ var knownGeneratedFiles = [
189
+ 'package.json' , 'npm-debug.log' , 'yarn-error.log' , 'yarn-debug.log' , 'node_modules'
190
+ ] ;
191
+ var currentFiles = fs . readdirSync ( path . join ( root ) ) ;
192
+ currentFiles . forEach ( function ( file ) {
193
+ knownGeneratedFiles . forEach ( function ( fileToMatch ) {
194
+ // This will catch `(npm-debug|yarn-error|yarn-debug).log*` files
195
+ // and the rest of knownGeneratedFiles.
196
+ if ( ( fileToMatch . match ( / .l o g / g) && file . indexOf ( fileToMatch ) === 0 ) || file === fileToMatch ) {
197
+ console . log ( 'Deleting generated file...' , chalk . cyan ( file ) ) ;
198
+ fs . removeSync ( path . join ( root , file ) ) ;
199
+ }
200
+ } ) ;
201
+ } ) ;
202
+ var remainingFiles = fs . readdirSync ( path . join ( root ) ) ;
203
+ if ( ! remainingFiles . length ) {
204
+ // Delete target folder if empty
205
+ console . log ( 'Deleting' , chalk . cyan ( appName + '/' ) , 'from' , chalk . cyan ( path . resolve ( root , '..' ) ) ) ;
206
+ fs . removeSync ( path . join ( root ) ) ;
207
+ }
208
+ console . log ( 'Done.' ) ;
186
209
process . exit ( 1 ) ;
187
210
}
188
211
0 commit comments