Usage

Installation

npm install --save @thebespokepixel/badges

Example

With this source.markdown:

  Badges:
  ${badges}

Read it in as a template and merge the AST:

/* Import the module… */
import {readFileSync} from 'fs'
import _ from 'lodash'
import remark from 'remark'
import badges from 'badges'

/* …then read the 'badges.readme' stanza from package.json and send the AST into remark etc. */
const content = {
  badges: await badges('readme')
}

const template = _.template(readFileSync('./source.markdown'))
const page = await remark().process(template(content))

Configuration

In package.json...

...
"badges": {
  "github": "MarkGriffiths", // github user
  "npm": "thebespokepixel", // npm user
  "codeclimate": "a0a755b0fce22eb0b784", // codeclimate badge asset id
  "name": "badges", // Package name
  "style": "square", // Badge style (default 'flat')
  "providers": { // Non-default badge provider configuration
    "status": {
      "text": "beta",
      "color": "blue"
    },
    "aux1": {
      "title": "github",
      "text": "source",
      "color": "4E73B6",
      "link": "https://github.com/MarkGriffiths/badges"
    }
  }
  "readme": { // Section with subtitles as map of arrays
    "Status": [
      [ "status", "npm", "travis", "david" ],
      [ "code-climate", "code-climate-coverage", "snyk" ]
    ],
    "Developer": [ "david-dev", "rollup" ],
    "Help": [ "inch", "gitter" ]
  },
  "docs": [ // Lines as an array of arrays
    [ "aux1", "travis" ],
    [ "code-climate", "code-climate-coverage" ],
    [ "david" ]
  ]
}

Supported badges

- status (plus similar aux1 and aux2)
- travis
- travis-pro (requires a 'travis' token)
- david and david-dev
- code-climate and code-climate-coverage (requires a 'codeclimate' token)
- inch
- npm
- rollup
- snyk
- gitter

CLI

  > compile-readme --help

  Inject project badges into a tagged markdown-formatted source file.

  Usage:
  compile-readme [options] > outputFile

  Options:
  -h, --help     Display help.
  -v, --version  Print version to stdout. -vv Print name & version.
  -V, --verbose  Be verbose. -VV Be loquacious.
  -c, --context  The named badges context in package.json.
  -u, --usage    Path to a usage markdown example
  --color        Force color output. Disable with --no-color

  © 2020 The Bespoke Pixel. Released under the MIT License.

API

Render project badge configuration as markdown.

render(context: String, asAST: Boolean) → Promise
Parameters
context (String) The desired render context i.e: readme , docs as defined in package.json .
asAST (Boolean = false) Render badges as MDAST
Returns
Promise: A promise that resolves to the markdown formatted output.