react-native-architecture-generator 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +389 -0
- package/dist/bin/rn_arch_gen.d.ts +2 -0
- package/dist/bin/rn_arch_gen.js +41 -0
- package/dist/lib/commands/feature.d.ts +3 -0
- package/dist/lib/commands/feature.js +52 -0
- package/dist/lib/commands/init.d.ts +3 -0
- package/dist/lib/commands/init.js +75 -0
- package/dist/lib/commands/model.d.ts +3 -0
- package/dist/lib/commands/model.js +94 -0
- package/dist/lib/commands/screen.d.ts +4 -0
- package/dist/lib/commands/screen.js +82 -0
- package/dist/lib/index.d.ts +12 -0
- package/dist/lib/index.js +12 -0
- package/dist/lib/models/config.d.ts +27 -0
- package/dist/lib/models/config.js +27 -0
- package/dist/lib/templates/base-templates.d.ts +18 -0
- package/dist/lib/templates/base-templates.js +453 -0
- package/dist/lib/utils/config-helper.d.ts +6 -0
- package/dist/lib/utils/config-helper.js +27 -0
- package/dist/lib/utils/feature-helper.d.ts +24 -0
- package/dist/lib/utils/feature-helper.js +400 -0
- package/dist/lib/utils/file-helper.d.ts +4 -0
- package/dist/lib/utils/file-helper.js +62 -0
- package/dist/lib/utils/packagejson-helper.d.ts +4 -0
- package/dist/lib/utils/packagejson-helper.js +76 -0
- package/dist/lib/utils/string-utils.d.ts +9 -0
- package/dist/lib/utils/string-utils.js +28 -0
- package/package.json +72 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
- **New: 4 Architecture Patterns**
|
|
6
|
+
- Added support for multiple project structures: Clean Architecture, Feature-Based, Atomic Design, and MVVM.
|
|
7
|
+
- Architecture choice is prompted during `init` and respected by all other commands.
|
|
8
|
+
- **Updated: Architecture-Aware Commands**
|
|
9
|
+
- `feature`: Generates directory structures and files specific to the selected architecture.
|
|
10
|
+
- `screen`: Resolves correct screen paths (e.g., `presentation/screens` vs `views/screens`).
|
|
11
|
+
- `model`: Generates models in the appropriate format (Classes for Clean Arch, factory functions for MVVM, Interfaces for Feature-Based).
|
|
12
|
+
- **Improved: Latest Dependency Versions**
|
|
13
|
+
- Updated all injected dependencies to 2025/2026 latest versions.
|
|
14
|
+
- Upgraded to React Navigation v7+, Redux Toolkit v2.11+, and Zustand v5+.
|
|
15
|
+
- Upgraded CLI dependencies (Chalk 5, Inquirer 13, Ora 9).
|
|
16
|
+
- **Added: Public API**
|
|
17
|
+
- `lib/index.ts` now exports all core helpers and types for programmatic usage.
|
|
18
|
+
|
|
19
|
+
## 1.0.0
|
|
20
|
+
|
|
21
|
+
- Initial release
|
|
22
|
+
- Scaffold complete React Native Clean Architecture
|
|
23
|
+
- State Management: Redux Toolkit, Zustand, Context API
|
|
24
|
+
- Routing: React Navigation, Expo Router
|
|
25
|
+
- Material-style Light/Dark theming
|
|
26
|
+
- Axios HTTP client with interceptors
|
|
27
|
+
- Failures/Error management
|
|
28
|
+
- Firebase & i18next support
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 acrocoder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
# ๐๏ธ React Native Architecture Generator
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/react-native-architecture-generator)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
A powerful, production-ready CLI tool to instantly scaffold professional React Native applications with **4 architecture patterns**, **3 state management** options, and full auto-wiring.
|
|
7
|
+
|
|
8
|
+
Stop wasting hours on boilerplate. Generate a complete, scalable project architecture in seconds โ with state management, networking, routing, theming, and tests all wired up and ready to go.
|
|
9
|
+
|
|
10
|
+
## โจ Why This Tool?
|
|
11
|
+
|
|
12
|
+
| Feature | |
|
|
13
|
+
|---------|---|
|
|
14
|
+
| ๐ **Zero to Production** | Generates a complete architecture with Networking, Routing, State Management, and Theming in seconds |
|
|
15
|
+
| ๐๏ธ **4 Architecture Patterns** | Clean Architecture, Feature-Based, Atomic Design, or MVVM โ choose what fits your team |
|
|
16
|
+
| ๐ง **Context-Aware** | Remembers your project config so subsequent commands "just work" |
|
|
17
|
+
| โก **Auto-Wiring** | New features auto-register in your navigation and router โ no manual wiring |
|
|
18
|
+
| ๐จ **Premium Auth UI** | Includes polished Login & Register screens out of the box |
|
|
19
|
+
| ๐ฆ **Latest Packages** | All dependencies pinned to the most recent stable versions |
|
|
20
|
+
| ๐งช **Test Ready** | Generates architecture-specific tests for every feature |
|
|
21
|
+
|
|
22
|
+
## ๐๏ธ Architecture Patterns
|
|
23
|
+
|
|
24
|
+
### 1๏ธโฃ Clean Architecture (Domain โ Data โ Presentation)
|
|
25
|
+
|
|
26
|
+
The gold standard for large-scale enterprise apps. Strict separation of concerns with explicit layers.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
features/auth/
|
|
30
|
+
โโโ data/
|
|
31
|
+
โ โโโ datasources/AuthRemoteDataSource.ts
|
|
32
|
+
โ โโโ models/AuthModel.ts
|
|
33
|
+
โ โโโ repositories/AuthRepositoryImpl.ts
|
|
34
|
+
โโโ domain/
|
|
35
|
+
โ โโโ entities/authEntity.ts
|
|
36
|
+
โ โโโ repositories/AuthRepository.ts
|
|
37
|
+
โ โโโ usecases/GetAuthUseCase.ts
|
|
38
|
+
โโโ presentation/
|
|
39
|
+
โโโ redux/authSlice.ts # (or zustand/ or context/)
|
|
40
|
+
โโโ screens/LoginScreen.tsx
|
|
41
|
+
โโโ components/
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Best for:** Enterprise apps, large teams, complex business logic
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
### 2๏ธโฃ Feature-Based Architecture (Lightweight)
|
|
49
|
+
|
|
50
|
+
A flat, pragmatic structure that keeps things simple โ services, hooks, screens, and types per feature.
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
features/auth/
|
|
54
|
+
โโโ components/
|
|
55
|
+
โโโ hooks/useAuth.ts
|
|
56
|
+
โโโ screens/LoginScreen.tsx
|
|
57
|
+
โโโ services/auth.service.ts
|
|
58
|
+
โโโ types/auth.types.ts
|
|
59
|
+
โโโ utils/
|
|
60
|
+
โโโ index.ts # Barrel export
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Best for:** Startups, MVPs, small-to-medium apps, rapid prototyping
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
### 3๏ธโฃ Atomic Design + Feature
|
|
68
|
+
|
|
69
|
+
Brad Frost's Atomic Design methodology applied to React Native. Build UIs from atoms up.
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
features/auth/
|
|
73
|
+
โโโ atoms/AuthButton.tsx # Smallest UI elements
|
|
74
|
+
โโโ molecules/AuthFormField.tsx # Combinations of atoms
|
|
75
|
+
โโโ organisms/AuthCard.tsx # Complex, self-contained sections
|
|
76
|
+
โโโ templates/AuthLayout.tsx # Page-level layouts
|
|
77
|
+
โโโ screens/LoginScreen.tsx
|
|
78
|
+
โโโ hooks/useAuth.ts
|
|
79
|
+
โโโ services/auth.service.ts
|
|
80
|
+
โโโ types/auth.types.ts
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Best for:** Design system-driven teams, component libraries, highly reusable UI
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
### 4๏ธโฃ MVVM with Hooks (Model โ ViewModel โ View)
|
|
88
|
+
|
|
89
|
+
The classic MVVM pattern implemented with React hooks as ViewModels.
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
features/auth/
|
|
93
|
+
โโโ models/AuthModel.ts # Data structures
|
|
94
|
+
โโโ viewmodels/useAuthViewModel.ts # Business logic (custom hooks)
|
|
95
|
+
โโโ views/
|
|
96
|
+
โ โโโ screens/LoginScreen.tsx # Full-page views
|
|
97
|
+
โ โโโ components/AuthListItem.tsx
|
|
98
|
+
โโโ services/AuthService.ts # API layer
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Best for:** Teams from Android/iOS/WPF background, clear separation of UI and logic
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## ๐ฏ Supported Features
|
|
106
|
+
|
|
107
|
+
### State Management
|
|
108
|
+
|
|
109
|
+
| Option | Generated Code |
|
|
110
|
+
|--------|----------------|
|
|
111
|
+
| **Redux Toolkit** | Redux slice with async thunk, typed hooks |
|
|
112
|
+
| **Zustand** | Zustand store with async actions |
|
|
113
|
+
| **Context API** | React Context + useReducer pattern |
|
|
114
|
+
|
|
115
|
+
### Routing
|
|
116
|
+
|
|
117
|
+
| Option | Generated Code |
|
|
118
|
+
|--------|----------------|
|
|
119
|
+
| **React Navigation** | Stack Navigator with typed params, auto-registration |
|
|
120
|
+
| **Expo Router** | File-based routing placeholder |
|
|
121
|
+
|
|
122
|
+
### Additional Features
|
|
123
|
+
|
|
124
|
+
| Feature | Details |
|
|
125
|
+
|---------|---------|
|
|
126
|
+
| **Axios HTTP Client** | Pre-configured with timeout, interceptors |
|
|
127
|
+
| **TypeScript Models** | Model classes with `fromJson` / `toJson` serialization |
|
|
128
|
+
| **Environment Config** | `.env.development` and `.env.production` with `react-native-config` |
|
|
129
|
+
| **Firebase** | `@react-native-firebase/app` initialization |
|
|
130
|
+
| **Localization (i18n)** | `i18next` + `react-i18next` with locale JSON files |
|
|
131
|
+
| **Light/Dark Theming** | Theme context with system auto-detection |
|
|
132
|
+
| **Error Handling** | Failure classes: `ServerFailure`, `CacheFailure`, `NetworkFailure` |
|
|
133
|
+
| **Unit Tests** | Architecture-specific tests generated per feature |
|
|
134
|
+
|
|
135
|
+
## ๐ฆ Package Versions (Latest)
|
|
136
|
+
|
|
137
|
+
| Package | Version | Purpose |
|
|
138
|
+
|---------|---------|---------|
|
|
139
|
+
| axios | ^1.7.2 | HTTP networking |
|
|
140
|
+
| @reduxjs/toolkit | ^2.2.1 | Redux state management |
|
|
141
|
+
| zustand | ^4.5.2 | Zustand state management |
|
|
142
|
+
| @react-navigation/native | ^6.1.14 | Navigation |
|
|
143
|
+
| @react-navigation/native-stack | ^6.9.22 | Stack navigation |
|
|
144
|
+
| react-native-config | ^1.5.1 | Environment variables |
|
|
145
|
+
| i18next | ^23.10.1 | Internationalization |
|
|
146
|
+
| react-i18next | ^14.1.0 | React i18n integration |
|
|
147
|
+
| @react-native-firebase/app | ^19.0.1 | Firebase initialization |
|
|
148
|
+
| jest | ^29.7.0 | Testing |
|
|
149
|
+
| @testing-library/react-native | ^12.4.3 | React Native testing utils |
|
|
150
|
+
|
|
151
|
+
## ๐ Installation
|
|
152
|
+
|
|
153
|
+
### Global Installation (Recommended)
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npm install -g react-native-architecture-generator
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
This adds the `rn-arch-gen` command to your PATH.
|
|
160
|
+
|
|
161
|
+
### Verify Installation
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
rn-arch-gen --help
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## โก Quick Start
|
|
168
|
+
|
|
169
|
+
### 1. Create a React Native project
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
npx react-native init my_awesome_app
|
|
173
|
+
cd my_awesome_app
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 2. Initialize the architecture
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
rn-arch-gen init
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
You'll be prompted to choose:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
? Select architecture pattern: (Use arrow keys)
|
|
186
|
+
โฏ ๐๏ธ Clean Architecture (Domain โ Data โ Presentation)
|
|
187
|
+
๐ฆ Feature-Based (Lightweight, flat structure)
|
|
188
|
+
โ๏ธ Atomic Design + Feature (Atoms โ Molecules โ Organisms)
|
|
189
|
+
๐งฉ MVVM with Hooks (Model โ ViewModel โ View)
|
|
190
|
+
|
|
191
|
+
? Select state management:
|
|
192
|
+
โฏ redux
|
|
193
|
+
zustand
|
|
194
|
+
context
|
|
195
|
+
|
|
196
|
+
? Select routing:
|
|
197
|
+
โฏ reactNavigation
|
|
198
|
+
expoRouter
|
|
199
|
+
|
|
200
|
+
? Enable localization (i18next)? (Y/n)
|
|
201
|
+
? Enable Firebase? (y/N)
|
|
202
|
+
? Enable tests? (Y/n)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### 3. Install dependencies
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
npm install
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### 4. Run your app
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
npx react-native run-android
|
|
215
|
+
# or
|
|
216
|
+
npx react-native run-ios
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
That's it! You now have a complete architecture with state management, routing, theming, networking, and an example auth feature โ all production-ready.
|
|
220
|
+
|
|
221
|
+
## ๐ Commands Reference
|
|
222
|
+
|
|
223
|
+
### `rn-arch-gen init`
|
|
224
|
+
|
|
225
|
+
Initializes the complete project architecture with interactive prompts.
|
|
226
|
+
|
|
227
|
+
**What it generates:**
|
|
228
|
+
- Directory structure based on chosen architecture
|
|
229
|
+
- `App.tsx` with initialization pipeline & theming
|
|
230
|
+
- `apiClient.ts` with Axios configuration
|
|
231
|
+
- `AppTheme.ts` with light/dark theme
|
|
232
|
+
- `AppNavigator.tsx` with React Navigation config
|
|
233
|
+
- `store.ts` with state management setup
|
|
234
|
+
- `failures.ts` with error hierarchy
|
|
235
|
+
- `.env.development` / `.env.production` environment files
|
|
236
|
+
- `.gitignore` with security exclusions
|
|
237
|
+
- Example auth feature with Login & Register screens
|
|
238
|
+
- Localization files (if enabled)
|
|
239
|
+
- Test scaffolding (if enabled)
|
|
240
|
+
|
|
241
|
+
### `rn-arch-gen feature <name>`
|
|
242
|
+
|
|
243
|
+
Generates a complete feature module following your chosen architecture.
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
# Basic usage
|
|
247
|
+
rn-arch-gen feature products
|
|
248
|
+
|
|
249
|
+
# PascalCase input is auto-normalized
|
|
250
|
+
rn-arch-gen feature UserProfile # โ features/user_profile/
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
**Generated structure varies by architecture:**
|
|
254
|
+
|
|
255
|
+
| Architecture | Generated Layers |
|
|
256
|
+
|-------------|-----------------|
|
|
257
|
+
| Clean Architecture | `data/` `domain/` `presentation/` + state management |
|
|
258
|
+
| Feature-Based | `services/` `hooks/` `screens/` `types/` + barrel export |
|
|
259
|
+
| Atomic Design | `atoms/` `molecules/` `organisms/` `templates/` `screens/` |
|
|
260
|
+
| MVVM | `models/` `viewmodels/` `views/` `services/` |
|
|
261
|
+
|
|
262
|
+
**Auto-wiring (all architectures):**
|
|
263
|
+
- โ
Adds screen + import to `AppNavigator.tsx`
|
|
264
|
+
- โ
Adds route type to `RootStackParamList`
|
|
265
|
+
- โ
Generates architecture-specific tests
|
|
266
|
+
|
|
267
|
+
### `rn-arch-gen model <name> [-f feature]`
|
|
268
|
+
|
|
269
|
+
Generates a TypeScript model with JSON serialization.
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
# Inside a feature
|
|
273
|
+
rn-arch-gen model Product -f shop
|
|
274
|
+
|
|
275
|
+
# Standalone (in src/core/models/)
|
|
276
|
+
rn-arch-gen model AppUser
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### `rn-arch-gen screen <name> [-f feature]`
|
|
280
|
+
|
|
281
|
+
Generates a new screen with optional navigation auto-registration.
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
# Inside a feature
|
|
285
|
+
rn-arch-gen screen Settings -f settings
|
|
286
|
+
|
|
287
|
+
# Standalone screen
|
|
288
|
+
rn-arch-gen screen About
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**Screen path adapts to architecture:**
|
|
292
|
+
- Clean Architecture โ `presentation/screens/`
|
|
293
|
+
- Feature-Based / Atomic โ `screens/`
|
|
294
|
+
- MVVM โ `views/screens/`
|
|
295
|
+
|
|
296
|
+
## ๐ Generated Structure (Common Base)
|
|
297
|
+
|
|
298
|
+
```
|
|
299
|
+
src/
|
|
300
|
+
โโโ App.tsx # App entry point
|
|
301
|
+
โโโ core/
|
|
302
|
+
โ โโโ api/apiClient.ts # Axios HTTP client
|
|
303
|
+
โ โโโ constants/AppConstants.ts # Global constants
|
|
304
|
+
โ โโโ components/ # Shared components
|
|
305
|
+
โ โโโ errors/failures.ts # Error hierarchy
|
|
306
|
+
โ โโโ theme/
|
|
307
|
+
โ โ โโโ AppTheme.ts # Colors, Spacing, FontSizes
|
|
308
|
+
โ โ โโโ ThemeContext.tsx # Light/Dark theme provider
|
|
309
|
+
โ โโโ utils/
|
|
310
|
+
โโโ features/ # Architecture-specific feature modules
|
|
311
|
+
โโโ navigation/AppNavigator.tsx # Auto-updated navigation
|
|
312
|
+
โโโ state/store.ts # State management setup
|
|
313
|
+
โโโ i18n/ # (if localization enabled)
|
|
314
|
+
โโโ .env.development
|
|
315
|
+
โโโ .env.production
|
|
316
|
+
โโโ .gitignore
|
|
317
|
+
โโโ .rn_arch_gen.json # Persisted project config
|
|
318
|
+
|
|
319
|
+
__tests__/
|
|
320
|
+
โโโ features/ # Architecture-specific tests
|
|
321
|
+
โโโ unit/sample.test.ts
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## ๐พ Configuration Persistence
|
|
325
|
+
|
|
326
|
+
After running `init`, your choices are saved in `.rn_arch_gen.json`:
|
|
327
|
+
|
|
328
|
+
```json
|
|
329
|
+
{
|
|
330
|
+
"architecture": "cleanArchitecture",
|
|
331
|
+
"stateManagement": "redux",
|
|
332
|
+
"routing": "reactNavigation",
|
|
333
|
+
"localization": true,
|
|
334
|
+
"firebase": false,
|
|
335
|
+
"tests": true
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
All subsequent commands (`feature`, `model`, `screen`) automatically read this config โ no need to pass flags every time.
|
|
340
|
+
|
|
341
|
+
## ๐ง Post-Generation Steps
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
# 1. Install all dependencies
|
|
345
|
+
npm install
|
|
346
|
+
|
|
347
|
+
# 2. Configure your API base URL
|
|
348
|
+
# Edit .env.development and .env.production with your actual endpoints
|
|
349
|
+
|
|
350
|
+
# 3. Run your app
|
|
351
|
+
npx react-native run-android
|
|
352
|
+
# or
|
|
353
|
+
npx react-native run-ios
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## โ FAQ
|
|
357
|
+
|
|
358
|
+
**Q: Can I use this on an existing project?**
|
|
359
|
+
A: Yes! Run `rn-arch-gen init` in your existing React Native project root. It will add files alongside your existing code.
|
|
360
|
+
|
|
361
|
+
**Q: Does it modify my existing `package.json`?**
|
|
362
|
+
A: Yes, it adds the required dependencies. Existing dependencies are not overwritten โ only new ones are added.
|
|
363
|
+
|
|
364
|
+
**Q: Can I switch architectures later?**
|
|
365
|
+
A: You can re-run `rn-arch-gen init` with a different architecture. Existing files won't be deleted โ only new ones are created.
|
|
366
|
+
|
|
367
|
+
**Q: Does it work on Windows?**
|
|
368
|
+
A: Yes! All path handling uses cross-platform `path.join` to ensure correct behavior on Windows, macOS, and Linux.
|
|
369
|
+
|
|
370
|
+
**Q: What naming convention is used?**
|
|
371
|
+
A: Files use PascalCase for component files and snake_case for directories. Input like `UserProfile` or `user_profile` both work correctly.
|
|
372
|
+
|
|
373
|
+
## ๐ค Contributing
|
|
374
|
+
|
|
375
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
376
|
+
|
|
377
|
+
1. Fork the repository
|
|
378
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
379
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
380
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
381
|
+
5. Open a Pull Request
|
|
382
|
+
|
|
383
|
+
## ๐ License
|
|
384
|
+
|
|
385
|
+
This project is licensed under the MIT License โ see the [LICENSE](LICENSE) file for details.
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
|
|
389
|
+
Made with โค๏ธ for the React Native community
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { InitCommand } from '../lib/commands/init.js';
|
|
4
|
+
import { FeatureCommand } from '../lib/commands/feature.js';
|
|
5
|
+
import { ModelCommand } from '../lib/commands/model.js';
|
|
6
|
+
import { ScreenCommand } from '../lib/commands/screen.js';
|
|
7
|
+
const program = new Command();
|
|
8
|
+
program
|
|
9
|
+
.name('rn-arch-gen')
|
|
10
|
+
.description('A powerful CLI tool to instantly generate a production-ready React Native project architecture.')
|
|
11
|
+
.version('1.1.0');
|
|
12
|
+
program
|
|
13
|
+
.command('init')
|
|
14
|
+
.description('Initialize React Native project architecture.')
|
|
15
|
+
.action(async () => {
|
|
16
|
+
await InitCommand.run();
|
|
17
|
+
});
|
|
18
|
+
program
|
|
19
|
+
.command('feature <name>')
|
|
20
|
+
.description('Generate a complete feature module using the selected architecture.')
|
|
21
|
+
.action(async (name) => {
|
|
22
|
+
await FeatureCommand.run(name);
|
|
23
|
+
});
|
|
24
|
+
program
|
|
25
|
+
.command('model <name>')
|
|
26
|
+
.description('Generate a TypeScript model/interface with validation.')
|
|
27
|
+
.option('-f, --feature <feature>', 'Target feature module')
|
|
28
|
+
.action(async (name, options) => {
|
|
29
|
+
await ModelCommand.run(name, options.feature);
|
|
30
|
+
});
|
|
31
|
+
program
|
|
32
|
+
.command('screen <name>')
|
|
33
|
+
.description('Generate a new screen with optional navigation registration.')
|
|
34
|
+
.option('-f, --feature <feature>', 'Target feature module')
|
|
35
|
+
.action(async (name, options) => {
|
|
36
|
+
await ScreenCommand.run(name, options.feature);
|
|
37
|
+
});
|
|
38
|
+
program.parse(process.argv);
|
|
39
|
+
if (!process.argv.slice(2).length) {
|
|
40
|
+
program.outputHelp();
|
|
41
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import { ConfigHelper } from '../utils/config-helper.js';
|
|
4
|
+
import { FeatureHelper } from '../utils/feature-helper.js';
|
|
5
|
+
import { Architecture, ArchitectureLabels } from '../models/config.js';
|
|
6
|
+
export class FeatureCommand {
|
|
7
|
+
static async run(name) {
|
|
8
|
+
const config = await ConfigHelper.getConfig();
|
|
9
|
+
if (!config) {
|
|
10
|
+
console.error(chalk.red('Error: Architecture not initialized. Run "rn-arch-gen init" first.'));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const spinner = ora(`๐ Generating feature: ${name}...`).start();
|
|
14
|
+
try {
|
|
15
|
+
await FeatureHelper.generateFeature(name, config);
|
|
16
|
+
spinner.succeed(`Feature "${name}" generated with ${ArchitectureLabels[config.architecture]}! โ
`);
|
|
17
|
+
console.log('');
|
|
18
|
+
console.log(chalk.green('Generated:'));
|
|
19
|
+
switch (config.architecture) {
|
|
20
|
+
case Architecture.cleanArchitecture:
|
|
21
|
+
console.log(` โ
Entity, Repository, UseCase (Domain layer)`);
|
|
22
|
+
console.log(` โ
Model, DataSource, RepoImpl (Data layer)`);
|
|
23
|
+
console.log(` โ
Screen, State Management (Presentation layer)`);
|
|
24
|
+
break;
|
|
25
|
+
case Architecture.featureBased:
|
|
26
|
+
console.log(` โ
Service (API layer)`);
|
|
27
|
+
console.log(` โ
Custom Hook`);
|
|
28
|
+
console.log(` โ
Screen, Types, Barrel export`);
|
|
29
|
+
break;
|
|
30
|
+
case Architecture.atomicDesign:
|
|
31
|
+
console.log(` โ
Atoms (Button, Input)`);
|
|
32
|
+
console.log(` โ
Molecules (FormField)`);
|
|
33
|
+
console.log(` โ
Organisms (Card) + Template (Layout)`);
|
|
34
|
+
console.log(` โ
Screen, Hook, Service`);
|
|
35
|
+
break;
|
|
36
|
+
case Architecture.mvvm:
|
|
37
|
+
console.log(` โ
Model (data structures)`);
|
|
38
|
+
console.log(` โ
ViewModel (custom hook)`);
|
|
39
|
+
console.log(` โ
View (Screen + ListItem component)`);
|
|
40
|
+
console.log(` โ
Service (API layer)`);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
console.log(` โ
Navigation auto-registered`);
|
|
44
|
+
if (config.tests) {
|
|
45
|
+
console.log(` โ
Tests generated`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
spinner.fail(`Failed to generate feature: ${error}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import ora from 'ora';
|
|
4
|
+
import { Architecture, ArchitectureLabels, StateManagement, Routing } from '../models/config.js';
|
|
5
|
+
import { FileHelper } from '../utils/file-helper.js';
|
|
6
|
+
import { FeatureHelper } from '../utils/feature-helper.js';
|
|
7
|
+
export class InitCommand {
|
|
8
|
+
static async run() {
|
|
9
|
+
console.log(chalk.blue('๐ Initializing React Native Architecture...'));
|
|
10
|
+
console.log('');
|
|
11
|
+
const answers = await inquirer.prompt([
|
|
12
|
+
{
|
|
13
|
+
type: 'list',
|
|
14
|
+
name: 'architecture',
|
|
15
|
+
message: 'Select architecture pattern:',
|
|
16
|
+
choices: Object.values(Architecture).map((arch) => ({
|
|
17
|
+
name: ArchitectureLabels[arch],
|
|
18
|
+
value: arch,
|
|
19
|
+
})),
|
|
20
|
+
default: Architecture.cleanArchitecture,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: 'list',
|
|
24
|
+
name: 'stateManagement',
|
|
25
|
+
message: 'Select state management:',
|
|
26
|
+
choices: Object.values(StateManagement),
|
|
27
|
+
default: StateManagement.redux,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: 'list',
|
|
31
|
+
name: 'routing',
|
|
32
|
+
message: 'Select routing:',
|
|
33
|
+
choices: Object.values(Routing),
|
|
34
|
+
default: Routing.reactNavigation,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'confirm',
|
|
38
|
+
name: 'localization',
|
|
39
|
+
message: 'Enable localization (i18next)?',
|
|
40
|
+
default: true,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: 'confirm',
|
|
44
|
+
name: 'firebase',
|
|
45
|
+
message: 'Enable Firebase?',
|
|
46
|
+
default: false,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: 'confirm',
|
|
50
|
+
name: 'tests',
|
|
51
|
+
message: 'Enable tests?',
|
|
52
|
+
default: true,
|
|
53
|
+
},
|
|
54
|
+
]);
|
|
55
|
+
const config = answers;
|
|
56
|
+
const spinner = ora('Generating structure...').start();
|
|
57
|
+
try {
|
|
58
|
+
await FileHelper.generateBaseStructure(config);
|
|
59
|
+
spinner.text = 'Generating example feature: auth...';
|
|
60
|
+
await FeatureHelper.generateFeature('auth', config);
|
|
61
|
+
spinner.succeed('Architecture and example feature generated! โ
');
|
|
62
|
+
console.log('');
|
|
63
|
+
console.log(chalk.green('Architecture: ') + chalk.cyan(ArchitectureLabels[config.architecture]));
|
|
64
|
+
console.log('');
|
|
65
|
+
console.log(chalk.green('Next steps:'));
|
|
66
|
+
console.log('1. Run ' + chalk.yellow('npm install') + ' or ' + chalk.yellow('yarn'));
|
|
67
|
+
console.log('2. Configure your environments in .env files');
|
|
68
|
+
console.log('3. Run ' + chalk.yellow('npx react-native run-android') + ' or ' + chalk.yellow('npx react-native run-ios'));
|
|
69
|
+
console.log('4. Happy coding! ๐');
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
spinner.fail('Failed to generate architecture: ' + error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|