Home / File/ view.ts — ui Source File

view.ts — ui Source File

Architecture documentation for view.ts, a typescript file in the ui codebase. 13 imports, 0 dependents.

File typescript FrameworkTooling TemplateSync 13 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  3f70379c_fbf1_9ff8_2596_7f5153a582bb["view.ts"]
  d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5["path"]
  3f70379c_fbf1_9ff8_2596_7f5153a582bb --> d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5
  81c8b1a1_346a_8b27_dd1e_b8bbb29008b8["api"]
  3f70379c_fbf1_9ff8_2596_7f5153a582bb --> 81c8b1a1_346a_8b27_dd1e_b8bbb29008b8
  1f2f79fc_356c_e956_002d_737290df27fd["config"]
  3f70379c_fbf1_9ff8_2596_7f5153a582bb --> 1f2f79fc_356c_e956_002d_737290df27fd
  ff842930_3a95_1c03_7d51_b342f47a7971["context"]
  3f70379c_fbf1_9ff8_2596_7f5153a582bb --> ff842930_3a95_1c03_7d51_b342f47a7971
  57e5010f_701c_22f8_5921_3e11fc3c65aa["validator"]
  3f70379c_fbf1_9ff8_2596_7f5153a582bb --> 57e5010f_701c_22f8_5921_3e11fc3c65aa
  a3b2545e_3d8c_699d_ef11_6ab18db14666["schema"]
  3f70379c_fbf1_9ff8_2596_7f5153a582bb --> a3b2545e_3d8c_699d_ef11_6ab18db14666
  b900020d_484b_aaae_1b3f_6d4201875bd9["env-loader"]
  3f70379c_fbf1_9ff8_2596_7f5153a582bb --> b900020d_484b_aaae_1b3f_6d4201875bd9
  b2895591_2a74_d518_deda_2f26be766dcb["get-config"]
  3f70379c_fbf1_9ff8_2596_7f5153a582bb --> b2895591_2a74_d518_deda_2f26be766dcb
  6be7d8a9_c93c_8743_3ef7_968efff25479["handle-error"]
  3f70379c_fbf1_9ff8_2596_7f5153a582bb --> 6be7d8a9_c93c_8743_3ef7_968efff25479
  a54774e0_4fdd_ca8d_dfff_060d01ad3f57["registries"]
  3f70379c_fbf1_9ff8_2596_7f5153a582bb --> a54774e0_4fdd_ca8d_dfff_060d01ad3f57
  7d629454_eee6_73fe_2526_919af8d00ef9["commander"]
  3f70379c_fbf1_9ff8_2596_7f5153a582bb --> 7d629454_eee6_73fe_2526_919af8d00ef9
  f9f5e551_eb59_1a6b_8bf2_b97e73eb13de["fs-extra"]
  3f70379c_fbf1_9ff8_2596_7f5153a582bb --> f9f5e551_eb59_1a6b_8bf2_b97e73eb13de
  6802ce19_522d_e5fb_e458_8826d9f6952e["zod"]
  3f70379c_fbf1_9ff8_2596_7f5153a582bb --> 6802ce19_522d_e5fb_e458_8826d9f6952e
  style 3f70379c_fbf1_9ff8_2596_7f5153a582bb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import path from "path"
import { getRegistryItems } from "@/src/registry/api"
import { configWithDefaults } from "@/src/registry/config"
import { clearRegistryContext } from "@/src/registry/context"
import { validateRegistryConfigForItems } from "@/src/registry/validator"
import { rawConfigSchema } from "@/src/schema"
import { loadEnvFiles } from "@/src/utils/env-loader"
import { getConfig } from "@/src/utils/get-config"
import { handleError } from "@/src/utils/handle-error"
import { ensureRegistriesInConfig } from "@/src/utils/registries"
import { Command } from "commander"
import fsExtra from "fs-extra"
import { z } from "zod"

const viewOptionsSchema = z.object({
  cwd: z.string(),
})

export const view = new Command()
  .name("view")
  .description("view items from the registry")
  .argument("<items...>", "the item names or URLs to view")
  .option(
    "-c, --cwd <cwd>",
    "the working directory. defaults to the current directory.",
    process.cwd()
  )
  .action(async (items: string[], opts) => {
    try {
      const options = viewOptionsSchema.parse({
        cwd: path.resolve(opts.cwd),
      })

      await loadEnvFiles(options.cwd)

      // Start with a shadow config to support partial components.json.
      let shadowConfig = configWithDefaults({})

      // Check if there's a components.json file (partial or complete).
      const componentsJsonPath = path.resolve(options.cwd, "components.json")
      if (fsExtra.existsSync(componentsJsonPath)) {
        const existingConfig = await fsExtra.readJson(componentsJsonPath)
        const partialConfig = rawConfigSchema.partial().parse(existingConfig)
        shadowConfig = configWithDefaults(partialConfig)
      }

      // Try to get the full config, but fall back to shadow config if it fails.
      let config = shadowConfig
      try {
        const fullConfig = await getConfig(options.cwd)
        if (fullConfig) {
          config = configWithDefaults(fullConfig)
        }
      } catch {
        // Use shadow config if getConfig fails (partial components.json).
      }

      const { config: updatedConfig, newRegistries } =
        await ensureRegistriesInConfig(items, config, {
          silent: true,
          writeFile: false,
        })
      if (newRegistries.length > 0) {
        config.registries = updatedConfig.registries
      }

      // Validate registries early for better error messages.
      validateRegistryConfigForItems(items, config)

      const payload = await getRegistryItems(items, { config })
      console.log(JSON.stringify(payload, null, 2))
      process.exit(0)
    } catch (error) {
      handleError(error)
    } finally {
      clearRegistryContext()
    }
  })

Subdomains

Functions

Dependencies

  • api
  • commander
  • config
  • context
  • env-loader
  • fs-extra
  • get-config
  • handle-error
  • path
  • registries
  • schema
  • validator
  • zod

Frequently Asked Questions

What does view.ts do?
view.ts is a source file in the ui codebase, written in typescript. It belongs to the FrameworkTooling domain, TemplateSync subdomain.
What functions are defined in view.ts?
view.ts defines 1 function(s): view.
What does view.ts depend on?
view.ts imports 13 module(s): api, commander, config, context, env-loader, fs-extra, get-config, handle-error, and 5 more.
Where is view.ts in the architecture?
view.ts is located at packages/shadcn/src/commands/view.ts (domain: FrameworkTooling, subdomain: TemplateSync, directory: packages/shadcn/src/commands).

Analyze Your Own Codebase

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

Try Supermodel Free