(
componentName: string,
options: Partial<InstallOptions> = {}
)
| 13 | import { determineImportPath } from "../utils/file-system"; |
| 14 | |
| 15 | export async function addCommand( |
| 16 | componentName: string, |
| 17 | options: Partial<InstallOptions> = {} |
| 18 | ): Promise<boolean> { |
| 19 | const targetPath = process.cwd(); |
| 20 | |
| 21 | // Check if craftrn-ui folder exists, if not, run init |
| 22 | const craftrnUiPath = path.join(targetPath, "craftrn-ui"); |
| 23 | if (!(await fs.pathExists(craftrnUiPath))) { |
| 24 | console.log( |
| 25 | chalk.blue( |
| 26 | "😅 @craftreactnative/ui not found. Initializing project first...\n" |
| 27 | ) |
| 28 | ); |
| 29 | await initCommand(); |
| 30 | console.log(chalk.blue("\nNow adding component...\n")); |
| 31 | } |
| 32 | |
| 33 | // Validate component exists |
| 34 | const spinner = ora(`Checking component ${componentName}...`).start(); |
| 35 | |
| 36 | const componentInfo = await getComponentInfo(componentName); |
| 37 | if (!componentInfo) { |
| 38 | spinner.fail(`Component ${chalk.red(componentName)} not found`); |
| 39 | |
| 40 | // Show available components only if not using --all flag |
| 41 | if (!options.all) { |
| 42 | const available = await getAvailableComponents(); |
| 43 | if (available.length > 0) { |
| 44 | console.log(chalk.blue("\nAvailable components:")); |
| 45 | available.forEach((comp) => console.log(` - ${comp}`)); |
| 46 | } |
| 47 | } |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | spinner.succeed(`Found component ${chalk.green(componentName)}`); |
| 52 | |
| 53 | // Resolve dependencies |
| 54 | const loadingSpinner = ora("Resolving dependencies...").start(); |
| 55 | |
| 56 | try { |
| 57 | const dependencies = await resolveDependencies(componentName); |
| 58 | loadingSpinner.succeed( |
| 59 | `Resolved ${dependencies.length} component(s): ${chalk.cyan( |
| 60 | dependencies.join(", ") |
| 61 | )}` |
| 62 | ); |
| 63 | |
| 64 | // Copy components |
| 65 | const copySpinner = ora("Copying components...").start(); |
| 66 | |
| 67 | for (const dep of dependencies) { |
| 68 | const componentPath = path.join( |
| 69 | targetPath, |
| 70 | "craftrn-ui", |
| 71 | "components", |
| 72 | dep |
no test coverage detected