@@ -104,7 +104,7 @@ function rmDir(dir, rmSelf) {
104104 // check if user want to delete the directory ir just the files in this directory
105105 fs . rmdirSync ( dir ) ;
106106 }
107-
107+
108108}
109109
110110async function cleanupFiles ( workingDir ) {
@@ -137,18 +137,38 @@ async function cleanupFiles(workingDir) {
137137 * @param {string } isLocal define if the repo is local or remote
138138 */
139139async function build ( { repo, codeBranch, setupBranch, isLocal } ) {
140-
141- const gitModule = simpleGit ( __dirname ) ;
142140
143- const startCleanup = cleanupFiles ( workingDir ) ;
141+ let git ;
142+ let isSubModule = false ;
144143
145- if ( startCleanup ) {
146- console . log ( 'Clenned old files from git module...' ) ;
144+ if ( isLocal ) {
145+ git = simpleGit ( repo ) ;
147146 }
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+ }
148158
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+ }
150171
151- const git = simpleGit ( path . join ( __dirname , workingDir ) ) ;
152172 await git . fetch ( ) ;
153173
154174 // checkout the branch to load configuration and content branch
@@ -215,22 +235,22 @@ async function build({ repo, codeBranch, setupBranch, isLocal }) {
215235 theLevel . setup . commits . push ( commit . hash . substr ( 0 , 7 ) ) ;
216236 }
217237 }
218-
219238 }
220-
221239 } ;
222240
223241 // 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+ }
228248 }
229249
230250 const isValid = validate ( config ) ;
231251
232252 if ( ! isValid ) return validate . errors ;
233-
253+
234254 return config ;
235255
236256}
0 commit comments