@moamc/rn-cli 1.3.1 → 1.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moamc/rn-cli",
3
- "version": "1.3.1",
3
+ "version": "1.4.1",
4
4
  "description": "Enterprise-grade Code Generation CLI for React Native Applications",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -45,7 +45,7 @@ const generateHookTemplate = (hookName, hasForm = false, formFields = [], eventN
45
45
  import { showToastNotification } from '../../../../helpers/common';${hasDate ? '\nimport moment from \'moment\';' : ''}
46
46
  import { validate${hookName} } from '../validation';
47
47
 
48
- export const use${hookName} = () => {
48
+ export const use${hookName} = ({ navigation }) => {
49
49
  \tconst [formData, setFormData] = useState({
50
50
  ${formFields.map(f => `\t\t${f.name}: '',`).join('\n')}
51
51
  \t});
@@ -121,9 +121,15 @@ export const use${hookName} = ({ navigation }) => {
121
121
  \t\t}
122
122
  \t}, [error]);
123
123
 
124
+ \tconst handleSubmit = () => {
125
+ \t\t// Add your submit logic here
126
+ \t\tshowToastNotification('Submit clicked');
127
+ \t};
128
+
124
129
  \treturn {
125
130
  \t\tloading: isLoading,
126
131
  \t\tdata,
132
+ \t\thandleSubmit,
127
133
  \t};
128
134
  };
129
135
  `;
@@ -50,9 +50,99 @@ const generateEnhancedTemplate = (screenName, featureName, hasForm = false, form
50
50
  const componentName = screenName;
51
51
  const hasDropdown = formFields.some(f => f.type === 'dropdown');
52
52
  const hasDate = formFields.some(f => f.type === 'date');
53
- const { headerImportPath } = detectProjectStructure();
53
+ const { headerImportPath, hasHeadersFolder } = detectProjectStructure();
54
+ const isDistributorStyle = !hasHeadersFolder;
54
55
 
55
- return `import React, { useState } from 'react';
56
+ let bottomSheetCode = '';
57
+ if (hasDropdown) {
58
+ bottomSheetCode = `
59
+ \t\t\t<BottomSheet
60
+ \t\t\t\tmodalVisible={!!openBottomNote}
61
+ \t\t\t\tsetIsModalVisible={() => setOpenBottomNote(null)}
62
+ \t\t\t>
63
+ \t\t\t\t<DropDownReview
64
+ \t\t\t\t\tFundBuyType={/* Add options */[]}
65
+ \t\t\t\t\tselectValue={formData[bottomSheetType]}
66
+ \t\t\t\t\tonSelectValue={e => {
67
+ \t\t\t\t\t\thandleChange(e, bottomSheetType);
68
+ \t\t\t\t\t\tsetOpenBottomNote(null);
69
+ \t\t\t\t\t}}
70
+ \t\t\t\t\tlabel={bottomSheetType}
71
+ \t\t\t\t/>
72
+ \t\t\t</BottomSheet>`;
73
+ }
74
+
75
+ let datePickerCode = '';
76
+ if (hasDate) {
77
+ datePickerCode = `
78
+ \t\t\t<DatePickerCustom
79
+ \t\t\t\tmodalTransparent={true}
80
+ \t\t\t\tonDateChange={data => {
81
+ \t\t\t\t\thandleChange(moment(data).format('DD MMM YYYY'), 'dateField');
82
+ \t\t\t\t}}
83
+ \t\t\t\tsetModalVisible={() => setOpenCalendar(!openCalendar)}
84
+ \t\t\t\tmodalVisible={openCalendar}
85
+ \t\t\t\tminimumDate={new Date(1920, 0, 1)}
86
+ \t\t\t/>`;
87
+ }
88
+
89
+ if (isDistributorStyle) {
90
+ return `import React, { useState } from 'react';
91
+ import { Text, ScrollView, View, StyleSheet } from 'react-native';
92
+ import { colorConstant, fonts, utilities } from '../../../assets/styles';
93
+ import Container from '../../../components/common/Container';
94
+ import Header from '../../../components/common/Header';
95
+ import Footer from '../../../components/common/Footer';
96
+ import Loader from '../../../components/common/Loader';
97
+ import { FloatingTextInput, FormButton } 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\';' : ''}
98
+ import { use${componentName} } from './hooks/use${componentName}';
99
+
100
+ const ${componentName} = ({ navigation }) => {
101
+ \tconst {
102
+ \t\tformData,
103
+ \t\terrors,
104
+ \t\ttouched,
105
+ \t\tloading,
106
+ \t\thandleChange,
107
+ \t\thandleSubmit${hasDropdown ? ',\n\t\topenBottomSheet,\n\t\tbottomSheetType' : ''}${hasDate ? ',\n\t\topenCalendar,\n\t\tsetOpenCalendar' : ''}
108
+ \t} = use${componentName}({ navigation });
109
+ \t${hasDropdown ? '\n\tconst [openBottomNote, setOpenBottomNote] = useState(false);' : ''}
110
+
111
+ \tif (loading) {
112
+ \t\treturn <Loader loaderText="Hang On..." />;
113
+ \t}
114
+
115
+ \treturn (
116
+ \t\t<>
117
+ \t\t\t<Container>
118
+ \t\t\t\t<Header redirect={() => navigation.goBack()} />
119
+ \t\t\t\t<ScrollView
120
+ \t\t\t\t\tshowsVerticalScrollIndicator={false}
121
+ \t\t\t\t\tcontentContainerStyle={[utilities.rowPadding24]}
122
+ \t\t\t\t>
123
+ \t\t\t\t\t<Text style={styles.heading}>${screenName}</Text>
124
+ ${generateFormFields(formFields)}
125
+ \t\t\t\t</ScrollView>
126
+ \t\t\t</Container>
127
+ \t\t\t<Footer isBottom={true}>
128
+ \t\t\t\t<FormButton title="Submit" onPress={handleSubmit} />
129
+ \t\t\t</Footer>${bottomSheetCode}${datePickerCode}
130
+ \t\t</>
131
+ \t);
132
+ };
133
+
134
+ const styles = StyleSheet.create({
135
+ \theading: {
136
+ \t\t...fonts.fontWSSB18,
137
+ \t\tcolor: colorConstant.moBlack,
138
+ \t\tmarginVertical: 20,
139
+ \t},
140
+ });
141
+
142
+ export default ${componentName};
143
+ `;
144
+ } else {
145
+ return `import React, { useState } from 'react';
56
146
  import { Text, ScrollView, View } from 'react-native';
57
147
  import { TouchableRipple } from 'react-native-paper';
58
148
  import { colorConstant, utilities } from '../../../assets/styles';
@@ -91,49 +181,78 @@ ${generateFormFields(formFields)}
91
181
  \t\t\t</Container>
92
182
  \t\t\t<Footer style={styles.footerDesign}>
93
183
  \t\t\t\t<FormButton title="Submit" onPress={handleSubmit} />
94
- \t\t\t</Footer>${hasDropdown ? `
95
- \t\t\t<BottomSheet
96
- \t\t\t\tmodalVisible={!!openBottomNote}
97
- \t\t\t\tsetIsModalVisible={() => setOpenBottomNote(null)}
98
- \t\t\t>
99
- \t\t\t\t<DropDownReview
100
- \t\t\t\t\tFundBuyType={/* Add options */[]}
101
- \t\t\t\t\tselectValue={formData[bottomSheetType]}
102
- \t\t\t\t\tonSelectValue={e => {
103
- \t\t\t\t\t\thandleChange(e, bottomSheetType);
104
- \t\t\t\t\t\tsetOpenBottomNote(null);
105
- \t\t\t\t\t}}
106
- \t\t\t\t\tlabel={bottomSheetType}
107
- \t\t\t\t/>
108
- \t\t\t</BottomSheet>` : ''}${hasDate ? `
109
- \t\t\t<DatePickerCustom
110
- \t\t\t\tmodalTransparent={true}
111
- \t\t\t\tonDateChange={data => {
112
- \t\t\t\t\thandleChange(moment(data).format('DD MMM YYYY'), 'dateField');
113
- \t\t\t\t}}
114
- \t\t\t\tsetModalVisible={() => setOpenCalendar(!openCalendar)}
115
- \t\t\t\tmodalVisible={openCalendar}
116
- \t\t\t\tminimumDate={new Date(1920, 0, 1)}
117
- \t\t\t/>` : ''}
184
+ \t\t\t</Footer>${bottomSheetCode}${datePickerCode}
118
185
  \t\t</>
119
186
  \t);
120
187
  };
121
188
 
122
189
  export default ${componentName};
123
190
  `;
191
+ }
124
192
  };
125
193
 
126
194
  const generateScreenTemplate = (screenName, featureName, hasForm = false, formFields = []) => {
127
- // Use enhanced template for form screens
128
195
  if (hasForm) {
129
196
  return generateEnhancedTemplate(screenName, featureName, hasForm, formFields);
130
197
  }
131
198
 
132
- // Simple screen template
133
199
  const componentName = screenName;
134
- const { headerImportPath } = detectProjectStructure();
200
+ const { headerImportPath, hasHeadersFolder } = detectProjectStructure();
201
+ const isDistributorStyle = !hasHeadersFolder;
135
202
 
136
- return `import React from 'react';
203
+ if (isDistributorStyle) {
204
+ return `import React from 'react';
205
+ import { View, Text, ScrollView, StyleSheet } from 'react-native';
206
+ import { colorConstant, fonts, utilities } from '../../../assets/styles';
207
+ import Container from '../../../components/common/Container';
208
+ import Header from '../../../components/common/Header';
209
+ import Footer from '../../../components/common/Footer';
210
+ import Loader from '../../../components/common/Loader';
211
+ import { FormButton } from '../../../components/form';
212
+ import { use${componentName} } from './hooks/use${componentName}';
213
+
214
+ const ${componentName} = ({ navigation }) => {
215
+ \tconst {
216
+ \t\tloading,
217
+ \t\tdata,
218
+ \t\thandleSubmit,
219
+ \t} = use${componentName}({ navigation });
220
+
221
+ \tif (loading) {
222
+ \t\treturn <Loader loaderText="Hang On..." />;
223
+ \t}
224
+
225
+ \treturn (
226
+ \t\t<>
227
+ \t\t\t<Container>
228
+ \t\t\t\t<Header redirect={() => navigation.goBack()} />
229
+ \t\t\t\t<ScrollView
230
+ \t\t\t\t\tshowsVerticalScrollIndicator={false}
231
+ \t\t\t\t\tcontentContainerStyle={[utilities.rowPadding24]}
232
+ \t\t\t\t>
233
+ \t\t\t\t\t<Text style={styles.heading}>${screenName}</Text>
234
+ \t\t\t\t\t{/* Add your content here */}
235
+ \t\t\t\t</ScrollView>
236
+ \t\t\t</Container>
237
+ \t\t\t<Footer isBottom={true}>
238
+ \t\t\t\t<FormButton title="Submit" onPress={handleSubmit} />
239
+ \t\t\t</Footer>
240
+ \t\t</>
241
+ \t);
242
+ };
243
+
244
+ const styles = StyleSheet.create({
245
+ \theading: {
246
+ \t\t...fonts.fontWSSB18,
247
+ \t\tcolor: colorConstant.moBlack,
248
+ \t\tmarginVertical: 20,
249
+ \t},
250
+ });
251
+
252
+ export default ${componentName};
253
+ `;
254
+ } else {
255
+ return `import React from 'react';
137
256
  import { View, Text, ScrollView } from 'react-native';
138
257
  import { Container, Loader } from '../../../components/common';
139
258
  import { Header } from '${headerImportPath}';
@@ -164,6 +283,7 @@ const ${componentName} = ({ navigation }) => {
164
283
 
165
284
  export default ${componentName};
166
285
  `;
286
+ }
167
287
  };
168
288
 
169
289
  module.exports = { generateScreenTemplate };