@@ -101,55 +101,75 @@ export const setupTemplate = async (
101
101
Logger . info ( `\nSetting up template in ${ chalk . magentaBright ( folderLocation ) } ...` ) ;
102
102
if ( ! template . path ) {
103
103
const spinner = ora ( "Cloning template..." ) . start ( ) ;
104
- await cloneRepo ( template . git , folderLocation , { silent : true } ) ;
105
104
try {
106
- fs . rmSync ( path . join ( folderLocation , ".git" ) , { recursive : true } ) ;
107
- } catch {
108
- Logger . warn ( "Failed to remove .git folder. Make sure to remove it manually before pushing to a new repo." ) ;
109
- }
110
- try {
111
- const githubFolderLocation = path . join ( folderLocation , ".github" ) ;
112
- if ( fileOrDirExists ( githubFolderLocation ) ) {
113
- fs . rmSync ( githubFolderLocation , { recursive : true } ) ;
105
+ await cloneRepo ( template . git , folderLocation , { silent : true } ) ;
106
+ try {
107
+ fs . rmSync ( path . join ( folderLocation , ".git" ) , { recursive : true } ) ;
108
+ } catch {
109
+ Logger . warn ( "Failed to remove .git folder. Make sure to remove it manually before pushing to a new repo." ) ;
114
110
}
115
- } catch {
116
- Logger . warn ( "Failed to remove .github folder. Make sure to remove it manually before pushing to a new repo." ) ;
111
+ try {
112
+ const githubFolderLocation = path . join ( folderLocation , ".github" ) ;
113
+ if ( fileOrDirExists ( githubFolderLocation ) ) {
114
+ fs . rmSync ( githubFolderLocation , { recursive : true } ) ;
115
+ }
116
+ } catch {
117
+ Logger . warn ( "Failed to remove .github folder. Make sure to remove it manually before pushing to a new repo." ) ;
118
+ }
119
+ spinner . succeed ( "Cloned template" ) ;
120
+ } catch ( error ) {
121
+ spinner . fail ( "Failed to clone template" ) ;
122
+ throw error ;
117
123
}
118
- spinner . succeed ( "Cloned template" ) ;
119
124
} else {
120
125
// We need to firstly clone the repo to a temp folder
121
126
// then copy required folder to the main folder
122
127
// then remove the temp folder
123
128
const cloneTempPath = path . join ( folderLocation , "___temp" ) ;
124
129
const spinner = ora ( "Cloning template..." ) . start ( ) ;
125
- await cloneRepo ( template . git , path . join ( folderLocation , "___temp" ) , { silent : true } ) ;
126
-
127
- const templatePath = path . join ( cloneTempPath , template . path ) ;
128
- if ( fileOrDirExists ( templatePath ) ) {
129
- try {
130
- // Copy the template to the folder location
131
- copyRecursiveSync ( templatePath , folderLocation ) ;
132
- // Remove the temp folder after copying
133
- fs . rmSync ( cloneTempPath , { recursive : true , force : true } ) ;
134
- } catch ( err ) {
135
- throw new Error ( "An error occurred while copying the template" ) ;
130
+ try {
131
+ await cloneRepo ( template . git , path . join ( folderLocation , "___temp" ) , { silent : true } ) ;
132
+
133
+ const templatePath = path . join ( cloneTempPath , template . path ) ;
134
+ if ( fileOrDirExists ( templatePath ) ) {
135
+ try {
136
+ // Copy the template to the folder location
137
+ copyRecursiveSync ( templatePath , folderLocation ) ;
138
+ // Remove the temp folder after copying
139
+ fs . rmSync ( cloneTempPath , { recursive : true , force : true } ) ;
140
+ } catch ( err ) {
141
+ throw new Error ( "An error occurred while copying the template" ) ;
142
+ }
143
+ } else {
144
+ throw new Error ( `The specified template path does not exist: ${ templatePath } ` ) ;
136
145
}
137
- } else {
138
- throw new Error ( `The specified template path does not exist: ${ templatePath } ` ) ;
146
+ spinner . succeed ( "Cloned template" ) ;
147
+ } catch ( error ) {
148
+ spinner . fail ( "Failed to clone template" ) ;
149
+ throw error ;
139
150
}
140
- spinner . succeed ( "Cloned template" ) ;
141
151
}
142
152
if ( Object . keys ( env ) . length > 0 ) {
143
153
const spinner = ora ( "Setting up environment variables..." ) . start ( ) ;
144
- setupEnv ( folderLocation , env ) ;
154
+ try {
155
+ setupEnv ( folderLocation , env ) ;
156
+ } catch ( error ) {
157
+ spinner . fail ( "Failed to set up environment variables" ) ;
158
+ throw error ;
159
+ }
145
160
spinner . succeed ( "Environment variables set up" ) ;
146
161
}
147
162
148
163
const spinner = ora (
149
164
`Installing dependencies with ${ chalk . bold ( packageManager ) } ... This may take a couple minutes.`
150
165
) . start ( ) ;
151
166
if ( await packageManagers [ packageManager ] . isInstalled ( ) ) {
152
- await executeCommand ( packageManagers [ packageManager ] . install ( ) , { cwd : folderLocation , silent : true } ) ;
167
+ try {
168
+ await executeCommand ( packageManagers [ packageManager ] . install ( ) , { cwd : folderLocation , silent : true } ) ;
169
+ } catch ( error ) {
170
+ spinner . fail ( "Failed to install dependencies" ) ;
171
+ throw error ;
172
+ }
153
173
spinner . succeed ( "Dependencies installed" ) ;
154
174
} else {
155
175
spinner . fail (
0 commit comments