Home / File/ preflight-add.ts — ui Source File

preflight-add.ts — ui Source File

Architecture documentation for preflight-add.ts, a typescript file in the ui codebase. 8 imports, 0 dependents.

File typescript FrameworkTooling CLICore 8 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  97e802ab_4029_5b6c_ffde_beefedf0a4c4["preflight-add.ts"]
  d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5["path"]
  97e802ab_4029_5b6c_ffde_beefedf0a4c4 --> d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5
  751e37a3_64e3_964c_ad62_cd1f108b59e7["add"]
  97e802ab_4029_5b6c_ffde_beefedf0a4c4 --> 751e37a3_64e3_964c_ad62_cd1f108b59e7
  2dce5b77_ae3e_67df_2221_13714429e261["errors"]
  97e802ab_4029_5b6c_ffde_beefedf0a4c4 --> 2dce5b77_ae3e_67df_2221_13714429e261
  b2895591_2a74_d518_deda_2f26be766dcb["get-config"]
  97e802ab_4029_5b6c_ffde_beefedf0a4c4 --> b2895591_2a74_d518_deda_2f26be766dcb
  15e8bad0_00cc_3d96_8e33_2f062120ea7f["highlighter"]
  97e802ab_4029_5b6c_ffde_beefedf0a4c4 --> 15e8bad0_00cc_3d96_8e33_2f062120ea7f
  1df8bbed_5110_29f0_12f0_996fc7a1eda1["logger"]
  97e802ab_4029_5b6c_ffde_beefedf0a4c4 --> 1df8bbed_5110_29f0_12f0_996fc7a1eda1
  f9f5e551_eb59_1a6b_8bf2_b97e73eb13de["fs-extra"]
  97e802ab_4029_5b6c_ffde_beefedf0a4c4 --> f9f5e551_eb59_1a6b_8bf2_b97e73eb13de
  6802ce19_522d_e5fb_e458_8826d9f6952e["zod"]
  97e802ab_4029_5b6c_ffde_beefedf0a4c4 --> 6802ce19_522d_e5fb_e458_8826d9f6952e
  style 97e802ab_4029_5b6c_ffde_beefedf0a4c4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import path from "path"
import { addOptionsSchema } from "@/src/commands/add"
import * as ERRORS from "@/src/utils/errors"
import { getConfig } from "@/src/utils/get-config"
import { highlighter } from "@/src/utils/highlighter"
import { logger } from "@/src/utils/logger"
import fs from "fs-extra"
import { z } from "zod"

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

Functions

Dependencies

  • add
  • errors
  • fs-extra
  • get-config
  • highlighter
  • logger
  • path
  • zod

Frequently Asked Questions

What does preflight-add.ts do?
preflight-add.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 preflight-add.ts?
preflight-add.ts defines 1 function(s): preFlightAdd.
What does preflight-add.ts depend on?
preflight-add.ts imports 8 module(s): add, errors, fs-extra, get-config, highlighter, logger, path, zod.
Where is preflight-add.ts in the architecture?
preflight-add.ts is located at packages/shadcn/src/preflights/preflight-add.ts (domain: FrameworkTooling, subdomain: CLICore, directory: packages/shadcn/src/preflights).

Analyze Your Own Codebase

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

Try Supermodel Free