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

preflight-migrate.ts — ui Source File

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

import path from "path"
import { addOptionsSchema } from "@/src/commands/add"
import { migrateOptionsSchema } from "@/src/commands/migrate"
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 preFlightMigrate(
  options: z.infer<typeof migrateOptionsSchema>
) {
  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 run a migration, 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
  • migrate
  • path
  • zod

Frequently Asked Questions

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