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