-
Notifications
You must be signed in to change notification settings - Fork 16
feature: extend CLI for expo / gt-react-native #790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
Extended CLI to support Expo/React Native projects with gt-react-native library integration.
Key changes:
- Added
ReactNativeCLIclass with Expo-specific setup workflow - Implemented entry point detection for various Expo configurations (expo-router, standard RN)
- Created babel config AST manipulation to inject
gt-react-native/plugin - Added JSX wrapping logic to insert
<T>tags andGTProviderin root layouts - Generated
loadTranslations.jswith locale-specific require statements - Extended setup wizard with Expo framework option and automatic package installation
Issues found:
console.warnused in CLI code instead oflogWarningutility (line 45 in createLoadTranslations.ts)- Path construction bug in wrapContent.ts when generating relative imports for nested files (missing
./prefix)
Confidence Score: 4/5
- Safe to merge with minor fixes for console.warn and import path bug
- Well-structured implementation with comprehensive tests. Two issues found: console.warn usage violates custom rule, and relative import path construction will break for nested layouts. Both are fixable but the path bug could cause runtime errors.
- Pay attention to
packages/cli/src/react-native/parse/wrapContent.ts(import path bug) andpackages/cli/src/react-native/parse/createLoadTranslations.ts(console.warn usage)
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| packages/cli/src/react-native/parse/createLoadTranslations.ts | 4/5 | Creates loadTranslations.js for Expo projects with locale-specific require statements. Has console.warn in CLI code that should use logWarning instead. |
| packages/cli/src/react-native/parse/wrapContent.ts | 3/5 | Wraps JSX content with T tags and adds GTProvider to root layout. Has path construction bug for relative imports that may break when fileDir != cwd. |
| packages/cli/src/react-native/utils/updateBabelConfig.ts | 5/5 | Updates babel.config.js with gt-react-native plugin using AST manipulation. Well-structured with proper checks for existing config. |
| packages/cli/src/react-native/utils/detectEntryPoint.ts | 5/5 | Detects Expo entry point with fallback strategies. Logic correctly handles node_modules entries vs local files. |
| packages/cli/src/setup/wizard.ts | 5/5 | Added Expo framework option to setup wizard with automatic gt-react-native installation and initialization flow. |
Sequence Diagram
sequenceDiagram
participant User
participant CLI as CLI/Wizard
participant Detect as detectEntryPoint
participant Babel as updateBabelConfig
participant Wrap as wrapContent
participant Init as handleInitGT
User->>CLI: Run setup command
CLI->>CLI: Detect gt-react-native in package.json
CLI->>CLI: Install gt-react-native if needed
CLI->>Detect: detectEntryPoint(projectRoot)
Detect->>Detect: Check package.json main field
Detect->>Detect: Check for existing entry files
Detect-->>CLI: Return strategy & entryPoint
CLI->>Init: handleInitGT(paths, detectionResult)
Init->>Babel: updateBabelConfig(babelPath, entryPath)
Babel->>Babel: Parse existing babel.config.js AST
Babel->>Babel: Add/update gt-react-native plugin
Babel-->>Init: Config updated
Init->>Init: Create index.js wrapper if needed
Init->>Init: Update package.json main field
Init-->>CLI: Initialization complete
CLI->>Wrap: wrapContentReactNative(options)
Wrap->>Wrap: Match files in src directory
loop For each file
Wrap->>Wrap: Parse file as AST
Wrap->>Wrap: Check if root layout (_layout.tsx)
Wrap->>Wrap: Add GTProvider with config imports
Wrap->>Wrap: Wrap JSX elements with T tags
Wrap->>Wrap: Generate updated code
end
Wrap-->>CLI: Return filesUpdated list
CLI->>CLI: Create loadTranslations.js
CLI->>CLI: Create gt.config.json
CLI-->>User: Setup complete
19 files reviewed, 2 comments
ErnestM1234
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please bring this up to date
No description provided.