MCPcopy Create free account
hub / github.com/craftreactnative/ui / addUnistylesImport

Function addUnistylesImport

cli/src/commands/init.ts:299–346  ·  view source on GitHub ↗
(targetPath: string)

Source from the content-addressed store, hash-verified

297}
298
299async function addUnistylesImport(targetPath: string): Promise<void> {
300 const possibleEntryFiles = ["App.tsx", "app/_layout.tsx", "index.tsx"];
301
302 let entryFile: string | null = null;
303
304 // Find the main entry file
305 for (const file of possibleEntryFiles) {
306 const filePath = path.join(targetPath, file);
307 if (await fs.pathExists(filePath)) {
308 entryFile = filePath;
309 break;
310 }
311 }
312
313 if (!entryFile) {
314 throw new Error(
315 "Could not find main entry file (App.tsx, App.ts, index.ts, etc.)"
316 );
317 }
318
319 const content = await fs.readFile(entryFile, "utf8");
320
321 // Determine the correct import path based on project structure and existing patterns
322 const importPath = await determineImportPath(
323 targetPath,
324 entryFile,
325 "craftrn-ui/themes/unistyles"
326 );
327 const importStatement = `import "${importPath}";`;
328
329 // Check if import already exists (any variant)
330 if (
331 content.includes(importStatement) ||
332 content.includes(`import '${importPath}'`) ||
333 content.includes("craftrn-ui/themes/unistyles")
334 ) {
335 return; // Already imported
336 }
337
338 // Add import at the very top of the file
339 const lines = content.split("\n");
340
341 // Insert at the very beginning (index 0)
342 lines.splice(0, 0, importStatement);
343 const newContent = lines.join("\n");
344
345 await fs.writeFile(entryFile, newContent, "utf8");
346}
347
348function isNativeDependency(packageName: string): boolean {
349 return (

Callers 1

initCommandFunction · 0.85

Calls 1

determineImportPathFunction · 0.90

Tested by

no test coverage detected