@admin-layout/gluestack-ui-mobile 9.0.4-alpha.12 → 9.0.4-alpha.19

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.
@@ -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,8 +63,12 @@ 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
+ #mobileStackPath: string = 'mobile-stack-react';
70
+ //#layoutSettings: any = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
71
+ #appDirPath: any;
74
72
  #modules: any;
75
73
  #initialRouteName: string;
76
74
  #unauthenticatedComponentPath: string;
@@ -79,25 +77,26 @@ export class GenerateMobileNavigations {
79
77
  #customHeaderPath: string;
80
78
  #i18Options: any;
81
79
 
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;
80
+ constructor({ configFilePath }: IGenerateMobileNavigationsProps) {
81
+ this.#configFilePath = configFilePath;
82
+ const config = this.#readConfigFile(configFilePath);
83
+ this.#configFileData = config;
84
+ // this.#layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
85
+ this.#appPath = config?.appPath ?? 'app';
86
+ this.#mobileStackPath = config?.mobileStackPath ?? 'mobile-stack-react';
87
+ this.#appDirPath = path.join(path.dirname(configFilePath), this.#appPath);
88
+ this.#modules = config?.modules ?? [];
89
+ this.#initialRouteName = config?.initialRouteName ?? '';
90
+ this.#unauthenticatedComponentPath = config?.unauthenticatedComponentPath ?? '';
91
+ this.#customTabBarPath = config?.customTabBarPath ?? '';
92
+ this.#customDrawerPath = config?.customDrawerPath ?? '';
93
+ this.#customHeaderPath = config?.customHeaderPath ?? '';
94
+ this.#i18Options = config?.i18n ?? {};
95
+ }
96
+
97
+ #readConfigFile(configFilePath: any) {
98
+ const jsonData = fs.readFileSync(configFilePath, 'utf-8');
99
+ return JSON.parse(jsonData);
101
100
  }
102
101
 
103
102
  async #readJsonFile(filePath) {
@@ -193,14 +192,16 @@ export class GenerateMobileNavigations {
193
192
  return value;
194
193
  }
195
194
 
196
- async #generateAppRoutesJson({ appDirPath }) {
197
- const parentDirPath = path.dirname(appDirPath);
195
+ async #generateAppRoutesJson() {
196
+ const appDirPath = this.#appDirPath;
197
+ const parentDirPath = path.dirname(this.#configFileData?.mobileConfig?.computeFilePath ?? this.#configFilePath);
198
198
  const parentDirName = path.basename(parentDirPath);
199
199
  const appDirName = path.basename(appDirPath);
200
200
  // const tsFile = 'src/compute.ts';
201
201
  // const outputDir = 'src/app';
202
202
  const tsFile = `${parentDirName}/compute.ts`;
203
- const outputDir = `${parentDirName}/${appDirName}`;
203
+ // const outputDir = `${parentDirName}/${appDirName}`;
204
+ const outputDir = `${appDirName}`;
204
205
  const tscCommand = `tsc ${tsFile} --outDir ${outputDir} --target es6 --module esnext --jsx react --allowSyntheticDefaultImports true --moduleResolution node --esModuleInterop true --forceConsistentCasingInFileNames true --skipLibCheck true`;
205
206
  const mainRoutesJsFile = path.join(appDirPath, '/compute.js');
206
207
  const mainRoutesMjsFile = path.join(appDirPath, '/compute.mjs');
@@ -216,13 +217,12 @@ export class GenerateMobileNavigations {
216
217
  const noWhitespaceJsData = noCommentsData.replace(/\s+/g, '');
217
218
  if (noWhitespaceJsData?.length == 0) {
218
219
  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;
220
+ try {
221
+ await this.#makeDir(outPutDirName);
222
+ await this.#writeFile(outputFile, JSON.stringify(allFilteredRoutes));
223
+ } catch (error) {
224
+ console.log('Error directory/file create', error);
225
+ }
226
226
  } else {
227
227
  const newFilePath = mainRoutesJsFile.replace('.js', '.mjs');
228
228
  const renameFileResponse = await this.#renameFile(mainRoutesJsFile, newFilePath);
@@ -242,46 +242,45 @@ export class GenerateMobileNavigations {
242
242
  return { [routConfig.path]: routConfig };
243
243
  }) ?? [];
244
244
  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;
245
+ try {
246
+ const writeFileResponse = await this.#writeFile(
247
+ outputFile,
248
+ JSON.stringify(allFilteredRoutes, null, 2),
249
+ );
250
+
251
+ if (writeFileResponse) fs.unlinkSync(mainRoutesMjsFile);
252
+ } catch (error) {
253
+ console.log('Error creating main routes file', error);
254
+ }
254
255
  }
255
- } else return false;
256
- } else return false;
256
+ }
257
+ }
257
258
  }
258
259
  } else {
259
260
  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;
261
+ try {
262
+ await this.#makeDir(outPutDirName);
263
+ await this.#writeFile(outputFile, JSON.stringify(allFilteredRoutes));
264
+ } catch (error) {
265
+ console.log('Error creating main routes file', error);
266
+ }
267
267
  }
268
268
  // return true;
269
269
  } catch (error) {
270
270
  console.error(`exec error: ${error.message}`);
271
271
  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;
272
+ try {
273
+ await this.#makeDir(outPutDirName);
274
+ await this.#writeFile(outputFile, JSON.stringify(allFilteredRoutes));
275
+ } catch (error) {
276
+ console.log('Error creating main routes file', error);
277
+ }
279
278
  }
280
279
  }
281
280
 
282
281
  async #generateImportStatements({ modules, initialRouteName }) {
283
282
  try {
284
- const layoutSettings = this.#layoutSettings;
283
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
285
284
  const layoutConfigFileData = await this.#getLayoutConfig();
286
285
  const hostRouteConfig = layoutConfigFileData['host-bottom'];
287
286
  const hostRouteKey = Object.keys(hostRouteConfig)[1];
@@ -401,7 +400,7 @@ export class GenerateMobileNavigations {
401
400
 
402
401
  async #generateMainRoutesFile({ initialRouteName, i18Options }) {
403
402
  try {
404
- const layoutSettings = this.#layoutSettings;
403
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
405
404
  const layoutConfigFileData = await this.#getLayoutConfig();
406
405
  const hostRouteConfig = layoutConfigFileData['host-bottom'];
407
406
  const hostRouteKey = Object.keys(hostRouteConfig)[1];
@@ -517,7 +516,6 @@ export class GenerateMobileNavigations {
517
516
  return { appFeatures };
518
517
  } catch (err) {
519
518
  console.error('Error:', err);
520
- return false;
521
519
  }
522
520
  }
523
521
 
@@ -525,12 +523,11 @@ export class GenerateMobileNavigations {
525
523
  const mainRoutesFile = path.join(appDirPath, `/${mainRoutesJsFileName}`);
526
524
  const imports: any = await this.#generateMainRoutesFile({ initialRouteName, i18Options });
527
525
  const { appFeatures } = imports;
528
- if (appFeatures) {
529
- const writeFileResponse = await this.#writeFile(mainRoutesFile, appFeatures);
530
- if (writeFileResponse) return true;
531
- else return false;
526
+ try {
527
+ await this.#writeFile(mainRoutesFile, appFeatures);
528
+ } catch (err) {
529
+ console.error('Error generating main routes:', err);
532
530
  }
533
- return false;
534
531
  }
535
532
 
536
533
  async #generateAppFile({ initialRouteName, i18Options }) {
@@ -589,7 +586,6 @@ export class GenerateMobileNavigations {
589
586
  return { appFeatures };
590
587
  } catch (err) {
591
588
  console.error('Error:', err);
592
- return false;
593
589
  }
594
590
  }
595
591
 
@@ -597,18 +593,17 @@ export class GenerateMobileNavigations {
597
593
  const mainRoutesFile = path.join(appDirPath, `/${mainAppFileName}`);
598
594
  const imports: any = await this.#generateAppFile({ initialRouteName, i18Options });
599
595
  const { appFeatures } = imports;
600
- if (appFeatures) {
601
- const writeFileResponse = await this.#writeFile(mainRoutesFile, appFeatures);
602
- if (writeFileResponse) return true;
603
- else return false;
596
+ try {
597
+ await this.#writeFile(mainRoutesFile, appFeatures);
598
+ } catch (err) {
599
+ console.error('Error generating app:', err);
604
600
  }
605
- return false;
606
601
  }
607
602
 
608
603
  async #generateStackNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) {
609
604
  const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
610
605
  const stackDirPath = path.join(appDirPath, `/${stacksDirPath}`);
611
- const layoutSettings = this.#layoutSettings;
606
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
612
607
  const layoutConfigFileData = await this.#getLayoutConfig();
613
608
  const layoutType = layoutSettings?.layout || 'bottom';
614
609
  const layoutRouteConfig = layoutConfigFileData[layoutType];
@@ -765,17 +760,17 @@ export class GenerateMobileNavigations {
765
760
  moduleRender = `export default ({Stack,...rest}) => { return (<>${moduleContent}</>)}`;
766
761
  }
767
762
  stackNavigator = importStatements + '\n' + moduleRender;
768
- if (stackNavigator) {
769
- let stackNavigation = stackNavigator;
770
- stackNavigation = prettier.format(stackNavigation, { parser: 'babel' });
771
- const stackDirName = path.dirname(stackDirPath);
763
+ let stackNavigation = stackNavigator;
764
+ stackNavigation = prettier.format(stackNavigation, { parser: 'babel' });
765
+ const stackDirName = path.dirname(stackDirPath);
766
+ try {
772
767
  const isDirCreated = await this.#makeDir(stackDirName);
773
768
  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;
769
+ await this.#writeFile(stackDirPath, stackNavigation);
770
+ }
771
+ } catch (error) {
772
+ console.log('Error generating stack navigation', error);
773
+ }
779
774
  }
780
775
 
781
776
  async #generateDrawerNavigationsFile({ drawerConfig, unauthenticatedComponentPath, drawerDirPath }) {
@@ -913,20 +908,18 @@ export class GenerateMobileNavigations {
913
908
 
914
909
  moduleRender = `export default ({Drawer,...rest}) => { return (<>${moduleContent}</>)}`;
915
910
  moduleNavigation = importStatements + '\n' + moduleRender;
916
-
917
911
  const drawerNavigator = moduleNavigation;
918
- if (drawerNavigator) {
919
- let drawerNavigation = drawerNavigator;
920
- drawerNavigation = prettier.format(drawerNavigation, { parser: 'babel' });
921
- const drawerDirName = path.dirname(drawerDirPath);
912
+ let drawerNavigation = drawerNavigator;
913
+ drawerNavigation = prettier.format(drawerNavigation, { parser: 'babel' });
914
+ const drawerDirName = path.dirname(drawerDirPath);
915
+ try {
922
916
  const isDirCreated = await this.#makeDir(drawerDirName);
923
917
  if (isDirCreated) {
924
- const writeFileResponse = await this.#writeFile(drawerDirPath, drawerNavigation);
925
- if (writeFileResponse) return true;
926
- else return false;
927
- } else return false;
918
+ await this.#writeFile(drawerDirPath, drawerNavigation);
919
+ }
920
+ } catch (error) {
921
+ console.log('Error generating drawer navigation file', error);
928
922
  }
929
- return false;
930
923
  }
931
924
 
932
925
  async #generateDrawerNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) {
@@ -934,7 +927,7 @@ export class GenerateMobileNavigations {
934
927
  const drawerDirPath = path.join(appDirPath, `/${drawerFilePath}`);
935
928
  const hostDirPath = path.join(appDirPath, `/${hostDrawerFilePath}`);
936
929
 
937
- const layoutSettings = this.#layoutSettings;
930
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
938
931
  const layoutConfigFileData = await this.#getLayoutConfig();
939
932
  const layoutType = 'side';
940
933
  const layoutRouteConfig = layoutConfigFileData[layoutType];
@@ -972,31 +965,32 @@ export class GenerateMobileNavigations {
972
965
  return a?.props?.options?.priority - b?.props?.options?.priority;
973
966
  }) ?? [];
974
967
 
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)
968
+ try {
969
+ if (layoutSettings?.layout == 'side') {
970
+ if (drawerConfig) {
983
971
  await this.#generateDrawerNavigationsFile({
984
- drawerConfig: hostDrawerConfig,
972
+ drawerConfig: drawerConfig,
985
973
  unauthenticatedComponentPath,
986
- drawerDirPath: hostDirPath,
974
+ drawerDirPath: drawerDirPath,
987
975
  });
988
- return true;
989
- } else {
990
- if (hostDrawerConfig) {
991
- const isDrawerGenerated = await this.#generateDrawerNavigationsFile({
976
+ await this.#generateDrawerNavigationsFile({
992
977
  drawerConfig: hostDrawerConfig,
993
978
  unauthenticatedComponentPath,
994
979
  drawerDirPath: hostDirPath,
995
980
  });
996
- return isDrawerGenerated;
997
- } else return false;
981
+ } else {
982
+ if (hostDrawerConfig) {
983
+ await this.#generateDrawerNavigationsFile({
984
+ drawerConfig: hostDrawerConfig,
985
+ unauthenticatedComponentPath,
986
+ drawerDirPath: hostDirPath,
987
+ });
988
+ }
989
+ }
998
990
  }
999
- } else return false;
991
+ } catch (error) {
992
+ console.log('Error generating drawer navigation', error);
993
+ }
1000
994
  }
1001
995
 
1002
996
  async #generateBottomTabNavigationsFile({
@@ -1154,18 +1148,17 @@ export class GenerateMobileNavigations {
1154
1148
  moduleRender = `export default ({Tab,...rest}) => { return (<>${moduleContent}</>)}`;
1155
1149
  moduleNavigation = importStatements + '\n' + moduleRender;
1156
1150
  const bottomTabNavigator = moduleNavigation;
1157
- if (bottomTabNavigator) {
1158
- let bottomTabNavigation = bottomTabNavigator;
1159
- bottomTabNavigation = prettier.format(bottomTabNavigation, { parser: 'babel' });
1160
- const bottomDirName = path.dirname(bottomDirPath);
1151
+ let bottomTabNavigation = bottomTabNavigator;
1152
+ bottomTabNavigation = prettier.format(bottomTabNavigation, { parser: 'babel' });
1153
+ const bottomDirName = path.dirname(bottomDirPath);
1154
+ try {
1161
1155
  const isDirCreated = await this.#makeDir(bottomDirName);
1162
1156
  if (isDirCreated) {
1163
- const writeFileResponse = await this.#writeFile(bottomDirPath, bottomTabNavigation);
1164
- if (writeFileResponse) return true;
1165
- else return false;
1166
- } else return false;
1157
+ await this.#writeFile(bottomDirPath, bottomTabNavigation);
1158
+ }
1159
+ } catch (error) {
1160
+ console.log('Error generating bottom tab navigation file', error);
1167
1161
  }
1168
- return false;
1169
1162
  }
1170
1163
 
1171
1164
  async #generateBottomTabNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) {
@@ -1173,7 +1166,7 @@ export class GenerateMobileNavigations {
1173
1166
  const bottomDirPath = path.join(appDirPath, `/${bottomFilePath}`);
1174
1167
  const hostBottomDirPath = path.join(appDirPath, `/${hostBottomFilePath}`);
1175
1168
 
1176
- const layoutSettings = this.#layoutSettings;
1169
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
1177
1170
  const layoutConfigFileData = await this.#getLayoutConfig();
1178
1171
  const layoutType = layoutSettings?.layout ?? 'bottom';
1179
1172
  const layoutRouteConfig = layoutConfigFileData[layoutType];
@@ -1213,34 +1206,35 @@ export class GenerateMobileNavigations {
1213
1206
  if (b?.props?.options?.priority === undefined) return -1;
1214
1207
  return a?.props?.options?.priority - b?.props?.options?.priority;
1215
1208
  }) ?? [];
1216
- if (layoutType == 'bottom' || layoutType == 'mixSide') {
1217
- if (bottomTabConfig) {
1218
- const drawerNavigation = await this.#generateBottomTabNavigationsFile({
1219
- bottomTabConfig: bottomTabConfig,
1220
- unauthenticatedComponentPath,
1221
- bottomDirPath: bottomDirPath,
1222
- mixLayout,
1223
- });
1224
- if (drawerNavigation)
1209
+ try {
1210
+ if (layoutType == 'bottom' || layoutType == 'mixSide') {
1211
+ if (bottomTabConfig) {
1225
1212
  await this.#generateBottomTabNavigationsFile({
1226
- bottomTabConfig: hostBottomTabConfig,
1213
+ bottomTabConfig: bottomTabConfig,
1227
1214
  unauthenticatedComponentPath,
1228
- bottomDirPath: hostBottomDirPath,
1215
+ bottomDirPath: bottomDirPath,
1229
1216
  mixLayout,
1230
1217
  });
1231
- return true;
1232
- } else {
1233
- if (hostBottomTabConfig) {
1234
- const isHostGenerated = await this.#generateBottomTabNavigationsFile({
1218
+ await this.#generateBottomTabNavigationsFile({
1235
1219
  bottomTabConfig: hostBottomTabConfig,
1236
1220
  unauthenticatedComponentPath,
1237
1221
  bottomDirPath: hostBottomDirPath,
1238
1222
  mixLayout,
1239
1223
  });
1240
- return isHostGenerated;
1241
- } else return false;
1224
+ } else {
1225
+ if (hostBottomTabConfig) {
1226
+ await this.#generateBottomTabNavigationsFile({
1227
+ bottomTabConfig: hostBottomTabConfig,
1228
+ unauthenticatedComponentPath,
1229
+ bottomDirPath: hostBottomDirPath,
1230
+ mixLayout,
1231
+ });
1232
+ }
1233
+ }
1242
1234
  }
1243
- } else return false;
1235
+ } catch (error) {
1236
+ console.log('Error generating bottom tab navigation', error);
1237
+ }
1244
1238
  }
1245
1239
 
1246
1240
  async #generateBottomTabDrawerNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) {
@@ -1250,7 +1244,7 @@ export class GenerateMobileNavigations {
1250
1244
  const drawerDirPath = path.join(appDirPath, `/${drawerFilePath}`);
1251
1245
  const hostDirPath = path.join(appDirPath, `/${hostDrawerFilePath}`);
1252
1246
 
1253
- const layoutSettings = this.#layoutSettings;
1247
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
1254
1248
  const layoutConfigFileData = await this.#getLayoutConfig();
1255
1249
  const layoutType = layoutSettings?.layout ?? 'bottom';
1256
1250
  const layoutRouteConfig = layoutConfigFileData[layoutType];
@@ -1313,39 +1307,41 @@ export class GenerateMobileNavigations {
1313
1307
  }) ?? [];
1314
1308
 
1315
1309
  if (bottomTabConfig) {
1316
- const drawerNavigation = await this.#generateBottomTabNavigationsFile({
1317
- bottomTabConfig: bottomTabConfig,
1318
- unauthenticatedComponentPath,
1319
- bottomDirPath: bottomDirPath,
1320
- mixLayout,
1321
- });
1322
- if (drawerNavigation)
1310
+ try {
1323
1311
  await this.#generateBottomTabNavigationsFile({
1324
- bottomTabConfig: hostBottomTabConfig,
1312
+ bottomTabConfig: bottomTabConfig,
1325
1313
  unauthenticatedComponentPath,
1326
- bottomDirPath: hostBottomDirPath,
1314
+ bottomDirPath: bottomDirPath,
1327
1315
  mixLayout,
1328
1316
  });
1329
- if (drawerConfig) {
1330
- const drawerNavigation = await this.#generateDrawerNavigationsFile({
1331
- drawerConfig: drawerConfig,
1317
+
1318
+ await this.#generateBottomTabNavigationsFile({
1319
+ bottomTabConfig: hostBottomTabConfig,
1332
1320
  unauthenticatedComponentPath,
1333
- drawerDirPath: drawerDirPath,
1321
+ bottomDirPath: hostBottomDirPath,
1322
+ mixLayout,
1334
1323
  });
1335
- if (drawerNavigation)
1324
+ if (drawerConfig) {
1325
+ await this.#generateDrawerNavigationsFile({
1326
+ drawerConfig: drawerConfig,
1327
+ unauthenticatedComponentPath,
1328
+ drawerDirPath: drawerDirPath,
1329
+ });
1336
1330
  await this.#generateDrawerNavigationsFile({
1337
1331
  drawerConfig: hostDrawerConfig,
1338
1332
  unauthenticatedComponentPath,
1339
1333
  drawerDirPath: hostDirPath,
1340
1334
  });
1341
- return true;
1342
- } else return true;
1343
- } else return false;
1335
+ }
1336
+ } catch (error) {
1337
+ console.log('Error in generating drawer bottom tab navigation', error);
1338
+ }
1339
+ }
1344
1340
  }
1345
1341
 
1346
1342
  async #generateAppNavigationFile({ appDirPath, customTabBarPath, customDrawerPath, customHeaderPath }) {
1347
1343
  const navigationDirPath = path.join(appDirPath, `/${appNavigationFileName}`);
1348
- const layoutSettings = this.#layoutSettings;
1344
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
1349
1345
  const layoutConfigFileData = await this.#getLayoutConfig();
1350
1346
  const layoutType = layoutSettings?.layout || 'bottom';
1351
1347
  const layoutRouteConfig = layoutConfigFileData[layoutType];
@@ -1574,9 +1570,11 @@ export class GenerateMobileNavigations {
1574
1570
  `;
1575
1571
  appNavigation = importStatements + '\n' + rootComponent + '\n' + appComponent;
1576
1572
  appNavigation = prettier.format(appNavigation, { parser: 'babel' });
1577
- const writeFileResponse = await this.#writeFile(navigationDirPath, appNavigation);
1578
- if (writeFileResponse) return true;
1579
- else return false;
1573
+ try {
1574
+ await this.#writeFile(navigationDirPath, appNavigation);
1575
+ } catch (error) {
1576
+ console.log('Error in generating app navigationfile', error);
1577
+ }
1580
1578
  }
1581
1579
 
1582
1580
  async #setLayoutAndGenerateNavigation() {
@@ -1589,92 +1587,150 @@ export class GenerateMobileNavigations {
1589
1587
  const customHeaderPath = this.#customHeaderPath;
1590
1588
  const i18Options = this.#i18Options;
1591
1589
 
1592
- const layoutSettings = this.#layoutSettings;
1590
+ const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
1593
1591
  const layoutConfigFileData = await this.#getLayoutConfig();
1594
1592
  const layoutType = layoutSettings?.layout || 'bottom';
1595
- const isAppRoutesGenerated = await this.#generateAppRoutesJson({ appDirPath });
1596
- if (isAppRoutesGenerated) {
1597
- // await this.#generateModulesTsFile({
1598
- // appDirPath,
1599
- // modules,
1600
- // initialRouteName,
1601
- // });
1593
+ try {
1594
+ await this.#generateAppRoutesJson();
1602
1595
  await this.#generateMainRoutes({
1603
1596
  appDirPath,
1604
1597
  i18Options,
1605
1598
  initialRouteName,
1606
1599
  });
1607
- const isAppFileGenerated = await this.#generateApp({
1600
+ await this.#generateApp({
1608
1601
  appDirPath,
1609
1602
  i18Options,
1610
1603
  initialRouteName,
1611
1604
  });
1612
- if (isAppFileGenerated) {
1613
- const isStackCreated = await this.#generateStackNavigations({
1614
- appDirPath,
1615
- modules,
1616
- initialRouteName,
1617
- unauthenticatedComponentPath,
1618
- });
1619
- if (isStackCreated) {
1620
- if (layoutType == 'side') {
1621
- const isDrawerGenerated = await this.#generateDrawerNavigations({
1622
- appDirPath,
1623
- modules,
1624
- initialRouteName,
1625
- unauthenticatedComponentPath,
1626
- });
1627
- if (isDrawerGenerated) {
1628
- const appNavigationGenerated = await this.#generateAppNavigationFile({
1629
- appDirPath,
1630
- customTabBarPath,
1631
- customDrawerPath,
1632
- customHeaderPath,
1633
- });
1634
- if (appNavigationGenerated) return appNavigationGenerated;
1635
- else return true;
1636
- } else return false;
1637
- } else if (layoutType == 'bottom' || layoutType == 'host-bottom') {
1638
- const isBottomTabGenerated = await this.#generateBottomTabNavigations({
1639
- appDirPath,
1640
- modules,
1641
- initialRouteName,
1642
- unauthenticatedComponentPath,
1643
- });
1644
- if (isBottomTabGenerated) {
1645
- const appNavigationGenerated = await this.#generateAppNavigationFile({
1646
- appDirPath,
1647
- customTabBarPath,
1648
- customDrawerPath,
1649
- customHeaderPath,
1650
- });
1651
- if (appNavigationGenerated) return appNavigationGenerated;
1652
- else return true;
1653
- } else return false;
1654
- } else {
1655
- const isBottomTabDrawerGenerated = await this.#generateBottomTabDrawerNavigations({
1656
- appDirPath,
1657
- modules,
1658
- initialRouteName,
1659
- unauthenticatedComponentPath,
1660
- });
1661
- if (isBottomTabDrawerGenerated) {
1662
- const appNavigationGenerated = await this.#generateAppNavigationFile({
1663
- appDirPath,
1664
- customTabBarPath,
1665
- customDrawerPath,
1666
- customHeaderPath,
1667
- });
1668
- if (appNavigationGenerated) return appNavigationGenerated;
1669
- else return true;
1670
- } else return false;
1671
- }
1672
- } else return false;
1673
- } else return false;
1674
- } else return false;
1605
+
1606
+ await this.#generateStackNavigations({
1607
+ appDirPath,
1608
+ modules,
1609
+ initialRouteName,
1610
+ unauthenticatedComponentPath,
1611
+ });
1612
+
1613
+ if (layoutType == 'side') {
1614
+ try {
1615
+ await this.#generateDrawerNavigations({
1616
+ appDirPath,
1617
+ modules,
1618
+ initialRouteName,
1619
+ unauthenticatedComponentPath,
1620
+ });
1621
+ await this.#generateAppNavigationFile({
1622
+ appDirPath,
1623
+ customTabBarPath,
1624
+ customDrawerPath,
1625
+ customHeaderPath,
1626
+ });
1627
+ } catch (error) {
1628
+ console.log('Error in generating side navigation', error);
1629
+ }
1630
+ } else if (layoutType == 'bottom' || layoutType == 'host-bottom') {
1631
+ try {
1632
+ await this.#generateBottomTabNavigations({
1633
+ appDirPath,
1634
+ modules,
1635
+ initialRouteName,
1636
+ unauthenticatedComponentPath,
1637
+ });
1638
+ await this.#generateAppNavigationFile({
1639
+ appDirPath,
1640
+ customTabBarPath,
1641
+ customDrawerPath,
1642
+ customHeaderPath,
1643
+ });
1644
+ } catch (error) {
1645
+ console.log('Error in generating bottom navigation', error);
1646
+ }
1647
+ } else {
1648
+ try {
1649
+ await this.#generateBottomTabDrawerNavigations({
1650
+ appDirPath,
1651
+ modules,
1652
+ initialRouteName,
1653
+ unauthenticatedComponentPath,
1654
+ });
1655
+
1656
+ await this.#generateAppNavigationFile({
1657
+ appDirPath,
1658
+ customTabBarPath,
1659
+ customDrawerPath,
1660
+ customHeaderPath,
1661
+ });
1662
+ } catch (error) {
1663
+ console.log('Error in generating drawer bottom navigation', error);
1664
+ }
1665
+ }
1666
+ } catch (error) {
1667
+ console.log('Error generating app navigations', error);
1668
+ }
1669
+ }
1670
+
1671
+ async #performCopyOperations() {
1672
+ const config = this.#configFileData;
1673
+ try {
1674
+ await performCopyOperations(config);
1675
+ await this.#setLayoutAndGenerateNavigation();
1676
+ } catch (error) {
1677
+ console.error('PerformCopyOperations error:', error);
1678
+ }
1679
+ }
1680
+
1681
+ async #deleteDirectoryRecursive(dirPath: any) {
1682
+ if (fs.existsSync(dirPath)) {
1683
+ const files = fs.readdirSync(dirPath);
1684
+ for (const file of files) {
1685
+ const curPath = path.join(dirPath, file);
1686
+ if (fs.lstatSync(curPath).isDirectory()) {
1687
+ // Recursively delete subdirectories
1688
+ await this.#deleteDirectoryRecursive(curPath);
1689
+ } else {
1690
+ // Delete files
1691
+ fs.unlinkSync(curPath);
1692
+ }
1693
+ }
1694
+ // Delete the directory itself
1695
+ fs.rmdirSync(dirPath);
1696
+ }
1697
+ }
1698
+
1699
+ async #createAppDirectory() {
1700
+ const appDir = this.#appDirPath;
1701
+
1702
+ try {
1703
+ // Check if the directory exists
1704
+ if (fs.existsSync(appDir)) {
1705
+ console.log('Directory exists. Recreating it...');
1706
+ // Delete the directory and its contents
1707
+ await this.#deleteDirectoryRecursive(appDir);
1708
+ }
1709
+
1710
+ // Create the directory
1711
+ fs.mkdirSync(appDir);
1712
+ console.log('Directory created');
1713
+ // Add 'app' to .gitignore if not already present
1714
+ const gitignorePath = path.resolve(appDir, '.gitignore');
1715
+ let gitignoreContent = '';
1716
+ if (fs.existsSync(gitignorePath)) {
1717
+ gitignoreContent = fs.readFileSync(gitignorePath, 'utf8');
1718
+ } else {
1719
+ fs.writeFileSync(gitignorePath, '');
1720
+ console.log('Created .gitignore file');
1721
+ }
1722
+
1723
+ if (!gitignoreContent.includes('*')) {
1724
+ fs.appendFileSync(gitignorePath, '*\n');
1725
+ console.log('Added "*" to .gitignore');
1726
+ }
1727
+ await this.#performCopyOperations();
1728
+ } catch (error) {
1729
+ console.error('Error creating app directory:', error);
1730
+ }
1675
1731
  }
1676
1732
 
1677
1733
  async generateAppNavigations() {
1678
- return this.#setLayoutAndGenerateNavigation();
1734
+ return this.#createAppDirectory();
1679
1735
  }
1680
1736
  }