Omlet Docs
BlogChangelogAsk the CommunityContact Sales
  • Get started
    • What is Omlet?
    • CLI & Dashboard
  • Omlet for VS Code
  • CLI & Dashboard
    • CLI
      • Your first scan
      • Set up your dashbard
      • Future scans
      • Ensure data accuracy
      • Config file
        • Exports configuration
        • Mapping aliases
        • Excluding certain components & files
        • Tutorial: Config file
      • Custom component properties
        • CLI hooks
        • Tutorial 1: Team/code owner usage
        • Tutorial 2: Package version tracking
        • Other example scripts
      • Set up regular scans
      • CLI commands
        • init
        • analyze
        • login
    • Analytics
      • Popular charts
      • Create custom charts
      • Save charts to dashboard
      • Share charts and dashboards with your team
      • Download chart data
    • Components
      • Search and filter components
      • Component tags
      • Dependency Tree
      • Props tracking
    • Workspace & Account
      • Invite team members
      • Renaming projects
      • Update your email address
      • Access your billing details & invoices
  • Security
    • Security in Omlet
    • Data collection
  • Help
    • Pricing
    • FAQs
      • How detection works?
      • Monorepo support
      • How to delete scans?
      • Omlet vs. React Scanner
      • Working with multiple workspaces
    • Troubleshooting
      • Debugging CLI issues
      • Some components aren't detected
      • API failed or timeout
      • Are you behind a proxy?
      • Troubleshooting Git errors
Powered by GitBook
On this page
  1. CLI & Dashboard
  2. CLI
  3. Custom component properties

Tutorial 1: Team/code owner usage

Step-by-step tutorial to add Team/Codeowner information to components and analyze them.

PreviousCLI hooksNextTutorial 2: Package version tracking

Last updated 1 month ago

In this tutorial, we'll create a hook script that'll process the CODEOWNERS file and add the owner information as a custom component property to each component. This will help you analyze the design system adoption across different teams.

1

CODEOWNERS file

CODEOWNERS is a file used in many repositories (e.g., GitHub, GitLab, Bitbucket) to define the owners of specific files or directories in a codebase. Here is an example of a CODEOWNERS file:

.github/CODEOWNERS
# Default owner for all files
* @acme/design-system

# Owners for specific applications
applications/mail/ @acme/mail-team
applications/calendar/ @acme/calendar-team
applications/drive/ @acme/drive-team
applications/vpn-settings/ @acme/vpn-team
applications/pass/ @acme/pass-team

# Owners for shared packages
packages/components/ @acme/frontend-team
packages/utils/ @acme/frontend-team

# Owners for configuration and tooling
.yarn/ @acme/devops-team
.eslintrc.js @acme/devops-team
.prettier.config.mjs @acme/devops-team

Before stepping into the hook script, make sure that the package is installed as a dependency to your project. It'll help us process the CODEOWNER file:

npm install codeowners --save-dev
yarn add codeowners --dev
pnpm add codeowners --save-dev
2

Setting up the hook script

Create a file named hook-script.js in the root of your repository and copy the following code.

hook-script.js
const Codeowners = require("codeowners");

const repo = new Codeowners();
function getOwners(filePath) {
    const owners = repo.getOwner(`${filePath}`);
    if (owners.length === 0) {
        owners.push("unknown");
    }
    return owners
        .filter((o) => o !== "")
        .map((o) => `${o}`)
        .join(",");
}

/**
 * @type {import('@omlet/cli').CliHookModule}
 */
module.exports = {
    async afterScan(components) {
        for (const component of components) {
            const owners = getOwners(component.filePath);
            component.setMetadata("Codeowner", owners);
        }
    },
};

The setMetadata function will add the Codeowner property to each component. Feel free to update the property to a preferred name.

3

Scan your repo

4

Filter components by owner

Once the CLI scan complete, the Codeowner property will be associated with each component.

Navigate to the "Components" page. From the "Custom properties" filter, click Codeowner and select some of the owners from the revealed dropdown. This will list all the components assigned to the selected owners.

You can create a tag based on this filter to easily access it later on and generate charts for your specific needs.

5

Analyze the usage

To analyze component usage, open your Analytics dashboard and click "Create new analysis" button on top-right. Under the Analyze section, select "Codeowner" from "Custom properties". Total number of component usages for each Codeowner will be listed.

You can break down the chart to gain deeper insights into how teams are utilizing components. For example, adding a “Tag” breakdown will allow you to compare each team’s design system usage to overall component usage.

codeowners

Feel free to customize the script based on your setup—reach us at for any questions/feedback.

support@omlet.dev

Use the --hook-script argument with the analyze command, specifying the path to your script:

npx @omlet/cli analyze --hook-script ./hook-script.js
yarn dlx @omlet/cli analyze --hook-script ./hook-script.js
pnpm dlx @omlet/cli analyze --hook-script ./hook-script.js