npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

get-git-version

v0.5.5

Published

Gets Git version and commit information for one or more repositories.

Downloads

663

Readme

get-git-version

npm node

Gets Git version and commit information for one or more repositories. This is useful for applications that span multiple repositories or use submodules.

Prerequisites

Git is expected to be preinstalled (and in PATH).

The script simply runs shell commands similar to:

  • repository: git config --get remote.origin.url
  • branch: git rev-parse --abbrev-ref HEAD
  • sha1: git rev-parse HEAD
  • date: git --no-pager log --pretty=format:"%at" -n1
  • clean: git diff-index --quiet HEAD --
  • version: git describe --tags --match "v[0-9]*" HEAD

Install

npm install -g get-git-version

Usage

To get information about the current directory, run:

get-git-version

If the working directory contains a package.json file, it will be used to set the name and default version.

Otherwise, the name of the current folder is used as the name and version is not set.

Sample Output

{
  "name": "get-git-version",
  "version": "0.0.4",
  "git": {
    "repository": "https://github.com/polys/git-version.git",
    "branch": "master",
    "sha1": "dccb48950fa60511c3b235404209f17610aab67e",
    "date": "2018-04-21T17:31:35+01:00",
    "clean": false
  },
  "components": []
}

or with --version-only:

{
  "name": "get-git-version",
  "version": "0.1.4"
}

Command-line Options

  • -w [path] or --working-dir [path] overrides the working directory (defaults to the current directory)
  • -o [path] or --out-file [path] writes the output to a file instead of stdout
  • -c [path] or --config-file [path] overrides the config file name (defaults to .git-version.config.json)
  • --app-id [id] overrides the application id (defaults to app)
  • --version-tag-prefix [prefix] overrides the default version tag prefix (defaults to v[0-9]*)
  • --no-pretty disables pretty printing the output JSON
  • --version-only returns only the version, without git information
  • -h or --help outputs usage information

Configuration file example

Create a .git-version.config.json file with a simple array, similar to:

[
  {
    "id": "app",
    "name": "Test App",
    "path": ".",
    "versionTagPrefix": "v[0-9]*",
    "version": "0.1"
  },
  {
    "id": "dummy",
    "name": "Dummy Component",
    "path": ".",
    "versionTagPrefix": "v[0-9]*"
  }
]

All entries are expected to have an id.

If name is specified, it's simply copied to the output.

If path is specified, it's joined to the working directory path; otherwise, defaults to the working directory.

An item whose id is app (can be overridden using the --app-id command-line option) is required and treated as the main application. All other items are considered components of that application.

If versionTagPrefix is specified, a version is computed for the component, based on the most recent git tag that starts with this prefix. If no matching tag is not found, version won't be defined.