@admin-layout/gluestack-ui-mobile 7.3.8-alpha.8 → 8.5.3-alpha.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.
Files changed (100) hide show
  1. package/CHANGELOG.md +1 -17
  2. package/lib/components/ApplicationErrorFillWrapper.js +1 -1
  3. package/lib/components/ApplicationErrorFillWrapper.js.map +1 -1
  4. package/lib/components/ApplicationErrorHandler.js +3 -3
  5. package/lib/components/ApplicationErrorHandler.js.map +1 -1
  6. package/lib/components/AuthWrapper.d.ts +1 -0
  7. package/lib/components/AuthWrapper.js +27 -0
  8. package/lib/components/AuthWrapper.js.map +1 -0
  9. package/lib/components/ErrorBounday.js.map +1 -1
  10. package/lib/components/Fallback.js +1 -2
  11. package/lib/components/Fallback.js.map +1 -1
  12. package/lib/components/Layout/components/BasicLayout.js +3 -1
  13. package/lib/components/Layout/components/BasicLayout.js.map +1 -1
  14. package/lib/components/Layout/components/BottomTabBar.d.ts +1 -0
  15. package/lib/components/Layout/components/BottomTabBar.js +11 -24
  16. package/lib/components/Layout/components/BottomTabBar.js.map +1 -1
  17. package/lib/components/Layout/components/Drawer.d.ts +1 -0
  18. package/lib/components/Layout/components/Drawer.js +101 -117
  19. package/lib/components/Layout/components/Drawer.js.map +1 -1
  20. package/lib/components/Layout/components/Header.d.ts +2 -1
  21. package/lib/components/Layout/components/Header.js +5 -4
  22. package/lib/components/Layout/components/Header.js.map +1 -1
  23. package/lib/components/Layout/components/SettingDrawer/LayoutButton.js +26 -19
  24. package/lib/components/Layout/components/SettingDrawer/LayoutButton.js.map +1 -1
  25. package/lib/components/Layout/components/SettingDrawer/ThemeColorButton.js +5 -13
  26. package/lib/components/Layout/components/SettingDrawer/ThemeColorButton.js.map +1 -1
  27. package/lib/components/Layout/components/SideBar.js +2 -2
  28. package/lib/components/Layout/components/SideBar.js.map +1 -1
  29. package/lib/components/Layout/components/util.js.map +1 -1
  30. package/lib/components/Layout/compute.js +51 -52
  31. package/lib/components/Layout/compute.js.map +1 -1
  32. package/lib/components/NavigationComponent.js +24 -31
  33. package/lib/components/NavigationComponent.js.map +1 -1
  34. package/lib/components/ToastAlert.js +1 -1
  35. package/lib/components/ToastAlert.js.map +1 -1
  36. package/lib/components/UnAuthenticatedComponent.d.ts +3 -0
  37. package/lib/components/UnAuthenticatedComponent.js +16 -0
  38. package/lib/components/UnAuthenticatedComponent.js.map +1 -0
  39. package/lib/components/index.d.ts +1 -0
  40. package/lib/components/index.js +1 -0
  41. package/lib/components/index.js.map +1 -1
  42. package/lib/components/with-interactions-lifecycle-managed.d.ts +4 -0
  43. package/lib/components/with-interactions-lifecycle-managed.js +50 -0
  44. package/lib/components/with-interactions-lifecycle-managed.js.map +1 -0
  45. package/lib/components/with-interactions-managed.js +2 -2
  46. package/lib/components/with-interactions-managed.js.map +1 -1
  47. package/lib/config/config.js +2 -2
  48. package/lib/config/config.js.map +1 -1
  49. package/lib/config/i18next.js +1 -2
  50. package/lib/config/i18next.js.map +1 -1
  51. package/lib/containers/layout/BasicLayout.d.ts +2 -2
  52. package/lib/containers/layout/BasicLayout.js +3 -3
  53. package/lib/containers/layout/BasicLayout.js.map +1 -1
  54. package/lib/containers/layout/DrawerBottomNavigationConfig.d.ts +2 -2
  55. package/lib/containers/layout/DrawerBottomNavigationConfig.js +2 -2
  56. package/lib/containers/layout/DrawerBottomNavigationConfig.js.map +1 -1
  57. package/lib/containers/layout/DrawerConfig.d.ts +1 -1
  58. package/lib/containers/layout/DrawerConfig.js +1 -1
  59. package/lib/containers/layout/DrawerConfig.js.map +1 -1
  60. package/lib/containers/layout/Lifecycle.js +2 -14
  61. package/lib/containers/layout/Lifecycle.js.map +1 -1
  62. package/lib/containers/layout/ProLayout.js +4 -5
  63. package/lib/containers/layout/ProLayout.js.map +1 -1
  64. package/lib/hooks/use-after-interactions.d.ts +0 -1
  65. package/lib/hooks/use-after-interactions.js +1 -1
  66. package/lib/hooks/use-after-interactions.js.map +1 -1
  67. package/lib/hooks/useIsReady.js.map +1 -1
  68. package/lib/hooks/useLayoutSetting/index.js +16 -14
  69. package/lib/hooks/useLayoutSetting/index.js.map +1 -1
  70. package/lib/index.d.ts +3 -1
  71. package/lib/index.js +3 -1
  72. package/lib/index.js.map +1 -1
  73. package/lib/layout.json +153 -0
  74. package/lib/redux/settings.d.ts +8 -8
  75. package/lib/redux/settings.js +8 -2
  76. package/lib/redux/settings.js.map +1 -1
  77. package/lib/utils/generateAppNavigations.d.mts +43 -0
  78. package/lib/utils/generateAppNavigations.mjs +958 -0
  79. package/lib/utils/generateAppNavigations.mjs.map +1 -0
  80. package/lib/utils/getReplacedRouteConfig.d.ts +11 -0
  81. package/lib/utils/getReplacedRouteConfig.js +276 -0
  82. package/lib/utils/getReplacedRouteConfig.js.map +1 -0
  83. package/lib/utils/getReplacedRouteConfig.mjs +265 -0
  84. package/lib/utils/routeConfigKeyReplace.js +17 -19
  85. package/lib/utils/routeConfigKeyReplace.js.map +1 -1
  86. package/package.json +7 -5
  87. package/src/components/ApplicationErrorHandler.tsx +26 -21
  88. package/src/components/AuthWrapper.tsx +29 -0
  89. package/src/components/Layout/components/BottomTabBar.tsx +2 -0
  90. package/src/components/Layout/components/Drawer.tsx +4 -1
  91. package/src/components/Layout/components/Header.tsx +7 -3
  92. package/src/components/UnAuthenticatedComponent.tsx +38 -0
  93. package/src/components/index.ts +1 -0
  94. package/src/components/with-interactions-lifecycle-managed.tsx +105 -0
  95. package/src/index.ts +4 -1
  96. package/src/layout.json +153 -0
  97. package/src/utils/generateAppNavigations.mjs +990 -0
  98. package/src/utils/getReplacedRouteConfig.mjs_ok +317 -0
  99. package/src/utils/getReplacedRouteConfig.ts +330 -0
  100. package/tsconfig.json +4 -1
@@ -0,0 +1,990 @@
1
+
2
+ import * as fs from 'fs';
3
+ import path from 'path';
4
+ import prettier from 'prettier';
5
+ import { fileURLToPath } from 'url';
6
+ import { promisify } from 'util';
7
+ import glob from 'glob';
8
+ import dotenv from 'dotenv';
9
+ import { createRequire } from 'module';
10
+ import { exec as execCallback } from 'child_process';
11
+ import {getSortedNavigations} from '@common-stack/client-react/lib/route/react-navigation/get-navigation-utils.js';
12
+ import {getReplacedRouteConfig} from './getReplacedRouteConfig.mjs';
13
+ dotenv.config({ path: `${process.cwd()}/${process.env.ENV_FILE}` })
14
+ const require = createRequire(import.meta.url);
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = path.dirname(__filename);
17
+ const exec = promisify(execCallback);
18
+ const globPromise = promisify(glob.glob);
19
+ const configFilePath = path.join(__dirname, '../layout.json');
20
+ const appNavigationFileName = 'navigation.tsx';
21
+ const mainRoutesFileName = 'main_routes.json';
22
+ const modulesFileName = 'modules.ts';
23
+ const stacksDirPath = 'stack/index.tsx';
24
+ const drawerFilePath = 'drawer/index.tsx';
25
+ const hostDrawerFilePath = 'host_drawer/index.tsx';
26
+ const bottomFilePath = 'bottom/index.tsx';
27
+ const hostBottomFilePath = 'host_bottom/index.tsx';
28
+
29
+
30
+ const readJsonFile = (filePath) => {
31
+ return new Promise((resolve, reject) => {
32
+ fs.readFile(filePath, 'utf8', (err, data) => {
33
+ if (err) {
34
+ return reject(err);
35
+ }
36
+ try {
37
+ const jsonData = JSON.parse(data);
38
+ resolve(jsonData);
39
+ } catch (parseErr) {
40
+ reject(parseErr);
41
+ }
42
+ });
43
+ });
44
+ };
45
+
46
+ const execPromise = async (command) => {
47
+ return new Promise(function (resolve, reject) {
48
+ execCallback(command, (error, stdout, stderr) => {
49
+ if (error) {
50
+ return resolve(false);
51
+ }
52
+ return resolve(true);
53
+ });
54
+ });
55
+ };
56
+
57
+
58
+ const renameFile = (file, new_name) => {
59
+ return new Promise((resolve) => {
60
+ fs.access(file, fs.constants.F_OK, (err) => {
61
+ if (err) {
62
+ resolve(false);
63
+ }
64
+
65
+ return fs.rename(file, new_name, (err) => {
66
+ if(err) resolve(false);
67
+ resolve(true);
68
+ });
69
+ });
70
+ });
71
+ }
72
+
73
+ const writeFile = (file, content) => {
74
+ return new Promise((resolve) => {
75
+ return fs.writeFile(file, content,'utf-8', (err) => {
76
+ if(err) resolve(false);
77
+ resolve(true);
78
+ });
79
+ });
80
+ }
81
+
82
+ const makeDir = (dirName) => {
83
+ return new Promise((resolve) => {
84
+ return fs.mkdir(dirName,{ recursive: true }, (err) => {
85
+ if(err) resolve(false);
86
+ resolve(true);
87
+ });
88
+ });
89
+ }
90
+
91
+ const getLayoutConfig = async () => {
92
+ const layoutConfigFileData = await readJsonFile(configFilePath);
93
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
94
+ return {layoutConfigFileData,layoutSettings}
95
+ }
96
+
97
+ const getModulesRouteConfig = async ({modules}) => {
98
+ const allFilteredRoutes = [];
99
+ for (const pkg of modules) {
100
+ const pkgPath = require.resolve(pkg);
101
+ const pkgDirPath = path.dirname(pkgPath);
102
+ const pkgFile = path.join(pkgDirPath, 'routes.json');
103
+ if(fs.existsSync(pkgFile)){
104
+ const fileModuleJSON = await import(pkgFile, { assert: { type: "json" } });
105
+ if (fileModuleJSON.default) {
106
+ allFilteredRoutes.push([...fileModuleJSON.default]);
107
+ }
108
+
109
+ }
110
+ }
111
+ return allFilteredRoutes;
112
+ }
113
+
114
+ const generateAppRoutesJson = async ({appDirPath}) => {
115
+ const parentDirPath = path.dirname(appDirPath);
116
+ const parentDirName = path.basename(parentDirPath);
117
+ const appDirName = path.basename(appDirPath);
118
+ // const tsFile = 'src/compute.ts';
119
+ // const outputDir = 'src/app';
120
+ const tsFile = `${parentDirName}/compute.ts`;
121
+ const outputDir = `${parentDirName}/${appDirName}`;
122
+ const tscCommand = `tsc ${tsFile} --outDir ${outputDir} --target es6 --module esnext --jsx react --allowSyntheticDefaultImports true --moduleResolution node --esModuleInterop true --forceConsistentCasingInFileNames true --skipLibCheck true`;
123
+ const mainRoutesJsFile = path.join(appDirPath, '/compute.js');
124
+ const mainRoutesMjsFile = path.join(appDirPath, '/compute.mjs');
125
+ const outputFile = path.join(appDirPath, `/${mainRoutesFileName}`);
126
+ // const mainRoutesJsFile = path.join(rootDirPath, './src/app/compute.js');
127
+ // const mainRoutesMjsFile = path.join(rootDirPath, './src/app/compute.mjs');
128
+ //const outputFile = mainRoutes;
129
+ const allFilteredRoutes = [];
130
+ try {
131
+ const execResult = await execPromise(tscCommand);
132
+ if (execResult && fs.existsSync(mainRoutesJsFile)) {
133
+ const jsFiledata = fs.readFileSync(mainRoutesJsFile, 'utf8');
134
+ const noCommentsData = jsFiledata
135
+ .replace(/\/\/.*$/gm, '') // Remove single-line comments
136
+ .replace(/\/\*[\s\S]*?\*\//g, ''); // Remove multi-line comments
137
+ const noWhitespaceJsData = noCommentsData.replace(/\s+/g, '');
138
+ if(noWhitespaceJsData?.length == 0){
139
+ const outPutDirName = path.dirname(outputFile);
140
+ const isDirCreated = await makeDir(outPutDirName);
141
+ if(isDirCreated){
142
+ const writeFileResponse = await writeFile(outputFile,JSON.stringify(allFilteredRoutes));
143
+ if(writeFileResponse) {
144
+ return true;
145
+ }
146
+ else return false;
147
+ }
148
+ else return false;
149
+ }
150
+ else{
151
+ const newFilePath = mainRoutesJsFile.replace('.js', '.mjs');
152
+ const renameFileResponse = await renameFile(mainRoutesJsFile, newFilePath);
153
+ if(renameFileResponse){
154
+ if (fs.existsSync(mainRoutesMjsFile)) {
155
+ // Dynamically import the JS file assuming it exports filteredRoutes
156
+ const module = await import(mainRoutesMjsFile); // file is already absolute
157
+ if (module.filteredRoutes) {
158
+ const newRoutes = (module.filteredRoutes).map((filteredRoute) => {
159
+ const routConfig = Object.values(filteredRoute)[0];
160
+ const importPath = routConfig.component.toString().match(/import\(['"](.*)['"]\)/)[1];
161
+ // routConfig.componentPath = `../.${importPath}`;
162
+ routConfig.componentPath = `.${importPath}.js`;
163
+ return { [routConfig.path]: routConfig };
164
+ });
165
+ allFilteredRoutes.push(...newRoutes);
166
+ const writeFileResponse = await writeFile(outputFile,JSON.stringify(allFilteredRoutes, null, 2));
167
+
168
+ if(writeFileResponse) {
169
+ fs.unlinkSync(mainRoutesMjsFile);
170
+ return true;
171
+ }
172
+ else return false;
173
+ }
174
+ } else return false;
175
+ }
176
+ else return false;
177
+ }
178
+
179
+ }
180
+ else {
181
+ const outPutDirName = path.dirname(outputFile);
182
+ const isDirCreated = await makeDir(outPutDirName);
183
+ if(isDirCreated){
184
+ const writeFileResponse = await writeFile(outputFile,JSON.stringify(allFilteredRoutes));
185
+ if(writeFileResponse) {
186
+ return true;
187
+ }
188
+ else return false;
189
+ }
190
+ else return false;
191
+ }
192
+ // return true;
193
+
194
+ } catch (error) {
195
+ console.error(`exec error: ${error.message}`);
196
+ const outPutDirName = path.dirname(outputFile);
197
+ const isDirCreated = await makeDir(outPutDirName);
198
+ if(isDirCreated){
199
+ const writeFileResponse = await writeFile(outputFile,JSON.stringify(allFilteredRoutes));
200
+ if(writeFileResponse) {
201
+ return true;
202
+ }
203
+ else return false;
204
+ }
205
+ else return false;
206
+ }
207
+ }
208
+
209
+ const generateImportStatements = async ({modules,initialRouteName}) => {
210
+ try {
211
+ const {layoutConfigFileData,layoutSettings} = await getLayoutConfig();
212
+ const hostRouteConfig = layoutConfigFileData['host-bottom'];
213
+ const hostRouteKey = Object.keys(hostRouteConfig)[1];
214
+ const hostLayout = hostRouteConfig[hostRouteKey];
215
+
216
+ let importStatements = '';
217
+ let moduleNames = '';
218
+ let moduleRouteConfig = '';
219
+ let moduleNumber = 0;
220
+ importStatements += `import React,{useState} from 'react';\n`;
221
+ importStatements += `import {Feature} from '@common-stack/client-react/lib/connector/connector.native.js';\n`;
222
+ //importStatements += `import {getSortedNavigations} from '@common-stack/client-react/lib/route/react-navigation/get-navigation-utils.js';\n`;
223
+ importStatements += `import { useSelector, useDispatch } from 'react-redux';\n`;
224
+ importStatements += `import { CHANGE_SETTINGS_ACTION } from '@admin-layout/client';\n`;
225
+ importStatements += `import {layoutRouteConfig,getReplacedRouteConfig } from '@admin-layout/gluestack-ui-mobile';\n`;
226
+ importStatements += `import mainRouteConfig from './main_routes.json';\n`;
227
+
228
+ modules?.forEach( packageName => {
229
+ moduleNumber++;
230
+ importStatements += `import module${moduleNumber} from '${packageName}';\n`;
231
+ // moduleNames += `${moduleName}, `;
232
+ moduleNames += `module${moduleNumber}, `;
233
+ moduleRouteConfig += `...[module${moduleNumber}?.routeConfig], `;
234
+ });
235
+
236
+ //const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
237
+
238
+ let classStructure = `
239
+ const features = new Feature(
240
+ ${moduleNames.trim()}
241
+ );
242
+
243
+ const mainAppRoutes = mainRouteConfig || [];
244
+
245
+ const appRoutes = [...[mainAppRoutes],${moduleRouteConfig}]?.filter((rc)=>rc.length)??[];
246
+
247
+ const featureRouteConfig = appRoutes?.flat(1)??features?.routeConfig;
248
+ features.routeConfig = featureRouteConfig;
249
+
250
+ export function useGetModules(){
251
+ const dispatch = useDispatch();
252
+ const defaultSettings = useSelector((state:any) => state.settings);
253
+ const initialRouteName = '${initialRouteName}';
254
+ const layoutSettings = ${JSON.stringify({...layoutSettings,hostLayout:hostLayout.key})}
255
+ const [appRouteConfig, setAppRouteConfig]:any = useState(null);
256
+
257
+ React.useEffect(() => {
258
+ setDefalutSettings();
259
+ }, []);
260
+
261
+
262
+ const setDefalutSettings = React.useCallback(()=>{
263
+ const config: any = {
264
+ ...defaultSettings,
265
+ ...layoutSettings,
266
+ };
267
+ dispatch({
268
+ type: CHANGE_SETTINGS_ACTION,
269
+ payload: config,
270
+ });
271
+ },[]);
272
+
273
+ React.useEffect(() => {
274
+ if (defaultSettings) {
275
+ const settingObj: any = { ...defaultSettings };
276
+ const layoutType: any = settingObj.layout;
277
+ const {replacedConfiguredRouteConfig} = getReplacedRouteConfig({
278
+ layoutType: layoutType,
279
+ routeConfig: appRoutes,
280
+ layoutConfigData: layoutRouteConfig,
281
+ initialRouteName,
282
+ });
283
+ if(replacedConfiguredRouteConfig){
284
+ const moduleRouteConfigObject = Object.assign({}, ...replacedConfiguredRouteConfig?.flat(1)??[]);
285
+ const replacedRouteConfig = Object.fromEntries(Object.entries(moduleRouteConfigObject));
286
+ const appReplacedRouteConfig = replacedRouteConfig ? Object.keys(replacedRouteConfig)?.map((k)=>({[k]:replacedRouteConfig[k]})) : [];
287
+
288
+ if (appReplacedRouteConfig) {
289
+ const hostRouteConfig = appReplacedRouteConfig?.map((obj)=> Object.fromEntries(Object.entries(obj)?.filter(([key,val])=>key === '/' || key.startsWith('//'+layoutSettings.hostLayout))))?.filter(value => Object.keys(value).length !== 0)??[];
290
+ const layoutRouteConfig = appReplacedRouteConfig?.map((obj)=> Object.fromEntries(Object.entries(obj)?.filter(([key,val])=>key === '/' || !key.startsWith('//'+layoutSettings.hostLayout))))?.filter(value => Object.keys(value).length !== 0)??[];
291
+ const featureRouteConfig = defaultSettings?.layout == 'host-bottom' ? hostRouteConfig:layoutRouteConfig;
292
+ // features.routeConfig = featureRouteConfig;
293
+ setAppRouteConfig(featureRouteConfig);
294
+ }
295
+ }
296
+ }
297
+ }, [defaultSettings]);
298
+
299
+ return {appRouteConfig};
300
+ }
301
+
302
+ export default features;
303
+ `.replace(/,(\s*)$/, ''); // Removes trailing comma
304
+
305
+ // Use Prettier to format the code
306
+ classStructure = prettier.format(classStructure, { parser: 'babel' });
307
+
308
+ const appFeatures = importStatements + '\n' + classStructure;
309
+
310
+ return { appFeatures };
311
+ } catch (err) {
312
+ console.error('Error:', err);
313
+ return false;
314
+ }
315
+ };
316
+
317
+ const generateModulesTsFile = async ({appDirPath,modules,initialRouteName}) => {
318
+ const moduleTsFile = path.join(appDirPath, `/${modulesFileName}`);
319
+ const { appFeatures } = await generateImportStatements({modules,initialRouteName});
320
+ if(appFeatures){
321
+ const writeFileResponse = await writeFile(moduleTsFile,appFeatures);
322
+ if(writeFileResponse) return true;
323
+ else return false;
324
+ }
325
+ return false;
326
+ }
327
+
328
+
329
+ const generateStackNavigations = async ({appDirPath,modules,initialRouteName}) => {
330
+ const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
331
+ const stackDirPath = path.join(appDirPath, `/${stacksDirPath}`);
332
+ const {layoutConfigFileData,layoutSettings} = await getLayoutConfig();
333
+ const layoutType = layoutSettings.layout || 'bottom';
334
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
335
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
336
+ const appLayout = layoutRouteConfig[layoutRouteKey];
337
+ const modulesRouteConfig = await getModulesRouteConfig({modules:modules});
338
+ const mainRouteConfig = await readJsonFile(mainRoutes);
339
+ const allRoutes = [...[mainRouteConfig??[]],...modulesRouteConfig??[]];
340
+
341
+ const {replacedNavigationRouteConfig:routeConfig} = getReplacedRouteConfig({
342
+ layoutType: layoutType,
343
+ routeConfig: allRoutes,
344
+ layoutConfigData: layoutConfigFileData,
345
+ initialRouteName:initialRouteName,
346
+ });
347
+ const keyToReplace = appLayout.key || 'bottom_tab';
348
+ const stackRouteConfig = routeConfig
349
+ ?.map(rArray =>
350
+ rArray
351
+ ?.map(r => {
352
+ const route = r[Object.keys(r)[0]];
353
+ const path = route.path;
354
+ const isExcluded = path === '/' ||
355
+ path.startsWith(`/${keyToReplace}`) ||
356
+ path.startsWith(`/:orgName/${keyToReplace}`) ||
357
+ path.startsWith('/host_tab') ||
358
+ path.startsWith('/:orgName/host_tab');
359
+ return isExcluded ? false : route;
360
+ })
361
+ ?.filter(route => route !== false)??[] // Filter out false values
362
+ )
363
+ ?.filter(subArray => subArray.length > 0)??[];
364
+
365
+
366
+ let moduleNumber = 0;
367
+ let importStatements = '';
368
+ let moduleContent ='';
369
+ let moduleRender = '';
370
+ let stackNavigator = '';
371
+ for (const pkg of stackRouteConfig) {
372
+ moduleContent += `<Stack.Group>`;
373
+ for(const pkgRouteConfig of pkg){
374
+ moduleNumber++;
375
+ importStatements += `import Component${moduleNumber} from '${pkgRouteConfig.componentPath}';\n`;
376
+ moduleContent += `<Stack.Screen
377
+ key="${pkgRouteConfig.key}"
378
+ name="${pkgRouteConfig.name}"
379
+ component={Component${moduleNumber}}
380
+ initialParams={${JSON.stringify(pkgRouteConfig?.props?.initialParams || {})}}
381
+ options={${JSON.stringify(pkgRouteConfig?.props?.options || {})}}
382
+ />`;
383
+ }
384
+ moduleContent += `</Stack.Group>`;
385
+ moduleRender = `export default ({Stack,...rest}:any) => { return (<>${moduleContent}</>)}`;
386
+
387
+ }
388
+ stackNavigator = importStatements + '\n' + moduleRender;
389
+ if(stackNavigator){
390
+ let stackNavigation = stackNavigator;
391
+ stackNavigation = prettier.format(stackNavigation, { parser: 'babel' });
392
+ const stackDirName = path.dirname(stackDirPath);
393
+ const isDirCreated = await makeDir(stackDirName);
394
+ if(isDirCreated){
395
+ const writeFileResponse = await writeFile(stackDirPath,stackNavigation);
396
+ if(writeFileResponse) return true;
397
+ else return false;
398
+ }
399
+ else return false;
400
+ }
401
+ else return false;
402
+ }
403
+
404
+
405
+ const generateDrawerNavigationsFile = async ({drawerConfig,unauthenticatedComponentPath,drawerDirPath}) => {
406
+ let moduleNumber = 0;
407
+ let importStatements = '';
408
+ let moduleContent ='';
409
+ let moduleRender = '';
410
+ let moduleNavigation = '';
411
+ let icons = '';
412
+
413
+ importStatements += `import * as React from 'react';\n`;
414
+ importStatements += `import {AuthWrapper} from '@admin-layout/gluestack-ui-mobile';\n`;
415
+
416
+ if(unauthenticatedComponentPath)
417
+ importStatements += `import UnauthenticatedComponent from '${unauthenticatedComponentPath}';\n`;
418
+
419
+
420
+ for (const pkgRouteConfig of drawerConfig) {
421
+ moduleNumber++;
422
+ if(pkgRouteConfig?.icon && Object.keys(pkgRouteConfig.icon)?.length && pkgRouteConfig?.icon?.name){
423
+ icons += `${pkgRouteConfig?.icon?.name},`;
424
+ }
425
+ const options = JSON.stringify({...pkgRouteConfig?.props?.options || {}});
426
+ importStatements += `import Component${moduleNumber} from '${pkgRouteConfig.componentPath}';\n`;
427
+ moduleContent += `<Drawer.Screen
428
+ key="${pkgRouteConfig.key}"
429
+ name="${pkgRouteConfig.name}"
430
+ //component={Component${moduleNumber}}
431
+ initialParams={${JSON.stringify(pkgRouteConfig?.props?.initialParams || {})}}
432
+ options={{...${options},...{${pkgRouteConfig?.icon && Object.keys(pkgRouteConfig.icon)?.length ? `drawerIcon: ({ color, size }: { color: any,size:any }) => <${pkgRouteConfig?.icon?.name} name="${pkgRouteConfig?.icon?.props?.name??'home'}" size={${pkgRouteConfig?.icon?.props?.size??`size`}} color={${pkgRouteConfig?.icon?.props?.color??'color'}} />`:''}}}}
433
+ >{(props:any) => <AuthWrapper
434
+ auth={${pkgRouteConfig?.props?.initialParams?.auth??false}}
435
+ component={<Component${moduleNumber} {...props} />}
436
+ ${unauthenticatedComponentPath ? 'unauthenticatedComponent={<UnauthenticatedComponent/>}' : ""}
437
+ ${pkgRouteConfig?.withLifeCycle ? `withLifeCycle={${JSON.stringify(pkgRouteConfig?.withLifeCycle)}}` : ""}
438
+ ${pkgRouteConfig?.withInteraction ? `withInteraction={${JSON.stringify(pkgRouteConfig?.withInteraction)}}` : ""}
439
+ ${pkgRouteConfig?.withLifeCycleInteraction ? `withLifeCycleInteraction={${JSON.stringify(pkgRouteConfig?.withLifeCycleInteraction)}}` : ""}
440
+ />}</Drawer.Screen>`;
441
+ }
442
+ if(icons && icons?.length){
443
+ const uniqueIcons = [...new Set(icons.split(","))].join(",");
444
+ importStatements += `import { ${uniqueIcons} } from '@expo/vector-icons';\n`;
445
+ }
446
+
447
+ moduleRender = `export default ({Drawer,...rest}:any) => { return (<>${moduleContent}</>)}`;
448
+ moduleNavigation = importStatements + '\n' + moduleRender;
449
+
450
+ const drawerNavigator = moduleNavigation;
451
+ if(drawerNavigator){
452
+ let drawerNavigation = drawerNavigator;
453
+ drawerNavigation = prettier.format(drawerNavigation, { parser: 'babel' });
454
+ const drawerDirName = path.dirname(drawerDirPath);
455
+ const isDirCreated = await makeDir(drawerDirName);
456
+ if(isDirCreated){
457
+ const writeFileResponse = await writeFile(drawerDirPath,drawerNavigation);
458
+ if(writeFileResponse) return true;
459
+ else return false;
460
+ }
461
+ else return false;
462
+ }
463
+ return false;
464
+ }
465
+
466
+
467
+ const generateDrawerNavigations = async ({appDirPath,modules,initialRouteName,unauthenticatedComponentPath}) => {
468
+ const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
469
+ const drawerDirPath = path.join(appDirPath, `/${drawerFilePath}`);
470
+ const hostDirPath = path.join(appDirPath, `/${hostDrawerFilePath}`);
471
+
472
+ const {layoutConfigFileData,layoutSettings} = await getLayoutConfig();
473
+ const layoutType = 'side';
474
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
475
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
476
+ const appLayout = layoutRouteConfig[layoutRouteKey];
477
+ const hostRouteConfig = layoutConfigFileData['host-bottom'];
478
+ const hostRouteKey = Object.keys(hostRouteConfig)[1];
479
+ const hostLayout = hostRouteConfig[hostRouteKey];
480
+ const modulesRouteConfig = await getModulesRouteConfig({modules:modules});
481
+ const mainRouteConfig = await readJsonFile(mainRoutes);
482
+ const allRoutes = [...[mainRouteConfig??[]],...modulesRouteConfig??[]];
483
+ const {replacedNavigationRouteConfig:routeConfig} = getReplacedRouteConfig({
484
+ layoutType: layoutType,
485
+ routeConfig: allRoutes,
486
+ layoutConfigData: layoutConfigFileData,
487
+ initialRouteName:initialRouteName,
488
+ });
489
+ const keyToReplace = appLayout.key || 'bottom_tab';
490
+ const keyToReplaceHost = hostLayout.key || 'host_tab';
491
+ const moduleRouteConfigObject = Object.assign({}, ...routeConfig?.flat(1)??[]);
492
+ const configuredRoutes = await getSortedNavigations("/",moduleRouteConfigObject);
493
+ const layoutBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r)=>r?.key == keyToReplace);
494
+ const hostBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r)=>r?.key == keyToReplaceHost);
495
+
496
+ const drawerConfig = layoutBottomTabRouteConfig?.[0]?.children?.sort((a, b) => {
497
+ if (a?.props?.options?.priority === undefined) return 1; // Push items with missing 'id' to the end
498
+ if (b?.props?.options?.priority === undefined) return -1;
499
+ return a?.props?.options?.priority - b?.props?.options?.priority;
500
+ })??[];
501
+ const hostDrawerConfig = hostBottomTabRouteConfig?.[0]?.children?.sort((a, b) => {
502
+ if (a?.props?.options?.priority === undefined) return 1; // Push items with missing 'id' to the end
503
+ if (b?.props?.options?.priority === undefined) return -1;
504
+ return a?.props?.options?.priority - b?.props?.options?.priority;
505
+ })??[];
506
+
507
+ if(layoutSettings?.layout == 'side'){
508
+ if(drawerConfig){
509
+ const drawerNavigation = await generateDrawerNavigationsFile({drawerConfig:drawerConfig,unauthenticatedComponentPath,drawerDirPath:drawerDirPath});
510
+ if(drawerNavigation) await generateDrawerNavigationsFile({drawerConfig:hostDrawerConfig,unauthenticatedComponentPath,drawerDirPath:hostDirPath});
511
+ return true;
512
+ }
513
+ else {
514
+ if(hostDrawerConfig){
515
+ const isDrawerGenerated = await generateDrawerNavigationsFile({drawerConfig:hostDrawerConfig,unauthenticatedComponentPath,drawerDirPath:hostDirPath});
516
+ return isDrawerGenerated;
517
+ }
518
+ else return false;
519
+ }
520
+ }
521
+ else return false;
522
+ }
523
+
524
+ const generateBottomTabNavigationsFile = async ({bottomTabConfig,unauthenticatedComponentPath,bottomDirPath,mixLayout=null}) => {
525
+ let moduleNumber = 0;
526
+ let importStatements = '';
527
+ let moduleContent ='';
528
+ let moduleRender = '';
529
+ let moduleNavigation = '';
530
+ let icons = '';
531
+
532
+ importStatements += `import * as React from 'react';\n`;
533
+ importStatements += `import {AuthWrapper} from '@admin-layout/gluestack-ui-mobile';\n`;
534
+
535
+ if(unauthenticatedComponentPath)
536
+ importStatements += `import UnauthenticatedComponent from '${unauthenticatedComponentPath}';\n`;
537
+
538
+ for (const pkgRouteConfig of bottomTabConfig) {
539
+ moduleNumber++;
540
+ if(pkgRouteConfig?.icon && Object.keys(pkgRouteConfig.icon)?.length && pkgRouteConfig?.icon?.name){
541
+ icons += `${pkgRouteConfig?.icon?.name},`;
542
+ }
543
+
544
+ const options = JSON.stringify({...pkgRouteConfig?.props?.options,headerShown:mixLayout?false:pkgRouteConfig?.props?.options?.headerShown} || {headerShown:mixLayout?false:true});
545
+ importStatements += `import Component${moduleNumber} from '${pkgRouteConfig.componentPath}';\n`;
546
+ moduleContent += `<Tab.Screen
547
+ key="${pkgRouteConfig.key}"
548
+ name="${pkgRouteConfig.name}"
549
+ //component={Component${moduleNumber}}
550
+ initialParams={${JSON.stringify(pkgRouteConfig?.props?.initialParams || {})}}
551
+ options={{...${options},...{${pkgRouteConfig?.icon && Object.keys(pkgRouteConfig.icon)?.length ? `tabBarIcon: ({ color }: { color: any }) => <${pkgRouteConfig?.icon?.name} name="${pkgRouteConfig?.icon?.props?.name??'home'}" size={${pkgRouteConfig?.icon?.props?.size??24}} color={${pkgRouteConfig?.icon?.props?.color??'color'}} />`:''}}}}
552
+ >{(props:any) => <AuthWrapper
553
+ auth={${pkgRouteConfig?.props?.initialParams?.auth??false}}
554
+ component={<Component${moduleNumber} {...props} />}
555
+ ${unauthenticatedComponentPath ? 'unauthenticatedComponent={<UnauthenticatedComponent/>}' : ""}
556
+ ${pkgRouteConfig?.withLifeCycle ? `withLifeCycle={${JSON.stringify(pkgRouteConfig?.withLifeCycle)}}` : ""}
557
+ ${pkgRouteConfig?.withInteraction ? `withInteraction={${JSON.stringify(pkgRouteConfig?.withInteraction)}}` : ""}
558
+ ${pkgRouteConfig?.withLifeCycleInteraction ? `withLifeCycleInteraction={${JSON.stringify(pkgRouteConfig?.withLifeCycleInteraction)}}` : ""}
559
+ />}
560
+ </Tab.Screen>`;
561
+ }
562
+
563
+ if(icons && icons?.length){
564
+ const uniqueIcons = [...new Set(icons.split(","))].join(",");
565
+ importStatements += `import { ${uniqueIcons} } from '@expo/vector-icons';\n`;
566
+ }
567
+
568
+ moduleRender = `export default ({Tab,...rest}:any) => { return (<>${moduleContent}</>)}`;
569
+ moduleNavigation = importStatements + '\n' + moduleRender;
570
+ const bottomTabNavigator = moduleNavigation;
571
+ if(bottomTabNavigator){
572
+ let bottomTabNavigation = bottomTabNavigator;
573
+ bottomTabNavigation = prettier.format(bottomTabNavigation, { parser: 'babel' });
574
+ const bottomDirName = path.dirname(bottomDirPath);
575
+ const isDirCreated = await makeDir(bottomDirName);
576
+ if(isDirCreated){
577
+ const writeFileResponse = await writeFile(bottomDirPath,bottomTabNavigation);
578
+ if(writeFileResponse) return true;
579
+ else return false;
580
+ }
581
+ else return false;
582
+ }
583
+ return false;
584
+ }
585
+
586
+ const generateBottomTabNavigations = async ({appDirPath,modules,initialRouteName,unauthenticatedComponentPath}) => {
587
+ const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
588
+ const bottomDirPath = path.join(appDirPath, `/${bottomFilePath}`);
589
+ const hostBottomDirPath = path.join(appDirPath, `/${hostBottomFilePath}`);
590
+
591
+ const {layoutConfigFileData,layoutSettings} = await getLayoutConfig();
592
+ const layoutType = layoutSettings?.layout??'bottom';
593
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
594
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
595
+ const appLayout = layoutRouteConfig[layoutRouteKey];
596
+ const hostRouteConfig = layoutConfigFileData['host-bottom'];
597
+ const hostRouteKey = Object.keys(hostRouteConfig)[1];
598
+ const hostLayout = hostRouteConfig[hostRouteKey];
599
+ const mixLayoutRouteKey = Object.keys(layoutRouteConfig)?.[2] || null;
600
+ const mixLayout = mixLayoutRouteKey ? layoutRouteConfig[mixLayoutRouteKey] : null;
601
+ const modulesRouteConfig = await getModulesRouteConfig({modules:modules});
602
+ const mainRouteConfig = await readJsonFile(mainRoutes);
603
+ const allRoutes = [...[mainRouteConfig??[]],...modulesRouteConfig??[]];
604
+
605
+ const {replacedNavigationRouteConfig:routeConfig} = getReplacedRouteConfig({
606
+ layoutType: layoutType,
607
+ routeConfig: allRoutes,
608
+ layoutConfigData: layoutConfigFileData,
609
+ initialRouteName:initialRouteName,
610
+ });
611
+ const keyToReplace = appLayout.key || 'bottom_tab';
612
+ const keyToReplaceHost = hostLayout.key || 'host_tab';
613
+ const moduleRouteConfigObject = Object.assign({}, ...routeConfig?.flat(1)??[]);
614
+ const configuredRoutes = await getSortedNavigations("/",moduleRouteConfigObject);
615
+ const layoutBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r)=>r?.key == keyToReplace);
616
+ const hostBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r)=>r?.key == keyToReplaceHost);
617
+
618
+ const bottomTabConfig = layoutBottomTabRouteConfig?.[0]?.children?.sort((a, b) => {
619
+ if (a?.props?.options?.priority === undefined) return 1; // Push items with missing 'id' to the end
620
+ if (b?.props?.options?.priority === undefined) return -1;
621
+ return a?.props?.options?.priority - b?.props?.options?.priority;
622
+ })??[];
623
+ const hostBottomTabConfig = hostBottomTabRouteConfig?.[0]?.children?.sort((a, b) => {
624
+ if (a?.props?.options?.priority === undefined) return 1; // Push items with missing 'id' to the end
625
+ if (b?.props?.options?.priority === undefined) return -1;
626
+ return a?.props?.options?.priority - b?.props?.options?.priority;
627
+ })??[];
628
+ if(layoutType == 'bottom' || layoutType == 'mixSide'){
629
+ if(bottomTabConfig){
630
+ const drawerNavigation = await generateBottomTabNavigationsFile({bottomTabConfig:bottomTabConfig,unauthenticatedComponentPath,bottomDirPath:bottomDirPath,mixLayout});
631
+ if(drawerNavigation) await generateBottomTabNavigationsFile({bottomTabConfig:hostBottomTabConfig,unauthenticatedComponentPath,bottomDirPath:hostBottomDirPath,mixLayout});
632
+ return true;
633
+ }
634
+ else {
635
+ if(hostBottomTabConfig){
636
+ const isHostGenerated = await generateBottomTabNavigationsFile({bottomTabConfig:hostBottomTabConfig,unauthenticatedComponentPath,bottomDirPath:hostBottomDirPath,mixLayout});
637
+ return isHostGenerated;
638
+ }
639
+ else return false;
640
+ }
641
+ }
642
+ else return false;
643
+
644
+ }
645
+
646
+ const generateBottomTabDrawerNavigations = async ({appDirPath,modules,initialRouteName,unauthenticatedComponentPath}) => {
647
+ const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
648
+ const bottomDirPath = path.join(appDirPath, `/${bottomFilePath}`);
649
+ const hostBottomDirPath = path.join(appDirPath, `/${hostBottomFilePath}`);
650
+ const drawerDirPath = path.join(appDirPath, `/${drawerFilePath}`);
651
+ const hostDirPath = path.join(appDirPath, `/${hostDrawerFilePath}`);
652
+
653
+ const {layoutConfigFileData,layoutSettings} = await getLayoutConfig();
654
+ const layoutType = layoutSettings?.layout??'bottom';
655
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
656
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
657
+ const appLayout = layoutRouteConfig[layoutRouteKey];
658
+ const hostRouteConfig = layoutConfigFileData['host-bottom'];
659
+ const hostRouteKey = Object.keys(hostRouteConfig)[1];
660
+ const hostLayout = hostRouteConfig[hostRouteKey];
661
+ const mixLayoutRouteKey = Object.keys(layoutRouteConfig)?.[2] || null;
662
+ const mixLayout = mixLayoutRouteKey ? layoutRouteConfig[mixLayoutRouteKey] : null;
663
+ const modulesRouteConfig = await getModulesRouteConfig({modules:modules});
664
+ const mainRouteConfig = await readJsonFile(mainRoutes);
665
+ const allRoutes = [...[mainRouteConfig??[]],...modulesRouteConfig??[]];
666
+
667
+ const {replacedNavigationRouteConfig:routeConfig} = getReplacedRouteConfig({
668
+ layoutType: layoutType,
669
+ routeConfig: allRoutes,
670
+ layoutConfigData: layoutConfigFileData,
671
+ initialRouteName:initialRouteName,
672
+ });
673
+ const keyToReplace = appLayout.key || 'bottom_tab';
674
+ const keyToReplaceHost = hostLayout.key || 'host_tab';
675
+ const moduleRouteConfigObject = Object.assign({}, ...routeConfig?.flat(1)??[]);
676
+ const configuredRoutes = await getSortedNavigations("/",moduleRouteConfigObject);
677
+ const layoutBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r)=>r?.key == keyToReplace);
678
+ const hostBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r)=>r?.key == keyToReplaceHost);
679
+
680
+ const bottomTabConfig = layoutBottomTabRouteConfig?.[0]?.children?.filter((r)=>!r?.side)?.sort((a, b) => {
681
+ if (a?.props?.options?.priority === undefined) return 1; // Push items with missing 'id' to the end
682
+ if (b?.props?.options?.priority === undefined) return -1;
683
+ return a?.props?.options?.priority - b?.props?.options?.priority;
684
+ })??[];
685
+ const hostBottomTabConfig = hostBottomTabRouteConfig?.[0]?.children?.filter((r)=>!r?.side)?.sort((a, b) => {
686
+ if (a?.props?.options?.priority === undefined) return 1; // Push items with missing 'id' to the end
687
+ if (b?.props?.options?.priority === undefined) return -1;
688
+ return a?.props?.options?.priority - b?.props?.options?.priority;
689
+ })??[];
690
+
691
+ const drawerConfig = layoutBottomTabRouteConfig?.[0]?.children?.filter((r)=>r?.side)?.sort((a, b) => {
692
+ if (a?.props?.options?.priority === undefined) return 1; // Push items with missing 'id' to the end
693
+ if (b?.props?.options?.priority === undefined) return -1;
694
+ return a?.props?.options?.priority - b?.props?.options?.priority;
695
+ })??[];
696
+ const hostDrawerConfig = hostBottomTabRouteConfig?.[0]?.children?.filter((r)=>r?.side)?.sort((a, b) => {
697
+ if (a?.props?.options?.priority === undefined) return 1; // Push items with missing 'id' to the end
698
+ if (b?.props?.options?.priority === undefined) return -1;
699
+ return a?.props?.options?.priority - b?.props?.options?.priority;
700
+ })??[];
701
+
702
+ if(bottomTabConfig){
703
+ const drawerNavigation = await generateBottomTabNavigationsFile({bottomTabConfig:bottomTabConfig,unauthenticatedComponentPath,bottomDirPath:bottomDirPath,mixLayout});
704
+ if(drawerNavigation) await generateBottomTabNavigationsFile({bottomTabConfig:hostBottomTabConfig,unauthenticatedComponentPath,bottomDirPath:hostBottomDirPath,mixLayout});
705
+ if(drawerConfig){
706
+ const drawerNavigation = await generateDrawerNavigationsFile({drawerConfig:drawerConfig,unauthenticatedComponentPath,drawerDirPath:drawerDirPath});
707
+ if(drawerNavigation) await generateDrawerNavigationsFile({drawerConfig:hostDrawerConfig,unauthenticatedComponentPath,drawerDirPath:hostDirPath});
708
+ return true;
709
+ }
710
+ else return true;
711
+ }
712
+ else return false;
713
+ }
714
+
715
+ const generateAppNavigationFile = async ({appDirPath,customTabBarPath,customDrawerPath,customHeaderPath}) => {
716
+ const navigationDirPath = path.join(appDirPath, `/${appNavigationFileName}`);
717
+ const { layoutConfigFileData, layoutSettings } = await getLayoutConfig();
718
+ const layoutType = layoutSettings.layout || 'bottom';
719
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
720
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
721
+ const appLayout = layoutRouteConfig[layoutRouteKey];
722
+
723
+ const initialRouteName =
724
+ layoutType === 'mixSide'
725
+ ? appLayout?.[appLayout?.key]?.props?.initialRouteName ?? 'MainStack.Layout.Home'
726
+ : appLayout?.props?.initialRouteName || 'MainStack.Home';
727
+ const isShowTabs = layoutType === 'mixSide' || layoutType === 'bottom' ? true : false;
728
+ const isShowDefalutHeader = layoutType === 'mixSide' ? true : false;
729
+ const defaultHeaderProps = {
730
+ showToggle: layoutSettings.topLeftToggle || false,
731
+ right: layoutSettings.topRightSettingToggle || false,
732
+ };
733
+ const screenOptionsTab =
734
+ layoutType === 'mixSide'
735
+ ? { ...(appLayout?.[appLayout?.key]?.props?.screenOptions ?? {}) }
736
+ : appLayout?.props?.screenOptions || { headerShown: true, title: 'Home', headerTitle: 'Home' };
737
+ const screenOptions = appLayout?.props?.screenOptions || { headerShown: true, title: 'Home', headerTitle: 'Home' };
738
+ let importStatements = `
739
+ import * as React from 'react';
740
+ import { navigationRef } from '@common-stack/client-react';
741
+ import { createNativeStackNavigator } from '@react-navigation/native-stack';`;
742
+ let rootComponent = '';
743
+ let appComponent = '';
744
+ let appNavigation = '';
745
+ if (layoutType == 'side') {
746
+
747
+ if(customDrawerPath)
748
+ importStatements += `import CustomDrawerContent from '${customDrawerPath}';\n`;
749
+
750
+ if(customHeaderPath)
751
+ importStatements += `import CustomHeader from '${customHeaderPath}';\n`;
752
+
753
+ importStatements += `import { createDrawerNavigator } from '@react-navigation/drawer';
754
+ import { getHeaderTitle } from '@react-navigation/elements';
755
+ import { useSelector } from 'react-redux';
756
+ import stackNavigations from './stack';
757
+ import drawerNavigations from './drawer';
758
+ import hostDrawerNavigations from './host_drawer';
759
+ const Stack = createNativeStackNavigator();
760
+ const Drawer = createDrawerNavigator();
761
+ `;
762
+ rootComponent += `
763
+ const RootComponent = (props:any) => {
764
+ const settings = useSelector((state: any) => state.settings);
765
+ const defaultHeaderProps = ${JSON.stringify(defaultHeaderProps || {})};
766
+ return (
767
+ <Drawer.Navigator
768
+ initialRouteName={${JSON.stringify(initialRouteName)}}
769
+ //screenOptions={${JSON.stringify(screenOptions)}}
770
+ screenOptions={({ route }) => ({ ...${JSON.stringify(
771
+ screenOptions,
772
+ )} ,...{
773
+ ${customHeaderPath? `header: (props:any) => {
774
+ const title = getHeaderTitle(props.options, props.route.name);
775
+ return <CustomHeader {...defaultHeaderProps} {...props} title={title} style={props.options.headerStyle} />;
776
+ }`:""}
777
+ }})}
778
+ ${customDrawerPath ? 'drawerContent={(props) => <CustomDrawerContent {...props} />}' : ""}
779
+ >
780
+ {settings?.layout == 'host-bottom' ? hostDrawerNavigations({ Drawer }) : drawerNavigations({ Drawer })}
781
+ </Drawer.Navigator>
782
+ );
783
+ }
784
+ `;
785
+ }
786
+ if (layoutType == 'bottom') {
787
+
788
+ if(customTabBarPath)
789
+ importStatements += `import CustomTabBar from '${customTabBarPath}';\n`;
790
+
791
+ if(customHeaderPath)
792
+ importStatements += `import CustomHeader from '${customHeaderPath}';\n`;
793
+
794
+ importStatements += `import {Header,Drawer as DefaultDrawer} from '@admin-layout/gluestack-ui-mobile';
795
+ import { getHeaderTitle } from '@react-navigation/elements';
796
+ import { useSelector } from 'react-redux';
797
+ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
798
+ import stackNavigations from './stack';
799
+ import bottomNavigations from './bottom';
800
+ import hostBottomNavigations from './host_bottom';
801
+ const Stack = createNativeStackNavigator();
802
+ const Tab = createBottomTabNavigator();
803
+ `;
804
+ rootComponent += `
805
+ const RootComponent = (props:any) => {
806
+ const settings = useSelector((state: any) => state.settings);
807
+ const initialRouteName = ${JSON.stringify(initialRouteName)};
808
+ let defaultScreenOptions = ${JSON.stringify(screenOptionsTab)};
809
+ const defaultHeaderProps = ${JSON.stringify(defaultHeaderProps || {})};
810
+ const defaultHeader = {${
811
+ isShowDefalutHeader ? `header:(props:any)=><Header {...defaultHeaderProps} {...props} />` : ''
812
+ }};
813
+ return (
814
+ <Tab.Navigator
815
+ initialRouteName={initialRouteName}
816
+ screenOptions={(props:any)=>({...props,...defaultScreenOptions,...{${customHeaderPath? `header: (props:any) => {
817
+ const title = getHeaderTitle(props.options, props.route.name);
818
+ return <CustomHeader {...defaultHeaderProps} {...props} title={title} style={props.options.headerStyle} />;
819
+ }`:""}}})}
820
+ ${customTabBarPath ? 'tabBar={props => <CustomTabBar {...props} />}' : ""}
821
+ >
822
+ {settings?.layout == 'host-bottom' ? hostBottomNavigations({ Tab }) : bottomNavigations({Tab})}
823
+ </Tab.Navigator>
824
+ );
825
+ }
826
+ `;
827
+ }
828
+ if (layoutType == 'mixSide') {
829
+ if(customTabBarPath)
830
+ importStatements += `import CustomTabBar from '${customTabBarPath}';\n`;
831
+
832
+ if(customDrawerPath)
833
+ importStatements += `import CustomDrawerContent from '${customDrawerPath}';\n`;
834
+
835
+ if(customHeaderPath)
836
+ importStatements += `import CustomHeader from '${customHeaderPath}';\n`;
837
+
838
+ importStatements += `import {Header,Drawer as DefaultDrawer} from '@admin-layout/gluestack-ui-mobile';
839
+ import { useSelector } from 'react-redux';
840
+ import { MaterialIcons } from "@expo/vector-icons";
841
+ import { getHeaderTitle } from '@react-navigation/elements';
842
+ import { createDrawerNavigator } from '@react-navigation/drawer';
843
+ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
844
+ import stackNavigations from './stack';
845
+ import bottomNavigations from './bottom';
846
+ import hostBottomNavigations from './host_bottom';
847
+ import drawerNavigations from './drawer';
848
+ import hostDrawerNavigations from './host_drawer';
849
+ const Stack = createNativeStackNavigator();
850
+ const Drawer = createDrawerNavigator();
851
+ const Tab = createBottomTabNavigator();
852
+ `;
853
+ rootComponent += `
854
+ const TabNavigator = () => {
855
+ const settings = useSelector((state: any) => state.settings);
856
+ const initialRouteName = ${JSON.stringify(initialRouteName)};
857
+ let defaultScreenOptions = ${JSON.stringify(screenOptionsTab)};
858
+ const defaultHeaderProps = ${JSON.stringify(defaultHeaderProps || {})};
859
+ const defaultHeader = {${
860
+ isShowDefalutHeader ? `header:(props:any)=><Header {...defaultHeaderProps} {...props} />` : ''
861
+ }};
862
+
863
+ return (
864
+ <Tab.Navigator
865
+ initialRouteName={initialRouteName}
866
+ screenOptions={(props:any)=>({...props,...defaultScreenOptions,...{headerShown: false,header:()=>null},})}
867
+ ${customTabBarPath ? 'tabBar={props => <CustomTabBar {...props} />}' : ""}
868
+ >
869
+ {settings?.layout == 'host-bottom' ? hostBottomNavigations({ Tab }) : bottomNavigations({Tab})}
870
+ </Tab.Navigator>
871
+ )
872
+ }
873
+ const RootComponent = (props:any) => {
874
+ const initialRouteName = ${JSON.stringify(initialRouteName)};
875
+ const settings = useSelector((state: any) => state.settings);
876
+ let defaultScreenOptions = ${JSON.stringify(screenOptionsTab)};
877
+ const defaultHeaderProps = ${JSON.stringify(defaultHeaderProps || {})};
878
+ const defaultHeader = {${
879
+ isShowDefalutHeader ? `header:(props:any)=><Header {...defaultHeaderProps} {...props} />` : ''
880
+ }};
881
+ return (
882
+ <Drawer.Navigator
883
+ initialRouteName={${JSON.stringify(initialRouteName)}}
884
+ // screenOptions={${JSON.stringify(screenOptions)}}
885
+ screenOptions={({ route }) => ({ ...${JSON.stringify(
886
+ screenOptions,
887
+ )} ,...{headerTitle:navigationRef?.isReady() && navigationRef?.getCurrentRoute()
888
+ ? navigationRef?.getCurrentOptions()?.title
889
+ ? navigationRef?.getCurrentOptions()?.headerTitle
890
+ : navigationRef?.getCurrentRoute()?.route?.name
891
+ : "Home",
892
+ ${customHeaderPath? `header: (props:any) => {
893
+ const title = getHeaderTitle(props.options, props.route.name);
894
+ return <CustomHeader {...defaultHeaderProps} {...props} title={title} isMixedLayout={true} style={props.options.headerStyle} />;
895
+ }`:""}
896
+
897
+ }})}
898
+ ${customDrawerPath ? 'drawerContent={(props) => <CustomDrawerContent {...props} showDefaultRoutes={true} />}' : ""}
899
+ >
900
+ <Drawer.Screen name="Layout" options={{title:"Home", drawerIcon: ({ color, size }: { color: any, size: any }) => (
901
+ <MaterialIcons name="home" size={24} color={color} />
902
+ ),}}
903
+ component={TabNavigator} />
904
+ {settings?.layout == 'host-bottom' ? hostDrawerNavigations({ Drawer }) : drawerNavigations({ Drawer })}
905
+ </Drawer.Navigator>
906
+ );
907
+ }
908
+ `;
909
+ }
910
+ appComponent += `
911
+ const AppNavigations = () => {
912
+ return (
913
+ <Stack.Navigator initialRouteName="${initialRouteName}">
914
+ <Stack.Screen
915
+ name="MainStack"
916
+ options={{ headerShown: false }}
917
+ component={RootComponent}
918
+ />
919
+ {stackNavigations({ Stack })}
920
+ </Stack.Navigator>
921
+ )
922
+ }
923
+
924
+ export default AppNavigations;
925
+ `;
926
+ appNavigation = importStatements + '\n' + rootComponent + '\n' + appComponent;
927
+ appNavigation = prettier.format(appNavigation, { parser: 'babel' });
928
+ const writeFileResponse = await writeFile(navigationDirPath, appNavigation);
929
+ if (writeFileResponse) return true;
930
+ else return false;
931
+ }
932
+
933
+ const generateAppNavigations = async ({appDirPath,modules,initialRouteName='',unauthenticatedComponentPath=null,customTabBarPath=null,customDrawerPath=null,customHeaderPath=null}) => {
934
+ const {layoutSettings} = await getLayoutConfig();
935
+ const layoutType = layoutSettings.layout || 'bottom';
936
+ const isAppRoutesGenerated = await generateAppRoutesJson({appDirPath});
937
+ if(isAppRoutesGenerated){
938
+ const isModuleTsFileGenerated = await generateModulesTsFile({appDirPath,modules,initialRouteName});
939
+ if(isModuleTsFileGenerated){
940
+ const isStackCreated = await generateStackNavigations({appDirPath,modules,initialRouteName});
941
+ if(isStackCreated){
942
+ if(layoutType=='side'){
943
+ const isDrawerGenerated= await generateDrawerNavigations({appDirPath,modules,initialRouteName,unauthenticatedComponentPath});
944
+ if(isDrawerGenerated){
945
+ const appNavigationGenerated = await generateAppNavigationFile({appDirPath,customTabBarPath,customDrawerPath,customHeaderPath});
946
+ if(appNavigationGenerated) return appNavigationGenerated;
947
+ else return true;
948
+ }
949
+ else return false;
950
+ }
951
+ else if(layoutType=='bottom' || layoutType=='host-bottom'){
952
+ const isBottomTabGenerated = await generateBottomTabNavigations({appDirPath,modules,initialRouteName,unauthenticatedComponentPath});
953
+ if(isBottomTabGenerated){
954
+ const appNavigationGenerated = await generateAppNavigationFile({appDirPath,customTabBarPath,customDrawerPath,customHeaderPath});
955
+ if(appNavigationGenerated) return appNavigationGenerated;
956
+ else return true;
957
+ }
958
+ else return false;
959
+ }
960
+ else {
961
+ const isBottomTabDrawerGenerated = await generateBottomTabDrawerNavigations({appDirPath,modules,initialRouteName,unauthenticatedComponentPath});
962
+ if(isBottomTabDrawerGenerated){
963
+ const appNavigationGenerated = await generateAppNavigationFile({appDirPath,customTabBarPath,customDrawerPath,customHeaderPath});
964
+ if(appNavigationGenerated) return appNavigationGenerated;
965
+ else return true;
966
+ }
967
+ else return false;
968
+ }
969
+ }
970
+ else return false;
971
+ }
972
+ else return false;
973
+ }
974
+ else return false;
975
+ }
976
+
977
+
978
+
979
+ export {
980
+ getReplacedRouteConfig,
981
+ readJsonFile,
982
+ getLayoutConfig,
983
+ getModulesRouteConfig,
984
+ generateAppRoutesJson,
985
+ generateModulesTsFile,
986
+ generateStackNavigations,
987
+ generateDrawerNavigations,
988
+ generateBottomTabNavigations,
989
+ generateAppNavigations,
990
+ }