Giter VIP home page Giter VIP logo

dependency-version-badge's Introduction

dependency-version-badge demo CI CI

A little script to update README file with dependency version badge

Badge examples prettier version debug version

Example badge (in this readme) for dev dependency prettier (showing incorrect version 4.0.1)

![prettier version](https://img.shields.io/badge/prettier-4.0.1-brightgreen)

Can be updated by installing this module and running:

$ npm i -D dependency-version-badge
$ npx update-badge prettier
saving updated readme with [email protected]
# alternative without dev dependency
$ npx -p dependency-version-badge update-badge prettier

The README is updated to

![prettier version](https://img.shields.io/badge/prettier-2.0.5-brightgreen)

Good use: run this tool on push to master branch using GitHub Action, then push updated code (if any) back to the repository. See .github/workflows/demo.yml.

You can pass multiple names at once

npx update-badge prettier debug ...

If a badge is not found, a new badge will be inserted on the first line of the README file. If the version contains special characters like ~ or ^, they will be removed. If the version is *, then this tool will fail and exit with non-zero exit code.

Examples

cypress-svelte-unit-test, cy-rollup

Versions in remote repositories

You can look up dependency versions in package.json files in remote repositories

npx update-badge dependency-version-badge --from https://github.com/bahmutov/cypress-svelte-unit-test

Will update the badge below

![dependency-version-badge used in cypress-svelte-unit-test version](... badge url ...)

For GitHub urls, you can simply use --from <organization name>/<repo name> like this

npx update-badge dependency-version-badge --from bahmutov/cypress-svelte-unit-test

You can pass a single dependency name and multiple --from parameters

npx update-badge X --from bahmutov/repo1 --from bahmutov/repo2 --from bahmutov/repo3

You can shorten multiple --from parameters using commas without spaces

npx update-badge X --from bahmutov/repo1,bahmutov/repo2,bahmutov/repo3

You can use custom file instead README.md using --file parameter

npx update-badge --file ./folder1/folder2/info.md

Examples table

Badge Example repo
dependency-version-badge used in cypress-svelte-unit-test version cypress-svelte-unit-test
dependency-version-badge used in cy-rollup version cy-rollup

Tip: you can set a GitHub workflow to run using a schedule to update those badges periodically. For example, to update the badges every night:

on:
  schedule:
    # update badges every night
    # because we have a few badges that are linked
    # to the external repositories
    - cron: '0 3 * * *'

See example in cypress-react-unit-test

Short badge

You can update a "short" badge where only the version of the dependency is listed. Use --short flag:

npx update-badge dependency-version-badge --short --from bahmutov/cy-rollup

The badge is below

dependency-version-badge used in cy-rollup short

Behind the latest version

By default every badge is bright green. But you can look up the latest version of the dependency and color code the badge depending on how far the current version is behind the latest version. If the current version is the latest, or a couple of minor versions behind, the badge is green. If the current version is more than a couple of minor releases behind, but is still on the same major version, the badge is yellow. If the current version is 1 or more major versions behind, the badge is red.

Latest version Current version Badge
2.3.0 2.2.0 up-to-date badge
2.3.0 2.0.0 a few minor versions behind badge
2.3.0 1.19.12 major version behind badge

To get a color-coded badge, use CLI flag --behind

Example color-coded badges for ava and execa dependencies are below

$ npm run demo:behind
Dependency Badge Short badge
ava version ava short
execa version execa short

Debugging

Run with environment variable DEBUG=dependency-version-badge to see verbose logs

License

MIT license

dependency-version-badge's People

Contributors

bahmutov avatar hollote avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

dependency-version-badge's Issues

Allow multiple --from parameters in a single command

Right now we allow updating multiple dependencies using same command

update-badge X Y Z

It would be nice to be able to update single dependency but from multiple repos

update-badge X --from R1 --from R2 --from R3

If trying to pass multiple dependency names AND multiple repos, should throw an error

conflicting script name

The name of the bin alias is update-badge which clashes with the name of the script from check-code-coverage

Screen Shot 2020-10-17 at 1 55 04 PM

Probably just change to dependency-version-badge, which is a breaking change

Allow --from shortcut

Where we just provide organization name plus repo name

--from https://github.com/bahmutov/storybook-code-coverage

should be the same as

--from bahmutov/storybook-code-coverage

Pull version for given dependency from another GitHub repo

For example when working on library X it would be nice to have badges for this library from the project's that use X.

update-badge X --from https://github.com/org/X-example1

It would go into the repo org/X-example1, find package.json file, read the version of X there and then would update the badge for it in the current README.md file.

If the own dependency badge is

![X version](...)

The for external repos we can do the following format

![X-example1 uses X version](...)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.