MCPcopy Index your code
hub / github.com/craftreactnative/ui / initCommand

Function initCommand

cli/src/commands/init.ts:23–248  ·  view source on GitHub ↗
(options: InitOptions = {})

Source from the content-addressed store, hash-verified

21}
22
23export async function initCommand(options: InitOptions = {}): Promise<void> {
24 const targetPath = process.cwd();
25 const packageJsonPath = path.join(targetPath, "package.json");
26
27 let packageJson;
28 try {
29 packageJson = await fs.readJson(packageJsonPath);
30 } catch (error) {
31 console.error(chalk.red("Error: Could not read package.json"));
32 return;
33 }
34
35 console.log(
36 chalk.blue("🚀 Initializing @craftreactnative/ui in your project...\n")
37 );
38
39 // Detect project type once at the beginning
40 const isExpoProject = await isExpo(targetPath);
41
42 // Install required dependencies
43 if (!options.skipDeps) {
44 const requiredDeps = [
45 "react-native-unistyles@^3",
46 "react-native-edge-to-edge@^1",
47 "react-native-nitro-modules@0.29.4",
48 "react-native-gesture-handler@^2",
49 "react-native-reanimated@^3",
50 "react-native-svg@^14",
51 ];
52
53 const missingDeps = requiredDeps.filter((dep) => {
54 // Extract package name from version specifier (e.g., "react-native-unistyles@^3" -> "react-native-unistyles")
55 const packageName = dep.split("@")[0];
56 return (
57 !packageJson.dependencies?.[packageName] &&
58 !packageJson.devDependencies?.[packageName]
59 );
60 });
61
62 if (missingDeps.length > 0) {
63 console.log(
64 chalk.blue(
65 `📦 Installing ${missingDeps.length} missing dependencies...\n`
66 )
67 );
68
69 try {
70 // Install dependencies one by one
71 for (const dep of missingDeps) {
72 const packageName = dep.split("@")[0];
73 const isNativeDep = isNativeDependency(packageName);
74
75 const method =
76 isExpoProject && isNativeDep ? "expo install" : "package manager";
77 const depSpinner = ora(
78 `Installing ${chalk.cyan(packageName)} with ${method}...`
79 ).start();
80

Callers 2

cli.tsFile · 0.90
addCommandFunction · 0.90

Calls 12

isExpoFunction · 0.90
copyThemesFunction · 0.90
hasExpoRouterFunction · 0.90
setupBabelConfigFunction · 0.90
getImportInstructionsFunction · 0.90
isNativeDependencyFunction · 0.85
installDependencyFunction · 0.85
showSetupInstructionsFunction · 0.85
addUnistylesImportFunction · 0.85

Tested by

no test coverage detected