@@ -22,8 +22,17 @@ export class CreatePluginCommand implements ICommand {
22
22
const selectedPath = path . resolve ( pathToProject || "." ) ;
23
23
const projectDir = path . join ( selectedPath , pluginRepoName ) ;
24
24
25
- await this . downloadPackage ( selectedTemplate , projectDir ) ;
26
- await this . setupSeed ( projectDir , pluginRepoName ) ;
25
+ // Must be out of try catch block, because will throw error if folder alredy exists and we don't want to delete it.
26
+ this . ensurePackageDir ( projectDir ) ;
27
+
28
+ try {
29
+ await this . downloadPackage ( selectedTemplate , projectDir ) ;
30
+ await this . setupSeed ( projectDir , pluginRepoName ) ;
31
+ } catch ( err ) {
32
+ // The call to this.ensurePackageDir() above will throw error if folder alredy exists, so it is safe to delete here.
33
+ this . $fs . deleteDirectory ( projectDir ) ;
34
+ throw err ;
35
+ }
27
36
28
37
this . $logger . printMarkdown ( "Solution for `%s` was successfully created." , pluginRepoName ) ;
29
38
}
@@ -66,13 +75,15 @@ export class CreatePluginCommand implements ICommand {
66
75
}
67
76
}
68
77
69
- private async downloadPackage ( selectedTemplate : string , projectDir : string ) : Promise < void > {
78
+ private ensurePackageDir ( projectDir : string ) : void {
70
79
this . $fs . createDirectory ( projectDir ) ;
71
80
72
81
if ( this . $fs . exists ( projectDir ) && ! this . $fs . isEmptyDir ( projectDir ) ) {
73
82
this . $errors . fail ( "Path already exists and is not empty %s" , projectDir ) ;
74
83
}
84
+ }
75
85
86
+ private async downloadPackage ( selectedTemplate : string , projectDir : string ) : Promise < void > {
76
87
if ( selectedTemplate ) {
77
88
this . $logger . printMarkdown ( "Make sure your custom template is compatible with the Plugin Seed at https://github.com/NativeScript/nativescript-plugin-seed/" ) ;
78
89
} else {
@@ -84,9 +95,6 @@ export class CreatePluginCommand implements ICommand {
84
95
try {
85
96
spinner . start ( ) ;
86
97
await this . $pacoteService . extractPackage ( packageToInstall , projectDir ) ;
87
- } catch ( err ) {
88
- this . $fs . deleteDirectory ( projectDir ) ;
89
- throw err ;
90
98
} finally {
91
99
spinner . stop ( ) ;
92
100
}
0 commit comments