Home / Function/ preFlightInit() — ui Function Reference

preFlightInit() — ui Function Reference

Architecture documentation for the preFlightInit() function in preflight-init.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  bb1ed138_b8f5_634b_225d_48b9872563d6["preFlightInit()"]
  2c33207d_5e31_095b_ecdb_be9749a4d953["preflight-init.ts"]
  bb1ed138_b8f5_634b_225d_48b9872563d6 -->|defined in| 2c33207d_5e31_095b_ecdb_be9749a4d953
  style bb1ed138_b8f5_634b_225d_48b9872563d6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shadcn/src/preflights/preflight-init.ts lines 11–162

export async function preFlightInit(
  options: z.infer<typeof initOptionsSchema>
) {
  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,
      projectInfo: null,
    }
  }

  const projectSpinner = spinner(`Preflight checks.`, {
    silent: options.silent,
  }).start()

  if (
    fs.existsSync(path.resolve(options.cwd, "components.json")) &&
    !options.force
  ) {
    projectSpinner?.fail()
    logger.break()
    logger.error(
      `A ${highlighter.info(
        "components.json"
      )} file already exists at ${highlighter.info(
        options.cwd
      )}.\nTo start over, remove the ${highlighter.info(
        "components.json"
      )} file and run ${highlighter.info("init")} again.`
    )
    logger.break()
    process.exit(1)
  }

  projectSpinner?.succeed()

  const frameworkSpinner = spinner(`Verifying framework.`, {
    silent: options.silent,
  }).start()
  const projectInfo = await getProjectInfo(options.cwd)
  if (!projectInfo || projectInfo?.framework.name === "manual") {
    errors[ERRORS.UNSUPPORTED_FRAMEWORK] = true
    frameworkSpinner?.fail()
    logger.break()
    if (projectInfo?.framework.links.installation) {
      logger.error(
        `We could not detect a supported framework at ${highlighter.info(
          options.cwd
        )}.\n` +
          `Visit ${highlighter.info(
            projectInfo?.framework.links.installation
          )} to manually configure your project.\nOnce configured, you can use the cli to add components.`
      )
    }
    logger.break()
    process.exit(1)
  }
  frameworkSpinner?.succeed(
    `Verifying framework. Found ${highlighter.info(
      projectInfo.framework.label
    )}.`
  )

  let tailwindSpinnerMessage = "Validating Tailwind CSS."

  if (projectInfo.tailwindVersion === "v4") {
    tailwindSpinnerMessage = `Validating Tailwind CSS config. Found ${highlighter.info(
      "v4"
    )}.`
  }

  const tailwindSpinner = spinner(tailwindSpinnerMessage, {
    silent: options.silent,
  }).start()

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free