@@ -104,7 +104,7 @@ function rmDir(dir, rmSelf) {
104
104
// check if user want to delete the directory ir just the files in this directory
105
105
fs . rmdirSync ( dir ) ;
106
106
}
107
-
107
+
108
108
}
109
109
110
110
async function cleanupFiles ( workingDir ) {
@@ -137,18 +137,38 @@ async function cleanupFiles(workingDir) {
137
137
*@param {string } isLocal define if the repo is local or remote
138
138
*/
139
139
async function build ( { repo, codeBranch, setupBranch, isLocal} ) {
140
-
141
- const gitModule = simpleGit ( __dirname ) ;
142
140
143
- const startCleanup = cleanupFiles ( workingDir ) ;
141
+ let git ;
142
+ let isSubModule = false ;
144
143
145
- if ( startCleanup ) {
146
- console . log ( 'Clenned old files from gitmodule...' ) ;
144
+ if ( isLocal ) {
145
+ git = simpleGit ( repo ) ;
147
146
}
147
+ else {
148
+ const gitTest = simpleGit ( __dirname ) ;
149
+ const isRepo = await gitTest . checkIsRepo ( ) ;
150
+
151
+ if ( isRepo ) {
152
+ // Add the new one as a submodule
153
+ const startCleanup = cleanupFiles ( workingDir ) ;
154
+
155
+ if ( startCleanup ) {
156
+ console . log ( 'Clenned old files from git module...' ) ;
157
+ }
148
158
149
- await gitModule . submoduleAdd ( repo , workingDir ) ;
159
+ await gitTest . submoduleAdd ( repo , workingDir ) ;
160
+
161
+ git = simpleGit ( path . join ( __dirname , workingDir ) ) ;
162
+
163
+ isSubModule = true ;
164
+
165
+ }
166
+ else {
167
+ await gitTest . clone ( repo ) ;
168
+ git = simpleGit ( __dirname ) ;
169
+ }
170
+ }
150
171
151
- const git = simpleGit ( path . join ( __dirname , workingDir ) ) ;
152
172
await git . fetch ( ) ;
153
173
154
174
// checkout the branch to load configuration and content branch
@@ -215,22 +235,22 @@ async function build({ repo, codeBranch, setupBranch, isLocal }) {
215
235
theLevel . setup . commits . push ( commit . hash . substr ( 0 , 7 ) ) ;
216
236
}
217
237
}
218
-
219
238
}
220
-
221
239
} ;
222
240
223
241
// cleanup the submodules
224
- const endCleanup = await cleanupFiles ( workingDir ) ;
225
-
226
- if ( ! endCleanup ) {
227
- console . log ( 'Error when deleting the git submodules' ) ;
242
+ if ( ! isLocal ) {
243
+ const endCleanup = await cleanupFiles ( workingDir ) ;
244
+
245
+ if ( ! endCleanup ) {
246
+ console . log ( 'Error when deleting the git submodules' ) ;
247
+ }
228
248
}
229
249
230
250
const isValid = validate ( config ) ;
231
251
232
252
if ( ! isValid ) return validate . errors ;
233
-
253
+
234
254
return config ;
235
255
236
256
}