export interface IUserInput { owner: string repo: string branch?: string snykProjectId?: string snykOrgId?: string packageName?: string } /** * Generate and return the text to be displayed at the _TOP_ of a README file. * It contains all of the Markdown text that is used to display the badges. */ export function getBadgeHeader(input: IUserInput): string { let header = '[![Drone][Drone-Badge]][Drone-Project] ' // Verify the necessary properties are provided for the Snyk badge. if (input.packageName && input.snykOrgId && input.snykProjectId) { header += '[![Snyk][Snyk-Badge]][Snyk-Project] ' } header += '[![Prettier][Prettier-Badge]][Prettier-Project] ' if (input.packageName) { header += '[![NPM License][NPM-License-Badge]][NPM-Package-Page] [![NPM Version][NPM-Version-Badge]][NPM-Package-Page]' } header += '\n\n[![Discord][Discord-Badge]][Discord-Invite] [![Twitter-Profile][Twitter-Badge]][Twitter-Profile]' return header } /** * Generates and returns the text to be displayed at the _BOTTOM_ of a README * file. It contains the URLs for all of the badges. */ export function getBadgeFooter({ owner, repo, branch, snykOrgId, snykProjectId, packageName }: IUserInput): string[] { const rows: string[] = [] rows.push( `[Drone-Badge]: https://img.shields.io/drone/build/${owner}/${repo}?server=https%3A%2F%2Fdrone.4lch4.io&style=flat-square` ) // Check if a branch was provided. If so, set the Drone-Project URL to include // the branch. if (branch) { rows.push( `[Drone-Project]: https://drone.4lch4.io/api/badges/${owner}/${repo}/status.svg?refs=refs/heads/${branch}` ) } else { // If no branch was provided, set the Drone-Project URL to the default // branch. rows.push( `[Drone-Project]: https://drone.4lch4.io/api/badges/${owner}/${repo}/status.svg` ) } // Check if an NPM package name was provided, if so, then add the NPM License, // NPM Version, a link to the package page, and the Snyk badges. if (packageName) { rows.push( `[NPM-License-Badge]: https://flat.badgen.net/npm/license/${packageName}` ) rows.push( `[NPM-Version-Badge]: https://flat.badgen.net/npm/v/${packageName}` ) rows.push(`[NPM-Package-Page]: https://npmjs.com/package/${packageName}`) rows.push( `[Snyk-Badge]: https://img.shields.io/snyk/vulnerabilities/npm/${packageName}?style=flat-square` ) } // Check if a Snyk org & project id were provided. If so, add the Snyk-Project // badge. if (snykOrgId && snykProjectId) { rows.push( `[Snyk-Project]: https://app.snyk.io/org/${snykOrgId}/project/${snykProjectId}` ) } // No matter what, add the Discord Badge, Invite, Twitter Badge, Twitter // Profile URL, and Prettier badges. rows.push( '[Prettier-Badge]: https://flat.badgen.net/badge/code%20style/prettier/ff69b4' ) rows.push('[Prettier-Repo]: https://github.com/prettier/prettier') rows.push( '[Discord-Badge]: https://img.shields.io/discord/325504841541746688?color=7289DA&style=flat-square' ) rows.push('[Discord-Invite]: https://discord.gg/W72x4Ks') rows.push('[Twitter-Badge]: https://flat.badgen.net/twitter/follow/4lch4') rows.push('[Twitter-Profile]: https://twitter.com/4lch4') return rows }