Skip to content

Commit

Permalink
refactor teardown strategy for execute command (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErwanRaulo authored Dec 26, 2024
1 parent c55c20e commit c72043d
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions bin/commands/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,23 @@ export async function execute(options = {}) {
console.log(`>> title: ${kleur.cyan().bold(report.title)}`);
console.log(`>> reporters: ${kleur.magenta().bold(report.reporters.join(","))}\n`);

store.run(config, () => {
fetchPackagesAndRepositoriesData()
.then((data) => {
if (debugMode) {
debug(data);
}

return reporting.proceed(data);
})
.catch((error) => {
console.error(error);
})
.finally(teardown);
store.run(config, async() => {
try {
const data = await fetchPackagesAndRepositoriesData();
if (debugMode) {
debug(data);
}
await reporting.proceed(data);
console.log(kleur.green().bold("\n>> Security report successfully generated! Enjoy 🚀.\n"));
}
catch (error) {
console.error(error);
}
finally {
await fs.rm(CONSTANTS.DIRS.CLONES, {
recursive: true, force: true
});
}
});
}

Expand All @@ -71,14 +75,6 @@ function init() {
);
}

function teardown() {
console.log(kleur.green().bold("\n>> Security report successfully generated! Enjoy 🚀.\n"));

return fs.rm(CONSTANTS.DIRS.CLONES, {
recursive: true, force: true
});
}

function debug(obj) {
const filePath = path.join(CONSTANTS.DIRS.REPORTS, `debug-pkg-repo.txt`);
writeFileSync(filePath, inspect(obj, { showHidden: true, depth: null }), "utf8");
Expand Down

0 comments on commit c72043d

Please sign in to comment.