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-metric

v0.1.7

Published

Git Metric is a tool for tracking file-based metrics in a git repository. Git Metric is ideal for projects with an ongoing incremental migration.

Downloads

15

Readme

Git Metric

Git Metric is a tool for tracking file-based metrics in a git repository. Git Metric is ideal for projects with an ongoing incremental migration, for example:

  • Migrating from AngularJS to React
  • Migrating from JavaScript to TypeScript
  • Any incremental removal of an old library or framework

Git Metric provides commit-based metrics, which can be easily displayed on a chart to provide meaningful insights.

See below the output of the example usage, which analyzes the TypeScriptSamples repository. The chart shows the number of JS, TS, Angular-related and React-related files for each commit in the repository. Chart example for TypeScriptSamples

Git Metric is extremely fast, and can be used with projects with various sizes and ages. Please note: if you need to collect metrics which depends on more than just the files content (like code coverage or complitation warnings), this tool can't help you.

How it works

When used, Git Metric will:

  • Fetch the repository's commits the git history using gitlog.
  • Calculate the metrics for each commit using git ls-tree and git grep.

Git Metric is written in TypeScript, and supplies d.ts files for you convenience.

Installation

npm install git-metric

Usage

import gitMetric from 'gitMetric';

gitMetric.run({
    repositoryPath: '/full/path/to/repo',
    trackByFileExtension: { // Tracks a metric by the file extension
        'Extension Metric 1': ['glob1', 'glob2'], // Each extension metric secifies the globs to look for
        // For example:
        'JS File Count': ['**.js', '**.jsx'],
        'TS File Count': ['**.ts', '**.tsx'],
    },
    trackByFileContent: { // Tracks a metric by the file's content
        'Content Metric 1': { // Each file content metric specifies the file globs and the phrase to look for in each file:
            globs: ['glob10', 'glob20',],
            phrase: 'some_phrase',
        },
        // For example:
        'React Related': {
            globs: ['**.js', '**.jsx', '**.ts', '**.tsx'],
            phrase: 'react'
        },
    },
    commitsSince: '1-15-2010', //MM-DD-YYYY
    commitsUntil: '11-18-2021', //MM-DD-YYYY
    maxCommitsCount: 450,
}).then(commitsWithMetrics => {
    // Resolves with details about each commit, along with its metric. See below.
})

run() resolves with an array of commits with metrics. Each element in the result contains two properties:

  1. metrics - a map between a configured metric, and its value for this commit. A result for the configuration from the usage example will look like the following:
{
    'Extension Metric 1': 23
    'JS File Count': 174,
    'TS File Count': 320,
}
  1. commit - additional details about the commit: hash, authorName, subject, authorDate, authorEmail, files and status. The details are provided by gitlog.

Psst.. If you only want a one-time analyze of your project, you can just adjust the example code for your need.

Running the Example

  1. Clone the repo - git clone https://github.com/omril321/git-metric.git
  2. cd git-metric/example
  3. npm install
  4. npm start
  5. Open the link on the console to view the chart

Contributing

If you wish to contribute, please contact me at any way. I'd be happy to work with you :)