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