@admin-layout/gluestack-ui-mobile 9.0.4-alpha.0 → 9.0.4-alpha.102

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 (70) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/lib/components/AuthWrapper.d.ts +4 -2
  3. package/lib/components/AuthWrapper.js +5 -5
  4. package/lib/components/AuthWrapper.js.map +1 -1
  5. package/lib/components/Layout/components/Drawer.js +9 -9
  6. package/lib/components/Layout/components/Drawer.js.map +1 -1
  7. package/lib/components/Layout/components/Header.js +28 -15
  8. package/lib/components/Layout/components/Header.js.map +1 -1
  9. package/lib/components/Layout/components/SettingDrawer/LayoutButton.js +14 -6
  10. package/lib/components/Layout/components/SettingDrawer/LayoutButton.js.map +1 -1
  11. package/lib/components/Layout/components/SettingDrawer/SettingDrawer.d.ts +1 -1
  12. package/lib/components/Layout/components/SettingDrawer/SettingDrawer.js +55 -15
  13. package/lib/components/Layout/components/SettingDrawer/SettingDrawer.js.map +1 -1
  14. package/lib/components/Layout/components/SettingDrawer/ThemeColorButton.js +1 -1
  15. package/lib/components/NavigationComponent.js +11 -2
  16. package/lib/components/NavigationComponent.js.map +1 -1
  17. package/lib/components/WithConfiguration.d.ts +18 -0
  18. package/lib/components/WithConfiguration.js +42 -0
  19. package/lib/components/WithConfiguration.js.map +1 -0
  20. package/lib/components/WithPermission.d.ts +31 -0
  21. package/lib/components/WithPermission.js +53 -0
  22. package/lib/components/WithPermission.js.map +1 -0
  23. package/lib/components/WithPolicy.d.ts +13 -0
  24. package/lib/components/WithPolicy.js +18 -0
  25. package/lib/components/WithPolicy.js.map +1 -0
  26. package/lib/components/index.d.ts +5 -0
  27. package/lib/components/index.js +5 -0
  28. package/lib/components/index.js.map +1 -1
  29. package/lib/components/usePermissionAutoFetch.d.ts +75 -0
  30. package/lib/components/usePermissionAutoFetch.js +63 -0
  31. package/lib/components/usePermissionAutoFetch.js.map +1 -0
  32. package/lib/components/useSetting.d.ts +25 -0
  33. package/lib/components/useSetting.js +87 -0
  34. package/lib/components/useSetting.js.map +1 -0
  35. package/lib/components/with-interactions-lifecycle-managed.d.ts +3 -3
  36. package/lib/components/with-interactions-lifecycle-managed.js +23 -15
  37. package/lib/components/with-interactions-lifecycle-managed.js.map +1 -1
  38. package/lib/containers/layout/BasicLayout.d.ts +2 -2
  39. package/lib/containers/layout/DrawerBottomNavigationConfig.d.ts +393 -88
  40. package/lib/containers/layout/DrawerConfig.d.ts +266 -60
  41. package/lib/containers/layout/module.js +2 -2
  42. package/lib/containers/layout/module.js.map +1 -1
  43. package/lib/redux/settings.d.ts +8 -8
  44. package/lib/utils/ThemeColor.js +11 -1
  45. package/lib/utils/ThemeColor.js.map +1 -1
  46. package/lib/utils/generateMobileNavigations.d.ts +4 -11
  47. package/lib/utils/generateMobileNavigations.js +498 -298
  48. package/lib/utils/generateMobileNavigations.js.map +1 -1
  49. package/package.json +7 -7
  50. package/src/components/AuthWrapper.tsx +6 -4
  51. package/src/components/Layout/components/Drawer.tsx +19 -20
  52. package/src/components/Layout/components/Header.tsx +154 -93
  53. package/src/components/Layout/components/SettingDrawer/LayoutButton.tsx +27 -13
  54. package/src/components/Layout/components/SettingDrawer/SettingDrawer.tsx +151 -48
  55. package/src/components/Layout/components/SettingDrawer/ThemeColorButton.tsx +2 -2
  56. package/src/components/NavigationComponent.tsx +9 -2
  57. package/src/components/WithConfiguration.tsx +74 -0
  58. package/src/components/WithPermission.tsx +81 -0
  59. package/src/components/WithPolicy.tsx +32 -0
  60. package/src/components/index.ts +6 -1
  61. package/src/components/usePermissionAutoFetch.tsx +78 -0
  62. package/src/components/useSetting.tsx +137 -0
  63. package/src/components/with-interactions-lifecycle-managed.tsx +62 -26
  64. package/src/containers/layout/module.ts +2 -2
  65. package/src/utils/ThemeColor.ts +11 -1
  66. package/src/utils/generateMobileNavigations.ts +543 -276
  67. package/lib/components/Layout/components/util.d.ts +0 -1
  68. package/lib/components/Layout/components/util.js +0 -15
  69. package/lib/components/Layout/components/util.js.map +0 -1
  70. package/src/components/Layout/components/util.ts +0 -14
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'url';
5
5
  import { createRequire } from 'module';
6
6
  import { exec as execCallback } from 'child_process';
7
7
  import { getSortedNavigations } from '@common-stack/client-react/lib/route/react-navigation/get-navigation-utils.js';
8
+ import { performCopyOperations } from '@common-stack/rollup-vite-utils/lib/preStartup/configLoader/configLoader.js';
8
9
  import { getReplacedRouteConfig } from './getReplacedRouteConfig.js';
9
10
  const require = createRequire(import.meta.url);
10
11
  const __filename = fileURLToPath(import.meta.url);
@@ -22,14 +23,7 @@ const mainRoutesJsFileName = 'mainRoutes.js';
22
23
  const mainAppFileName = 'index.js';
23
24
 
24
25
  type IGenerateMobileNavigationsProps = {
25
- appDirPath: string;
26
- modules: any;
27
- initialRouteName?: string;
28
- unauthenticatedComponentPath?: string;
29
- customTabBarPath?: string;
30
- customDrawerPath?: string;
31
- customHeaderPath?: string;
32
- i18Options: any;
26
+ configFilePath: any;
33
27
  };
34
28
 
35
29
  export const readJsonFile = (filePath) => {
@@ -69,35 +63,46 @@ export const getLayoutConfig = async () => {
69
63
  };
70
64
 
71
65
  export class GenerateMobileNavigations {
72
- #layoutSettings: any = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
73
- #appDirPath: string;
66
+ #configFileData: any = {};
67
+ #configFilePath: any;
68
+ #appPath: string = 'app';
69
+ #isDefaultPackagePathMobileRoot: boolean;
70
+ #mobileStackPath: string = 'mobile-stack-react';
71
+ //#layoutSettings: any = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
72
+ #appDirPath: any;
74
73
  #modules: any;
74
+ #initialRouteNameRootStack: string;
75
75
  #initialRouteName: string;
76
76
  #unauthenticatedComponentPath: string;
77
77
  #customTabBarPath: string;
78
78
  #customDrawerPath: string;
79
79
  #customHeaderPath: string;
80
80
  #i18Options: any;
81
+ #iconsRepository: string;
82
+
83
+ constructor({ configFilePath }: IGenerateMobileNavigationsProps) {
84
+ this.#configFilePath = configFilePath;
85
+ const config = this.#readConfigFile(configFilePath);
86
+ this.#configFileData = config;
87
+ // this.#layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
88
+ this.#appPath = config?.commonPaths?.appPath ?? 'app';
89
+ this.#isDefaultPackagePathMobileRoot = config?.mobileConfig?.isDefaultPackagePathMobileRoot ?? false;
90
+ this.#iconsRepository = config?.iconsRepository ?? '';
91
+ this.#mobileStackPath = config?.mobileStackPath ?? 'mobile-stack-react';
92
+ this.#appDirPath = path.join(path.dirname(configFilePath), this.#appPath);
93
+ this.#modules = config?.modules ?? [];
94
+ this.#initialRouteName = config?.mobileConfig?.initialRouteName ?? '';
95
+ this.#initialRouteNameRootStack = config?.mobileConfig?.initialRouteNameRootStack ?? 'MainStack';
96
+ this.#unauthenticatedComponentPath = config?.mobileConfig?.unauthenticatedComponentPath ?? '';
97
+ this.#customTabBarPath = config?.mobileConfig?.customTabBarPath ?? '';
98
+ this.#customDrawerPath = config?.mobileConfig?.customDrawerPath ?? '';
99
+ this.#customHeaderPath = config?.mobileConfig?.customHeaderPath ?? '';
100
+ this.#i18Options = config?.i18n ?? {};
101
+ }
81
102
 
82
- constructor({
83
- appDirPath,
84
- modules,
85
- initialRouteName = '',
86
- unauthenticatedComponentPath = null,
87
- customTabBarPath = null,
88
- customDrawerPath = null,
89
- customHeaderPath = null,
90
- i18Options = {},
91
- }: IGenerateMobileNavigationsProps) {
92
- this.#layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
93
- this.#appDirPath = appDirPath;
94
- this.#modules = modules;
95
- this.#initialRouteName = initialRouteName;
96
- this.#unauthenticatedComponentPath = unauthenticatedComponentPath;
97
- this.#customTabBarPath = customTabBarPath;
98
- this.#customDrawerPath = customDrawerPath;
99
- this.#customHeaderPath = customHeaderPath;
100
- this.#i18Options = i18Options;
103
+ #readConfigFile(configFilePath: any) {
104
+ const jsonData = fs.readFileSync(configFilePath, 'utf-8');
105
+ return JSON.parse(jsonData);
101
106
  }
102
107
 
103
108
  async #readJsonFile(filePath) {
@@ -154,10 +159,20 @@ export class GenerateMobileNavigations {
154
159
 
155
160
  async #getModulesRouteConfig({ modules }) {
156
161
  const allFilteredRoutes = [];
162
+ let pkgFile;
157
163
  for (const pkg of modules) {
158
- const pkgPath = require.resolve(pkg);
159
- const pkgDirPath = path.dirname(pkgPath);
160
- const pkgFile = path.join(pkgDirPath, 'routes.json');
164
+ if (this.#isDefaultPackagePathMobileRoot) {
165
+ const pkgRootFilePath = path.join(
166
+ path.join(path.dirname(this.#configFilePath), 'node_modules/lib'),
167
+ pkg,
168
+ );
169
+ pkgFile = path.join(pkgRootFilePath, 'routes.json');
170
+ } else {
171
+ const pkgPath = require.resolve(pkg);
172
+ const pkgDirPath = path.dirname(pkgPath);
173
+ pkgFile = path.join(pkgDirPath, 'routes.json');
174
+ }
175
+
161
176
  if (fs.existsSync(pkgFile)) {
162
177
  const fileModuleJSON: any = await readJsonFile(pkgFile);
163
178
  if (fileModuleJSON) {
@@ -193,14 +208,16 @@ export class GenerateMobileNavigations {
193
208
  return value;
194
209
  }
195
210
 
196
- async #generateAppRoutesJson({ appDirPath }) {
197
- const parentDirPath = path.dirname(appDirPath);
211
+ async #generateAppRoutesJson() {
212
+ const appDirPath = this.#appDirPath;
213
+ const parentDirPath = path.dirname(this.#configFileData?.mobileConfig?.computeFilePath ?? this.#configFilePath);
198
214
  const parentDirName = path.basename(parentDirPath);
199
215
  const appDirName = path.basename(appDirPath);
200
216
  // const tsFile = 'src/compute.ts';
201
217
  // const outputDir = 'src/app';
202
218
  const tsFile = `${parentDirName}/compute.ts`;
203
- const outputDir = `${parentDirName}/${appDirName}`;
219
+ // const outputDir = `${parentDirName}/${appDirName}`;
220
+ const outputDir = `${appDirName}`;
204
221
  const tscCommand = `tsc ${tsFile} --outDir ${outputDir} --target es6 --module esnext --jsx react --allowSyntheticDefaultImports true --moduleResolution node --esModuleInterop true --forceConsistentCasingInFileNames true --skipLibCheck true`;
205
222
  const mainRoutesJsFile = path.join(appDirPath, '/compute.js');
206
223
  const mainRoutesMjsFile = path.join(appDirPath, '/compute.mjs');
@@ -216,13 +233,12 @@ export class GenerateMobileNavigations {
216
233
  const noWhitespaceJsData = noCommentsData.replace(/\s+/g, '');
217
234
  if (noWhitespaceJsData?.length == 0) {
218
235
  const outPutDirName = path.dirname(outputFile);
219
- const isDirCreated = await this.#makeDir(outPutDirName);
220
- if (isDirCreated) {
221
- const writeFileResponse = await this.#writeFile(outputFile, JSON.stringify(allFilteredRoutes));
222
- if (writeFileResponse) {
223
- return true;
224
- } else return false;
225
- } else return false;
236
+ try {
237
+ await this.#makeDir(outPutDirName);
238
+ await this.#writeFile(outputFile, JSON.stringify(allFilteredRoutes));
239
+ } catch (error) {
240
+ console.log('Error directory/file create', error);
241
+ }
226
242
  } else {
227
243
  const newFilePath = mainRoutesJsFile.replace('.js', '.mjs');
228
244
  const renameFileResponse = await this.#renameFile(mainRoutesJsFile, newFilePath);
@@ -242,46 +258,45 @@ export class GenerateMobileNavigations {
242
258
  return { [routConfig.path]: routConfig };
243
259
  }) ?? [];
244
260
  allFilteredRoutes.push(...newRoutes);
245
- const writeFileResponse = await this.#writeFile(
246
- outputFile,
247
- JSON.stringify(allFilteredRoutes, null, 2),
248
- );
249
-
250
- if (writeFileResponse) {
251
- fs.unlinkSync(mainRoutesMjsFile);
252
- return true;
253
- } else return false;
261
+ try {
262
+ const writeFileResponse = await this.#writeFile(
263
+ outputFile,
264
+ JSON.stringify(allFilteredRoutes, null, 2),
265
+ );
266
+
267
+ if (writeFileResponse) fs.unlinkSync(mainRoutesMjsFile);
268
+ } catch (error) {
269
+ console.log('Error creating main routes file', error);
270
+ }
254
271
  }
255
- } else return false;
256
- } else return false;
272
+ }
273
+ }
257
274
  }
258
275
  } else {
259
276
  const outPutDirName = path.dirname(outputFile);
260
- const isDirCreated = await this.#makeDir(outPutDirName);
261
- if (isDirCreated) {
262
- const writeFileResponse = await this.#writeFile(outputFile, JSON.stringify(allFilteredRoutes));
263
- if (writeFileResponse) {
264
- return true;
265
- } else return false;
266
- } else return false;
277
+ try {
278
+ await this.#makeDir(outPutDirName);
279
+ await this.#writeFile(outputFile, JSON.stringify(allFilteredRoutes));
280
+ } catch (error) {
281
+ console.log('Error creating main routes file', error);
282
+ }
267
283
  }
268
284
  // return true;
269
285
  } catch (error) {
270
286
  console.error(`exec error: ${error.message}`);
271
287
  const outPutDirName = path.dirname(outputFile);
272
- const isDirCreated = await this.#makeDir(outPutDirName);
273
- if (isDirCreated) {
274
- const writeFileResponse = await this.#writeFile(outputFile, JSON.stringify(allFilteredRoutes));
275
- if (writeFileResponse) {
276
- return true;
277
- } else return false;
278
- } else return false;
288
+ try {
289
+ await this.#makeDir(outPutDirName);
290
+ await this.#writeFile(outputFile, JSON.stringify(allFilteredRoutes));
291
+ } catch (error) {
292
+ console.log('Error creating main routes file', error);
293
+ }
279
294
  }
280
295
  }
281
296
 
282
297
  async #generateImportStatements({ modules, initialRouteName }) {
283
298
  try {
284
- const layoutSettings = this.#layoutSettings;
299
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
285
300
  const layoutConfigFileData = await this.#getLayoutConfig();
286
301
  const hostRouteConfig = layoutConfigFileData['host-bottom'];
287
302
  const hostRouteKey = Object.keys(hostRouteConfig)[1];
@@ -401,7 +416,7 @@ export class GenerateMobileNavigations {
401
416
 
402
417
  async #generateMainRoutesFile({ initialRouteName, i18Options }) {
403
418
  try {
404
- const layoutSettings = this.#layoutSettings;
419
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
405
420
  const layoutConfigFileData = await this.#getLayoutConfig();
406
421
  const hostRouteConfig = layoutConfigFileData['host-bottom'];
407
422
  const hostRouteKey = Object.keys(hostRouteConfig)[1];
@@ -469,8 +484,24 @@ export class GenerateMobileNavigations {
469
484
  const appReplacedRouteConfig = replacedRouteConfig ? Object.keys(replacedRouteConfig)?.map((k)=>({[k]:replacedRouteConfig[k]})) : [];
470
485
 
471
486
  if (appReplacedRouteConfig) {
472
- 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)??[];
473
- 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)??[];
487
+ const hostRouteConfig = appReplacedRouteConfig.filter(item => {
488
+ return Object.keys(item).some(key =>
489
+ key === "/" ||
490
+ (key.startsWith("//" + layoutSettings.hostLayout) || key.startsWith("//:orgName/" + layoutSettings.hostLayout))
491
+ );
492
+ })?.filter((value) => Object.keys(value).length !== 0) ?? [];
493
+
494
+
495
+ const layoutRouteConfig = appReplacedRouteConfig.filter(item => {
496
+ return Object.keys(item).some(key =>
497
+ key === "/" ||
498
+ (!key.startsWith("//" + layoutSettings.hostLayout) && !key.startsWith("//:orgName/" + layoutSettings.hostLayout))
499
+ );
500
+ })?.filter((value) => Object.keys(value).length !== 0) ?? [];
501
+
502
+
503
+ // 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)??[];
504
+ // 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)??[];
474
505
  const featureRouteConfig = defaultSettings?.layout == 'host-bottom' ? hostRouteConfig:layoutRouteConfig;
475
506
  features.routeConfig = featureRouteConfig;
476
507
  setMainFeatures(features);
@@ -517,7 +548,6 @@ export class GenerateMobileNavigations {
517
548
  return { appFeatures };
518
549
  } catch (err) {
519
550
  console.error('Error:', err);
520
- return false;
521
551
  }
522
552
  }
523
553
 
@@ -525,12 +555,11 @@ export class GenerateMobileNavigations {
525
555
  const mainRoutesFile = path.join(appDirPath, `/${mainRoutesJsFileName}`);
526
556
  const imports: any = await this.#generateMainRoutesFile({ initialRouteName, i18Options });
527
557
  const { appFeatures } = imports;
528
- if (appFeatures) {
529
- const writeFileResponse = await this.#writeFile(mainRoutesFile, appFeatures);
530
- if (writeFileResponse) return true;
531
- else return false;
558
+ try {
559
+ await this.#writeFile(mainRoutesFile, appFeatures);
560
+ } catch (err) {
561
+ console.error('Error generating main routes:', err);
532
562
  }
533
- return false;
534
563
  }
535
564
 
536
565
  async #generateAppFile({ initialRouteName, i18Options }) {
@@ -589,7 +618,6 @@ export class GenerateMobileNavigations {
589
618
  return { appFeatures };
590
619
  } catch (err) {
591
620
  console.error('Error:', err);
592
- return false;
593
621
  }
594
622
  }
595
623
 
@@ -597,18 +625,17 @@ export class GenerateMobileNavigations {
597
625
  const mainRoutesFile = path.join(appDirPath, `/${mainAppFileName}`);
598
626
  const imports: any = await this.#generateAppFile({ initialRouteName, i18Options });
599
627
  const { appFeatures } = imports;
600
- if (appFeatures) {
601
- const writeFileResponse = await this.#writeFile(mainRoutesFile, appFeatures);
602
- if (writeFileResponse) return true;
603
- else return false;
628
+ try {
629
+ await this.#writeFile(mainRoutesFile, appFeatures);
630
+ } catch (err) {
631
+ console.error('Error generating app:', err);
604
632
  }
605
- return false;
606
633
  }
607
634
 
608
635
  async #generateStackNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) {
609
636
  const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
610
637
  const stackDirPath = path.join(appDirPath, `/${stacksDirPath}`);
611
- const layoutSettings = this.#layoutSettings;
638
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
612
639
  const layoutConfigFileData = await this.#getLayoutConfig();
613
640
  const layoutType = layoutSettings?.layout || 'bottom';
614
641
  const layoutRouteConfig = layoutConfigFileData[layoutType];
@@ -711,7 +738,12 @@ export class GenerateMobileNavigations {
711
738
  }}}}
712
739
  >{(props) => <AuthWrapper
713
740
  auth={${pkgRouteConfig?.props?.initialParams?.auth ?? false}}
714
- component={<Component${moduleNumber} {...props} />}
741
+ authority={${JSON.stringify(pkgRouteConfig?.authority) ?? null}}
742
+ extraPermissions={${JSON.stringify(pkgRouteConfig?.extraPermissions) ?? null}}
743
+ component={<Component${moduleNumber} {...props}
744
+ permissions={${JSON.stringify(pkgRouteConfig?.authority) ?? null}}
745
+ extraPermissions={${JSON.stringify(pkgRouteConfig?.extraPermissions) ?? null}}
746
+ />}
715
747
  ${
716
748
  pkgRouteConfig?.unauthenticatedComponent && customUnauthenticatedComponentPath
717
749
  ? `unauthenticatedComponent={<${customUnauthenticatedComponentName}/>}`
@@ -765,17 +797,17 @@ export class GenerateMobileNavigations {
765
797
  moduleRender = `export default ({Stack,...rest}) => { return (<>${moduleContent}</>)}`;
766
798
  }
767
799
  stackNavigator = importStatements + '\n' + moduleRender;
768
- if (stackNavigator) {
769
- let stackNavigation = stackNavigator;
770
- stackNavigation = prettier.format(stackNavigation, { parser: 'babel' });
771
- const stackDirName = path.dirname(stackDirPath);
800
+ let stackNavigation = stackNavigator;
801
+ stackNavigation = prettier.format(stackNavigation, { parser: 'babel' });
802
+ const stackDirName = path.dirname(stackDirPath);
803
+ try {
772
804
  const isDirCreated = await this.#makeDir(stackDirName);
773
805
  if (isDirCreated) {
774
- const writeFileResponse = await this.#writeFile(stackDirPath, stackNavigation);
775
- if (writeFileResponse) return true;
776
- else return false;
777
- } else return false;
778
- } else return false;
806
+ await this.#writeFile(stackDirPath, stackNavigation);
807
+ }
808
+ } catch (error) {
809
+ console.log('Error generating stack navigation', error);
810
+ }
779
811
  }
780
812
 
781
813
  async #generateDrawerNavigationsFile({ drawerConfig, unauthenticatedComponentPath, drawerDirPath }) {
@@ -793,6 +825,7 @@ export class GenerateMobileNavigations {
793
825
 
794
826
  importStatements += `import * as React from 'react';\n`;
795
827
  importStatements += `import AuthWrapper from '@admin-layout/gluestack-ui-mobile/lib/components/AuthWrapper.js';\n`;
828
+ importStatements += `import DynamicIcons from '@app/selectiveIcons';\n`;
796
829
 
797
830
  if (unauthenticatedComponentPath)
798
831
  importStatements += `import UnauthenticatedComponent from '${unauthenticatedComponentPath}';\n`;
@@ -838,11 +871,36 @@ export class GenerateMobileNavigations {
838
871
  initialParams={${JSON.stringify(pkgRouteConfig?.props?.initialParams || {})}}
839
872
  options={{...${options},...{${
840
873
  pkgRouteConfig?.icon && Object.keys(pkgRouteConfig.icon)?.length && pkgRouteConfig?.icon?.name
841
- ? `drawerIcon: ({ color, size }) => <${pkgRouteConfig?.icon?.name} name="${
842
- pkgRouteConfig?.icon?.props?.name ?? 'home'
843
- }" size={${pkgRouteConfig?.icon?.props?.size ?? `size`}} color={${
844
- pkgRouteConfig?.icon?.props?.color ?? 'color'
845
- }} />,`
874
+ ? `drawerIcon: ({ color }) => {
875
+ const focused = color === '${pkgRouteConfig?.props?.options?.tabBarActiveTintColor}' ? true : false;
876
+ const SelectedIcon = DynamicIcons('${pkgRouteConfig?.icon?.name}');
877
+ return (<SelectedIcon
878
+ {...{
879
+ ...${JSON.stringify({ ...(pkgRouteConfig?.icon?.props || {}) })},
880
+ ...{
881
+ color:focused ? ${
882
+ JSON.stringify(
883
+ pkgRouteConfig?.icon?.props?.color ??
884
+ pkgRouteConfig?.props?.options?.tabBarActiveTintColor,
885
+ ) ?? 'black'
886
+ }
887
+ :${
888
+ JSON.stringify(pkgRouteConfig?.props?.options?.tabBarInactiveTintColor) ??
889
+ 'grey'
890
+ },
891
+ stroke:focused ? ${
892
+ JSON.stringify(
893
+ pkgRouteConfig?.icon?.props?.color ??
894
+ pkgRouteConfig?.props?.options?.tabBarActiveTintColor,
895
+ ) ?? 'black'
896
+ }
897
+ :${
898
+ JSON.stringify(pkgRouteConfig?.props?.options?.tabBarInactiveTintColor) ??
899
+ 'grey'
900
+ }
901
+ }
902
+ }}
903
+ />)},`
846
904
  : ''
847
905
  }
848
906
  ${
@@ -856,7 +914,12 @@ export class GenerateMobileNavigations {
856
914
  }}}}
857
915
  >{(props) => <AuthWrapper
858
916
  auth={${pkgRouteConfig?.props?.initialParams?.auth ?? false}}
859
- component={<Component${moduleNumber} {...props} />}
917
+ authority={${JSON.stringify(pkgRouteConfig?.authority) ?? null}}
918
+ extraPermissions={${JSON.stringify(pkgRouteConfig?.extraPermissions) ?? null}}
919
+ component={<Component${moduleNumber} {...props}
920
+ permissions={${JSON.stringify(pkgRouteConfig?.authority) ?? null}}
921
+ extraPermissions={${JSON.stringify(pkgRouteConfig?.extraPermissions) ?? null}}
922
+ />}
860
923
  ${
861
924
  pkgRouteConfig?.unauthenticatedComponent && customUnauthenticatedComponentPath
862
925
  ? `unauthenticatedComponent={<${customUnauthenticatedComponentName}/>}`
@@ -883,10 +946,10 @@ export class GenerateMobileNavigations {
883
946
  }
884
947
  />}</Drawer.Screen>`;
885
948
  }
886
- if (icons && icons?.length) {
887
- const uniqueIcons = [...new Set(icons.split(','))].join(',');
888
- importStatements += `import { ${uniqueIcons} } from '@expo/vector-icons';\n`;
889
- }
949
+ // if (icons && icons?.length) {
950
+ // const uniqueIcons = [...new Set(icons.split(','))].join(',');
951
+ // importStatements += `import Icons from '@expo/vector-icons';\n`;
952
+ // }
890
953
 
891
954
  if (customHeaderPaths && customHeaderPaths?.length) {
892
955
  const uniqueHeaderNames = [...new Set(customHeaderNames.split(','))]?.filter((str) => str?.length);
@@ -913,20 +976,18 @@ export class GenerateMobileNavigations {
913
976
 
914
977
  moduleRender = `export default ({Drawer,...rest}) => { return (<>${moduleContent}</>)}`;
915
978
  moduleNavigation = importStatements + '\n' + moduleRender;
916
-
917
979
  const drawerNavigator = moduleNavigation;
918
- if (drawerNavigator) {
919
- let drawerNavigation = drawerNavigator;
920
- drawerNavigation = prettier.format(drawerNavigation, { parser: 'babel' });
921
- const drawerDirName = path.dirname(drawerDirPath);
980
+ let drawerNavigation = drawerNavigator;
981
+ drawerNavigation = prettier.format(drawerNavigation, { parser: 'babel' });
982
+ const drawerDirName = path.dirname(drawerDirPath);
983
+ try {
922
984
  const isDirCreated = await this.#makeDir(drawerDirName);
923
985
  if (isDirCreated) {
924
- const writeFileResponse = await this.#writeFile(drawerDirPath, drawerNavigation);
925
- if (writeFileResponse) return true;
926
- else return false;
927
- } else return false;
986
+ await this.#writeFile(drawerDirPath, drawerNavigation);
987
+ }
988
+ } catch (error) {
989
+ console.log('Error generating drawer navigation file', error);
928
990
  }
929
- return false;
930
991
  }
931
992
 
932
993
  async #generateDrawerNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) {
@@ -934,7 +995,7 @@ export class GenerateMobileNavigations {
934
995
  const drawerDirPath = path.join(appDirPath, `/${drawerFilePath}`);
935
996
  const hostDirPath = path.join(appDirPath, `/${hostDrawerFilePath}`);
936
997
 
937
- const layoutSettings = this.#layoutSettings;
998
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
938
999
  const layoutConfigFileData = await this.#getLayoutConfig();
939
1000
  const layoutType = 'side';
940
1001
  const layoutRouteConfig = layoutConfigFileData[layoutType];
@@ -972,31 +1033,32 @@ export class GenerateMobileNavigations {
972
1033
  return a?.props?.options?.priority - b?.props?.options?.priority;
973
1034
  }) ?? [];
974
1035
 
975
- if (layoutSettings?.layout == 'side') {
976
- if (drawerConfig) {
977
- const drawerNavigation = await this.#generateDrawerNavigationsFile({
978
- drawerConfig: drawerConfig,
979
- unauthenticatedComponentPath,
980
- drawerDirPath: drawerDirPath,
981
- });
982
- if (drawerNavigation)
1036
+ try {
1037
+ if (layoutSettings?.layout == 'side') {
1038
+ if (drawerConfig) {
983
1039
  await this.#generateDrawerNavigationsFile({
984
- drawerConfig: hostDrawerConfig,
1040
+ drawerConfig: drawerConfig,
985
1041
  unauthenticatedComponentPath,
986
- drawerDirPath: hostDirPath,
1042
+ drawerDirPath: drawerDirPath,
987
1043
  });
988
- return true;
989
- } else {
990
- if (hostDrawerConfig) {
991
- const isDrawerGenerated = await this.#generateDrawerNavigationsFile({
1044
+ await this.#generateDrawerNavigationsFile({
992
1045
  drawerConfig: hostDrawerConfig,
993
1046
  unauthenticatedComponentPath,
994
1047
  drawerDirPath: hostDirPath,
995
1048
  });
996
- return isDrawerGenerated;
997
- } else return false;
1049
+ } else {
1050
+ if (hostDrawerConfig) {
1051
+ await this.#generateDrawerNavigationsFile({
1052
+ drawerConfig: hostDrawerConfig,
1053
+ unauthenticatedComponentPath,
1054
+ drawerDirPath: hostDirPath,
1055
+ });
1056
+ }
1057
+ }
998
1058
  }
999
- } else return false;
1059
+ } catch (error) {
1060
+ console.log('Error generating drawer navigation', error);
1061
+ }
1000
1062
  }
1001
1063
 
1002
1064
  async #generateBottomTabNavigationsFile({
@@ -1020,6 +1082,7 @@ export class GenerateMobileNavigations {
1020
1082
 
1021
1083
  importStatements += `import * as React from 'react';\n`;
1022
1084
  importStatements += `import AuthWrapper from '@admin-layout/gluestack-ui-mobile/lib/components/AuthWrapper.js';\n`;
1085
+ importStatements += `import DynamicIcons from '@app/selectiveIcons';\n`;
1023
1086
 
1024
1087
  if (unauthenticatedComponentPath)
1025
1088
  importStatements += `import UnauthenticatedComponent from '${unauthenticatedComponentPath}';\n`;
@@ -1059,10 +1122,12 @@ export class GenerateMobileNavigations {
1059
1122
  }
1060
1123
 
1061
1124
  const options = JSON.stringify(
1062
- {
1063
- ...pkgRouteConfig?.props?.options,
1064
- headerShown: mixLayout ? false : pkgRouteConfig?.props?.options?.headerShown,
1065
- } || { headerShown: mixLayout ? false : true },
1125
+ pkgRouteConfig?.props?.options
1126
+ ? {
1127
+ ...pkgRouteConfig.props.options,
1128
+ headerShown: mixLayout ? false : pkgRouteConfig.props.options.headerShown,
1129
+ }
1130
+ : { headerShown: mixLayout ? false : true },
1066
1131
  );
1067
1132
  importStatements += `import Component${moduleNumber} from '${pkgRouteConfig.componentPath}';\n`;
1068
1133
  moduleContent += `<Tab.Screen
@@ -1072,11 +1137,37 @@ export class GenerateMobileNavigations {
1072
1137
  initialParams={${JSON.stringify(pkgRouteConfig?.props?.initialParams || {})}}
1073
1138
  options={{...${options},...{${
1074
1139
  pkgRouteConfig?.icon && Object.keys(pkgRouteConfig.icon)?.length && pkgRouteConfig?.icon?.name
1075
- ? `tabBarIcon: ({ color }) => <${pkgRouteConfig?.icon?.name} name="${
1076
- pkgRouteConfig?.icon?.props?.name ?? 'home'
1077
- }" size={${pkgRouteConfig?.icon?.props?.size ?? 24}} color={${
1078
- pkgRouteConfig?.icon?.props?.color ?? 'color'
1079
- }} />`
1140
+ ? `tabBarIcon: ({ color }) => {
1141
+ const focused = color === '${pkgRouteConfig?.props?.options?.tabBarActiveTintColor}' ? true : false;
1142
+ const SelectedIcon = DynamicIcons('${pkgRouteConfig?.icon?.name}');
1143
+ return (<SelectedIcon
1144
+ {...{
1145
+ ...${JSON.stringify({ ...(pkgRouteConfig?.icon?.props || {}) })},
1146
+ ...{
1147
+ color:focused ? ${
1148
+ JSON.stringify(
1149
+ pkgRouteConfig?.icon?.props?.color ??
1150
+ pkgRouteConfig?.props?.options?.tabBarActiveTintColor,
1151
+ ) ?? 'black'
1152
+ }
1153
+ :${
1154
+ JSON.stringify(pkgRouteConfig?.props?.options?.tabBarInactiveTintColor) ??
1155
+ 'grey'
1156
+ },
1157
+ stroke:focused ? ${
1158
+ JSON.stringify(
1159
+ pkgRouteConfig?.icon?.props?.color ??
1160
+ pkgRouteConfig?.props?.options?.tabBarActiveTintColor,
1161
+ ) ?? 'black'
1162
+ }
1163
+ :${
1164
+ JSON.stringify(pkgRouteConfig?.props?.options?.tabBarInactiveTintColor) ??
1165
+ 'grey'
1166
+ }
1167
+ }
1168
+ }}
1169
+
1170
+ />)}`
1080
1171
  : ''
1081
1172
  }
1082
1173
  ${
@@ -1091,7 +1182,12 @@ export class GenerateMobileNavigations {
1091
1182
  }}}
1092
1183
  >{(props) => <AuthWrapper
1093
1184
  auth={${pkgRouteConfig?.props?.initialParams?.auth ?? false}}
1094
- component={<Component${moduleNumber} {...props} />}
1185
+ authority={${JSON.stringify(pkgRouteConfig?.authority) ?? null}}
1186
+ extraPermissions={${JSON.stringify(pkgRouteConfig?.extraPermissions) ?? null}}
1187
+ component={<Component${moduleNumber} {...props}
1188
+ permissions={${JSON.stringify(pkgRouteConfig?.authority) ?? null}}
1189
+ extraPermissions={${JSON.stringify(pkgRouteConfig?.extraPermissions) ?? null}}
1190
+ />}
1095
1191
  ${
1096
1192
  pkgRouteConfig?.unauthenticatedComponent && customUnauthenticatedComponentPath
1097
1193
  ? `unauthenticatedComponent={<${customUnauthenticatedComponentName}/>}`
@@ -1120,10 +1216,10 @@ export class GenerateMobileNavigations {
1120
1216
  </Tab.Screen>`;
1121
1217
  }
1122
1218
 
1123
- if (icons && icons?.length) {
1124
- const uniqueIcons = [...new Set(icons.split(','))].join(',');
1125
- importStatements += `import { ${uniqueIcons} } from '@expo/vector-icons';\n`;
1126
- }
1219
+ // if (icons && icons?.length) {
1220
+ // const uniqueIcons = [...new Set(icons.split(','))].join(',');
1221
+ // importStatements += `import { ${uniqueIcons} } from '@expo/vector-icons';\n`;
1222
+ // }
1127
1223
 
1128
1224
  if (customHeaderPaths && customHeaderPaths?.length) {
1129
1225
  const uniqueHeaderNames = [...new Set(customHeaderNames.split(','))]?.filter((str) => str?.length);
@@ -1151,18 +1247,17 @@ export class GenerateMobileNavigations {
1151
1247
  moduleRender = `export default ({Tab,...rest}) => { return (<>${moduleContent}</>)}`;
1152
1248
  moduleNavigation = importStatements + '\n' + moduleRender;
1153
1249
  const bottomTabNavigator = moduleNavigation;
1154
- if (bottomTabNavigator) {
1155
- let bottomTabNavigation = bottomTabNavigator;
1156
- bottomTabNavigation = prettier.format(bottomTabNavigation, { parser: 'babel' });
1157
- const bottomDirName = path.dirname(bottomDirPath);
1250
+ let bottomTabNavigation = bottomTabNavigator;
1251
+ bottomTabNavigation = prettier.format(bottomTabNavigation, { parser: 'babel' });
1252
+ const bottomDirName = path.dirname(bottomDirPath);
1253
+ try {
1158
1254
  const isDirCreated = await this.#makeDir(bottomDirName);
1159
1255
  if (isDirCreated) {
1160
- const writeFileResponse = await this.#writeFile(bottomDirPath, bottomTabNavigation);
1161
- if (writeFileResponse) return true;
1162
- else return false;
1163
- } else return false;
1256
+ await this.#writeFile(bottomDirPath, bottomTabNavigation);
1257
+ }
1258
+ } catch (error) {
1259
+ console.log('Error generating bottom tab navigation file', error);
1164
1260
  }
1165
- return false;
1166
1261
  }
1167
1262
 
1168
1263
  async #generateBottomTabNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) {
@@ -1170,7 +1265,7 @@ export class GenerateMobileNavigations {
1170
1265
  const bottomDirPath = path.join(appDirPath, `/${bottomFilePath}`);
1171
1266
  const hostBottomDirPath = path.join(appDirPath, `/${hostBottomFilePath}`);
1172
1267
 
1173
- const layoutSettings = this.#layoutSettings;
1268
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
1174
1269
  const layoutConfigFileData = await this.#getLayoutConfig();
1175
1270
  const layoutType = layoutSettings?.layout ?? 'bottom';
1176
1271
  const layoutRouteConfig = layoutConfigFileData[layoutType];
@@ -1210,34 +1305,35 @@ export class GenerateMobileNavigations {
1210
1305
  if (b?.props?.options?.priority === undefined) return -1;
1211
1306
  return a?.props?.options?.priority - b?.props?.options?.priority;
1212
1307
  }) ?? [];
1213
- if (layoutType == 'bottom' || layoutType == 'mixSide') {
1214
- if (bottomTabConfig) {
1215
- const drawerNavigation = await this.#generateBottomTabNavigationsFile({
1216
- bottomTabConfig: bottomTabConfig,
1217
- unauthenticatedComponentPath,
1218
- bottomDirPath: bottomDirPath,
1219
- mixLayout,
1220
- });
1221
- if (drawerNavigation)
1308
+ try {
1309
+ if (layoutType == 'bottom' || layoutType == 'mixSide') {
1310
+ if (bottomTabConfig) {
1222
1311
  await this.#generateBottomTabNavigationsFile({
1223
- bottomTabConfig: hostBottomTabConfig,
1312
+ bottomTabConfig: bottomTabConfig,
1224
1313
  unauthenticatedComponentPath,
1225
- bottomDirPath: hostBottomDirPath,
1314
+ bottomDirPath: bottomDirPath,
1226
1315
  mixLayout,
1227
1316
  });
1228
- return true;
1229
- } else {
1230
- if (hostBottomTabConfig) {
1231
- const isHostGenerated = await this.#generateBottomTabNavigationsFile({
1317
+ await this.#generateBottomTabNavigationsFile({
1232
1318
  bottomTabConfig: hostBottomTabConfig,
1233
1319
  unauthenticatedComponentPath,
1234
1320
  bottomDirPath: hostBottomDirPath,
1235
1321
  mixLayout,
1236
1322
  });
1237
- return isHostGenerated;
1238
- } else return false;
1323
+ } else {
1324
+ if (hostBottomTabConfig) {
1325
+ await this.#generateBottomTabNavigationsFile({
1326
+ bottomTabConfig: hostBottomTabConfig,
1327
+ unauthenticatedComponentPath,
1328
+ bottomDirPath: hostBottomDirPath,
1329
+ mixLayout,
1330
+ });
1331
+ }
1332
+ }
1239
1333
  }
1240
- } else return false;
1334
+ } catch (error) {
1335
+ console.log('Error generating bottom tab navigation', error);
1336
+ }
1241
1337
  }
1242
1338
 
1243
1339
  async #generateBottomTabDrawerNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) {
@@ -1247,7 +1343,7 @@ export class GenerateMobileNavigations {
1247
1343
  const drawerDirPath = path.join(appDirPath, `/${drawerFilePath}`);
1248
1344
  const hostDirPath = path.join(appDirPath, `/${hostDrawerFilePath}`);
1249
1345
 
1250
- const layoutSettings = this.#layoutSettings;
1346
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
1251
1347
  const layoutConfigFileData = await this.#getLayoutConfig();
1252
1348
  const layoutType = layoutSettings?.layout ?? 'bottom';
1253
1349
  const layoutRouteConfig = layoutConfigFileData[layoutType];
@@ -1310,52 +1406,57 @@ export class GenerateMobileNavigations {
1310
1406
  }) ?? [];
1311
1407
 
1312
1408
  if (bottomTabConfig) {
1313
- const drawerNavigation = await this.#generateBottomTabNavigationsFile({
1314
- bottomTabConfig: bottomTabConfig,
1315
- unauthenticatedComponentPath,
1316
- bottomDirPath: bottomDirPath,
1317
- mixLayout,
1318
- });
1319
- if (drawerNavigation)
1409
+ try {
1320
1410
  await this.#generateBottomTabNavigationsFile({
1321
- bottomTabConfig: hostBottomTabConfig,
1411
+ bottomTabConfig: bottomTabConfig,
1322
1412
  unauthenticatedComponentPath,
1323
- bottomDirPath: hostBottomDirPath,
1413
+ bottomDirPath: bottomDirPath,
1324
1414
  mixLayout,
1325
1415
  });
1326
- if (drawerConfig) {
1327
- const drawerNavigation = await this.#generateDrawerNavigationsFile({
1328
- drawerConfig: drawerConfig,
1416
+
1417
+ await this.#generateBottomTabNavigationsFile({
1418
+ bottomTabConfig: hostBottomTabConfig,
1329
1419
  unauthenticatedComponentPath,
1330
- drawerDirPath: drawerDirPath,
1420
+ bottomDirPath: hostBottomDirPath,
1421
+ mixLayout,
1331
1422
  });
1332
- if (drawerNavigation)
1423
+ if (drawerConfig) {
1424
+ await this.#generateDrawerNavigationsFile({
1425
+ drawerConfig: drawerConfig,
1426
+ unauthenticatedComponentPath,
1427
+ drawerDirPath: drawerDirPath,
1428
+ });
1333
1429
  await this.#generateDrawerNavigationsFile({
1334
1430
  drawerConfig: hostDrawerConfig,
1335
1431
  unauthenticatedComponentPath,
1336
1432
  drawerDirPath: hostDirPath,
1337
1433
  });
1338
- return true;
1339
- } else return true;
1340
- } else return false;
1434
+ }
1435
+ } catch (error) {
1436
+ console.log('Error in generating drawer bottom tab navigation', error);
1437
+ }
1438
+ }
1341
1439
  }
1342
1440
 
1343
1441
  async #generateAppNavigationFile({ appDirPath, customTabBarPath, customDrawerPath, customHeaderPath }) {
1344
1442
  const navigationDirPath = path.join(appDirPath, `/${appNavigationFileName}`);
1345
- const layoutSettings = this.#layoutSettings;
1443
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
1346
1444
  const layoutConfigFileData = await this.#getLayoutConfig();
1347
1445
  const layoutType = layoutSettings?.layout || 'bottom';
1348
1446
  const layoutRouteConfig = layoutConfigFileData[layoutType];
1349
1447
  const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
1350
1448
  const appLayout = layoutRouteConfig[layoutRouteKey];
1351
-
1352
- const initialRouteName =
1353
- layoutType === 'mixSide'
1354
- ? appLayout?.[appLayout?.key]?.props?.initialRouteName ?? 'MainStack.Layout.Home'
1355
- : appLayout?.props?.initialRouteName || 'MainStack.Home';
1449
+ const initialRouteNameRootStack = this.#initialRouteNameRootStack;
1450
+ const layoutInitialRouteName = this.#initialRouteName;
1451
+ const initialRouteName = layoutInitialRouteName
1452
+ ? layoutInitialRouteName
1453
+ : layoutType === 'mixSide'
1454
+ ? appLayout?.[appLayout?.key]?.props?.initialRouteName ?? 'MainStack.Layout.Home'
1455
+ : appLayout?.props?.initialRouteName || 'MainStack.Home';
1356
1456
  const isShowTabs = layoutType === 'mixSide' || layoutType === 'bottom' ? true : false;
1357
1457
  const isShowDefalutHeader = layoutType === 'mixSide' ? true : false;
1358
1458
  const defaultHeaderProps = {
1459
+ ...(layoutSettings || {}),
1359
1460
  showToggle: layoutSettings?.topLeftToggle || false,
1360
1461
  right: layoutSettings?.topRightSettingToggle || false,
1361
1462
  };
@@ -1407,7 +1508,11 @@ export class GenerateMobileNavigations {
1407
1508
  : ''
1408
1509
  }
1409
1510
  }})}
1410
- ${customDrawerPath ? 'drawerContent={(props) => <CustomDrawerContent {...props} />}' : ''}
1511
+ ${
1512
+ customDrawerPath
1513
+ ? 'drawerContent={(props) => <CustomDrawerContent {...props} {...defaultHeaderProps || {}} />}'
1514
+ : ''
1515
+ }
1411
1516
  >
1412
1517
  {settings?.layout == 'host-bottom' ? hostDrawerNavigations({ Drawer }) : drawerNavigations({ Drawer })}
1413
1518
  </Drawer.Navigator>
@@ -1556,7 +1661,7 @@ export class GenerateMobileNavigations {
1556
1661
  appComponent += `
1557
1662
  const AppNavigations = () => {
1558
1663
  return (
1559
- <Stack.Navigator initialRouteName="${initialRouteName}">
1664
+ <Stack.Navigator initialRouteName="${initialRouteNameRootStack}">
1560
1665
  <Stack.Screen
1561
1666
  name="MainStack"
1562
1667
  options={{ headerShown: false }}
@@ -1571,9 +1676,110 @@ export class GenerateMobileNavigations {
1571
1676
  `;
1572
1677
  appNavigation = importStatements + '\n' + rootComponent + '\n' + appComponent;
1573
1678
  appNavigation = prettier.format(appNavigation, { parser: 'babel' });
1574
- const writeFileResponse = await this.#writeFile(navigationDirPath, appNavigation);
1575
- if (writeFileResponse) return true;
1576
- else return false;
1679
+ try {
1680
+ await this.#writeFile(navigationDirPath, appNavigation);
1681
+ } catch (error) {
1682
+ console.log('Error in generating app navigationfile', error);
1683
+ }
1684
+ }
1685
+
1686
+ async #generateSelectiveIconsFile({ appDirPath, modules }) {
1687
+ const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
1688
+ const modulesRouteConfig = await this.#getModulesRouteConfig({ modules: modules });
1689
+ const mainRouteConfig = await this.#readJsonFile(mainRoutes);
1690
+ const allRoutes = [...[mainRouteConfig ?? []], ...(modulesRouteConfig ?? [])];
1691
+ let iconNames = [];
1692
+ allRoutes?.flat(1)?.forEach((route) => {
1693
+ const key = Object.keys(route)[0];
1694
+ const value = route[key];
1695
+ if (value?.icon && typeof value.icon === 'object') {
1696
+ if (typeof value.icon.name === 'string') {
1697
+ if (!iconNames.includes(value.icon.name)) iconNames.push(value.icon.name);
1698
+ }
1699
+ } else if (value?.icon && typeof value.icon === 'string') {
1700
+ if (!iconNames.includes(value.icon)) iconNames.push(value.icon);
1701
+ }
1702
+
1703
+ if (value?.extraIcons && Array.isArray(value.extraIcons) && value?.extraIcons?.length > 0) {
1704
+ value?.extraIcons?.map((icon) => {
1705
+ if (typeof icon === 'string') {
1706
+ if (!iconNames.includes(icon)) iconNames.push(icon);
1707
+ } else {
1708
+ console.warn(`Invalid icon type: ${typeof icon}`);
1709
+ }
1710
+ });
1711
+ } else if (value?.extraIcons && typeof value.extraIcons === 'string') {
1712
+ if (!iconNames.includes(value.extraIcons)) iconNames.push(value.extraIcons);
1713
+ }
1714
+ });
1715
+
1716
+ const iconsRepository = this.#iconsRepository;
1717
+ const expoIcons = [
1718
+ 'AntDesign',
1719
+ 'Entypo',
1720
+ 'EvilIcons',
1721
+ 'Feather',
1722
+ 'FontAwesome',
1723
+ 'FontAwesome5',
1724
+ 'Fontisto',
1725
+ 'Foundation',
1726
+ 'Ionicons',
1727
+ 'MaterialCommunityIcons',
1728
+ 'MaterialIcons',
1729
+ 'Octicons',
1730
+ 'SimpleLineIcons',
1731
+ 'Zocial',
1732
+ ];
1733
+
1734
+ let content = `
1735
+ function __variableDynamicIcon(icon) {
1736
+ switch (icon) {
1737
+ `;
1738
+ iconNames.forEach((name) => {
1739
+ let prefix, iconName;
1740
+ if (name.includes('.')) {
1741
+ [prefix, iconName] = name.split('.');
1742
+ }
1743
+ if (prefix && iconsRepository[prefix]) {
1744
+ const importPath = iconsRepository[prefix].replace(
1745
+ '{iconName}',
1746
+ prefix === 'expo' ? iconName : iconName + '.native',
1747
+ );
1748
+ // prefix = prefix.charAt(0).toUpperCase() + prefix.slice(1).toLowerCase();
1749
+ content += `
1750
+ case '${prefix + '.' + iconName}':
1751
+ return require('${importPath}')?.default;
1752
+ `;
1753
+ } else {
1754
+ content += `
1755
+ case '${name}':
1756
+ return ${
1757
+ expoIcons.includes(name)
1758
+ ? `require('@expo/vector-icons/${name}.js')?.default`
1759
+ : `require('@expo/vector-icons/FontAwesome.js')?.default;`
1760
+ };
1761
+ `;
1762
+ }
1763
+ });
1764
+
1765
+ content += `
1766
+ default:
1767
+ console.warn('Sorry, the icon named "', icon, '" could not be found in "@react-icon/all-files" and "@app/icons". Please check again.');
1768
+ return require('@expo/vector-icons/FontAwesome.js')?.default;
1769
+ }
1770
+ }
1771
+ export default function(icon) {
1772
+ return __variableDynamicIcon(icon);
1773
+ }
1774
+ `;
1775
+ const rootPath = process.cwd();
1776
+ const fileName = `selectiveIcons.js`;
1777
+ const newFilePath = path.join(rootPath, 'app', fileName);
1778
+ // Ensure the directory exists
1779
+ if (!fs.existsSync(path.dirname(newFilePath))) {
1780
+ fs.mkdirSync(path.dirname(newFilePath), { recursive: true });
1781
+ }
1782
+ fs.writeFileSync(newFilePath, content, 'utf8');
1577
1783
  }
1578
1784
 
1579
1785
  async #setLayoutAndGenerateNavigation() {
@@ -1586,92 +1792,153 @@ export class GenerateMobileNavigations {
1586
1792
  const customHeaderPath = this.#customHeaderPath;
1587
1793
  const i18Options = this.#i18Options;
1588
1794
 
1589
- const layoutSettings = this.#layoutSettings;
1795
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
1590
1796
  const layoutConfigFileData = await this.#getLayoutConfig();
1591
1797
  const layoutType = layoutSettings?.layout || 'bottom';
1592
- const isAppRoutesGenerated = await this.#generateAppRoutesJson({ appDirPath });
1593
- if (isAppRoutesGenerated) {
1594
- // await this.#generateModulesTsFile({
1595
- // appDirPath,
1596
- // modules,
1597
- // initialRouteName,
1598
- // });
1798
+ try {
1799
+ await this.#generateAppRoutesJson();
1800
+ await this.#generateSelectiveIconsFile({ appDirPath, modules });
1599
1801
  await this.#generateMainRoutes({
1600
1802
  appDirPath,
1601
1803
  i18Options,
1602
1804
  initialRouteName,
1603
1805
  });
1604
- const isAppFileGenerated = await this.#generateApp({
1806
+ await this.#generateApp({
1605
1807
  appDirPath,
1606
1808
  i18Options,
1607
1809
  initialRouteName,
1608
1810
  });
1609
- if (isAppFileGenerated) {
1610
- const isStackCreated = await this.#generateStackNavigations({
1611
- appDirPath,
1612
- modules,
1613
- initialRouteName,
1614
- unauthenticatedComponentPath,
1615
- });
1616
- if (isStackCreated) {
1617
- if (layoutType == 'side') {
1618
- const isDrawerGenerated = await this.#generateDrawerNavigations({
1619
- appDirPath,
1620
- modules,
1621
- initialRouteName,
1622
- unauthenticatedComponentPath,
1623
- });
1624
- if (isDrawerGenerated) {
1625
- const appNavigationGenerated = await this.#generateAppNavigationFile({
1626
- appDirPath,
1627
- customTabBarPath,
1628
- customDrawerPath,
1629
- customHeaderPath,
1630
- });
1631
- if (appNavigationGenerated) return appNavigationGenerated;
1632
- else return true;
1633
- } else return false;
1634
- } else if (layoutType == 'bottom' || layoutType == 'host-bottom') {
1635
- const isBottomTabGenerated = await this.#generateBottomTabNavigations({
1636
- appDirPath,
1637
- modules,
1638
- initialRouteName,
1639
- unauthenticatedComponentPath,
1640
- });
1641
- if (isBottomTabGenerated) {
1642
- const appNavigationGenerated = await this.#generateAppNavigationFile({
1643
- appDirPath,
1644
- customTabBarPath,
1645
- customDrawerPath,
1646
- customHeaderPath,
1647
- });
1648
- if (appNavigationGenerated) return appNavigationGenerated;
1649
- else return true;
1650
- } else return false;
1651
- } else {
1652
- const isBottomTabDrawerGenerated = await this.#generateBottomTabDrawerNavigations({
1653
- appDirPath,
1654
- modules,
1655
- initialRouteName,
1656
- unauthenticatedComponentPath,
1657
- });
1658
- if (isBottomTabDrawerGenerated) {
1659
- const appNavigationGenerated = await this.#generateAppNavigationFile({
1660
- appDirPath,
1661
- customTabBarPath,
1662
- customDrawerPath,
1663
- customHeaderPath,
1664
- });
1665
- if (appNavigationGenerated) return appNavigationGenerated;
1666
- else return true;
1667
- } else return false;
1668
- }
1669
- } else return false;
1670
- } else return false;
1671
- } else return false;
1811
+
1812
+ await this.#generateStackNavigations({
1813
+ appDirPath,
1814
+ modules,
1815
+ initialRouteName,
1816
+ unauthenticatedComponentPath,
1817
+ });
1818
+
1819
+ if (layoutType == 'side') {
1820
+ try {
1821
+ await this.#generateDrawerNavigations({
1822
+ appDirPath,
1823
+ modules,
1824
+ initialRouteName,
1825
+ unauthenticatedComponentPath,
1826
+ });
1827
+ await this.#generateAppNavigationFile({
1828
+ appDirPath,
1829
+ customTabBarPath,
1830
+ customDrawerPath,
1831
+ customHeaderPath,
1832
+ });
1833
+ } catch (error) {
1834
+ console.log('Error in generating side navigation', error);
1835
+ }
1836
+ } else if (layoutType == 'bottom' || layoutType == 'host-bottom') {
1837
+ try {
1838
+ await this.#generateBottomTabNavigations({
1839
+ appDirPath,
1840
+ modules,
1841
+ initialRouteName,
1842
+ unauthenticatedComponentPath,
1843
+ });
1844
+ await this.#generateAppNavigationFile({
1845
+ appDirPath,
1846
+ customTabBarPath,
1847
+ customDrawerPath,
1848
+ customHeaderPath,
1849
+ });
1850
+ } catch (error) {
1851
+ console.log('Error in generating bottom navigation', error);
1852
+ }
1853
+ } else {
1854
+ try {
1855
+ await this.#generateBottomTabDrawerNavigations({
1856
+ appDirPath,
1857
+ modules,
1858
+ initialRouteName,
1859
+ unauthenticatedComponentPath,
1860
+ });
1861
+
1862
+ await this.#generateAppNavigationFile({
1863
+ appDirPath,
1864
+ customTabBarPath,
1865
+ customDrawerPath,
1866
+ customHeaderPath,
1867
+ });
1868
+ } catch (error) {
1869
+ console.log('Error in generating drawer bottom navigation', error);
1870
+ }
1871
+ }
1872
+ } catch (error) {
1873
+ console.log('Error generating app navigations', error);
1874
+ }
1875
+ }
1876
+
1877
+ async #performCopyOperations() {
1878
+ const config = this.#configFileData;
1879
+ try {
1880
+ await performCopyOperations(config);
1881
+ await this.#setLayoutAndGenerateNavigation();
1882
+ } catch (error) {
1883
+ console.error('PerformCopyOperations error:', error);
1884
+ }
1885
+ }
1886
+
1887
+ async #deleteDirectoryRecursive(dirPath: any) {
1888
+ if (fs.existsSync(dirPath)) {
1889
+ const files = fs.readdirSync(dirPath);
1890
+ for (const file of files) {
1891
+ const curPath = path.join(dirPath, file);
1892
+ if (fs.lstatSync(curPath).isDirectory()) {
1893
+ // Recursively delete subdirectories
1894
+ await this.#deleteDirectoryRecursive(curPath);
1895
+ } else {
1896
+ // Delete files
1897
+ fs.unlinkSync(curPath);
1898
+ }
1899
+ }
1900
+ // Delete the directory itself
1901
+ fs.rmdirSync(dirPath);
1902
+ }
1903
+ }
1904
+
1905
+ async #createAppDirectory() {
1906
+ const appDir = this.#appDirPath;
1907
+
1908
+ try {
1909
+ // Check if the directory exists
1910
+ if (fs.existsSync(appDir)) {
1911
+ console.log('Directory exists. Recreating it...');
1912
+ // Delete the directory and its contents
1913
+ await this.#deleteDirectoryRecursive(appDir);
1914
+ }
1915
+
1916
+ // Create the directory
1917
+ fs.mkdirSync(appDir);
1918
+ console.log('Directory created');
1919
+ // Add 'app' to .gitignore if not already present
1920
+ const gitignorePath = path.resolve(appDir, '.gitignore');
1921
+ let gitignoreContent = '';
1922
+ if (fs.existsSync(gitignorePath)) {
1923
+ gitignoreContent = fs.readFileSync(gitignorePath, 'utf8');
1924
+ } else {
1925
+ fs.writeFileSync(gitignorePath, '');
1926
+ console.log('Created .gitignore file');
1927
+ }
1928
+
1929
+ if (!gitignoreContent.includes('*')) {
1930
+ fs.appendFileSync(gitignorePath, '*\n');
1931
+ console.log('Added "*" to .gitignore');
1932
+ }
1933
+ await this.#performCopyOperations();
1934
+ } catch (error) {
1935
+ console.error('Error creating app directory:', error);
1936
+ }
1672
1937
  }
1673
1938
 
1674
1939
  async generateAppNavigations() {
1675
- return this.#setLayoutAndGenerateNavigation();
1940
+ return this.#createAppDirectory();
1676
1941
  }
1677
1942
  }
1943
+
1944
+ export default GenerateMobileNavigations;