diff --git a/README-(ZH).md b/README-(ZH).md index 58871e52..6520a43f 100644 --- a/README-(ZH).md +++ b/README-(ZH).md @@ -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 diff --git a/bin/coverage.ts b/bin/coverage.ts index 6014b31c..c4e1b1e8 100644 --- a/bin/coverage.ts +++ b/bin/coverage.ts @@ -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);