Home / Function/ build() — ui Function Reference

build() — ui Function Reference

Architecture documentation for the build() function in build.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  1f84185c_151c_6684_7950_21469ba170db["build()"]
  60e84aa7_59a8_dec8_e6ff_bc217496a380["build.ts"]
  1f84185c_151c_6684_7950_21469ba170db -->|defined in| 60e84aa7_59a8_dec8_e6ff_bc217496a380
  style 1f84185c_151c_6684_7950_21469ba170db fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shadcn/src/commands/build.ts lines 32–99

  .action(async (registry: string, opts) => {
    try {
      const options = buildOptionsSchema.parse({
        cwd: path.resolve(opts.cwd),
        registryFile: registry,
        outputDir: opts.output,
      })

      const { resolvePaths } = await preFlightBuild(options)
      const content = await fs.readFile(resolvePaths.registryFile, "utf-8")

      const result = registrySchema.safeParse(JSON.parse(content))

      if (!result.success) {
        logger.error(
          `Invalid registry file found at ${highlighter.info(
            resolvePaths.registryFile
          )}.`
        )
        process.exit(1)
      }

      const buildSpinner = spinner("Building registry...")
      for (const registryItem of result.data.items) {
        buildSpinner.start(`Building ${registryItem.name}...`)

        // Add the schema to the registry item.
        registryItem["$schema"] =
          "https://ui.shadcn.com/schema/registry-item.json"

        // Loop through each file in the files array.
        for (const file of registryItem.files ?? []) {
          file["content"] = await fs.readFile(
            path.resolve(resolvePaths.cwd, file.path),
            "utf-8"
          )
        }

        // Validate the registry item.
        const result = registryItemSchema.safeParse(registryItem)
        if (!result.success) {
          logger.error(
            `Invalid registry item found for ${highlighter.info(
              registryItem.name
            )}.`
          )
          continue
        }

        // Write the registry item to the output directory.
        await fs.writeFile(
          path.resolve(resolvePaths.outputDir, `${result.data.name}.json`),
          JSON.stringify(result.data, null, 2)
        )
      }

      // Copy registry.json to the output directory.
      await fs.copyFile(
        resolvePaths.registryFile,
        path.resolve(resolvePaths.outputDir, "registry.json")
      )

      buildSpinner.succeed("Building registry.")
    } catch (error) {
      logger.break()
      handleError(error)
    }
  })

Subdomains

Frequently Asked Questions

What does build() do?
build() is a function in the ui codebase, defined in packages/shadcn/src/commands/build.ts.
Where is build() defined?
build() is defined in packages/shadcn/src/commands/build.ts at line 32.

Analyze Your Own Codebase

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

Try Supermodel Free