@moamc/rn-cli 1.3.0 → 1.3.1

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/README.md CHANGED
@@ -11,6 +11,7 @@ Enterprise-grade Code Generation CLI for React Native Applications
11
11
  - ✅ Support for multiple field types (text, number, email, date, dropdown, etc.)
12
12
  - ✅ Automatic validation generation
13
13
  - ✅ TypeScript-ready templates
14
+ - ✅ **Cross-project compatibility** - Automatically detects and adapts to different project structures
14
15
 
15
16
  ## 📦 Installation
16
17
 
@@ -88,6 +89,29 @@ project-root/
88
89
  └── navigations/
89
90
  ```
90
91
 
92
+ ### Component Structure Compatibility
93
+
94
+ The CLI automatically detects your project's component structure:
95
+
96
+ **Option 1: Nested Structure** (e.g., investor-app)
97
+ ```
98
+ components/
99
+ └── common/
100
+ ├── headers/
101
+ │ └── Header.js
102
+ └── Container.js
103
+ ```
104
+
105
+ **Option 2: Flat Structure** (e.g., distributor-app)
106
+ ```
107
+ components/
108
+ └── common/
109
+ ├── Header.js
110
+ └── Container.js
111
+ ```
112
+
113
+ The CLI will automatically generate the correct import paths for your project structure.
114
+
91
115
  ## 🎨 Form Field Types
92
116
 
93
117
  - **Text** - Standard text input
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moamc/rn-cli",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Enterprise-grade Code Generation CLI for React Native Applications",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,4 +1,5 @@
1
1
  const { generateFormField, FIELD_TYPES } = require('./fieldGeneratorTemplate');
2
+ const { detectProjectStructure } = require('../utils/fileUtils');
2
3
 
3
4
  const groupFieldsByRows = (formFields) => {
4
5
  const rows = [];
@@ -49,13 +50,14 @@ const generateEnhancedTemplate = (screenName, featureName, hasForm = false, form
49
50
  const componentName = screenName;
50
51
  const hasDropdown = formFields.some(f => f.type === 'dropdown');
51
52
  const hasDate = formFields.some(f => f.type === 'date');
53
+ const { headerImportPath } = detectProjectStructure();
52
54
 
53
55
  return `import React, { useState } from 'react';
54
56
  import { Text, ScrollView, View } from 'react-native';
55
57
  import { TouchableRipple } from 'react-native-paper';
56
58
  import { colorConstant, utilities } from '../../../assets/styles';
57
59
  import { Container } from '../../../components/common';
58
- import { Header } from '../../../components/common/headers';
60
+ import { Header } from '${headerImportPath}';
59
61
  import Footer from '../../../components/common/Footer';
60
62
  import FormButton from '../../../components/form/FormButton';
61
63
  import { FloatingTextInput } from '../../../components/form';${hasDropdown ? '\nimport { BottomSheet } from \'../../../components/common\';\nimport DropDownReview from \'../../../components/common/DropDownReview\';' : ''}${hasDate ? '\nimport { DatePickerCustom } from \'../../../components/form/DatePicker\';\nimport moment from \'moment\';' : ''}
@@ -129,10 +131,12 @@ const generateScreenTemplate = (screenName, featureName, hasForm = false, formFi
129
131
 
130
132
  // Simple screen template
131
133
  const componentName = screenName;
134
+ const { headerImportPath } = detectProjectStructure();
135
+
132
136
  return `import React from 'react';
133
137
  import { View, Text, ScrollView } from 'react-native';
134
138
  import { Container, Loader } from '../../../components/common';
135
- import { Header } from '../../../components/common/headers';
139
+ import { Header } from '${headerImportPath}';
136
140
  import { colorConstant, utilities } from '../../../assets/styles';
137
141
  import { use${componentName} } from './hooks/use${componentName}';
138
142
  import { styles } from './components/styles';
@@ -1,3 +1,5 @@
1
+ const { detectProjectStructure } = require('../utils/fileUtils');
2
+
1
3
  const generateFormFields = (formFields = []) => {
2
4
  if (!formFields || formFields.length === 0) return '\t\t\t\t{/* Add your form fields here */}';
3
5
 
@@ -55,6 +57,7 @@ const generateFormFields = (formFields = []) => {
55
57
 
56
58
  const generateScreenTemplate = (screenName, featureName, hasForm = false, formFields = []) => {
57
59
  const componentName = screenName;
60
+ const { headerImportPath } = detectProjectStructure();
58
61
 
59
62
  if (hasForm) {
60
63
  const formFieldsCode = generateFormFields(formFields);
@@ -64,7 +67,7 @@ const generateScreenTemplate = (screenName, featureName, hasForm = false, formFi
64
67
  return `import React from 'react';
65
68
  import { View, Text, ScrollView, StyleSheet } from 'react-native';
66
69
  import { Container, Footer, Loader } from '../../../components/common';
67
- import { Header } from '../../../components/common/headers';
70
+ import { Header } from '${headerImportPath}';
68
71
  import { FloatingTextInput, FormButton } from '../../../components/form';${hasDropdown ? '\nimport RadioForm from \'../../../components/form/RadioForm\';' : ''}${hasCheckbox ? '\nimport CheckBox from \'../../../components/common/CheckBox\';' : ''}
69
72
  import { withUser } from '../../../components/HOC';
70
73
  import { colorConstant, fonts, utilities } from '../../../assets/styles';
@@ -110,7 +113,7 @@ export default withUser(${componentName});
110
113
  return `import React from 'react';
111
114
  import { View, Text, ScrollView, StyleSheet } from 'react-native';
112
115
  import { Container, Loader } from '../../../components/common';
113
- import { Header } from '../../../components/common/headers';
116
+ import { Header } from '${headerImportPath}';
114
117
  import { withUser } from '../../../components/HOC';
115
118
  import { colorConstant, fonts, utilities } from '../../../assets/styles';
116
119
  import { use${componentName} } from './use${componentName}';
@@ -19,6 +19,19 @@ const findProjectRoot = () => {
19
19
 
20
20
  const PROJECT_ROOT = findProjectRoot();
21
21
 
22
+ // Detect project structure for imports
23
+ const detectProjectStructure = () => {
24
+ const headersPath = path.join(PROJECT_ROOT, 'components', 'common', 'headers');
25
+ const hasHeadersFolder = fs.existsSync(headersPath);
26
+
27
+ return {
28
+ hasHeadersFolder,
29
+ headerImportPath: hasHeadersFolder
30
+ ? "../../../components/common/headers"
31
+ : "../../../components/common"
32
+ };
33
+ };
34
+
22
35
  const ensureDirectoryExists = (dirPath) => {
23
36
  if (!fs.existsSync(dirPath)) {
24
37
  fs.mkdirSync(dirPath, { recursive: true });
@@ -113,4 +126,5 @@ module.exports = {
113
126
  logWarning,
114
127
  logError,
115
128
  confirmOverwrite,
129
+ detectProjectStructure,
116
130
  };