Skip to content

Commit

Permalink
doc(README-ZH): coverage badge
Browse files Browse the repository at this point in the history
  • Loading branch information
bhsd-harry committed Jan 22, 2025
1 parent d11e8bc commit 2b707cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions README-(ZH).md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![CI](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/node.js.yml/badge.svg)](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/node.js.yml)
[![jsDelivr hits (npm)](https://img.shields.io/jsdelivr/npm/hm/wikiparser-node)](https://www.npmjs.com/package/wikiparser-node)
[![codebeat badge](https://codebeat.co/badges/7cdd51e6-2c5d-4a22-aae1-f5e352047d54)](https://codebeat.co/projects/github-com-bhsd-harry-wikiparser-node-main)
![Istanbul coverage](./coverage/badge.svg)

# Other Languages

Expand Down
12 changes: 11 additions & 1 deletion bin/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,15 @@ declare interface Coverage {

// eslint-disable-next-line n/no-missing-require
const {total: {statements: {pct}}}: Coverage = require('../../coverage/coverage-summary.json');
const svg = fs.readFileSync('coverage/badge.svg', 'utf8').replace(/\b\d{2}(?=%)/gu, String(Math.round(pct)));
const colors = ['#4c1', '#dfb317', '#e05d44'] as const;
let color: string;
if (pct >= 80) {
[color] = colors;
} else if (pct >= 60) {
[, color] = colors;
} else {
[,, color] = colors;
}
const svg = fs.readFileSync('coverage/badge.svg', 'utf8').replace(/\b\d{2}(?=%)/gu, String(Math.round(pct)))
.replace(new RegExp(colors.join('|'), 'u'), color);
fs.writeFileSync('coverage/badge.svg', svg);

0 comments on commit 2b707cb

Please sign in to comment.