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