@@ -84,27 +84,29 @@ function parseContent(md) {
84
84
85
85
function rmDir ( dir , rmSelf ) {
86
86
87
- let files ;
88
- rmSelf = ( rmSelf === undefined ) ?true :rmSelf ;
89
- // dir = dir + path.sep;
90
-
91
- try { files = fs . readdirSync ( dir ) ; } catch ( e ) { console . log ( `Sorry, directory '${ dir } ' doesn't exist.` ) ; return ; }
92
-
93
- if ( files . length > 0 ) {
94
- files . forEach ( function ( x , i ) {
95
- if ( fs . statSync ( path . join ( dir , x ) ) . isDirectory ( ) ) {
96
- rmDir ( path . join ( dir , x ) ) ;
97
- } else {
98
- fs . unlinkSync ( path . join ( dir , x ) ) ;
99
- }
100
- } ) ;
101
- }
87
+ try {
88
+ let files ;
89
+ rmSelf = ( rmSelf === undefined ) ?true :rmSelf ;
102
90
103
- if ( rmSelf ) {
104
- // check if user want to delete the directory ir just the files in this directory
105
- fs . rmdirSync ( dir ) ;
106
- }
91
+ try { files = fs . readdirSync ( dir ) ; } catch ( e ) { console . log ( `Sorry, directory '${ dir } ' doesn't exist.` ) ; return ; }
92
+
93
+ if ( files . length > 0 ) {
94
+ files . forEach ( function ( x , i ) {
95
+ if ( fs . statSync ( path . join ( dir , x ) ) . isDirectory ( ) ) {
96
+ rmDir ( path . join ( dir , x ) ) ;
97
+ } else {
98
+ fs . unlinkSync ( path . join ( dir , x ) ) ;
99
+ }
100
+ } ) ;
101
+ }
107
102
103
+ if ( rmSelf ) {
104
+ // check if user want to delete the directory ir just the files in this directory
105
+ fs . rmdirSync ( dir ) ;
106
+ }
107
+ } catch ( error ) {
108
+ return error ;
109
+ }
108
110
}
109
111
110
112
async function cleanupFiles ( workingDir ) {
@@ -118,9 +120,8 @@ async function cleanupFiles(workingDir) {
118
120
rmDir ( path . join ( process . cwd ( ) , '.git' , 'modules' , workingDir ) ) ;
119
121
rmDir ( workingDir ) ;
120
122
121
- return true ;
122
123
} catch ( error ) {
123
- return false ;
124
+ return error ;
124
125
}
125
126
}
126
127
@@ -144,27 +145,18 @@ async function build({ repo, codeBranch, setupBranch, isLocal }) {
144
145
else {
145
146
const gitTest = simpleGit ( process . cwd ( ) ) ;
146
147
const isRepo = await gitTest . checkIsRepo ( ) ;
148
+ localPath = path . join ( process . cwd ( ) , workingDir ) ;
147
149
148
150
if ( isRepo ) {
149
- const startCleanup = cleanupFiles ( workingDir ) ;
150
-
151
- if ( startCleanup ) {
152
- console . log ( 'Clenned old files from git module...' ) ;
153
- }
154
-
155
151
await gitTest . submoduleAdd ( repo , workingDir ) ;
156
152
157
- git = simpleGit ( path . join ( process . cwd ( ) , workingDir ) ) ;
158
-
159
153
isSubModule = true ;
160
- localPath = path . join ( process . cwd ( ) , workingDir ) ;
161
-
162
154
}
163
155
else {
164
- await gitTest . clone ( repo ) ;
165
- git = simpleGit ( process . cwd ( ) ) ;
166
- localPath = process . cwd ( ) ;
156
+ await gitTest . clone ( repo , localPath ) ;
167
157
}
158
+
159
+ git = simpleGit ( localPath ) ;
168
160
}
169
161
170
162
await git . fetch ( ) ;
@@ -238,10 +230,17 @@ async function build({ repo, codeBranch, setupBranch, isLocal }) {
238
230
239
231
// cleanup the submodules
240
232
if ( ! isLocal ) {
241
- const endCleanup = await cleanupFiles ( workingDir ) ;
233
+ let cleanupErr ;
234
+
235
+ if ( isSubModule ) {
236
+ cleanupErr = await cleanupFiles ( workingDir ) ;
237
+ }
238
+ else {
239
+ cleanupErr = rmDir ( path . join ( process . cwd ( ) , workingDir ) ) ;
240
+ }
242
241
243
- if ( ! endCleanup ) {
244
- console . log ( ' Error when deletingthe git submodules' ) ;
242
+ if ( ! cleanupErr ) {
243
+ console . log ( ` Error when deletingtemporary files on ${ isSubModule ? 'module' : 'folder' } ${ workingDir } .` ) ;
245
244
}
246
245
}
247
246