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

@livechat/design-system-metrics

v2.4.4

Published

<h1 align="center"> LiveChat Design System Metrics </h1>

Downloads

363

Readme

The metrics package provides a way to gather and display data in a consistent manner. It is designed to be customizable and easy to incorporate into your projects. Right now, there are two types of metrics available:

  • DesignTokens usage - a metric that shows how many times a design token is used in the project versus how many times inline color values are used.
  • Component usage - a metric that shows how many times a component is used in the project.

Installation

Run the following command using npm (or with you other favorite package manager, eg. yarn):

npm install -D @livechat/design-system-metrics

Intro

Library exports two functions that you can use to collect metrics data.

  • generateAndSendMetrics - a function that scans the project and sends the metrics data to the Flagman Service for further processing.
  • generateMetrics - a function that scans the project and returns an object with metrics data. Can be used to locally gather metrics data.

These functions are designed to be used in conjunction with the Flagman Service, which is a part of the LiveChat infrastructure.

How to use

generateAndSendMetrics

A main function that scans the project and sends the metrics data to the Flagman Service for further processing. It takes a few configuration objects as arguments:

  • scannerConfig - a configuration object for the react-scanner package. The only required property is rootDir - a path to the root directory of the project.
  • flagmanConfig - a configuration object for the Flagman Service. It should contain the following properties:
    • protocol - a protocol that is used to authenticate the request.
    • host - a host of the Flagman Service.
    • port - a port of the Flagman Service.
    • apiKey - an API key that is used to authenticate the request.
  • APP_ID - an ID of the application that the metrics are gathered for. Available AppIDs are: AGENT_APP, ACCOUNTS, HELPDESK.
  • BUILD_ID - an ID of the build that the metrics are gathered for.

Best way to automate metrics collection is to create a script in your project and run it as a part of your CI/CD pipeline. For example, you can add a metrics script to your package.json file and run it using npm run metrics command.

{
  "scripts": {
    "metrics": "node ./scripts/metrics.js"
  }
}
// scripts/metrics.js
const { generateAndSendMetrics } = require('@livechat/design-system-metrics');

(async () => {
  const APP_ID = 'AGENT_APP' | 'ACCOUNTS' | 'HELPDESK';
  await generateAndSendMetrics(
          { rootDir: 'src' },
          { protocol: 'http', host: 'flagman_host', port: 'flagman_port', apiKey: 'api_key' },
          APP_ID,
          BUILD_ID
  );
})();

generateMetrics

A simplified function that only scans the project and returns an object with metrics data. It takes a configuration object as an argument. The configuration object should contain the following properties:

  • rootDir - a path to the root directory of the project.
  • reactScannerConfig (optional) - a configuration object for the react-scanner package.
  • newDSLibraryAlias (optional) - an alias for the new design system library. By default, it is set to @livechat/design-system-react-components.
  • oldDSLibraryAlias (optional) - an alias for the old design system library. By default, it is set to @livechat/design-system.

Example usage:

const { generateMetrics } = require('@livechat/design-system-metrics');
   
const metricsData = await generateMetrics({
  rootDir: '/path/to/your/project',
});

Example result:

{
   "newDS": {
      "components": [{
         "name": "Button",
         "instances": 124,
         "props": {"onClick": 115, "kind": 124, "children": 124}
      }],
      "totalUses": 2097
   },
   "legacyDS": {
      "components": [],
      "totalUses": 488
   },
   "designTokenUsage": { "designTokenCount": 999, "colorStringLiteralCount": 999 }
}