@admin-layout/gluestack-ui-mobile 7.3.8-alpha.8 → 8.5.2-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 (96) 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 +19 -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-managed.js +2 -2
  43. package/lib/components/with-interactions-managed.js.map +1 -1
  44. package/lib/config/config.js +2 -2
  45. package/lib/config/config.js.map +1 -1
  46. package/lib/config/i18next.js +1 -2
  47. package/lib/config/i18next.js.map +1 -1
  48. package/lib/containers/layout/BasicLayout.d.ts +2 -2
  49. package/lib/containers/layout/BasicLayout.js +3 -3
  50. package/lib/containers/layout/BasicLayout.js.map +1 -1
  51. package/lib/containers/layout/DrawerBottomNavigationConfig.d.ts +2 -2
  52. package/lib/containers/layout/DrawerBottomNavigationConfig.js +2 -2
  53. package/lib/containers/layout/DrawerBottomNavigationConfig.js.map +1 -1
  54. package/lib/containers/layout/DrawerConfig.d.ts +1 -1
  55. package/lib/containers/layout/DrawerConfig.js +1 -1
  56. package/lib/containers/layout/DrawerConfig.js.map +1 -1
  57. package/lib/containers/layout/Lifecycle.js +2 -14
  58. package/lib/containers/layout/Lifecycle.js.map +1 -1
  59. package/lib/containers/layout/ProLayout.js +4 -5
  60. package/lib/containers/layout/ProLayout.js.map +1 -1
  61. package/lib/hooks/use-after-interactions.d.ts +0 -1
  62. package/lib/hooks/use-after-interactions.js +1 -1
  63. package/lib/hooks/use-after-interactions.js.map +1 -1
  64. package/lib/hooks/useIsReady.js.map +1 -1
  65. package/lib/hooks/useLayoutSetting/index.js +16 -14
  66. package/lib/hooks/useLayoutSetting/index.js.map +1 -1
  67. package/lib/index.d.ts +3 -1
  68. package/lib/index.js +3 -1
  69. package/lib/index.js.map +1 -1
  70. package/lib/layout.json +153 -0
  71. package/lib/redux/settings.d.ts +8 -8
  72. package/lib/redux/settings.js +8 -2
  73. package/lib/redux/settings.js.map +1 -1
  74. package/lib/utils/generateAppNavigations.d.mts +43 -0
  75. package/lib/utils/generateAppNavigations.mjs +952 -0
  76. package/lib/utils/generateAppNavigations.mjs.map +1 -0
  77. package/lib/utils/getReplacedRouteConfig.d.ts +11 -0
  78. package/lib/utils/getReplacedRouteConfig.js +276 -0
  79. package/lib/utils/getReplacedRouteConfig.js.map +1 -0
  80. package/lib/utils/getReplacedRouteConfig.mjs +265 -0
  81. package/lib/utils/routeConfigKeyReplace.js +17 -19
  82. package/lib/utils/routeConfigKeyReplace.js.map +1 -1
  83. package/package.json +7 -5
  84. package/src/components/ApplicationErrorHandler.tsx +26 -21
  85. package/src/components/AuthWrapper.tsx +19 -0
  86. package/src/components/Layout/components/BottomTabBar.tsx +2 -0
  87. package/src/components/Layout/components/Drawer.tsx +4 -1
  88. package/src/components/Layout/components/Header.tsx +7 -3
  89. package/src/components/UnAuthenticatedComponent.tsx +38 -0
  90. package/src/components/index.ts +1 -0
  91. package/src/index.ts +4 -1
  92. package/src/layout.json +153 -0
  93. package/src/utils/generateAppNavigations.mjs +984 -0
  94. package/src/utils/getReplacedRouteConfig.mjs_ok +317 -0
  95. package/src/utils/getReplacedRouteConfig.ts +330 -0
  96. package/tsconfig.json +4 -1
@@ -0,0 +1,952 @@
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
+ />}</Drawer.Screen>`;
422
+ }
423
+ if (icons && icons?.length) {
424
+ const uniqueIcons = [...new Set(icons.split(","))].join(",");
425
+ importStatements += `import { ${uniqueIcons} } from '@expo/vector-icons';\n`;
426
+ }
427
+ moduleRender = `export default ({Drawer,...rest}:any) => { return (<>${moduleContent}</>)}`;
428
+ moduleNavigation = importStatements + '\n' + moduleRender;
429
+ const drawerNavigator = moduleNavigation;
430
+ if (drawerNavigator) {
431
+ let drawerNavigation = drawerNavigator;
432
+ drawerNavigation = prettier.format(drawerNavigation, { parser: 'babel' });
433
+ const drawerDirName = path.dirname(drawerDirPath);
434
+ const isDirCreated = await makeDir(drawerDirName);
435
+ if (isDirCreated) {
436
+ const writeFileResponse = await writeFile(drawerDirPath, drawerNavigation);
437
+ if (writeFileResponse)
438
+ return true;
439
+ else
440
+ return false;
441
+ }
442
+ else
443
+ return false;
444
+ }
445
+ return false;
446
+ };
447
+ const generateDrawerNavigations = async ({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) => {
448
+ const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
449
+ const drawerDirPath = path.join(appDirPath, `/${drawerFilePath}`);
450
+ const hostDirPath = path.join(appDirPath, `/${hostDrawerFilePath}`);
451
+ const { layoutConfigFileData, layoutSettings } = await getLayoutConfig();
452
+ const layoutType = 'side';
453
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
454
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
455
+ const appLayout = layoutRouteConfig[layoutRouteKey];
456
+ const hostRouteConfig = layoutConfigFileData['host-bottom'];
457
+ const hostRouteKey = Object.keys(hostRouteConfig)[1];
458
+ const hostLayout = hostRouteConfig[hostRouteKey];
459
+ const modulesRouteConfig = await getModulesRouteConfig({ modules: modules });
460
+ const mainRouteConfig = await readJsonFile(mainRoutes);
461
+ const allRoutes = [...[mainRouteConfig ?? []], ...modulesRouteConfig ?? []];
462
+ const { replacedNavigationRouteConfig: routeConfig } = getReplacedRouteConfig({
463
+ layoutType: layoutType,
464
+ routeConfig: allRoutes,
465
+ layoutConfigData: layoutConfigFileData,
466
+ initialRouteName: initialRouteName,
467
+ });
468
+ const keyToReplace = appLayout.key || 'bottom_tab';
469
+ const keyToReplaceHost = hostLayout.key || 'host_tab';
470
+ const moduleRouteConfigObject = Object.assign({}, ...routeConfig?.flat(1) ?? []);
471
+ const configuredRoutes = await getSortedNavigations("/", moduleRouteConfigObject);
472
+ const layoutBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r) => r?.key == keyToReplace);
473
+ const hostBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r) => r?.key == keyToReplaceHost);
474
+ const drawerConfig = layoutBottomTabRouteConfig?.[0]?.children?.sort((a, b) => {
475
+ if (a?.props?.options?.priority === undefined)
476
+ return 1; // Push items with missing 'id' to the end
477
+ if (b?.props?.options?.priority === undefined)
478
+ return -1;
479
+ return a?.props?.options?.priority - b?.props?.options?.priority;
480
+ }) ?? [];
481
+ const hostDrawerConfig = hostBottomTabRouteConfig?.[0]?.children?.sort((a, b) => {
482
+ if (a?.props?.options?.priority === undefined)
483
+ return 1; // Push items with missing 'id' to the end
484
+ if (b?.props?.options?.priority === undefined)
485
+ return -1;
486
+ return a?.props?.options?.priority - b?.props?.options?.priority;
487
+ }) ?? [];
488
+ if (layoutSettings?.layout == 'side') {
489
+ if (drawerConfig) {
490
+ const drawerNavigation = await generateDrawerNavigationsFile({ drawerConfig: drawerConfig, unauthenticatedComponentPath, drawerDirPath: drawerDirPath });
491
+ if (drawerNavigation)
492
+ await generateDrawerNavigationsFile({ drawerConfig: hostDrawerConfig, unauthenticatedComponentPath, drawerDirPath: hostDirPath });
493
+ return true;
494
+ }
495
+ else {
496
+ if (hostDrawerConfig) {
497
+ const isDrawerGenerated = await generateDrawerNavigationsFile({ drawerConfig: hostDrawerConfig, unauthenticatedComponentPath, drawerDirPath: hostDirPath });
498
+ return isDrawerGenerated;
499
+ }
500
+ else
501
+ return false;
502
+ }
503
+ }
504
+ else
505
+ return false;
506
+ };
507
+ const generateBottomTabNavigationsFile = async ({ bottomTabConfig, unauthenticatedComponentPath, bottomDirPath, mixLayout = null }) => {
508
+ let moduleNumber = 0;
509
+ let importStatements = '';
510
+ let moduleContent = '';
511
+ let moduleRender = '';
512
+ let moduleNavigation = '';
513
+ let icons = '';
514
+ importStatements += `import * as React from 'react';\n`;
515
+ importStatements += `import {AuthWrapper} from '@admin-layout/gluestack-ui-mobile';\n`;
516
+ if (unauthenticatedComponentPath)
517
+ importStatements += `import UnauthenticatedComponent from '${unauthenticatedComponentPath}';\n`;
518
+ for (const pkgRouteConfig of bottomTabConfig) {
519
+ moduleNumber++;
520
+ if (pkgRouteConfig?.icon && Object.keys(pkgRouteConfig.icon)?.length && pkgRouteConfig?.icon?.name) {
521
+ icons += `${pkgRouteConfig?.icon?.name},`;
522
+ }
523
+ const options = JSON.stringify({ ...pkgRouteConfig?.props?.options, headerShown: mixLayout ? false : pkgRouteConfig?.props?.options?.headerShown } || { headerShown: mixLayout ? false : true });
524
+ importStatements += `import Component${moduleNumber} from '${pkgRouteConfig.componentPath}';\n`;
525
+ moduleContent += `<Tab.Screen
526
+ key="${pkgRouteConfig.key}"
527
+ name="${pkgRouteConfig.name}"
528
+ //component={Component${moduleNumber}}
529
+ initialParams={${JSON.stringify(pkgRouteConfig?.props?.initialParams || {})}}
530
+ 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'}} />` : ''}}}}
531
+ >{(props:any) => <AuthWrapper
532
+ auth={${pkgRouteConfig?.props?.initialParams?.auth ?? false}}
533
+ component={<Component${moduleNumber} {...props} />}
534
+ ${unauthenticatedComponentPath ? 'unauthenticatedComponent={<UnauthenticatedComponent/>}' : ""}
535
+ />}
536
+ </Tab.Screen>`;
537
+ }
538
+ if (icons && icons?.length) {
539
+ const uniqueIcons = [...new Set(icons.split(","))].join(",");
540
+ importStatements += `import { ${uniqueIcons} } from '@expo/vector-icons';\n`;
541
+ }
542
+ moduleRender = `export default ({Tab,...rest}:any) => { return (<>${moduleContent}</>)}`;
543
+ moduleNavigation = importStatements + '\n' + moduleRender;
544
+ const bottomTabNavigator = moduleNavigation;
545
+ if (bottomTabNavigator) {
546
+ let bottomTabNavigation = bottomTabNavigator;
547
+ bottomTabNavigation = prettier.format(bottomTabNavigation, { parser: 'babel' });
548
+ const bottomDirName = path.dirname(bottomDirPath);
549
+ const isDirCreated = await makeDir(bottomDirName);
550
+ if (isDirCreated) {
551
+ const writeFileResponse = await writeFile(bottomDirPath, bottomTabNavigation);
552
+ if (writeFileResponse)
553
+ return true;
554
+ else
555
+ return false;
556
+ }
557
+ else
558
+ return false;
559
+ }
560
+ return false;
561
+ };
562
+ const generateBottomTabNavigations = async ({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) => {
563
+ const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
564
+ const bottomDirPath = path.join(appDirPath, `/${bottomFilePath}`);
565
+ const hostBottomDirPath = path.join(appDirPath, `/${hostBottomFilePath}`);
566
+ const { layoutConfigFileData, layoutSettings } = await getLayoutConfig();
567
+ const layoutType = layoutSettings?.layout ?? 'bottom';
568
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
569
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
570
+ const appLayout = layoutRouteConfig[layoutRouteKey];
571
+ const hostRouteConfig = layoutConfigFileData['host-bottom'];
572
+ const hostRouteKey = Object.keys(hostRouteConfig)[1];
573
+ const hostLayout = hostRouteConfig[hostRouteKey];
574
+ const mixLayoutRouteKey = Object.keys(layoutRouteConfig)?.[2] || null;
575
+ const mixLayout = mixLayoutRouteKey ? layoutRouteConfig[mixLayoutRouteKey] : null;
576
+ const modulesRouteConfig = await getModulesRouteConfig({ modules: modules });
577
+ const mainRouteConfig = await readJsonFile(mainRoutes);
578
+ const allRoutes = [...[mainRouteConfig ?? []], ...modulesRouteConfig ?? []];
579
+ const { replacedNavigationRouteConfig: routeConfig } = getReplacedRouteConfig({
580
+ layoutType: layoutType,
581
+ routeConfig: allRoutes,
582
+ layoutConfigData: layoutConfigFileData,
583
+ initialRouteName: initialRouteName,
584
+ });
585
+ const keyToReplace = appLayout.key || 'bottom_tab';
586
+ const keyToReplaceHost = hostLayout.key || 'host_tab';
587
+ const moduleRouteConfigObject = Object.assign({}, ...routeConfig?.flat(1) ?? []);
588
+ const configuredRoutes = await getSortedNavigations("/", moduleRouteConfigObject);
589
+ const layoutBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r) => r?.key == keyToReplace);
590
+ const hostBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r) => r?.key == keyToReplaceHost);
591
+ const bottomTabConfig = layoutBottomTabRouteConfig?.[0]?.children?.sort((a, b) => {
592
+ if (a?.props?.options?.priority === undefined)
593
+ return 1; // Push items with missing 'id' to the end
594
+ if (b?.props?.options?.priority === undefined)
595
+ return -1;
596
+ return a?.props?.options?.priority - b?.props?.options?.priority;
597
+ }) ?? [];
598
+ const hostBottomTabConfig = hostBottomTabRouteConfig?.[0]?.children?.sort((a, b) => {
599
+ if (a?.props?.options?.priority === undefined)
600
+ return 1; // Push items with missing 'id' to the end
601
+ if (b?.props?.options?.priority === undefined)
602
+ return -1;
603
+ return a?.props?.options?.priority - b?.props?.options?.priority;
604
+ }) ?? [];
605
+ if (layoutType == 'bottom' || layoutType == 'mixSide') {
606
+ if (bottomTabConfig) {
607
+ const drawerNavigation = await generateBottomTabNavigationsFile({ bottomTabConfig: bottomTabConfig, unauthenticatedComponentPath, bottomDirPath: bottomDirPath, mixLayout });
608
+ if (drawerNavigation)
609
+ await generateBottomTabNavigationsFile({ bottomTabConfig: hostBottomTabConfig, unauthenticatedComponentPath, bottomDirPath: hostBottomDirPath, mixLayout });
610
+ return true;
611
+ }
612
+ else {
613
+ if (hostBottomTabConfig) {
614
+ const isHostGenerated = await generateBottomTabNavigationsFile({ bottomTabConfig: hostBottomTabConfig, unauthenticatedComponentPath, bottomDirPath: hostBottomDirPath, mixLayout });
615
+ return isHostGenerated;
616
+ }
617
+ else
618
+ return false;
619
+ }
620
+ }
621
+ else
622
+ return false;
623
+ };
624
+ const generateBottomTabDrawerNavigations = async ({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) => {
625
+ const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
626
+ const bottomDirPath = path.join(appDirPath, `/${bottomFilePath}`);
627
+ const hostBottomDirPath = path.join(appDirPath, `/${hostBottomFilePath}`);
628
+ const drawerDirPath = path.join(appDirPath, `/${drawerFilePath}`);
629
+ const hostDirPath = path.join(appDirPath, `/${hostDrawerFilePath}`);
630
+ const { layoutConfigFileData, layoutSettings } = await getLayoutConfig();
631
+ const layoutType = layoutSettings?.layout ?? 'bottom';
632
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
633
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
634
+ const appLayout = layoutRouteConfig[layoutRouteKey];
635
+ const hostRouteConfig = layoutConfigFileData['host-bottom'];
636
+ const hostRouteKey = Object.keys(hostRouteConfig)[1];
637
+ const hostLayout = hostRouteConfig[hostRouteKey];
638
+ const mixLayoutRouteKey = Object.keys(layoutRouteConfig)?.[2] || null;
639
+ const mixLayout = mixLayoutRouteKey ? layoutRouteConfig[mixLayoutRouteKey] : null;
640
+ const modulesRouteConfig = await getModulesRouteConfig({ modules: modules });
641
+ const mainRouteConfig = await readJsonFile(mainRoutes);
642
+ const allRoutes = [...[mainRouteConfig ?? []], ...modulesRouteConfig ?? []];
643
+ const { replacedNavigationRouteConfig: routeConfig } = getReplacedRouteConfig({
644
+ layoutType: layoutType,
645
+ routeConfig: allRoutes,
646
+ layoutConfigData: layoutConfigFileData,
647
+ initialRouteName: initialRouteName,
648
+ });
649
+ const keyToReplace = appLayout.key || 'bottom_tab';
650
+ const keyToReplaceHost = hostLayout.key || 'host_tab';
651
+ const moduleRouteConfigObject = Object.assign({}, ...routeConfig?.flat(1) ?? []);
652
+ const configuredRoutes = await getSortedNavigations("/", moduleRouteConfigObject);
653
+ const layoutBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r) => r?.key == keyToReplace);
654
+ const hostBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r) => r?.key == keyToReplaceHost);
655
+ const bottomTabConfig = layoutBottomTabRouteConfig?.[0]?.children?.filter((r) => !r?.side)?.sort((a, b) => {
656
+ if (a?.props?.options?.priority === undefined)
657
+ return 1; // Push items with missing 'id' to the end
658
+ if (b?.props?.options?.priority === undefined)
659
+ return -1;
660
+ return a?.props?.options?.priority - b?.props?.options?.priority;
661
+ }) ?? [];
662
+ const hostBottomTabConfig = hostBottomTabRouteConfig?.[0]?.children?.filter((r) => !r?.side)?.sort((a, b) => {
663
+ if (a?.props?.options?.priority === undefined)
664
+ return 1; // Push items with missing 'id' to the end
665
+ if (b?.props?.options?.priority === undefined)
666
+ return -1;
667
+ return a?.props?.options?.priority - b?.props?.options?.priority;
668
+ }) ?? [];
669
+ const drawerConfig = layoutBottomTabRouteConfig?.[0]?.children?.filter((r) => r?.side)?.sort((a, b) => {
670
+ if (a?.props?.options?.priority === undefined)
671
+ return 1; // Push items with missing 'id' to the end
672
+ if (b?.props?.options?.priority === undefined)
673
+ return -1;
674
+ return a?.props?.options?.priority - b?.props?.options?.priority;
675
+ }) ?? [];
676
+ const hostDrawerConfig = hostBottomTabRouteConfig?.[0]?.children?.filter((r) => r?.side)?.sort((a, b) => {
677
+ if (a?.props?.options?.priority === undefined)
678
+ return 1; // Push items with missing 'id' to the end
679
+ if (b?.props?.options?.priority === undefined)
680
+ return -1;
681
+ return a?.props?.options?.priority - b?.props?.options?.priority;
682
+ }) ?? [];
683
+ if (bottomTabConfig) {
684
+ const drawerNavigation = await generateBottomTabNavigationsFile({ bottomTabConfig: bottomTabConfig, unauthenticatedComponentPath, bottomDirPath: bottomDirPath, mixLayout });
685
+ if (drawerNavigation)
686
+ await generateBottomTabNavigationsFile({ bottomTabConfig: hostBottomTabConfig, unauthenticatedComponentPath, bottomDirPath: hostBottomDirPath, mixLayout });
687
+ if (drawerConfig) {
688
+ const drawerNavigation = await generateDrawerNavigationsFile({ drawerConfig: drawerConfig, unauthenticatedComponentPath, drawerDirPath: drawerDirPath });
689
+ if (drawerNavigation)
690
+ await generateDrawerNavigationsFile({ drawerConfig: hostDrawerConfig, unauthenticatedComponentPath, drawerDirPath: hostDirPath });
691
+ return true;
692
+ }
693
+ else
694
+ return true;
695
+ }
696
+ else
697
+ return false;
698
+ };
699
+ const generateAppNavigationFile = async ({ appDirPath, customTabBarPath, customDrawerPath, customHeaderPath }) => {
700
+ const navigationDirPath = path.join(appDirPath, `/${appNavigationFileName}`);
701
+ const { layoutConfigFileData, layoutSettings } = await getLayoutConfig();
702
+ const layoutType = layoutSettings.layout || 'bottom';
703
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
704
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
705
+ const appLayout = layoutRouteConfig[layoutRouteKey];
706
+ const initialRouteName = layoutType === 'mixSide'
707
+ ? appLayout?.[appLayout?.key]?.props?.initialRouteName ?? 'MainStack.Layout.Home'
708
+ : appLayout?.props?.initialRouteName || 'MainStack.Home';
709
+ const isShowTabs = layoutType === 'mixSide' || layoutType === 'bottom' ? true : false;
710
+ const isShowDefalutHeader = layoutType === 'mixSide' ? true : false;
711
+ const defaultHeaderProps = {
712
+ showToggle: layoutSettings.topLeftToggle || false,
713
+ right: layoutSettings.topRightSettingToggle || false,
714
+ };
715
+ const screenOptionsTab = layoutType === 'mixSide'
716
+ ? { ...(appLayout?.[appLayout?.key]?.props?.screenOptions ?? {}) }
717
+ : appLayout?.props?.screenOptions || { headerShown: true, title: 'Home', headerTitle: 'Home' };
718
+ const screenOptions = appLayout?.props?.screenOptions || { headerShown: true, title: 'Home', headerTitle: 'Home' };
719
+ let importStatements = `
720
+ import * as React from 'react';
721
+ import { navigationRef } from '@common-stack/client-react';
722
+ import { createNativeStackNavigator } from '@react-navigation/native-stack';`;
723
+ let rootComponent = '';
724
+ let appComponent = '';
725
+ let appNavigation = '';
726
+ if (layoutType == 'side') {
727
+ if (customDrawerPath)
728
+ importStatements += `import CustomDrawerContent from '${customDrawerPath}';\n`;
729
+ if (customHeaderPath)
730
+ importStatements += `import CustomHeader from '${customHeaderPath}';\n`;
731
+ importStatements += `import { createDrawerNavigator } from '@react-navigation/drawer';
732
+ import { getHeaderTitle } from '@react-navigation/elements';
733
+ import { useSelector } from 'react-redux';
734
+ import stackNavigations from './stack';
735
+ import drawerNavigations from './drawer';
736
+ import hostDrawerNavigations from './host_drawer';
737
+ const Stack = createNativeStackNavigator();
738
+ const Drawer = createDrawerNavigator();
739
+ `;
740
+ rootComponent += `
741
+ const RootComponent = (props:any) => {
742
+ const settings = useSelector((state: any) => state.settings);
743
+ const defaultHeaderProps = ${JSON.stringify(defaultHeaderProps || {})};
744
+ return (
745
+ <Drawer.Navigator
746
+ initialRouteName={${JSON.stringify(initialRouteName)}}
747
+ //screenOptions={${JSON.stringify(screenOptions)}}
748
+ screenOptions={({ route }) => ({ ...${JSON.stringify(screenOptions)} ,...{
749
+ ${customHeaderPath ? `header: (props:any) => {
750
+ const title = getHeaderTitle(props.options, props.route.name);
751
+ return <CustomHeader {...defaultHeaderProps} {...props} title={title} style={props.options.headerStyle} />;
752
+ }` : ""}
753
+ }})}
754
+ ${customDrawerPath ? 'drawerContent={(props) => <CustomDrawerContent {...props} />}' : ""}
755
+ >
756
+ {settings?.layout == 'host-bottom' ? hostDrawerNavigations({ Drawer }) : drawerNavigations({ Drawer })}
757
+ </Drawer.Navigator>
758
+ );
759
+ }
760
+ `;
761
+ }
762
+ if (layoutType == 'bottom') {
763
+ if (customTabBarPath)
764
+ importStatements += `import CustomTabBar from '${customTabBarPath}';\n`;
765
+ if (customHeaderPath)
766
+ importStatements += `import CustomHeader from '${customHeaderPath}';\n`;
767
+ importStatements += `import {Header,Drawer as DefaultDrawer} from '@admin-layout/gluestack-ui-mobile';
768
+ import { getHeaderTitle } from '@react-navigation/elements';
769
+ import { useSelector } from 'react-redux';
770
+ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
771
+ import stackNavigations from './stack';
772
+ import bottomNavigations from './bottom';
773
+ import hostBottomNavigations from './host_bottom';
774
+ const Stack = createNativeStackNavigator();
775
+ const Tab = createBottomTabNavigator();
776
+ `;
777
+ rootComponent += `
778
+ const RootComponent = (props:any) => {
779
+ const settings = useSelector((state: any) => state.settings);
780
+ const initialRouteName = ${JSON.stringify(initialRouteName)};
781
+ let defaultScreenOptions = ${JSON.stringify(screenOptionsTab)};
782
+ const defaultHeaderProps = ${JSON.stringify(defaultHeaderProps || {})};
783
+ const defaultHeader = {${isShowDefalutHeader ? `header:(props:any)=><Header {...defaultHeaderProps} {...props} />` : ''}};
784
+ return (
785
+ <Tab.Navigator
786
+ initialRouteName={initialRouteName}
787
+ screenOptions={(props:any)=>({...props,...defaultScreenOptions,...{${customHeaderPath ? `header: (props:any) => {
788
+ const title = getHeaderTitle(props.options, props.route.name);
789
+ return <CustomHeader {...defaultHeaderProps} {...props} title={title} style={props.options.headerStyle} />;
790
+ }` : ""}}})}
791
+ ${customTabBarPath ? 'tabBar={props => <CustomTabBar {...props} />}' : ""}
792
+ >
793
+ {settings?.layout == 'host-bottom' ? hostBottomNavigations({ Tab }) : bottomNavigations({Tab})}
794
+ </Tab.Navigator>
795
+ );
796
+ }
797
+ `;
798
+ }
799
+ if (layoutType == 'mixSide') {
800
+ if (customTabBarPath)
801
+ importStatements += `import CustomTabBar from '${customTabBarPath}';\n`;
802
+ if (customDrawerPath)
803
+ importStatements += `import CustomDrawerContent from '${customDrawerPath}';\n`;
804
+ if (customHeaderPath)
805
+ importStatements += `import CustomHeader from '${customHeaderPath}';\n`;
806
+ importStatements += `import {Header,Drawer as DefaultDrawer} from '@admin-layout/gluestack-ui-mobile';
807
+ import { useSelector } from 'react-redux';
808
+ import { MaterialIcons } from "@expo/vector-icons";
809
+ import { getHeaderTitle } from '@react-navigation/elements';
810
+ import { createDrawerNavigator } from '@react-navigation/drawer';
811
+ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
812
+ import stackNavigations from './stack';
813
+ import bottomNavigations from './bottom';
814
+ import hostBottomNavigations from './host_bottom';
815
+ import drawerNavigations from './drawer';
816
+ import hostDrawerNavigations from './host_drawer';
817
+ const Stack = createNativeStackNavigator();
818
+ const Drawer = createDrawerNavigator();
819
+ const Tab = createBottomTabNavigator();
820
+ `;
821
+ rootComponent += `
822
+ const TabNavigator = () => {
823
+ const settings = useSelector((state: any) => state.settings);
824
+ const initialRouteName = ${JSON.stringify(initialRouteName)};
825
+ let defaultScreenOptions = ${JSON.stringify(screenOptionsTab)};
826
+ const defaultHeaderProps = ${JSON.stringify(defaultHeaderProps || {})};
827
+ const defaultHeader = {${isShowDefalutHeader ? `header:(props:any)=><Header {...defaultHeaderProps} {...props} />` : ''}};
828
+
829
+ return (
830
+ <Tab.Navigator
831
+ initialRouteName={initialRouteName}
832
+ screenOptions={(props:any)=>({...props,...defaultScreenOptions,...{headerShown: false,header:()=>null},})}
833
+ ${customTabBarPath ? 'tabBar={props => <CustomTabBar {...props} />}' : ""}
834
+ >
835
+ {settings?.layout == 'host-bottom' ? hostBottomNavigations({ Tab }) : bottomNavigations({Tab})}
836
+ </Tab.Navigator>
837
+ )
838
+ }
839
+ const RootComponent = (props:any) => {
840
+ const initialRouteName = ${JSON.stringify(initialRouteName)};
841
+ const settings = useSelector((state: any) => state.settings);
842
+ let defaultScreenOptions = ${JSON.stringify(screenOptionsTab)};
843
+ const defaultHeaderProps = ${JSON.stringify(defaultHeaderProps || {})};
844
+ const defaultHeader = {${isShowDefalutHeader ? `header:(props:any)=><Header {...defaultHeaderProps} {...props} />` : ''}};
845
+ return (
846
+ <Drawer.Navigator
847
+ initialRouteName={${JSON.stringify(initialRouteName)}}
848
+ // screenOptions={${JSON.stringify(screenOptions)}}
849
+ screenOptions={({ route }) => ({ ...${JSON.stringify(screenOptions)} ,...{headerTitle:navigationRef?.isReady() && navigationRef?.getCurrentRoute()
850
+ ? navigationRef?.getCurrentOptions()?.title
851
+ ? navigationRef?.getCurrentOptions()?.headerTitle
852
+ : navigationRef?.getCurrentRoute()?.route?.name
853
+ : "Home",
854
+ ${customHeaderPath ? `header: (props:any) => {
855
+ const title = getHeaderTitle(props.options, props.route.name);
856
+ return <CustomHeader {...defaultHeaderProps} {...props} title={title} isMixedLayout={true} style={props.options.headerStyle} />;
857
+ }` : ""}
858
+
859
+ }})}
860
+ ${customDrawerPath ? 'drawerContent={(props) => <CustomDrawerContent {...props} showDefaultRoutes={true} />}' : ""}
861
+ >
862
+ <Drawer.Screen name="Layout" options={{title:"Home", drawerIcon: ({ color, size }: { color: any, size: any }) => (
863
+ <MaterialIcons name="home" size={24} color={color} />
864
+ ),}}
865
+ component={TabNavigator} />
866
+ {settings?.layout == 'host-bottom' ? hostDrawerNavigations({ Drawer }) : drawerNavigations({ Drawer })}
867
+ </Drawer.Navigator>
868
+ );
869
+ }
870
+ `;
871
+ }
872
+ appComponent += `
873
+ const AppNavigations = () => {
874
+ return (
875
+ <Stack.Navigator initialRouteName="${initialRouteName}">
876
+ <Stack.Screen
877
+ name="MainStack"
878
+ options={{ headerShown: false }}
879
+ component={RootComponent}
880
+ />
881
+ {stackNavigations({ Stack })}
882
+ </Stack.Navigator>
883
+ )
884
+ }
885
+
886
+ export default AppNavigations;
887
+ `;
888
+ appNavigation = importStatements + '\n' + rootComponent + '\n' + appComponent;
889
+ appNavigation = prettier.format(appNavigation, { parser: 'babel' });
890
+ const writeFileResponse = await writeFile(navigationDirPath, appNavigation);
891
+ if (writeFileResponse)
892
+ return true;
893
+ else
894
+ return false;
895
+ };
896
+ const generateAppNavigations = async ({ appDirPath, modules, initialRouteName = '', unauthenticatedComponentPath = null, customTabBarPath = null, customDrawerPath = null, customHeaderPath = null }) => {
897
+ const { layoutSettings } = await getLayoutConfig();
898
+ const layoutType = layoutSettings.layout || 'bottom';
899
+ const isAppRoutesGenerated = await generateAppRoutesJson({ appDirPath });
900
+ if (isAppRoutesGenerated) {
901
+ const isModuleTsFileGenerated = await generateModulesTsFile({ appDirPath, modules, initialRouteName });
902
+ if (isModuleTsFileGenerated) {
903
+ const isStackCreated = await generateStackNavigations({ appDirPath, modules, initialRouteName });
904
+ if (isStackCreated) {
905
+ if (layoutType == 'side') {
906
+ const isDrawerGenerated = await generateDrawerNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath });
907
+ if (isDrawerGenerated) {
908
+ const appNavigationGenerated = await generateAppNavigationFile({ appDirPath, customTabBarPath, customDrawerPath, customHeaderPath });
909
+ if (appNavigationGenerated)
910
+ return appNavigationGenerated;
911
+ else
912
+ return true;
913
+ }
914
+ else
915
+ return false;
916
+ }
917
+ else if (layoutType == 'bottom' || layoutType == 'host-bottom') {
918
+ const isBottomTabGenerated = await generateBottomTabNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath });
919
+ if (isBottomTabGenerated) {
920
+ const appNavigationGenerated = await generateAppNavigationFile({ appDirPath, customTabBarPath, customDrawerPath, customHeaderPath });
921
+ if (appNavigationGenerated)
922
+ return appNavigationGenerated;
923
+ else
924
+ return true;
925
+ }
926
+ else
927
+ return false;
928
+ }
929
+ else {
930
+ const isBottomTabDrawerGenerated = await generateBottomTabDrawerNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath });
931
+ if (isBottomTabDrawerGenerated) {
932
+ const appNavigationGenerated = await generateAppNavigationFile({ appDirPath, customTabBarPath, customDrawerPath, customHeaderPath });
933
+ if (appNavigationGenerated)
934
+ return appNavigationGenerated;
935
+ else
936
+ return true;
937
+ }
938
+ else
939
+ return false;
940
+ }
941
+ }
942
+ else
943
+ return false;
944
+ }
945
+ else
946
+ return false;
947
+ }
948
+ else
949
+ return false;
950
+ };
951
+ export { getReplacedRouteConfig, readJsonFile, getLayoutConfig, getModulesRouteConfig, generateAppRoutesJson, generateModulesTsFile, generateStackNavigations, generateDrawerNavigations, generateBottomTabNavigations, generateAppNavigations, };
952
+ //# sourceMappingURL=generateAppNavigations.mjs.map