|
1 | 1 | import process from "process"; |
2 | | -import { promises as fs } from "fs"; |
| 2 | +import fs from "fs"; |
3 | 3 | import path from "path"; |
4 | | -import { parse } from "./lcov"; |
5 | | -import { diff } from "./comment"; |
| 4 | +import { diff, diffForMonorepo } from "./comment"; |
| 5 | +import { getLcovArray, readLcov } from "./monorepo"; |
| 6 | +import { checkCoverage } from "./check"; |
| 7 | +import { createBadges } from "./badge"; |
6 | 8 |
|
| 9 | +const addPackageName = (x) => ({ |
| 10 | + ...x, |
| 11 | + ...{ packageName: x.dir.split("/").slice(-2)[0] }, |
| 12 | +}); |
7 | 13 | const main = async () => { |
8 | 14 | const file = process.argv[2]; |
9 | 15 | const beforeFile = process.argv[3]; |
10 | | - const prefix = `${path.dirname(path.dirname(path.resolve(file)))}/`; |
11 | | - |
12 | | - const content = await fs.readFile(file, "utf-8"); |
13 | | - const lcov = await parse(content); |
14 | | - |
15 | | - let before; |
16 | | - if (beforeFile) { |
17 | | - const contentBefore = await fs.readFile(beforeFile, "utf-8"); |
18 | | - before = await parse(contentBefore); |
19 | | - } |
20 | 16 |
|
| 17 | + const prefix = `${path.dirname(path.dirname(path.resolve(file)))}/`; |
21 | 18 | const options = { |
22 | 19 | repository: "example/foo", |
23 | 20 | commit: "f9d42291812ed03bb197e48050ac38ac6befe4e5", |
24 | 21 | prefix, |
25 | 22 | head: "feat/test", |
26 | 23 | base: "master", |
| 24 | + maxLines: "10", |
27 | 25 | }; |
28 | 26 |
|
29 | | - console.log(diff(lcov, before, options)); |
| 27 | + if (fs.statSync(file).isDirectory()) { |
| 28 | + const lcovArrayForMonorepo = ( |
| 29 | + await getLcovArray(file, "lcov.info") |
| 30 | + ).map(addPackageName); |
| 31 | + console.log( |
| 32 | + diffForMonorepo( |
| 33 | + lcovArrayForMonorepo, |
| 34 | + await getLcovArray(file, "lcov-base"), |
| 35 | + options, |
| 36 | + ), |
| 37 | + ); |
| 38 | + createBadges("./badges", lcovArrayForMonorepo, {}); |
| 39 | + console.log(checkCoverage(90, lcovArrayForMonorepo)); |
| 40 | + } else { |
| 41 | + const lcov = await readLcov(file); |
| 42 | + console.log( |
| 43 | + diff(lcov, beforeFile && (await readLcov(beforeFile)), options), |
| 44 | + ); |
| 45 | + createBadges( |
| 46 | + "./build", |
| 47 | + { |
| 48 | + packageName: "root", |
| 49 | + lcov, |
| 50 | + }, |
| 51 | + {}, |
| 52 | + ); |
| 53 | + console.log( |
| 54 | + checkCoverage(90, [ |
| 55 | + { |
| 56 | + packageName: "root", |
| 57 | + lcov, |
| 58 | + }, |
| 59 | + ]), |
| 60 | + ); |
| 61 | + } |
30 | 62 | }; |
31 | 63 |
|
32 | 64 | main().catch((err) => { |
|
0 commit comments