Skip to content

Commit

Permalink
refactor teardown strategy for execute command
Browse files Browse the repository at this point in the history
  • Loading branch information
ErwanRaulo committed Dec 25, 2024
1 parent 63d9c1a commit efb9912
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions bin/commands/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,24 @@ 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() => {
const data = await fetchPackagesAndRepositoriesData();
if (debugMode) {
debug(data);
}

try {
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 +76,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 efb9912

Please sign in to comment.