Home / Function/ preFlightAdd() — ui Function Reference

preFlightAdd() — ui Function Reference

Architecture documentation for the preFlightAdd() function in preflight-add.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  a8b6b3ff_1b19_c217_4e00_5703c6d07a3f["preFlightAdd()"]
  97e802ab_4029_5b6c_ffde_beefedf0a4c4["preflight-add.ts"]
  a8b6b3ff_1b19_c217_4e00_5703c6d07a3f -->|defined in| 97e802ab_4029_5b6c_ffde_beefedf0a4c4
  style a8b6b3ff_1b19_c217_4e00_5703c6d07a3f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shadcn/src/preflights/preflight-add.ts lines 10–61

export async function preFlightAdd(options: z.infer<typeof addOptionsSchema>) {
  const errors: Record<string, boolean> = {}

  // Ensure target directory exists.
  // Check for empty project. We assume if no package.json exists, the project is empty.
  if (
    !fs.existsSync(options.cwd) ||
    !fs.existsSync(path.resolve(options.cwd, "package.json"))
  ) {
    errors[ERRORS.MISSING_DIR_OR_EMPTY_PROJECT] = true
    return {
      errors,
      config: null,
    }
  }

  // Check for existing components.json file.
  if (!fs.existsSync(path.resolve(options.cwd, "components.json"))) {
    errors[ERRORS.MISSING_CONFIG] = true
    return {
      errors,
      config: null,
    }
  }

  try {
    const config = await getConfig(options.cwd)

    return {
      errors,
      config: config!,
    }
  } catch (error) {
    logger.break()
    logger.error(
      `An invalid ${highlighter.info(
        "components.json"
      )} file was found at ${highlighter.info(
        options.cwd
      )}.\nBefore you can add components, you must create a valid ${highlighter.info(
        "components.json"
      )} file by running the ${highlighter.info("init")} command.`
    )
    logger.error(
      `Learn more at ${highlighter.info(
        "https://ui.shadcn.com/docs/components-json"
      )}.`
    )
    logger.break()
    process.exit(1)
  }
}

Subdomains

Frequently Asked Questions

What does preFlightAdd() do?
preFlightAdd() is a function in the ui codebase, defined in packages/shadcn/src/preflights/preflight-add.ts.
Where is preFlightAdd() defined?
preFlightAdd() is defined in packages/shadcn/src/preflights/preflight-add.ts at line 10.

Analyze Your Own Codebase

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

Try Supermodel Free