|
1 | 1 | const aggregatorServiceLighthouse = require("./lighthouse/aggregatorService"); |
2 | 2 | const aggregatorServiceEcoIndex = require("./ecoIndex/aggregatorService"); |
3 | 3 | const aggregatorGlobalService = require("./globlalAggregation/aggregatorService"); |
4 | | -const { generateReports, generateReportsSonar } = require("./reporters/generatorReports"); |
| 4 | +const { |
| 5 | + generateReports, |
| 6 | + generateReportsSonar, |
| 7 | +} = require("./reporters/generatorReports"); |
5 | 8 |
|
6 | 9 | const path = require("path"); |
7 | 10 | const fs = require("fs"); |
8 | 11 |
|
9 | 12 | const defaultThreshold = { |
10 | 13 | pass: 90, |
11 | | - fail: 30 |
| 14 | + fail: 30, |
12 | 15 | }; |
13 | 16 |
|
14 | 17 | const formatReports = reports => { |
15 | | - if(!reports){ |
| 18 | + if (!reports) { |
16 | 19 | return []; |
17 | 20 | } |
18 | | - return Array.isArray(reports) ? reports : [reports]; |
| 21 | + try { |
| 22 | + reports = JSON.parse(reports); |
| 23 | + } finally { |
| 24 | + return Array.isArray(reports) ? reports : [reports]; |
| 25 | + } |
19 | 26 | }; |
20 | 27 |
|
21 | | -module.exports = async (_options) => { |
| 28 | +module.exports = async _options => { |
22 | 29 | let options = { |
23 | 30 | ...defaultThreshold, |
24 | | - ..._options |
| 31 | + ..._options, |
25 | 32 | }; |
26 | | - |
27 | | - if(options.config){ |
| 33 | + |
| 34 | + if (options.config) { |
28 | 35 | options = { |
29 | 36 | ...options, |
30 | | - ...require(options.config) |
| 37 | + ...require(options.config), |
31 | 38 | }; |
32 | 39 | } |
33 | 40 |
|
34 | 41 | const resultsGlobalLighthouse = await aggregatorServiceLighthouse(options); |
35 | 42 | const resultsGlobalEcoindex = await aggregatorServiceEcoIndex(options); |
36 | | - const resultsGlobal = aggregatorGlobalService(options, resultsGlobalLighthouse, resultsGlobalEcoindex); |
37 | | - |
| 43 | + const resultsGlobal = aggregatorGlobalService( |
| 44 | + options, |
| 45 | + resultsGlobalLighthouse, |
| 46 | + resultsGlobalEcoindex |
| 47 | + ); |
38 | 48 |
|
39 | 49 | const reports = formatReports(options.reports); |
40 | | - const destFolder = path.join(process.cwd(), options.outputPath ?? "globalReports"); |
41 | | - if(fs.existsSync(destFolder)){ |
| 50 | + const destFolder = path.join( |
| 51 | + process.cwd(), |
| 52 | + options.outputPath ?? "globalReports" |
| 53 | + ); |
| 54 | + if (fs.existsSync(destFolder)) { |
42 | 55 | fs.rmSync(destFolder, { recursive: true }); |
43 | 56 | } |
44 | 57 | fs.mkdirSync(destFolder, { recursive: true }); |
45 | 58 | options.outputPath = destFolder; |
46 | 59 |
|
47 | | - await Promise.all(reports.map(report => { |
48 | | - if(typeof report !== "string"){ |
49 | | - return report(options, resultsGlobal); |
50 | | - } |
51 | | - if (report === "html") { |
52 | | - return generateReports(options, resultsGlobal); |
53 | | - } |
54 | | - if (report === "sonar") { |
55 | | - return generateReportsSonar(options, resultsGlobal); |
56 | | - } |
57 | | - })); |
58 | | - |
| 60 | + await Promise.all( |
| 61 | + reports.map(report => { |
| 62 | + if (typeof report !== "string") { |
| 63 | + return report(options, resultsGlobal); |
| 64 | + } |
| 65 | + if (report === "html") { |
| 66 | + return generateReports(options, resultsGlobal); |
| 67 | + } |
| 68 | + if (report === "sonar") { |
| 69 | + return generateReportsSonar(options, resultsGlobal); |
| 70 | + } |
| 71 | + }) |
| 72 | + ); |
59 | 73 |
|
60 | 74 | return resultsGlobal; |
61 | 75 | }; |
0 commit comments