1.3.0 β€’ Published 4 months ago

badge-forge v1.3.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

πŸ› οΈ Badge Forge – Forge Your Own Badges! πŸ”₯

Badge Forge Badge Forge version Github stars Code coverage Continuous integration Prettier

Why waste time manually adding badges when you can forge them like a pro? βš’οΈπŸ”₯

Badge Forge transforms your configuration into a glorious set of shields.io badges, making your GitHub README shine ✨.

πŸš€ Why Use Badge Forge?

  • βœ… Automated badge generation – no more manual badge tinkering
  • βœ… Super simple setup – just run it and let the magic happen
  • βœ… Instantly boost your repo’s style points 😎
  • βœ… Faster than a blacksmith on caffeine β˜•βš‘

πŸ’Ύ Installation

npm install -g badge-forge

Start forging today! πŸ—οΈπŸ”—

πŸ›  Badge Forge – Configuration Guide & Usage

1️⃣ Basic Usage

badge-forge generate

βœ… Automatically loads the configuration from supported config files and generates badges.

2️⃣ Supported Configuration File Formats

Since Badge Forge uses cosmiconfig, it supports multiple configuration file formats and locations.

πŸ“Œ Supported File Names (searched automatically) The tool will look for configuration files in the following order:

  • YAML:
    • .badge-forgerc.yml
    • .badge-forgerc.yaml
  • JSON:
    • .badge-forgerc.json
  • JavaScript / TypeScript:
    • .badge-forgerc.js
    • .badge-forgerc.ts
    • badge-forge.config.js
    • badge-forge.config.ts
  • Package JSON (package.json)
    • Looks for a "badgeForge" key inside package.json

3️⃣ Example Configurations for Each Format

πŸ“„ YAML (.badge-forgerc.yml or .badge-forgerc.yaml)

badges:
    - label: Stars
      message: '{} ⭐'
      source: https://api.github.com/search/repositories?q=%22badge-forge%22
      path: $.items[?(@.full_name=='bakajvo/badge-forge')].stargazers_count
      color: 3dc8ff

    - label: Badge
      message: Forge πŸ”₯πŸ”¨
      color: b58259

    - label: Version
      message: '{}'
      source: package.json
      path: $.version
      color: 6aff3d

    - label: Coverage
      message: '{}%'
      source: coverage/coverage-summary.json
      path: $.total.statements.pct
      color: db0921

    - label: Code style
      message: prettier
      color: ff69b4
      filename: Prettier

πŸ“„ JSON (.badge-forgerc.json)

{
    "badges": [
        {
            "label": "Stars",
            "message": "{} ⭐",
            "source": "https://api.github.com/search/repositories?q=%22badge-forge%22",
            "path": "$.items[?(@.full_name=='bakajvo/badge-forge')].stargazers_count",
            "color": "3dc8ff"
        },
        {
            "label": "Badge",
            "message": "Forge πŸ”₯πŸ”¨",
            "color": "b58259"
        },
        {
            "label": "Version",
            "message": "{}",
            "source": "package.json",
            "path": "$.version",
            "color": "6aff3d"
        },
        {
            "label": "Coverage",
            "message": "{}%",
            "source": "coverage/coverage-summary.json",
            "path": "$.total.statements.pct",
            "color": "db0921"
        },
        {
            "label": "Code style",
            "message": "prettier",
            "color": "ff69b4",
            "filename": "Prettier"
        }
    ]
}

πŸ“„ JavaScript (badge-forge.config.js/ts or .badge-forgerc.js/ts)

export default {
    badges: [
        {
            label: 'Stars',
            message: '{} ⭐',
            source: 'https://api.github.com/search/repositories?q=%22badge-forge%22',
            path: "$.items[?(@.full_name=='bakajvo/badge-forge')].stargazers_count",
            color: '3dc8ff',
        },
        {
            label: 'Badge',
            message: 'Forge πŸ”₯πŸ”¨',
            color: 'b58259',
        },
        {
            label: 'Version',
            message: '{}',
            source: 'package.json',
            path: '$.version',
            color: '6aff3d',
        },
        {
            label: 'Coverage',
            message: '{}%',
            source: 'coverage/coverage-summary.json',
            path: '$.total.statements.pct',
            color: 'db0921',
        },
        {
            label: 'Code style',
            message: 'prettier',
            color: 'ff69b4',
            filename: 'Prettier',
        },
    ],
}

πŸ“„ Adding Configuration Inside package.json Instead of creating a separate file, you can add the configuration inside package.json:

{
    "name": "my-project",
    "version": "1.0.0",
    "badgeForge": {
        "badges": [
            {
                "label": "Stars",
                "message": "{} ⭐",
                "source": "https://api.github.com/search/repositories?q=%22badge-forge%22",
                "path": "$.items[?(@.full_name=='bakajvo/badge-forge')].stargazers_count",
                "color": "3dc8ff"
            },
            {
                "label": "Badge",
                "message": "Forge πŸ”₯πŸ”¨",
                "color": "b58259"
            },
            {
                "label": "Version",
                "message": "{}",
                "source": "package.json",
                "path": "$.version",
                "color": "6aff3d"
            }
        ]
    }
}

βœ… This allows badge-forge to fetch configuration directly from package.json.

4️⃣ Using in CI/CD Pipelines

πŸ“Œ Add a script in package.json

{
    "scripts": {
        "generate-badges": "badge-forge generate"
    }
}

Example of GitHub Action workflow that runs Badge Forge on every push to main or daily at midnight (UTC). πŸš€

πŸ“Œ .github/workflows/badge-forge.yml

name: Generate Badges

on:
push:
branches:
  - main
schedule:
  - cron: "0 0 * * *" # Runs daily at midnight UTC

jobs:
generate-badges:
  runs-on: ubuntu-latest
  steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Setup Node.js
      uses: actions/setup-node@v4
      with:
        node-version: 22
        cache: "npm"

    - name: Install dependencies
      run: npm ci

    - name: Generate badges
      run: npm run generate-badges # Ensure this script exists in package.json

    - name: Commit and push changes
      run: |
        git config --global user.name "github-actions[bot]"
        git config --global user.email "github-actions[bot]@users.noreply.github.com"
        git add README.md
        git commit -m "Auto-update badges" || echo "No changes to commit"
        git push
1.2.0

4 months ago

1.1.0

4 months ago

1.3.0

4 months ago

1.0.0

4 months ago