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

git-optimum-stats

v0.1.0

Published

Simple utility to get the optimum summary of your git repository.

Downloads

10

Readme

git-optimum-stats

utility to get the summary of your git repository. useful in adding a build/commit hash to your deployment/deployed scripts/html so you can track the deployment builds. Using it we can easily debug the issues in different environment and find the exact source present in that environment in case of multiple environments.

Usage

const stats = require('git-optimum-stats');
const gitDir = 'some/dir/containing/git/directory';
const info = {
  Version: stats.version(gitDir),
  Branch: stats.branch(gitDir),
  Hash: stats.hash(gitDir),
  LastCommitOn: stats.lastCommitOn(gitDir),
  LastCommitBy: stats.lastCommitBy(gitDir),
};

console.log(JSON.stringify(info, null, 2));

// {
//   "Version": "A_GIT_TAG-g<SHORT_HASH>-dirty",
//   "Branch": "CURRENT_BRANCH",
//   "Hash": "LONG_STRING_OF_APLHA-NUMERIC_CHARS",
//   "LastCommitOn": "DATE",
//   "LastCommitBy": "AUTHOR <AUTHOR_EMAIL>"
// }
const version = stats.rawCmd(gitDir, 'describe --always --tags --dirty="-dev"');

console.log("Version: ", version);
// "A_GIT_TAG-g<SHORT_HASH>-dev"
// hash as a class in html document
const hash = stats.hash(gitDir);

<body class="<%= hash %>"></body> // Sample ejs template

Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js 6.0.0 or higher is required.

Installation is done using the npm install command:

$ npm install git-optimum-stats

API

Note: All the below APIs has both sync and async versions - depending on the callback function.

All the below APIs take a root directory path containing a .git directory as a first param (this is a required param) and a optional custom git command as a second param.

#version(gitDir[, custom_command] [, callback])

  • Returns a string of git tags and short hash along with '-dirty' suffix (the suffix can be changed by passing the custom command.

#branch(gitDir[, custom_command] [, callback])

  • Returns a current git branch.

#hash(gitDir[, custom_command] [, callback])

  • Returns a current git hash in the form alpha-numeric string.

#lastCommitOn(gitDir[, custom_command] [, callback])

  • Returns a date when the latest commit is made.

#lastCommitBy(gitDir[, custom_command] [, callback])

  • Returns a name and the email address of latest commit author.

#rawCmd(gitDir, custom_command [, callback])

  • This a special function that takes a root directory path containing a .git directory as first param and any valid git command as second param. Both these params are required and a third optional param as a callback function.
  • Returns a result of passed git command.
  • Note: We are using child_process#exec functionality which has a default buffer limit of 200KB.

License

MIT