Home / File/ update-fonts.ts — ui Source File

update-fonts.ts — ui Source File

Architecture documentation for update-fonts.ts, a typescript file in the ui codebase. 9 imports, 1 dependents.

File typescript FrameworkTooling CLICore 9 imports 1 dependents 14 functions

Entity Profile

Dependency Diagram

graph LR
  b169f1bf_76c5_e7c9_f493_15fe0f296591["update-fonts.ts"]
  eac8f98f_e40a_7fe8_f505_372c83d20c7a["fs"]
  b169f1bf_76c5_e7c9_f493_15fe0f296591 --> eac8f98f_e40a_7fe8_f505_372c83d20c7a
  d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5["path"]
  b169f1bf_76c5_e7c9_f493_15fe0f296591 --> d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5
  a3b2545e_3d8c_699d_ef11_6ab18db14666["schema"]
  b169f1bf_76c5_e7c9_f493_15fe0f296591 --> a3b2545e_3d8c_699d_ef11_6ab18db14666
  b2895591_2a74_d518_deda_2f26be766dcb["get-config"]
  b169f1bf_76c5_e7c9_f493_15fe0f296591 --> b2895591_2a74_d518_deda_2f26be766dcb
  24fd9695_7ceb_b1f6_c84e_e349d5356c12["get-project-info"]
  b169f1bf_76c5_e7c9_f493_15fe0f296591 --> 24fd9695_7ceb_b1f6_c84e_e349d5356c12
  15e8bad0_00cc_3d96_8e33_2f062120ea7f["highlighter"]
  b169f1bf_76c5_e7c9_f493_15fe0f296591 --> 15e8bad0_00cc_3d96_8e33_2f062120ea7f
  a3e9bc4e_1faf_6261_a1db_396981c7761d["spinner"]
  b169f1bf_76c5_e7c9_f493_15fe0f296591 --> a3e9bc4e_1faf_6261_a1db_396981c7761d
  4f6f7e78_23ff_4f5f_c723_474454f64c85["ts-morph"]
  b169f1bf_76c5_e7c9_f493_15fe0f296591 --> 4f6f7e78_23ff_4f5f_c723_474454f64c85
  6802ce19_522d_e5fb_e458_8826d9f6952e["zod"]
  b169f1bf_76c5_e7c9_f493_15fe0f296591 --> 6802ce19_522d_e5fb_e458_8826d9f6952e
  abc53e7d_e788_42c1_5281_5d48cd66ef4e["update-fonts.test.ts"]
  abc53e7d_e788_42c1_5281_5d48cd66ef4e --> b169f1bf_76c5_e7c9_f493_15fe0f296591
  style b169f1bf_76c5_e7c9_f493_15fe0f296591 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { existsSync, promises as fs } from "fs"
import path from "path"
import { RegistryFontItem, registryResolvedItemsTreeSchema } from "@/src/schema"
import { Config } from "@/src/utils/get-config"
import { ProjectInfo, getProjectInfo } from "@/src/utils/get-project-info"
import { highlighter } from "@/src/utils/highlighter"
import { spinner } from "@/src/utils/spinner"
import {
  CallExpression,
  Project,
  ScriptKind,
  SyntaxKind,
  VariableDeclarationKind,
} from "ts-morph"
import z from "zod"

export async function massageTreeForFonts(
  tree: z.infer<typeof registryResolvedItemsTreeSchema>,
  config: Config
) {
  if (!tree.fonts?.length) {
    return tree
  }

  const projectInfo = await getProjectInfo(config.resolvedPaths.cwd)

  if (!projectInfo) {
    return tree
  }

  const [fontSans] = tree.fonts
  tree.cssVars ??= {}
  tree.cssVars.theme ??= {}

  if (
    projectInfo.framework.name === "next-app" ||
    projectInfo.framework.name === "next-pages"
  ) {
    tree.cssVars.theme[
      fontSans.font.variable
    ] = `var(${fontSans.font.variable})`
    return tree
  }

  // Other frameworks will use fontsource for now.
  const fontName = fontSans.name.replace("font-", "")
  const fontSourceDependency = `@fontsource-variable/${fontName}`
  tree.dependencies ??= []
  tree.dependencies.push(fontSourceDependency)
  tree.css ??= {}
  tree.css[`@import "${fontSourceDependency}"`] = {}
  tree.css["@layer base"] ??= {}
  tree.css["@layer base"].html = {
    "@apply font-sans": {},
  }
  tree.css["@layer base"].body = {
    "@apply font-sans bg-background text-foreground": {},
  }
  tree.cssVars.theme[fontSans.font.variable] = fontSans.font.family

// ... (466 more lines)

Subdomains

Dependencies

  • fs
  • get-config
  • get-project-info
  • highlighter
  • path
  • schema
  • spinner
  • ts-morph
  • zod

Frequently Asked Questions

What does update-fonts.ts do?
update-fonts.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 update-fonts.ts?
update-fonts.ts defines 14 function(s): buildFontOptions, ensureCnImport, findFontVariableDeclaration, findInsertPosition, findLayoutFile, insertFontVariablesIntoCn, massageTreeForFonts, parseTemplateLiteralToCnArgs, removeFontVariablesFromCn, toCamelCase, and 4 more.
What does update-fonts.ts depend on?
update-fonts.ts imports 9 module(s): fs, get-config, get-project-info, highlighter, path, schema, spinner, ts-morph, and 1 more.
What files import update-fonts.ts?
update-fonts.ts is imported by 1 file(s): update-fonts.test.ts.
Where is update-fonts.ts in the architecture?
update-fonts.ts is located at packages/shadcn/src/utils/updaters/update-fonts.ts (domain: FrameworkTooling, subdomain: CLICore, directory: packages/shadcn/src/utils/updaters).

Analyze Your Own Codebase

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

Try Supermodel Free