Skip to content

Commit

Permalink
fix(cnumr#27): Correction de la ProgressBar lors de la génération du …
Browse files Browse the repository at this point in the history
…rapport HTML
  • Loading branch information
jpreisner committed Apr 12, 2022
1 parent 683c203 commit 1514c34
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cli-core/reportHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ async function create_html_report(reportObject,options){

// write global report
const templateEngine = new TemplateEngine.TemplateEngine();
writeGlobalReport(templateEngine, globalReportVariables, OUTPUT_FILE);
writeGlobalReport(templateEngine, globalReportVariables, OUTPUT_FILE, progressBar);

// write all reports
const outputFolder = path.dirname(OUTPUT_FILE);
writeAllReports(templateEngine, allReportsVariables, outputFolder)
writeAllReports(templateEngine, allReportsVariables, outputFolder, progressBar);
}

function readAllReports(fileList) {
Expand Down Expand Up @@ -161,21 +161,31 @@ function extractBestPractices(bestPracticesFromReport) {
return bestPractices;
}

function writeGlobalReport(templateEngine, globalReportVariables, outputFile) {
function writeGlobalReport(templateEngine, globalReportVariables, outputFile, progressBar) {
templateEngine.processFile(path.join(__dirname, 'template/global.html'), globalReportVariables)
.then(globalReportHtml => {
fs.writeFileSync(outputFile, globalReportHtml);
if (progressBar){
progressBar.tick();
} else {
console.log(`Global report : ${outputFile} created`);
}
})
.catch(error => {
console.log("Error while reading HTML global template : ", error)
});
}

function writeAllReports(templateEngine, allReportsVariables, outputFolder) {
function writeAllReports(templateEngine, allReportsVariables, outputFolder, progressBar) {
allReportsVariables.forEach(reportVariables => {
templateEngine.processFile(path.join(__dirname, 'template/page.html'), reportVariables)
.then(singleReportHtml => {
fs.writeFileSync(`${outputFolder}/${reportVariables.filename}`, singleReportHtml);
if (progressBar){
progressBar.tick();
} else {
console.log(`Single report : ${reportVariables.filename} created`);
}
})
.catch(error => {
console.log(`Error while reading HTML template ${reportVariables.filename} : `, error)
Expand Down

0 comments on commit 1514c34

Please sign in to comment.