| 41 | * Validates package.json exists and checks for React Native/TypeScript setup |
| 42 | */ |
| 43 | export async function ensureProjectRoot(): Promise<void> { |
| 44 | const cwd = process.cwd(); |
| 45 | const packageJsonPath = path.join(cwd, "package.json"); |
| 46 | |
| 47 | if (!(await fs.pathExists(packageJsonPath))) { |
| 48 | console.error( |
| 49 | chalk.red("Error: No package.json found in current directory.") |
| 50 | ); |
| 51 | console.error( |
| 52 | chalk.yellow( |
| 53 | "Please run this command from your React Native project root." |
| 54 | ) |
| 55 | ); |
| 56 | process.exit(1); |
| 57 | } |
| 58 | |
| 59 | try { |
| 60 | const packageJson = await fs.readJson(packageJsonPath); |
| 61 | const deps = { |
| 62 | ...packageJson.dependencies, |
| 63 | ...packageJson.devDependencies, |
| 64 | }; |
| 65 | |
| 66 | // Check if it's a React Native project |
| 67 | const hasReactNative = |
| 68 | deps["react-native"] || deps["@react-native/cli"] || deps["expo"]; |
| 69 | |
| 70 | if (!hasReactNative) { |
| 71 | console.warn( |
| 72 | chalk.yellow( |
| 73 | "Warning: This doesn't appear to be a React Native project." |
| 74 | ) |
| 75 | ); |
| 76 | console.warn( |
| 77 | chalk.gray( |
| 78 | "@craftreactnative/ui components are designed for React Native apps." |
| 79 | ) |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | // Check if TypeScript is configured |
| 84 | const hasTypeScript = |
| 85 | deps["typescript"] || deps["@types/react"] || deps["@types/react-native"]; |
| 86 | |
| 87 | const hasTsConfig = await fs.pathExists(path.join(cwd, "tsconfig.json")); |
| 88 | |
| 89 | if (!hasTypeScript && !hasTsConfig) { |
| 90 | console.error(chalk.red("Error: TypeScript support not detected.")); |
| 91 | console.error( |
| 92 | chalk.yellow( |
| 93 | "@craftreactnative/ui components are written in TypeScript and require TypeScript support." |
| 94 | ) |
| 95 | ); |
| 96 | console.error(chalk.gray("Please set up TypeScript in your project:")); |
| 97 | console.error( |
| 98 | chalk.gray( |
| 99 | " npm install --save-dev typescript @types/react @types/react-native" |
| 100 | ) |