Home / File/ transform-menu.ts — ui Source File

transform-menu.ts — ui Source File

Architecture documentation for transform-menu.ts, a typescript file in the ui codebase. 2 imports, 0 dependents.

File typescript FrameworkTooling CLICore 2 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  f4ce2b89_2584_affd_7f0d_945da4db1c0b["transform-menu.ts"]
  e69863ed_3e2f_ef94_648a_ef0155c386ef["transformers"]
  f4ce2b89_2584_affd_7f0d_945da4db1c0b --> e69863ed_3e2f_ef94_648a_ef0155c386ef
  4f6f7e78_23ff_4f5f_c723_474454f64c85["ts-morph"]
  f4ce2b89_2584_affd_7f0d_945da4db1c0b --> 4f6f7e78_23ff_4f5f_c723_474454f64c85
  style f4ce2b89_2584_affd_7f0d_945da4db1c0b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { Transformer } from "@/src/utils/transformers"
import { SyntaxKind } from "ts-morph"

// Transforms cn-menu-target class based on config.menuColor.
// If menuColor is "inverted", replaces cn-menu-target with "dark".
// Otherwise, removes cn-menu-target entirely.
export const transformMenu: Transformer = async ({ sourceFile, config }) => {
  const menuColor = config.menuColor

  // If menuColor is not set or is "default", we remove the placeholder.
  const replacement = menuColor === "inverted" ? "dark" : ""

  for (const attr of sourceFile.getDescendantsOfKind(SyntaxKind.JsxAttribute)) {
    const attrName = attr.getNameNode().getText()
    if (attrName !== "className") {
      continue
    }

    const initializer = attr.getInitializer()
    if (!initializer) {
      continue
    }

    const text = initializer.getText()
    if (!text.includes("cn-menu-target")) {
      continue
    }

    // Replace cn-menu-target with the replacement value.
    let newText = text.replace(/cn-menu-target/g, replacement)

    // Clean up extra spaces if we removed the class.
    if (!replacement) {
      // Remove double spaces.
      newText = newText.replace(/\s{2,}/g, " ")
      // Clean up leading/trailing spaces in strings.
      newText = newText.replace(/"\s+/g, '"')
      newText = newText.replace(/\s+"/g, '"')
      // Clean up empty strings in cn() calls.
      newText = newText.replace(/,\s*""\s*,/g, ",")
      newText = newText.replace(/\(\s*""\s*,/g, "(")
      newText = newText.replace(/,\s*""\s*\)/g, ")")
    }

    attr.setInitializer(newText)
  }

  return sourceFile
}

Subdomains

Functions

Dependencies

  • transformers
  • ts-morph

Frequently Asked Questions

What does transform-menu.ts do?
transform-menu.ts is a source file in the ui codebase, written in typescript. It belongs to the FrameworkTooling domain, CLICore subdomain.
What functions are defined in transform-menu.ts?
transform-menu.ts defines 1 function(s): transformMenu.
What does transform-menu.ts depend on?
transform-menu.ts imports 2 module(s): transformers, ts-morph.
Where is transform-menu.ts in the architecture?
transform-menu.ts is located at packages/shadcn/src/utils/transformers/transform-menu.ts (domain: FrameworkTooling, subdomain: CLICore, directory: packages/shadcn/src/utils/transformers).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free