Skip to content

Commit e1bb7a4

Browse files
committed
Add error logs + WIP: fux submodule bug
1 parent de6b22c commit e1bb7a4

File tree

1 file changed

+36
-37
lines changed

1 file changed

+36
-37
lines changed

src/parse.js

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,29 @@ function parseContent(md) {
8484

8585
function rmDir(dir, rmSelf) {
8686

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;
10290

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+
}
107102

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+
}
108110
}
109111

110112
async function cleanupFiles(workingDir) {
@@ -118,9 +120,8 @@ async function cleanupFiles(workingDir) {
118120
rmDir(path.join(process.cwd(), '.git', 'modules', workingDir));
119121
rmDir(workingDir);
120122

121-
return true;
122123
} catch (error) {
123-
return false;
124+
return error;
124125
}
125126
}
126127

@@ -144,27 +145,18 @@ async function build({ repo, codeBranch, setupBranch, isLocal }) {
144145
else {
145146
const gitTest = simpleGit(process.cwd());
146147
const isRepo = await gitTest.checkIsRepo();
148+
localPath = path.join(process.cwd(), workingDir);
147149

148150
if (isRepo) {
149-
const startCleanup = cleanupFiles(workingDir);
150-
151-
if (startCleanup) {
152-
console.log('Clenned old files from git module...');
153-
}
154-
155151
await gitTest.submoduleAdd(repo, workingDir);
156152

157-
git = simpleGit(path.join(process.cwd(), workingDir));
158-
159153
isSubModule = true;
160-
localPath = path.join(process.cwd(), workingDir);
161-
162154
}
163155
else {
164-
await gitTest.clone(repo);
165-
git = simpleGit(process.cwd());
166-
localPath = process.cwd();
156+
await gitTest.clone(repo, localPath);
167157
}
158+
159+
git = simpleGit(localPath);
168160
}
169161

170162
await git.fetch();
@@ -238,10 +230,17 @@ async function build({ repo, codeBranch, setupBranch, isLocal }) {
238230

239231
// cleanup the submodules
240232
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+
}
242241

243-
if (!endCleanup) {
244-
console.log('Error when deleting the git submodules');
242+
if (!cleanupErr) {
243+
console.log(`Error when deleting temporary files on ${isSubModule ? 'module' : 'folder'} ${workingDir}.`);
245244
}
246245
}
247246

0 commit comments

Comments
 (0)