@admin-layout/gluestack-ui-mobile 8.5.7-alpha.0 → 8.5.8-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.
@@ -0,0 +1,1304 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _GenerateMobileNavigations_instances, _GenerateMobileNavigations_layoutSettings, _GenerateMobileNavigations_appDirPath, _GenerateMobileNavigations_modules, _GenerateMobileNavigations_initialRouteName, _GenerateMobileNavigations_unauthenticatedComponentPath, _GenerateMobileNavigations_customTabBarPath, _GenerateMobileNavigations_customDrawerPath, _GenerateMobileNavigations_customHeaderPath, _GenerateMobileNavigations_readJsonFile, _GenerateMobileNavigations_getLayoutConfig, _GenerateMobileNavigations_execPromise, _GenerateMobileNavigations_renameFile, _GenerateMobileNavigations_writeFile, _GenerateMobileNavigations_makeDir, _GenerateMobileNavigations_getModulesRouteConfig, _GenerateMobileNavigations_resolveImportPath, _GenerateMobileNavigations_generateAppRoutesJson, _GenerateMobileNavigations_generateImportStatements, _GenerateMobileNavigations_generateModulesTsFile, _GenerateMobileNavigations_generateStackNavigations, _GenerateMobileNavigations_generateDrawerNavigationsFile, _GenerateMobileNavigations_generateDrawerNavigations, _GenerateMobileNavigations_generateBottomTabNavigationsFile, _GenerateMobileNavigations_generateBottomTabNavigations, _GenerateMobileNavigations_generateBottomTabDrawerNavigations, _GenerateMobileNavigations_generateAppNavigationFile, _GenerateMobileNavigations_setLayoutAndGenerateNavigation;
13
+ import * as fs from 'fs';
14
+ import path from 'path';
15
+ import prettier from 'prettier';
16
+ import { fileURLToPath } from 'url';
17
+ import { createRequire } from 'module';
18
+ import { exec as execCallback } from 'child_process';
19
+ import { getSortedNavigations } from '@common-stack/client-react/lib/route/react-navigation/get-navigation-utils.js';
20
+ import { getReplacedRouteConfig } from './getReplacedRouteConfig.js';
21
+ const require = createRequire(import.meta.url);
22
+ const __filename = fileURLToPath(import.meta.url);
23
+ const __dirname = path.dirname(__filename);
24
+ const configFilePath = path.join(__dirname, '../layout.json');
25
+ const appNavigationFileName = 'navigation.tsx';
26
+ const mainRoutesFileName = 'main_routes.json';
27
+ const modulesFileName = 'modules.ts';
28
+ const stacksDirPath = 'stack/index.tsx';
29
+ const drawerFilePath = 'drawer/index.tsx';
30
+ const hostDrawerFilePath = 'host_drawer/index.tsx';
31
+ const bottomFilePath = 'bottom/index.tsx';
32
+ const hostBottomFilePath = 'host_bottom/index.tsx';
33
+ export const readJsonFile = (filePath) => {
34
+ return new Promise((resolve, reject) => {
35
+ fs.readFile(filePath, 'utf8', (err, data) => {
36
+ if (err) {
37
+ return reject(err);
38
+ }
39
+ try {
40
+ const jsonData = JSON.parse(data);
41
+ resolve(jsonData);
42
+ }
43
+ catch (parseErr) {
44
+ reject(parseErr);
45
+ }
46
+ });
47
+ });
48
+ };
49
+ export const getLayoutConfig = async () => {
50
+ const layoutConfigFileData = await readJsonFile(configFilePath);
51
+ return layoutConfigFileData;
52
+ };
53
+ export class GenerateMobileNavigations {
54
+ constructor({ appDirPath, modules, initialRouteName = '', unauthenticatedComponentPath = null, customTabBarPath = null, customDrawerPath = null, customHeaderPath = null, }) {
55
+ _GenerateMobileNavigations_instances.add(this);
56
+ _GenerateMobileNavigations_layoutSettings.set(this, process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null);
57
+ _GenerateMobileNavigations_appDirPath.set(this, void 0);
58
+ _GenerateMobileNavigations_modules.set(this, void 0);
59
+ _GenerateMobileNavigations_initialRouteName.set(this, void 0);
60
+ _GenerateMobileNavigations_unauthenticatedComponentPath.set(this, void 0);
61
+ _GenerateMobileNavigations_customTabBarPath.set(this, void 0);
62
+ _GenerateMobileNavigations_customDrawerPath.set(this, void 0);
63
+ _GenerateMobileNavigations_customHeaderPath.set(this, void 0);
64
+ __classPrivateFieldSet(this, _GenerateMobileNavigations_layoutSettings, process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null, "f");
65
+ __classPrivateFieldSet(this, _GenerateMobileNavigations_appDirPath, appDirPath, "f");
66
+ __classPrivateFieldSet(this, _GenerateMobileNavigations_modules, modules, "f");
67
+ __classPrivateFieldSet(this, _GenerateMobileNavigations_initialRouteName, initialRouteName, "f");
68
+ __classPrivateFieldSet(this, _GenerateMobileNavigations_unauthenticatedComponentPath, unauthenticatedComponentPath, "f");
69
+ __classPrivateFieldSet(this, _GenerateMobileNavigations_customTabBarPath, customTabBarPath, "f");
70
+ __classPrivateFieldSet(this, _GenerateMobileNavigations_customDrawerPath, customDrawerPath, "f");
71
+ __classPrivateFieldSet(this, _GenerateMobileNavigations_customHeaderPath, customHeaderPath, "f");
72
+ }
73
+ async generateAppNavigations() {
74
+ return __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_setLayoutAndGenerateNavigation).call(this);
75
+ }
76
+ }
77
+ _GenerateMobileNavigations_layoutSettings = new WeakMap(), _GenerateMobileNavigations_appDirPath = new WeakMap(), _GenerateMobileNavigations_modules = new WeakMap(), _GenerateMobileNavigations_initialRouteName = new WeakMap(), _GenerateMobileNavigations_unauthenticatedComponentPath = new WeakMap(), _GenerateMobileNavigations_customTabBarPath = new WeakMap(), _GenerateMobileNavigations_customDrawerPath = new WeakMap(), _GenerateMobileNavigations_customHeaderPath = new WeakMap(), _GenerateMobileNavigations_instances = new WeakSet(), _GenerateMobileNavigations_readJsonFile = async function _GenerateMobileNavigations_readJsonFile(filePath) {
78
+ return readJsonFile(filePath);
79
+ }, _GenerateMobileNavigations_getLayoutConfig = async function _GenerateMobileNavigations_getLayoutConfig() {
80
+ return getLayoutConfig();
81
+ }, _GenerateMobileNavigations_execPromise = async function _GenerateMobileNavigations_execPromise(command) {
82
+ return new Promise(function (resolve, reject) {
83
+ execCallback(command, (error, stdout, stderr) => {
84
+ if (error) {
85
+ return resolve(false);
86
+ }
87
+ return resolve(true);
88
+ });
89
+ });
90
+ }, _GenerateMobileNavigations_renameFile = async function _GenerateMobileNavigations_renameFile(file, new_name) {
91
+ return new Promise((resolve) => {
92
+ fs.access(file, fs.constants.F_OK, (err) => {
93
+ if (err) {
94
+ resolve(false);
95
+ }
96
+ return fs.rename(file, new_name, (err) => {
97
+ if (err)
98
+ resolve(false);
99
+ resolve(true);
100
+ });
101
+ });
102
+ });
103
+ }, _GenerateMobileNavigations_writeFile = async function _GenerateMobileNavigations_writeFile(file, content) {
104
+ return new Promise((resolve) => {
105
+ return fs.writeFile(file, content, 'utf-8', (err) => {
106
+ if (err)
107
+ resolve(false);
108
+ resolve(true);
109
+ });
110
+ });
111
+ }, _GenerateMobileNavigations_makeDir = async function _GenerateMobileNavigations_makeDir(dirName) {
112
+ return new Promise((resolve) => {
113
+ return fs.mkdir(dirName, { recursive: true }, (err) => {
114
+ if (err)
115
+ resolve(false);
116
+ resolve(true);
117
+ });
118
+ });
119
+ }, _GenerateMobileNavigations_getModulesRouteConfig = async function _GenerateMobileNavigations_getModulesRouteConfig({ modules }) {
120
+ const allFilteredRoutes = [];
121
+ for (const pkg of modules) {
122
+ const pkgPath = require.resolve(pkg);
123
+ const pkgDirPath = path.dirname(pkgPath);
124
+ const pkgFile = path.join(pkgDirPath, 'routes.json');
125
+ if (fs.existsSync(pkgFile)) {
126
+ const fileModuleJSON = await import(pkgFile, { assert: { type: 'json' } });
127
+ if (fileModuleJSON.default) {
128
+ allFilteredRoutes.push([...fileModuleJSON.default]);
129
+ }
130
+ }
131
+ }
132
+ return allFilteredRoutes;
133
+ }, _GenerateMobileNavigations_resolveImportPath = async function _GenerateMobileNavigations_resolveImportPath(routeConfig, importPath) {
134
+ // Remove the '$.' part from the importPath to get the path within the JSON object
135
+ const path = importPath?.replace('$.', '') ?? null;
136
+ // Split the path into parts for nested property access
137
+ const parts = path?.split('.') ?? [];
138
+ // Traverse the routeConfig object to get the actual value
139
+ let value = routeConfig;
140
+ for (let part of parts) {
141
+ if (value && Object.prototype.hasOwnProperty.call(value, part)) {
142
+ value = value[part];
143
+ }
144
+ else {
145
+ // Return null or handle missing path
146
+ return null;
147
+ }
148
+ }
149
+ return value;
150
+ }, _GenerateMobileNavigations_generateAppRoutesJson = async function _GenerateMobileNavigations_generateAppRoutesJson({ appDirPath }) {
151
+ const parentDirPath = path.dirname(appDirPath);
152
+ const parentDirName = path.basename(parentDirPath);
153
+ const appDirName = path.basename(appDirPath);
154
+ // const tsFile = 'src/compute.ts';
155
+ // const outputDir = 'src/app';
156
+ const tsFile = `${parentDirName}/compute.ts`;
157
+ const outputDir = `${parentDirName}/${appDirName}`;
158
+ const tscCommand = `tsc ${tsFile} --outDir ${outputDir} --target es6 --module esnext --jsx react --allowSyntheticDefaultImports true --moduleResolution node --esModuleInterop true --forceConsistentCasingInFileNames true --skipLibCheck true`;
159
+ const mainRoutesJsFile = path.join(appDirPath, '/compute.js');
160
+ const mainRoutesMjsFile = path.join(appDirPath, '/compute.mjs');
161
+ const outputFile = path.join(appDirPath, `/${mainRoutesFileName}`);
162
+ const allFilteredRoutes = [];
163
+ try {
164
+ const execResult = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_execPromise).call(this, tscCommand);
165
+ if (execResult && fs.existsSync(mainRoutesJsFile)) {
166
+ const jsFiledata = fs.readFileSync(mainRoutesJsFile, 'utf8');
167
+ const noCommentsData = jsFiledata
168
+ .replace(/\/\/.*$/gm, '') // Remove single-line comments
169
+ .replace(/\/\*[\s\S]*?\*\//g, ''); // Remove multi-line comments
170
+ const noWhitespaceJsData = noCommentsData.replace(/\s+/g, '');
171
+ if (noWhitespaceJsData?.length == 0) {
172
+ const outPutDirName = path.dirname(outputFile);
173
+ const isDirCreated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_makeDir).call(this, outPutDirName);
174
+ if (isDirCreated) {
175
+ const writeFileResponse = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_writeFile).call(this, outputFile, JSON.stringify(allFilteredRoutes));
176
+ if (writeFileResponse) {
177
+ return true;
178
+ }
179
+ else
180
+ return false;
181
+ }
182
+ else
183
+ return false;
184
+ }
185
+ else {
186
+ const newFilePath = mainRoutesJsFile.replace('.js', '.mjs');
187
+ const renameFileResponse = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_renameFile).call(this, mainRoutesJsFile, newFilePath);
188
+ if (renameFileResponse) {
189
+ if (fs.existsSync(mainRoutesMjsFile)) {
190
+ // Dynamically import the JS file assuming it exports filteredRoutes
191
+ const module = await import(mainRoutesMjsFile); // file is already absolute
192
+ if (module.filteredRoutes) {
193
+ const newRoutes = module.filteredRoutes.map((filteredRoute) => {
194
+ const routConfig = Object.values(filteredRoute)[0];
195
+ const importPath = routConfig.component
196
+ .toString()
197
+ .match(/import\(['"](.*)['"]\)/)[1];
198
+ // routConfig.componentPath = `../.${importPath}`;
199
+ routConfig.componentPath = `.${importPath}.js`;
200
+ return { [routConfig.path]: routConfig };
201
+ });
202
+ allFilteredRoutes.push(...newRoutes);
203
+ const writeFileResponse = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_writeFile).call(this, outputFile, JSON.stringify(allFilteredRoutes, null, 2));
204
+ if (writeFileResponse) {
205
+ fs.unlinkSync(mainRoutesMjsFile);
206
+ return true;
207
+ }
208
+ else
209
+ return false;
210
+ }
211
+ }
212
+ else
213
+ return false;
214
+ }
215
+ else
216
+ return false;
217
+ }
218
+ }
219
+ else {
220
+ const outPutDirName = path.dirname(outputFile);
221
+ const isDirCreated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_makeDir).call(this, outPutDirName);
222
+ if (isDirCreated) {
223
+ const writeFileResponse = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_writeFile).call(this, outputFile, JSON.stringify(allFilteredRoutes));
224
+ if (writeFileResponse) {
225
+ return true;
226
+ }
227
+ else
228
+ return false;
229
+ }
230
+ else
231
+ return false;
232
+ }
233
+ // return true;
234
+ }
235
+ catch (error) {
236
+ console.error(`exec error: ${error.message}`);
237
+ const outPutDirName = path.dirname(outputFile);
238
+ const isDirCreated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_makeDir).call(this, outPutDirName);
239
+ if (isDirCreated) {
240
+ const writeFileResponse = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_writeFile).call(this, outputFile, JSON.stringify(allFilteredRoutes));
241
+ if (writeFileResponse) {
242
+ return true;
243
+ }
244
+ else
245
+ return false;
246
+ }
247
+ else
248
+ return false;
249
+ }
250
+ }, _GenerateMobileNavigations_generateImportStatements = async function _GenerateMobileNavigations_generateImportStatements({ modules, initialRouteName }) {
251
+ try {
252
+ const layoutSettings = __classPrivateFieldGet(this, _GenerateMobileNavigations_layoutSettings, "f");
253
+ const layoutConfigFileData = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_getLayoutConfig).call(this);
254
+ const hostRouteConfig = layoutConfigFileData['host-bottom'];
255
+ const hostRouteKey = Object.keys(hostRouteConfig)[1];
256
+ const hostLayout = hostRouteConfig[hostRouteKey];
257
+ let importStatements = '';
258
+ let moduleNames = '';
259
+ let moduleRouteConfig = '';
260
+ let moduleNumber = 0;
261
+ importStatements += `import React,{useState} from 'react';\n`;
262
+ importStatements += `import {Feature} from '@common-stack/client-react/lib/connector/connector.native.js';\n`;
263
+ importStatements += `import { useSelector, useDispatch } from 'react-redux';\n`;
264
+ importStatements += `import { CHANGE_SETTINGS_ACTION } from '@admin-layout/client';\n`;
265
+ importStatements += `import {layoutRouteConfig,getReplacedRouteConfig } from '@admin-layout/gluestack-ui-mobile';\n`;
266
+ importStatements += `import mainRouteConfig from './main_routes.json';\n`;
267
+ modules?.forEach((packageName) => {
268
+ moduleNumber++;
269
+ importStatements += `import module${moduleNumber} from '${packageName}';\n`;
270
+ // moduleNames += `${moduleName}, `;
271
+ moduleNames += `module${moduleNumber}, `;
272
+ moduleRouteConfig += `...[module${moduleNumber}?.routeConfig], `;
273
+ });
274
+ //const layoutSettings = process.env.LAYOUT_SETTINGS ? JSON.parse(process.env.LAYOUT_SETTINGS) : null;
275
+ let classStructure = `
276
+ const features = new Feature(
277
+ ${moduleNames.trim()}
278
+ );
279
+
280
+ const mainAppRoutes = mainRouteConfig || [];
281
+
282
+ const appRoutes = [...[mainAppRoutes],${moduleRouteConfig}]?.filter((rc)=>rc.length)??[];
283
+
284
+ const featureRouteConfig = appRoutes?.flat(1)??features?.routeConfig;
285
+ features.routeConfig = featureRouteConfig;
286
+
287
+ export function useGetModules(){
288
+ const dispatch = useDispatch();
289
+ const defaultSettings = useSelector((state:any) => state.settings);
290
+ const initialRouteName = '${initialRouteName}';
291
+ const layoutSettings = ${JSON.stringify({ ...layoutSettings, hostLayout: hostLayout.key })}
292
+ const [appRouteConfig, setAppRouteConfig]:any = useState(null);
293
+
294
+ React.useEffect(() => {
295
+ setDefalutSettings();
296
+ }, []);
297
+
298
+
299
+ const setDefalutSettings = React.useCallback(()=>{
300
+ const config: any = {
301
+ ...defaultSettings,
302
+ ...layoutSettings,
303
+ };
304
+ dispatch({
305
+ type: CHANGE_SETTINGS_ACTION,
306
+ payload: config,
307
+ });
308
+ },[]);
309
+
310
+ React.useEffect(() => {
311
+ if (defaultSettings) {
312
+ const settingObj: any = { ...defaultSettings };
313
+ const layoutType: any = settingObj.layout;
314
+ const {replacedConfiguredRouteConfig} = getReplacedRouteConfig({
315
+ layoutType: layoutType,
316
+ routeConfig: appRoutes,
317
+ layoutConfigData: layoutRouteConfig,
318
+ initialRouteName,
319
+ });
320
+ if(replacedConfiguredRouteConfig){
321
+ const moduleRouteConfigObject = Object.assign({}, ...replacedConfiguredRouteConfig?.flat(1)??[]);
322
+ const replacedRouteConfig = Object.fromEntries(Object.entries(moduleRouteConfigObject));
323
+ const appReplacedRouteConfig = replacedRouteConfig ? Object.keys(replacedRouteConfig)?.map((k)=>({[k]:replacedRouteConfig[k]})) : [];
324
+
325
+ if (appReplacedRouteConfig) {
326
+ 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)??[];
327
+ 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)??[];
328
+ const featureRouteConfig = defaultSettings?.layout == 'host-bottom' ? hostRouteConfig:layoutRouteConfig;
329
+ // features.routeConfig = featureRouteConfig;
330
+ setAppRouteConfig(featureRouteConfig);
331
+ }
332
+ }
333
+ }
334
+ }, [defaultSettings]);
335
+
336
+ return {appRouteConfig};
337
+ }
338
+
339
+ export default features;
340
+ `.replace(/,(\s*)$/, ''); // Removes trailing comma
341
+ // Use Prettier to format the code
342
+ classStructure = prettier.format(classStructure, { parser: 'babel' });
343
+ const appFeatures = importStatements + '\n' + classStructure;
344
+ return { appFeatures };
345
+ }
346
+ catch (err) {
347
+ console.error('Error:', err);
348
+ return false;
349
+ }
350
+ }, _GenerateMobileNavigations_generateModulesTsFile = async function _GenerateMobileNavigations_generateModulesTsFile({ appDirPath, modules, initialRouteName }) {
351
+ const moduleTsFile = path.join(appDirPath, `/${modulesFileName}`);
352
+ const imports = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateImportStatements).call(this, { modules, initialRouteName });
353
+ const { appFeatures } = imports;
354
+ if (appFeatures) {
355
+ const writeFileResponse = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_writeFile).call(this, moduleTsFile, appFeatures);
356
+ if (writeFileResponse)
357
+ return true;
358
+ else
359
+ return false;
360
+ }
361
+ return false;
362
+ }, _GenerateMobileNavigations_generateStackNavigations = async function _GenerateMobileNavigations_generateStackNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) {
363
+ const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
364
+ const stackDirPath = path.join(appDirPath, `/${stacksDirPath}`);
365
+ const layoutSettings = __classPrivateFieldGet(this, _GenerateMobileNavigations_layoutSettings, "f");
366
+ const layoutConfigFileData = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_getLayoutConfig).call(this);
367
+ const layoutType = layoutSettings?.layout || 'bottom';
368
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
369
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
370
+ const appLayout = layoutRouteConfig[layoutRouteKey];
371
+ const modulesRouteConfig = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_getModulesRouteConfig).call(this, { modules: modules });
372
+ const mainRouteConfig = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_readJsonFile).call(this, mainRoutes);
373
+ const allRoutes = [...[mainRouteConfig ?? []], ...(modulesRouteConfig ?? [])];
374
+ const { replacedNavigationRouteConfig: routeConfig } = getReplacedRouteConfig({
375
+ layoutType: layoutType,
376
+ routeConfig: allRoutes,
377
+ layoutConfigData: layoutConfigFileData,
378
+ initialRouteName: initialRouteName,
379
+ });
380
+ const keyToReplace = appLayout.key || 'bottom_tab';
381
+ const stackRouteConfig = routeConfig
382
+ ?.map((rArray) => rArray
383
+ ?.map((r) => {
384
+ const route = r[Object.keys(r)[0]];
385
+ const path = route.path;
386
+ const isExcluded = path === '/' ||
387
+ path.startsWith(`/${keyToReplace}`) ||
388
+ path.startsWith(`/:orgName/${keyToReplace}`) ||
389
+ path.startsWith('/host_tab') ||
390
+ path.startsWith('/:orgName/host_tab');
391
+ return isExcluded ? false : route;
392
+ })
393
+ ?.filter((route) => route !== false) ?? [])
394
+ ?.filter((subArray) => subArray.length > 0) ?? [];
395
+ let moduleNumber = 0;
396
+ let importStatements = '';
397
+ let moduleContent = '';
398
+ let moduleRender = '';
399
+ let stackNavigator = '';
400
+ let customHeaderNames = '';
401
+ let customHeaderPaths = '';
402
+ let customUnauthenticatedComponentPaths = '';
403
+ let customUnauthenticatedComponentNames = '';
404
+ const regex = /\.(tsx|ts|jsx|js)$/i;
405
+ importStatements += `import * as React from 'react';\n`;
406
+ importStatements += `import {AuthWrapper} from '@admin-layout/gluestack-ui-mobile';\n`;
407
+ if (unauthenticatedComponentPath)
408
+ importStatements += `import UnauthenticatedComponent from '${unauthenticatedComponentPath}';\n`;
409
+ for (const pkg of stackRouteConfig) {
410
+ moduleContent += `<Stack.Group>`;
411
+ for (const pkgRouteConfig of pkg) {
412
+ moduleNumber++;
413
+ let customHeaderName = null;
414
+ const customHeaderComponentPath = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_resolveImportPath).call(this, pkgRouteConfig, pkgRouteConfig?.customHeader?.component);
415
+ if (pkgRouteConfig?.customHeader &&
416
+ Object.keys(pkgRouteConfig?.customHeader)?.length &&
417
+ customHeaderComponentPath) {
418
+ customHeaderPaths += `${customHeaderComponentPath},`;
419
+ customHeaderName =
420
+ `${pkgRouteConfig?.customHeader?.name ?? `CustomHeader${moduleNumber}`}` ||
421
+ `CustomHeader${moduleNumber}`;
422
+ customHeaderNames += `${customHeaderName},`;
423
+ }
424
+ let customUnauthenticatedComponentName = null;
425
+ const customUnauthenticatedComponentPath = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_resolveImportPath).call(this, pkgRouteConfig, pkgRouteConfig?.unauthenticatedComponent);
426
+ if (pkgRouteConfig?.unauthenticatedComponent && customUnauthenticatedComponentPath) {
427
+ customUnauthenticatedComponentPaths += `${customUnauthenticatedComponentPath},`;
428
+ customUnauthenticatedComponentName = `UnauthenticatedComponent${moduleNumber}`;
429
+ customUnauthenticatedComponentNames += `${customUnauthenticatedComponentName},`;
430
+ }
431
+ importStatements += `import Component${moduleNumber} from '${pkgRouteConfig.componentPath}';\n`;
432
+ const options = JSON.stringify({ ...(pkgRouteConfig?.props?.options || {}) });
433
+ moduleContent += `<Stack.Screen
434
+ key="${pkgRouteConfig.key}"
435
+ name="${pkgRouteConfig.name}"
436
+ initialParams={${JSON.stringify(pkgRouteConfig?.props?.initialParams || {})}}
437
+ options={{...${options},...{${pkgRouteConfig?.customHeader &&
438
+ Object.keys(pkgRouteConfig.customHeader)?.length &&
439
+ customHeaderComponentPath
440
+ ? `header: (props: any) => <${customHeaderName} {...props} {...${JSON.stringify(pkgRouteConfig?.customHeader?.props ?? '')}} />`
441
+ : ''}}}}
442
+ >{(props:any) => <AuthWrapper
443
+ auth={${pkgRouteConfig?.props?.initialParams?.auth ?? false}}
444
+ component={<Component${moduleNumber} {...props} />}
445
+ ${pkgRouteConfig?.unauthenticatedComponent && customUnauthenticatedComponentPath
446
+ ? `unauthenticatedComponent={<${customUnauthenticatedComponentName}/>}`
447
+ : unauthenticatedComponentPath
448
+ ? 'unauthenticatedComponent={<UnauthenticatedComponent/>}'
449
+ : ''}
450
+ ${pkgRouteConfig?.withLifeCycle
451
+ ? `withLifeCycle={${JSON.stringify(pkgRouteConfig?.withLifeCycle)}}`
452
+ : ''}
453
+ ${pkgRouteConfig?.withInteraction
454
+ ? `withInteraction={${JSON.stringify(pkgRouteConfig?.withInteraction)}}`
455
+ : ''}
456
+ ${pkgRouteConfig?.withLifeCycleInteraction
457
+ ? `withLifeCycleInteraction={${JSON.stringify(pkgRouteConfig?.withLifeCycleInteraction)}}`
458
+ : ''}
459
+ />}</Stack.Screen>`;
460
+ }
461
+ if (customHeaderPaths && customHeaderPaths?.length) {
462
+ const uniqueHeaderNames = [...new Set(customHeaderNames.split(','))]?.filter((str) => str?.length);
463
+ const uniqueHeaderPaths = [...new Set(customHeaderPaths.split(','))]?.filter((str) => str?.length);
464
+ uniqueHeaderPaths?.forEach(function (hPath, i) {
465
+ const impHeaderName = uniqueHeaderNames?.[i] ?? `customHeader${i}`;
466
+ importStatements += `import ${impHeaderName} from '${hPath}';\n`;
467
+ });
468
+ }
469
+ if (customUnauthenticatedComponentPaths && customUnauthenticatedComponentPaths?.length) {
470
+ const uniqueUnauthenticatedComponentNames = [
471
+ ...new Set(customUnauthenticatedComponentNames.split(',')),
472
+ ]?.filter((str) => str?.length);
473
+ const uniqueUnauthenticatedComponentPaths = [
474
+ ...new Set(customUnauthenticatedComponentPaths.split(',')),
475
+ ]?.filter((str) => str?.length);
476
+ uniqueUnauthenticatedComponentPaths?.forEach(function (unCompPath, i) {
477
+ const impUnauthenticatedName = uniqueUnauthenticatedComponentNames?.[i] ?? `UnauthenticatedComponent${i}`;
478
+ importStatements += `import ${impUnauthenticatedName} from '${unCompPath}';\n`;
479
+ });
480
+ }
481
+ moduleContent += `</Stack.Group>`;
482
+ moduleRender = `export default ({Stack,...rest}:any) => { return (<>${moduleContent}</>)}`;
483
+ }
484
+ stackNavigator = importStatements + '\n' + moduleRender;
485
+ if (stackNavigator) {
486
+ let stackNavigation = stackNavigator;
487
+ stackNavigation = prettier.format(stackNavigation, { parser: 'babel' });
488
+ const stackDirName = path.dirname(stackDirPath);
489
+ const isDirCreated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_makeDir).call(this, stackDirName);
490
+ if (isDirCreated) {
491
+ const writeFileResponse = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_writeFile).call(this, stackDirPath, stackNavigation);
492
+ if (writeFileResponse)
493
+ return true;
494
+ else
495
+ return false;
496
+ }
497
+ else
498
+ return false;
499
+ }
500
+ else
501
+ return false;
502
+ }, _GenerateMobileNavigations_generateDrawerNavigationsFile = async function _GenerateMobileNavigations_generateDrawerNavigationsFile({ drawerConfig, unauthenticatedComponentPath, drawerDirPath }) {
503
+ let moduleNumber = 0;
504
+ let importStatements = '';
505
+ let moduleContent = '';
506
+ let moduleRender = '';
507
+ let moduleNavigation = '';
508
+ let icons = '';
509
+ let customHeaderNames = '';
510
+ let customHeaderPaths = '';
511
+ let customUnauthenticatedComponentPaths = '';
512
+ let customUnauthenticatedComponentNames = '';
513
+ const regex = /\.(tsx|ts|jsx|js)$/i;
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 drawerConfig) {
519
+ moduleNumber++;
520
+ if (pkgRouteConfig?.icon && Object.keys(pkgRouteConfig.icon)?.length && pkgRouteConfig?.icon?.name) {
521
+ icons += `${pkgRouteConfig?.icon?.name},`;
522
+ }
523
+ let customHeaderName = null;
524
+ const customHeaderComponentPath = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_resolveImportPath).call(this, pkgRouteConfig, pkgRouteConfig?.customHeader?.component);
525
+ if (pkgRouteConfig?.customHeader &&
526
+ Object.keys(pkgRouteConfig?.customHeader)?.length &&
527
+ customHeaderComponentPath) {
528
+ customHeaderPaths += `${customHeaderComponentPath},`;
529
+ customHeaderName =
530
+ `${pkgRouteConfig?.customHeader?.name ?? `CustomHeader${moduleNumber}`}` ||
531
+ `CustomHeader${moduleNumber}`;
532
+ customHeaderNames += `${customHeaderName},`;
533
+ }
534
+ let customUnauthenticatedComponentName = null;
535
+ const customUnauthenticatedComponentPath = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_resolveImportPath).call(this, pkgRouteConfig, pkgRouteConfig?.unauthenticatedComponent);
536
+ if (pkgRouteConfig?.unauthenticatedComponent && customUnauthenticatedComponentPath) {
537
+ customUnauthenticatedComponentPaths += `${customUnauthenticatedComponentPath},`;
538
+ customUnauthenticatedComponentName = `UnauthenticatedComponent${moduleNumber}`;
539
+ customUnauthenticatedComponentNames += `${customUnauthenticatedComponentName},`;
540
+ }
541
+ const options = JSON.stringify({ ...(pkgRouteConfig?.props?.options || {}) });
542
+ importStatements += `import Component${moduleNumber} from '${pkgRouteConfig.componentPath}';\n`;
543
+ moduleContent += `<Drawer.Screen
544
+ key="${pkgRouteConfig.key}"
545
+ name="${pkgRouteConfig.name}"
546
+ //component={Component${moduleNumber}}
547
+ initialParams={${JSON.stringify(pkgRouteConfig?.props?.initialParams || {})}}
548
+ options={{...${options},...{${pkgRouteConfig?.icon && Object.keys(pkgRouteConfig.icon)?.length && pkgRouteConfig?.icon?.name
549
+ ? `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'}} />`
550
+ : ''}
551
+ ${pkgRouteConfig?.customHeader &&
552
+ Object.keys(pkgRouteConfig.customHeader)?.length &&
553
+ customHeaderComponentPath
554
+ ? `header: (props: any) => <${customHeaderName} {...props} {...${JSON.stringify(pkgRouteConfig?.customHeader?.props ?? '')}} />`
555
+ : ''}}}}
556
+ >{(props:any) => <AuthWrapper
557
+ auth={${pkgRouteConfig?.props?.initialParams?.auth ?? false}}
558
+ component={<Component${moduleNumber} {...props} />}
559
+ ${pkgRouteConfig?.unauthenticatedComponent && customUnauthenticatedComponentPath
560
+ ? `unauthenticatedComponent={<${customUnauthenticatedComponentName}/>}`
561
+ : unauthenticatedComponentPath
562
+ ? 'unauthenticatedComponent={<UnauthenticatedComponent/>}'
563
+ : ''}
564
+ ${pkgRouteConfig?.withLifeCycle
565
+ ? `withLifeCycle={${JSON.stringify(pkgRouteConfig?.withLifeCycle)}}`
566
+ : ''}
567
+ ${pkgRouteConfig?.withInteraction
568
+ ? `withInteraction={${JSON.stringify(pkgRouteConfig?.withInteraction)}}`
569
+ : ''}
570
+ ${pkgRouteConfig?.withLifeCycleInteraction
571
+ ? `withLifeCycleInteraction={${JSON.stringify(pkgRouteConfig?.withLifeCycleInteraction)}}`
572
+ : ''}
573
+ />}</Drawer.Screen>`;
574
+ }
575
+ if (icons && icons?.length) {
576
+ const uniqueIcons = [...new Set(icons.split(','))].join(',');
577
+ importStatements += `import { ${uniqueIcons} } from '@expo/vector-icons';\n`;
578
+ }
579
+ if (customHeaderPaths && customHeaderPaths?.length) {
580
+ const uniqueHeaderNames = [...new Set(customHeaderNames.split(','))]?.filter((str) => str?.length);
581
+ const uniqueHeaderPaths = [...new Set(customHeaderPaths.split(','))]?.filter((str) => str?.length);
582
+ uniqueHeaderPaths?.forEach(function (hPath, i) {
583
+ const impHeaderName = uniqueHeaderNames?.[i] ?? `customHeader${i}`;
584
+ importStatements += `import ${impHeaderName} from '${hPath}';\n`;
585
+ });
586
+ }
587
+ if (customUnauthenticatedComponentPaths && customUnauthenticatedComponentPaths?.length) {
588
+ const uniqueUnauthenticatedComponentNames = [
589
+ ...new Set(customUnauthenticatedComponentNames.split(',')),
590
+ ]?.filter((str) => str?.length);
591
+ const uniqueUnauthenticatedComponentPaths = [
592
+ ...new Set(customUnauthenticatedComponentPaths.split(',')),
593
+ ]?.filter((str) => str?.length);
594
+ uniqueUnauthenticatedComponentPaths?.forEach(function (unCompPath, i) {
595
+ const impUnauthenticatedName = uniqueUnauthenticatedComponentNames?.[i] ?? `UnauthenticatedComponent${i}`;
596
+ importStatements += `import ${impUnauthenticatedName} from '${unCompPath}';\n`;
597
+ });
598
+ }
599
+ moduleRender = `export default ({Drawer,...rest}:any) => { return (<>${moduleContent}</>)}`;
600
+ moduleNavigation = importStatements + '\n' + moduleRender;
601
+ const drawerNavigator = moduleNavigation;
602
+ if (drawerNavigator) {
603
+ let drawerNavigation = drawerNavigator;
604
+ drawerNavigation = prettier.format(drawerNavigation, { parser: 'babel' });
605
+ const drawerDirName = path.dirname(drawerDirPath);
606
+ const isDirCreated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_makeDir).call(this, drawerDirName);
607
+ if (isDirCreated) {
608
+ const writeFileResponse = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_writeFile).call(this, drawerDirPath, drawerNavigation);
609
+ if (writeFileResponse)
610
+ return true;
611
+ else
612
+ return false;
613
+ }
614
+ else
615
+ return false;
616
+ }
617
+ return false;
618
+ }, _GenerateMobileNavigations_generateDrawerNavigations = async function _GenerateMobileNavigations_generateDrawerNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) {
619
+ const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
620
+ const drawerDirPath = path.join(appDirPath, `/${drawerFilePath}`);
621
+ const hostDirPath = path.join(appDirPath, `/${hostDrawerFilePath}`);
622
+ const layoutSettings = __classPrivateFieldGet(this, _GenerateMobileNavigations_layoutSettings, "f");
623
+ const layoutConfigFileData = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_getLayoutConfig).call(this);
624
+ const layoutType = 'side';
625
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
626
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
627
+ const appLayout = layoutRouteConfig[layoutRouteKey];
628
+ const hostRouteConfig = layoutConfigFileData['host-bottom'];
629
+ const hostRouteKey = Object.keys(hostRouteConfig)[1];
630
+ const hostLayout = hostRouteConfig[hostRouteKey];
631
+ const modulesRouteConfig = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_getModulesRouteConfig).call(this, { modules: modules });
632
+ const mainRouteConfig = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_readJsonFile).call(this, mainRoutes);
633
+ const allRoutes = [...[mainRouteConfig ?? []], ...(modulesRouteConfig ?? [])];
634
+ const { replacedNavigationRouteConfig: routeConfig } = getReplacedRouteConfig({
635
+ layoutType: layoutType,
636
+ routeConfig: allRoutes,
637
+ layoutConfigData: layoutConfigFileData,
638
+ initialRouteName: initialRouteName,
639
+ });
640
+ const keyToReplace = appLayout.key || 'bottom_tab';
641
+ const keyToReplaceHost = hostLayout.key || 'host_tab';
642
+ const moduleRouteConfigObject = Object.assign({}, ...(routeConfig?.flat(1) ?? []));
643
+ const configuredRoutes = await getSortedNavigations('/', moduleRouteConfigObject);
644
+ const layoutBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r) => r?.key == keyToReplace);
645
+ const hostBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r) => r?.key == keyToReplaceHost);
646
+ const drawerConfig = layoutBottomTabRouteConfig?.[0]?.children?.sort((a, b) => {
647
+ if (a?.props?.options?.priority === undefined)
648
+ return 1; // Push items with missing 'id' to the end
649
+ if (b?.props?.options?.priority === undefined)
650
+ return -1;
651
+ return a?.props?.options?.priority - b?.props?.options?.priority;
652
+ }) ?? [];
653
+ const hostDrawerConfig = hostBottomTabRouteConfig?.[0]?.children?.sort((a, b) => {
654
+ if (a?.props?.options?.priority === undefined)
655
+ return 1; // Push items with missing 'id' to the end
656
+ if (b?.props?.options?.priority === undefined)
657
+ return -1;
658
+ return a?.props?.options?.priority - b?.props?.options?.priority;
659
+ }) ?? [];
660
+ if (layoutSettings?.layout == 'side') {
661
+ if (drawerConfig) {
662
+ const drawerNavigation = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateDrawerNavigationsFile).call(this, {
663
+ drawerConfig: drawerConfig,
664
+ unauthenticatedComponentPath,
665
+ drawerDirPath: drawerDirPath,
666
+ });
667
+ if (drawerNavigation)
668
+ await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateDrawerNavigationsFile).call(this, {
669
+ drawerConfig: hostDrawerConfig,
670
+ unauthenticatedComponentPath,
671
+ drawerDirPath: hostDirPath,
672
+ });
673
+ return true;
674
+ }
675
+ else {
676
+ if (hostDrawerConfig) {
677
+ const isDrawerGenerated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateDrawerNavigationsFile).call(this, {
678
+ drawerConfig: hostDrawerConfig,
679
+ unauthenticatedComponentPath,
680
+ drawerDirPath: hostDirPath,
681
+ });
682
+ return isDrawerGenerated;
683
+ }
684
+ else
685
+ return false;
686
+ }
687
+ }
688
+ else
689
+ return false;
690
+ }, _GenerateMobileNavigations_generateBottomTabNavigationsFile = async function _GenerateMobileNavigations_generateBottomTabNavigationsFile({ bottomTabConfig, unauthenticatedComponentPath, bottomDirPath, mixLayout = null, }) {
691
+ let moduleNumber = 0;
692
+ let importStatements = '';
693
+ let moduleContent = '';
694
+ let moduleRender = '';
695
+ let moduleNavigation = '';
696
+ let icons = '';
697
+ let customHeaderNames = '';
698
+ let customHeaderPaths = '';
699
+ let customUnauthenticatedComponentPaths = '';
700
+ let customUnauthenticatedComponentNames = '';
701
+ const regex = /\.(tsx|ts|jsx|js)$/i;
702
+ importStatements += `import * as React from 'react';\n`;
703
+ importStatements += `import {AuthWrapper} from '@admin-layout/gluestack-ui-mobile';\n`;
704
+ if (unauthenticatedComponentPath)
705
+ importStatements += `import UnauthenticatedComponent from '${unauthenticatedComponentPath}';\n`;
706
+ for (const pkgRouteConfig of bottomTabConfig) {
707
+ moduleNumber++;
708
+ if (pkgRouteConfig?.icon && Object.keys(pkgRouteConfig.icon)?.length && pkgRouteConfig?.icon?.name) {
709
+ icons += `${pkgRouteConfig?.icon?.name},`;
710
+ }
711
+ let customHeaderName = null;
712
+ const customHeaderComponentPath = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_resolveImportPath).call(this, pkgRouteConfig, pkgRouteConfig?.customHeader?.component);
713
+ if (pkgRouteConfig?.customHeader &&
714
+ Object.keys(pkgRouteConfig?.customHeader)?.length &&
715
+ customHeaderComponentPath) {
716
+ customHeaderPaths += `${customHeaderComponentPath},`;
717
+ customHeaderName =
718
+ `${pkgRouteConfig?.customHeader?.name ?? `CustomHeader${moduleNumber}`}` ||
719
+ `CustomHeader${moduleNumber}`;
720
+ customHeaderNames += `${customHeaderName},`;
721
+ }
722
+ let customUnauthenticatedComponentName = null;
723
+ const customUnauthenticatedComponentPath = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_resolveImportPath).call(this, pkgRouteConfig, pkgRouteConfig?.unauthenticatedComponent);
724
+ if (pkgRouteConfig?.unauthenticatedComponent && customUnauthenticatedComponentPath) {
725
+ customUnauthenticatedComponentPaths += `${customUnauthenticatedComponentPath},`;
726
+ customUnauthenticatedComponentName = `UnauthenticatedComponent${moduleNumber}`;
727
+ customUnauthenticatedComponentNames += `${customUnauthenticatedComponentName},`;
728
+ }
729
+ const options = JSON.stringify({
730
+ ...pkgRouteConfig?.props?.options,
731
+ headerShown: mixLayout ? false : pkgRouteConfig?.props?.options?.headerShown,
732
+ } || { headerShown: mixLayout ? false : true });
733
+ importStatements += `import Component${moduleNumber} from '${pkgRouteConfig.componentPath}';\n`;
734
+ moduleContent += `<Tab.Screen
735
+ key="${pkgRouteConfig.key}"
736
+ name="${pkgRouteConfig.name}"
737
+ //component={Component${moduleNumber}}
738
+ initialParams={${JSON.stringify(pkgRouteConfig?.props?.initialParams || {})}}
739
+ options={{...${options},...{${pkgRouteConfig?.icon && Object.keys(pkgRouteConfig.icon)?.length && pkgRouteConfig?.icon?.name
740
+ ? `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'}} />`
741
+ : ''}
742
+ ${pkgRouteConfig?.customHeader &&
743
+ Object.keys(pkgRouteConfig.customHeader)?.length &&
744
+ customHeaderComponentPath
745
+ ? `,header: (props: any) => <${customHeaderName} {...props} {...${JSON.stringify(pkgRouteConfig?.customHeader?.props ?? '')}} />`
746
+ : ''}
747
+ }}}
748
+ >{(props:any) => <AuthWrapper
749
+ auth={${pkgRouteConfig?.props?.initialParams?.auth ?? false}}
750
+ component={<Component${moduleNumber} {...props} />}
751
+ ${pkgRouteConfig?.unauthenticatedComponent && customUnauthenticatedComponentPath
752
+ ? `unauthenticatedComponent={<${customUnauthenticatedComponentName}/>}`
753
+ : unauthenticatedComponentPath
754
+ ? 'unauthenticatedComponent={<UnauthenticatedComponent/>}'
755
+ : ''}
756
+ ${pkgRouteConfig?.withLifeCycle
757
+ ? `withLifeCycle={${JSON.stringify(pkgRouteConfig?.withLifeCycle)}}`
758
+ : ''}
759
+ ${pkgRouteConfig?.withInteraction
760
+ ? `withInteraction={${JSON.stringify(pkgRouteConfig?.withInteraction)}}`
761
+ : ''}
762
+ ${pkgRouteConfig?.withLifeCycleInteraction
763
+ ? `withLifeCycleInteraction={${JSON.stringify(pkgRouteConfig?.withLifeCycleInteraction)}}`
764
+ : ''}
765
+ />}
766
+ </Tab.Screen>`;
767
+ }
768
+ if (icons && icons?.length) {
769
+ const uniqueIcons = [...new Set(icons.split(','))].join(',');
770
+ importStatements += `import { ${uniqueIcons} } from '@expo/vector-icons';\n`;
771
+ }
772
+ if (customHeaderPaths && customHeaderPaths?.length) {
773
+ const uniqueHeaderNames = [...new Set(customHeaderNames.split(','))]?.filter((str) => str?.length);
774
+ const uniqueHeaderPaths = [...new Set(customHeaderPaths.split(','))]?.filter((str) => str?.length);
775
+ uniqueHeaderPaths?.forEach(function (hPath, i) {
776
+ const impHeaderName = uniqueHeaderNames?.[i] ?? `customHeader${i}`;
777
+ importStatements += `import ${impHeaderName} from '${hPath}';\n`;
778
+ });
779
+ }
780
+ if (customUnauthenticatedComponentPaths && customUnauthenticatedComponentPaths?.length) {
781
+ const uniqueUnauthenticatedComponentNames = [
782
+ ...new Set(customUnauthenticatedComponentNames.split(',')),
783
+ ]?.filter((str) => str?.length);
784
+ const uniqueUnauthenticatedComponentPaths = [
785
+ ...new Set(customUnauthenticatedComponentPaths.split(',')),
786
+ ]?.filter((str) => str?.length);
787
+ uniqueUnauthenticatedComponentPaths?.forEach(function (unCompPath, i) {
788
+ const impUnauthenticatedName = uniqueUnauthenticatedComponentNames?.[i] ?? `UnauthenticatedComponent${i}`;
789
+ importStatements += `import ${impUnauthenticatedName} from '${unCompPath}';\n`;
790
+ });
791
+ }
792
+ moduleRender = `export default ({Tab,...rest}:any) => { return (<>${moduleContent}</>)}`;
793
+ moduleNavigation = importStatements + '\n' + moduleRender;
794
+ const bottomTabNavigator = moduleNavigation;
795
+ if (bottomTabNavigator) {
796
+ let bottomTabNavigation = bottomTabNavigator;
797
+ bottomTabNavigation = prettier.format(bottomTabNavigation, { parser: 'babel' });
798
+ const bottomDirName = path.dirname(bottomDirPath);
799
+ const isDirCreated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_makeDir).call(this, bottomDirName);
800
+ if (isDirCreated) {
801
+ const writeFileResponse = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_writeFile).call(this, bottomDirPath, bottomTabNavigation);
802
+ if (writeFileResponse)
803
+ return true;
804
+ else
805
+ return false;
806
+ }
807
+ else
808
+ return false;
809
+ }
810
+ return false;
811
+ }, _GenerateMobileNavigations_generateBottomTabNavigations = async function _GenerateMobileNavigations_generateBottomTabNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) {
812
+ const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
813
+ const bottomDirPath = path.join(appDirPath, `/${bottomFilePath}`);
814
+ const hostBottomDirPath = path.join(appDirPath, `/${hostBottomFilePath}`);
815
+ const layoutSettings = __classPrivateFieldGet(this, _GenerateMobileNavigations_layoutSettings, "f");
816
+ const layoutConfigFileData = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_getLayoutConfig).call(this);
817
+ const layoutType = layoutSettings?.layout ?? 'bottom';
818
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
819
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
820
+ const appLayout = layoutRouteConfig[layoutRouteKey];
821
+ const hostRouteConfig = layoutConfigFileData['host-bottom'];
822
+ const hostRouteKey = Object.keys(hostRouteConfig)[1];
823
+ const hostLayout = hostRouteConfig[hostRouteKey];
824
+ const mixLayoutRouteKey = Object.keys(layoutRouteConfig)?.[2] || null;
825
+ const mixLayout = mixLayoutRouteKey ? layoutRouteConfig[mixLayoutRouteKey] : null;
826
+ const modulesRouteConfig = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_getModulesRouteConfig).call(this, { modules: modules });
827
+ const mainRouteConfig = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_readJsonFile).call(this, mainRoutes);
828
+ const allRoutes = [...[mainRouteConfig ?? []], ...(modulesRouteConfig ?? [])];
829
+ const { replacedNavigationRouteConfig: routeConfig } = getReplacedRouteConfig({
830
+ layoutType: layoutType,
831
+ routeConfig: allRoutes,
832
+ layoutConfigData: layoutConfigFileData,
833
+ initialRouteName: initialRouteName,
834
+ });
835
+ const keyToReplace = appLayout.key || 'bottom_tab';
836
+ const keyToReplaceHost = hostLayout.key || 'host_tab';
837
+ const moduleRouteConfigObject = Object.assign({}, ...(routeConfig?.flat(1) ?? []));
838
+ const configuredRoutes = await getSortedNavigations('/', moduleRouteConfigObject);
839
+ const layoutBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r) => r?.key == keyToReplace);
840
+ const hostBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r) => r?.key == keyToReplaceHost);
841
+ const bottomTabConfig = layoutBottomTabRouteConfig?.[0]?.children?.sort((a, b) => {
842
+ if (a?.props?.options?.priority === undefined)
843
+ return 1; // Push items with missing 'id' to the end
844
+ if (b?.props?.options?.priority === undefined)
845
+ return -1;
846
+ return a?.props?.options?.priority - b?.props?.options?.priority;
847
+ }) ?? [];
848
+ const hostBottomTabConfig = hostBottomTabRouteConfig?.[0]?.children?.sort((a, b) => {
849
+ if (a?.props?.options?.priority === undefined)
850
+ return 1; // Push items with missing 'id' to the end
851
+ if (b?.props?.options?.priority === undefined)
852
+ return -1;
853
+ return a?.props?.options?.priority - b?.props?.options?.priority;
854
+ }) ?? [];
855
+ if (layoutType == 'bottom' || layoutType == 'mixSide') {
856
+ if (bottomTabConfig) {
857
+ const drawerNavigation = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateBottomTabNavigationsFile).call(this, {
858
+ bottomTabConfig: bottomTabConfig,
859
+ unauthenticatedComponentPath,
860
+ bottomDirPath: bottomDirPath,
861
+ mixLayout,
862
+ });
863
+ if (drawerNavigation)
864
+ await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateBottomTabNavigationsFile).call(this, {
865
+ bottomTabConfig: hostBottomTabConfig,
866
+ unauthenticatedComponentPath,
867
+ bottomDirPath: hostBottomDirPath,
868
+ mixLayout,
869
+ });
870
+ return true;
871
+ }
872
+ else {
873
+ if (hostBottomTabConfig) {
874
+ const isHostGenerated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateBottomTabNavigationsFile).call(this, {
875
+ bottomTabConfig: hostBottomTabConfig,
876
+ unauthenticatedComponentPath,
877
+ bottomDirPath: hostBottomDirPath,
878
+ mixLayout,
879
+ });
880
+ return isHostGenerated;
881
+ }
882
+ else
883
+ return false;
884
+ }
885
+ }
886
+ else
887
+ return false;
888
+ }, _GenerateMobileNavigations_generateBottomTabDrawerNavigations = async function _GenerateMobileNavigations_generateBottomTabDrawerNavigations({ appDirPath, modules, initialRouteName, unauthenticatedComponentPath }) {
889
+ const mainRoutes = path.join(appDirPath, `/${mainRoutesFileName}`);
890
+ const bottomDirPath = path.join(appDirPath, `/${bottomFilePath}`);
891
+ const hostBottomDirPath = path.join(appDirPath, `/${hostBottomFilePath}`);
892
+ const drawerDirPath = path.join(appDirPath, `/${drawerFilePath}`);
893
+ const hostDirPath = path.join(appDirPath, `/${hostDrawerFilePath}`);
894
+ const layoutSettings = __classPrivateFieldGet(this, _GenerateMobileNavigations_layoutSettings, "f");
895
+ const layoutConfigFileData = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_getLayoutConfig).call(this);
896
+ const layoutType = layoutSettings?.layout ?? 'bottom';
897
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
898
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
899
+ const appLayout = layoutRouteConfig[layoutRouteKey];
900
+ const hostRouteConfig = layoutConfigFileData['host-bottom'];
901
+ const hostRouteKey = Object.keys(hostRouteConfig)[1];
902
+ const hostLayout = hostRouteConfig[hostRouteKey];
903
+ const mixLayoutRouteKey = Object.keys(layoutRouteConfig)?.[2] || null;
904
+ const mixLayout = mixLayoutRouteKey ? layoutRouteConfig[mixLayoutRouteKey] : null;
905
+ const modulesRouteConfig = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_getModulesRouteConfig).call(this, { modules: modules });
906
+ const mainRouteConfig = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_readJsonFile).call(this, mainRoutes);
907
+ const allRoutes = [...[mainRouteConfig ?? []], ...(modulesRouteConfig ?? [])];
908
+ const { replacedNavigationRouteConfig: routeConfig } = getReplacedRouteConfig({
909
+ layoutType: layoutType,
910
+ routeConfig: allRoutes,
911
+ layoutConfigData: layoutConfigFileData,
912
+ initialRouteName: initialRouteName,
913
+ });
914
+ const keyToReplace = appLayout.key || 'bottom_tab';
915
+ const keyToReplaceHost = hostLayout.key || 'host_tab';
916
+ const moduleRouteConfigObject = Object.assign({}, ...(routeConfig?.flat(1) ?? []));
917
+ const configuredRoutes = await getSortedNavigations('/', moduleRouteConfigObject);
918
+ const layoutBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r) => r?.key == keyToReplace);
919
+ const hostBottomTabRouteConfig = configuredRoutes?.[0]?.children?.filter((r) => r?.key == keyToReplaceHost);
920
+ const bottomTabConfig = layoutBottomTabRouteConfig?.[0]?.children
921
+ ?.filter((r) => !r?.side)
922
+ ?.sort((a, b) => {
923
+ if (a?.props?.options?.priority === undefined)
924
+ return 1; // Push items with missing 'id' to the end
925
+ if (b?.props?.options?.priority === undefined)
926
+ return -1;
927
+ return a?.props?.options?.priority - b?.props?.options?.priority;
928
+ }) ?? [];
929
+ const hostBottomTabConfig = hostBottomTabRouteConfig?.[0]?.children
930
+ ?.filter((r) => !r?.side)
931
+ ?.sort((a, b) => {
932
+ if (a?.props?.options?.priority === undefined)
933
+ return 1; // Push items with missing 'id' to the end
934
+ if (b?.props?.options?.priority === undefined)
935
+ return -1;
936
+ return a?.props?.options?.priority - b?.props?.options?.priority;
937
+ }) ?? [];
938
+ const drawerConfig = layoutBottomTabRouteConfig?.[0]?.children
939
+ ?.filter((r) => r?.side)
940
+ ?.sort((a, b) => {
941
+ if (a?.props?.options?.priority === undefined)
942
+ return 1; // Push items with missing 'id' to the end
943
+ if (b?.props?.options?.priority === undefined)
944
+ return -1;
945
+ return a?.props?.options?.priority - b?.props?.options?.priority;
946
+ }) ?? [];
947
+ const hostDrawerConfig = hostBottomTabRouteConfig?.[0]?.children
948
+ ?.filter((r) => r?.side)
949
+ ?.sort((a, b) => {
950
+ if (a?.props?.options?.priority === undefined)
951
+ return 1; // Push items with missing 'id' to the end
952
+ if (b?.props?.options?.priority === undefined)
953
+ return -1;
954
+ return a?.props?.options?.priority - b?.props?.options?.priority;
955
+ }) ?? [];
956
+ if (bottomTabConfig) {
957
+ const drawerNavigation = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateBottomTabNavigationsFile).call(this, {
958
+ bottomTabConfig: bottomTabConfig,
959
+ unauthenticatedComponentPath,
960
+ bottomDirPath: bottomDirPath,
961
+ mixLayout,
962
+ });
963
+ if (drawerNavigation)
964
+ await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateBottomTabNavigationsFile).call(this, {
965
+ bottomTabConfig: hostBottomTabConfig,
966
+ unauthenticatedComponentPath,
967
+ bottomDirPath: hostBottomDirPath,
968
+ mixLayout,
969
+ });
970
+ if (drawerConfig) {
971
+ const drawerNavigation = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateDrawerNavigationsFile).call(this, {
972
+ drawerConfig: drawerConfig,
973
+ unauthenticatedComponentPath,
974
+ drawerDirPath: drawerDirPath,
975
+ });
976
+ if (drawerNavigation)
977
+ await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateDrawerNavigationsFile).call(this, {
978
+ drawerConfig: hostDrawerConfig,
979
+ unauthenticatedComponentPath,
980
+ drawerDirPath: hostDirPath,
981
+ });
982
+ return true;
983
+ }
984
+ else
985
+ return true;
986
+ }
987
+ else
988
+ return false;
989
+ }, _GenerateMobileNavigations_generateAppNavigationFile = async function _GenerateMobileNavigations_generateAppNavigationFile({ appDirPath, customTabBarPath, customDrawerPath, customHeaderPath }) {
990
+ const navigationDirPath = path.join(appDirPath, `/${appNavigationFileName}`);
991
+ const layoutSettings = __classPrivateFieldGet(this, _GenerateMobileNavigations_layoutSettings, "f");
992
+ const layoutConfigFileData = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_getLayoutConfig).call(this);
993
+ const layoutType = layoutSettings?.layout || 'bottom';
994
+ const layoutRouteConfig = layoutConfigFileData[layoutType];
995
+ const layoutRouteKey = Object.keys(layoutRouteConfig)[1];
996
+ const appLayout = layoutRouteConfig[layoutRouteKey];
997
+ const initialRouteName = layoutType === 'mixSide'
998
+ ? appLayout?.[appLayout?.key]?.props?.initialRouteName ?? 'MainStack.Layout.Home'
999
+ : appLayout?.props?.initialRouteName || 'MainStack.Home';
1000
+ const isShowTabs = layoutType === 'mixSide' || layoutType === 'bottom' ? true : false;
1001
+ const isShowDefalutHeader = layoutType === 'mixSide' ? true : false;
1002
+ const defaultHeaderProps = {
1003
+ showToggle: layoutSettings?.topLeftToggle || false,
1004
+ right: layoutSettings?.topRightSettingToggle || false,
1005
+ };
1006
+ const screenOptionsTab = layoutType === 'mixSide'
1007
+ ? { ...(appLayout?.[appLayout?.key]?.props?.screenOptions ?? {}) }
1008
+ : appLayout?.props?.screenOptions || { headerShown: true, title: 'Home', headerTitle: 'Home' };
1009
+ const screenOptions = appLayout?.props?.screenOptions || {
1010
+ headerShown: true,
1011
+ title: 'Home',
1012
+ headerTitle: 'Home',
1013
+ };
1014
+ let importStatements = `
1015
+ import * as React from 'react';
1016
+ import { navigationRef } from '@common-stack/client-react';
1017
+ import { createNativeStackNavigator } from '@react-navigation/native-stack';`;
1018
+ let rootComponent = '';
1019
+ let appComponent = '';
1020
+ let appNavigation = '';
1021
+ if (layoutType == 'side') {
1022
+ if (customDrawerPath)
1023
+ importStatements += `import CustomDrawerContent from '${customDrawerPath}';\n`;
1024
+ if (customHeaderPath)
1025
+ importStatements += `import CustomHeader from '${customHeaderPath}';\n`;
1026
+ importStatements += `import { createDrawerNavigator } from '@react-navigation/drawer';
1027
+ import { getHeaderTitle } from '@react-navigation/elements';
1028
+ import { useSelector } from 'react-redux';
1029
+ import stackNavigations from './stack';
1030
+ import drawerNavigations from './drawer';
1031
+ import hostDrawerNavigations from './host_drawer';
1032
+ const Stack = createNativeStackNavigator();
1033
+ const Drawer = createDrawerNavigator();
1034
+ `;
1035
+ rootComponent += `
1036
+ const RootComponent = (props:any) => {
1037
+ const settings = useSelector((state: any) => state.settings);
1038
+ const defaultHeaderProps = ${JSON.stringify(defaultHeaderProps || {})};
1039
+ return (
1040
+ <Drawer.Navigator
1041
+ initialRouteName={${JSON.stringify(initialRouteName)}}
1042
+ //screenOptions={${JSON.stringify(screenOptions)}}
1043
+ screenOptions={({ route }) => ({ ...${JSON.stringify(screenOptions)} ,...{
1044
+ ${customHeaderPath
1045
+ ? `header: (props:any) => {
1046
+ const title = getHeaderTitle(props.options, props.route.name);
1047
+ return <CustomHeader {...defaultHeaderProps} {...props} title={title} style={props.options.headerStyle} />;
1048
+ }`
1049
+ : ''}
1050
+ }})}
1051
+ ${customDrawerPath ? 'drawerContent={(props) => <CustomDrawerContent {...props} />}' : ''}
1052
+ >
1053
+ {settings?.layout == 'host-bottom' ? hostDrawerNavigations({ Drawer }) : drawerNavigations({ Drawer })}
1054
+ </Drawer.Navigator>
1055
+ );
1056
+ }
1057
+ `;
1058
+ }
1059
+ if (layoutType == 'bottom') {
1060
+ if (customTabBarPath)
1061
+ importStatements += `import CustomTabBar from '${customTabBarPath}';\n`;
1062
+ if (customHeaderPath)
1063
+ importStatements += `import CustomHeader from '${customHeaderPath}';\n`;
1064
+ importStatements += `import {Header,Drawer as DefaultDrawer} from '@admin-layout/gluestack-ui-mobile';
1065
+ import { getHeaderTitle } from '@react-navigation/elements';
1066
+ import { useSelector } from 'react-redux';
1067
+ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
1068
+ import stackNavigations from './stack';
1069
+ import bottomNavigations from './bottom';
1070
+ import hostBottomNavigations from './host_bottom';
1071
+ const Stack = createNativeStackNavigator();
1072
+ const Tab = createBottomTabNavigator();
1073
+ `;
1074
+ rootComponent += `
1075
+ const RootComponent = (props:any) => {
1076
+ const settings = useSelector((state: any) => state.settings);
1077
+ const initialRouteName = ${JSON.stringify(initialRouteName)};
1078
+ let defaultScreenOptions = ${JSON.stringify(screenOptionsTab)};
1079
+ const defaultHeaderProps = ${JSON.stringify(defaultHeaderProps || {})};
1080
+ const defaultHeader = {${isShowDefalutHeader ? `header:(props:any)=><Header {...defaultHeaderProps} {...props} />` : ''}};
1081
+ return (
1082
+ <Tab.Navigator
1083
+ initialRouteName={initialRouteName}
1084
+ screenOptions={(props:any)=>({...props,...defaultScreenOptions,...{${customHeaderPath
1085
+ ? `header: (props:any) => {
1086
+ const title = getHeaderTitle(props.options, props.route.name);
1087
+ return <CustomHeader {...defaultHeaderProps} {...props} title={title} style={props.options.headerStyle} />;
1088
+ }`
1089
+ : ''}}})}
1090
+ ${customTabBarPath
1091
+ ? 'tabBar={props => <CustomTabBar key={props?.key??"customTabBarKey"} {...props} />}'
1092
+ : ''}
1093
+ >
1094
+ {settings?.layout == 'host-bottom' ? hostBottomNavigations({ Tab }) : bottomNavigations({Tab})}
1095
+ </Tab.Navigator>
1096
+ );
1097
+ }
1098
+ `;
1099
+ }
1100
+ if (layoutType == 'mixSide') {
1101
+ if (customTabBarPath)
1102
+ importStatements += `import CustomTabBar from '${customTabBarPath}';\n`;
1103
+ if (customDrawerPath)
1104
+ importStatements += `import CustomDrawerContent from '${customDrawerPath}';\n`;
1105
+ if (customHeaderPath)
1106
+ importStatements += `import CustomHeader from '${customHeaderPath}';\n`;
1107
+ importStatements += `import {Header,Drawer as DefaultDrawer} from '@admin-layout/gluestack-ui-mobile';
1108
+ import { useSelector } from 'react-redux';
1109
+ import { MaterialIcons } from "@expo/vector-icons";
1110
+ import { getHeaderTitle } from '@react-navigation/elements';
1111
+ import { createDrawerNavigator } from '@react-navigation/drawer';
1112
+ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
1113
+ import stackNavigations from './stack';
1114
+ import bottomNavigations from './bottom';
1115
+ import hostBottomNavigations from './host_bottom';
1116
+ import drawerNavigations from './drawer';
1117
+ import hostDrawerNavigations from './host_drawer';
1118
+ const Stack = createNativeStackNavigator();
1119
+ const Drawer = createDrawerNavigator();
1120
+ const Tab = createBottomTabNavigator();
1121
+ `;
1122
+ rootComponent += `
1123
+ const TabNavigator = () => {
1124
+ const settings = useSelector((state: any) => state.settings);
1125
+ const initialRouteName = ${JSON.stringify(initialRouteName)};
1126
+ let defaultScreenOptions = ${JSON.stringify(screenOptionsTab)};
1127
+ const defaultHeaderProps = ${JSON.stringify(defaultHeaderProps || {})};
1128
+ const defaultHeader = {${isShowDefalutHeader ? `header:(props:any)=><Header {...defaultHeaderProps} {...props} />` : ''}};
1129
+
1130
+ return (
1131
+ <Tab.Navigator
1132
+ initialRouteName={initialRouteName}
1133
+ screenOptions={(props:any)=>({...props,...defaultScreenOptions,...{headerShown: false,header:()=>null},})}
1134
+ ${customTabBarPath
1135
+ ? 'tabBar={props => <CustomTabBar key={props?.key??"customTabBarKey"} {...props} />}'
1136
+ : ''}
1137
+ >
1138
+ {settings?.layout == 'host-bottom' ? hostBottomNavigations({ Tab }) : bottomNavigations({Tab})}
1139
+ </Tab.Navigator>
1140
+ )
1141
+ }
1142
+ const RootComponent = (props:any) => {
1143
+ const initialRouteName = ${JSON.stringify(initialRouteName)};
1144
+ const settings = useSelector((state: any) => state.settings);
1145
+ let defaultScreenOptions = ${JSON.stringify(screenOptionsTab)};
1146
+ const defaultHeaderProps = ${JSON.stringify(defaultHeaderProps || {})};
1147
+ const defaultHeader = {${isShowDefalutHeader ? `header:(props:any)=><Header {...defaultHeaderProps} {...props} />` : ''}};
1148
+ return (
1149
+ <Drawer.Navigator
1150
+ initialRouteName={${JSON.stringify(initialRouteName)}}
1151
+ // screenOptions={${JSON.stringify(screenOptions)}}
1152
+ screenOptions={({ route }) => ({ ...${JSON.stringify(screenOptions)} ,...{headerTitle:navigationRef?.isReady() && navigationRef?.getCurrentRoute()
1153
+ ? navigationRef?.getCurrentOptions()?.title
1154
+ ? navigationRef?.getCurrentOptions()?.headerTitle
1155
+ : navigationRef?.getCurrentRoute()?.route?.name
1156
+ : "Home",
1157
+ ${customHeaderPath
1158
+ ? `header: (props:any) => {
1159
+ const title = getHeaderTitle(props.options, props.route.name);
1160
+ return <CustomHeader {...defaultHeaderProps} {...props} title={title} isMixedLayout={true} style={props.options.headerStyle} />;
1161
+ }`
1162
+ : ''}
1163
+
1164
+ }})}
1165
+ ${customDrawerPath
1166
+ ? 'drawerContent={(props) => <CustomDrawerContent {...props} showDefaultRoutes={true} />}'
1167
+ : ''}
1168
+ >
1169
+ <Drawer.Screen name="Layout" options={{title:"Home", drawerIcon: ({ color, size }: { color: any, size: any }) => (
1170
+ <MaterialIcons name="home" size={24} color={color} />
1171
+ ),}}
1172
+ component={TabNavigator} />
1173
+ {settings?.layout == 'host-bottom' ? hostDrawerNavigations({ Drawer }) : drawerNavigations({ Drawer })}
1174
+ </Drawer.Navigator>
1175
+ );
1176
+ }
1177
+ `;
1178
+ }
1179
+ appComponent += `
1180
+ const AppNavigations = () => {
1181
+ return (
1182
+ <Stack.Navigator initialRouteName="${initialRouteName}">
1183
+ <Stack.Screen
1184
+ name="MainStack"
1185
+ options={{ headerShown: false }}
1186
+ component={RootComponent}
1187
+ />
1188
+ {stackNavigations({ Stack })}
1189
+ </Stack.Navigator>
1190
+ )
1191
+ }
1192
+
1193
+ export default AppNavigations;
1194
+ `;
1195
+ appNavigation = importStatements + '\n' + rootComponent + '\n' + appComponent;
1196
+ appNavigation = prettier.format(appNavigation, { parser: 'babel' });
1197
+ const writeFileResponse = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_writeFile).call(this, navigationDirPath, appNavigation);
1198
+ if (writeFileResponse)
1199
+ return true;
1200
+ else
1201
+ return false;
1202
+ }, _GenerateMobileNavigations_setLayoutAndGenerateNavigation = async function _GenerateMobileNavigations_setLayoutAndGenerateNavigation() {
1203
+ const appDirPath = __classPrivateFieldGet(this, _GenerateMobileNavigations_appDirPath, "f");
1204
+ const modules = __classPrivateFieldGet(this, _GenerateMobileNavigations_modules, "f");
1205
+ const initialRouteName = __classPrivateFieldGet(this, _GenerateMobileNavigations_initialRouteName, "f");
1206
+ const unauthenticatedComponentPath = __classPrivateFieldGet(this, _GenerateMobileNavigations_unauthenticatedComponentPath, "f");
1207
+ const customTabBarPath = __classPrivateFieldGet(this, _GenerateMobileNavigations_customTabBarPath, "f");
1208
+ const customDrawerPath = __classPrivateFieldGet(this, _GenerateMobileNavigations_customDrawerPath, "f");
1209
+ const customHeaderPath = __classPrivateFieldGet(this, _GenerateMobileNavigations_customHeaderPath, "f");
1210
+ const layoutSettings = __classPrivateFieldGet(this, _GenerateMobileNavigations_layoutSettings, "f");
1211
+ const layoutConfigFileData = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_getLayoutConfig).call(this);
1212
+ const layoutType = layoutSettings?.layout || 'bottom';
1213
+ const isAppRoutesGenerated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateAppRoutesJson).call(this, { appDirPath });
1214
+ if (isAppRoutesGenerated) {
1215
+ const isModuleTsFileGenerated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateModulesTsFile).call(this, {
1216
+ appDirPath,
1217
+ modules,
1218
+ initialRouteName,
1219
+ });
1220
+ if (isModuleTsFileGenerated) {
1221
+ const isStackCreated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateStackNavigations).call(this, {
1222
+ appDirPath,
1223
+ modules,
1224
+ initialRouteName,
1225
+ unauthenticatedComponentPath,
1226
+ });
1227
+ if (isStackCreated) {
1228
+ if (layoutType == 'side') {
1229
+ const isDrawerGenerated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateDrawerNavigations).call(this, {
1230
+ appDirPath,
1231
+ modules,
1232
+ initialRouteName,
1233
+ unauthenticatedComponentPath,
1234
+ });
1235
+ if (isDrawerGenerated) {
1236
+ const appNavigationGenerated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateAppNavigationFile).call(this, {
1237
+ appDirPath,
1238
+ customTabBarPath,
1239
+ customDrawerPath,
1240
+ customHeaderPath,
1241
+ });
1242
+ if (appNavigationGenerated)
1243
+ return appNavigationGenerated;
1244
+ else
1245
+ return true;
1246
+ }
1247
+ else
1248
+ return false;
1249
+ }
1250
+ else if (layoutType == 'bottom' || layoutType == 'host-bottom') {
1251
+ const isBottomTabGenerated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateBottomTabNavigations).call(this, {
1252
+ appDirPath,
1253
+ modules,
1254
+ initialRouteName,
1255
+ unauthenticatedComponentPath,
1256
+ });
1257
+ if (isBottomTabGenerated) {
1258
+ const appNavigationGenerated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateAppNavigationFile).call(this, {
1259
+ appDirPath,
1260
+ customTabBarPath,
1261
+ customDrawerPath,
1262
+ customHeaderPath,
1263
+ });
1264
+ if (appNavigationGenerated)
1265
+ return appNavigationGenerated;
1266
+ else
1267
+ return true;
1268
+ }
1269
+ else
1270
+ return false;
1271
+ }
1272
+ else {
1273
+ const isBottomTabDrawerGenerated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateBottomTabDrawerNavigations).call(this, {
1274
+ appDirPath,
1275
+ modules,
1276
+ initialRouteName,
1277
+ unauthenticatedComponentPath,
1278
+ });
1279
+ if (isBottomTabDrawerGenerated) {
1280
+ const appNavigationGenerated = await __classPrivateFieldGet(this, _GenerateMobileNavigations_instances, "m", _GenerateMobileNavigations_generateAppNavigationFile).call(this, {
1281
+ appDirPath,
1282
+ customTabBarPath,
1283
+ customDrawerPath,
1284
+ customHeaderPath,
1285
+ });
1286
+ if (appNavigationGenerated)
1287
+ return appNavigationGenerated;
1288
+ else
1289
+ return true;
1290
+ }
1291
+ else
1292
+ return false;
1293
+ }
1294
+ }
1295
+ else
1296
+ return false;
1297
+ }
1298
+ else
1299
+ return false;
1300
+ }
1301
+ else
1302
+ return false;
1303
+ };
1304
+ //# sourceMappingURL=generateMobileNavigations.js.map