Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# production
/build
bin
generated

# misc
.DS_Store
Expand Down
56 changes: 48 additions & 8 deletions src/badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const getBadgeColor = (percent: number): string => {
}

export const generateBadge = (results: Results): void => {
const { average, worst } = results.summary
const { average, median, worst } = results.summary
const { badgesDirectory } = results.options
const badgesPath = badgesDirectory[0] || '' // Fall back to root
const actualPath = slash(process.cwd()) + badgesPath
Expand All @@ -41,18 +41,58 @@ export const generateBadge = (results: Results): void => {
} catch (error) {
console.error(error)
}
try {
fs.writeFileSync(
`${actualPath}/med-maintainability.svg`,
badgen({
label: 'maintainability (median)',
status: `${median.toFixed(2)}`,
color: getBadgeColor(median),
}),
'utf8'
)
} catch (error) {
console.error(error)
}

try {
const global = Math.min(average,median);
fs.writeFileSync(
`${actualPath}/worst-maintainability.svg`,
badgen({
label: 'maintainability (worst)',
status: `${worst.toFixed(2)}`,
color: getBadgeColor(worst),
}),
'utf8'
`${actualPath}/global-maintainability.svg`,
badgen({
label: 'maintainability',
status: `${global.toPrecision(2)}`,
color: getBadgeColor(global),
}),
'utf8'
)
} catch (error) {
console.error(error)
}

try {
fs.writeFileSync(
`${actualPath}/worst-maintainability.svg`,
badgen({
label: 'maintainability (worst)',
status: `${worst.toFixed(2)}`,
color: getBadgeColor(worst),
}),
'utf8'
)
} catch (error) {
console.error(error)
}

try {
const global = Math.min(average,median);
fs.writeFileSync(`${actualPath}/summary.json`, JSON.stringify({global,average,median,worst}),'utf8')
} catch (error) {
console.error(error)
}
try {
fs.writeFileSync(`${actualPath}/maintainability-report.json`, JSON.stringify(results),'utf8')
} catch (error) {
console.error(error)
}
}