blend-kit 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/dist/helper/ApiHelper.js +0 -0
  2. package/dist/helper/BasicHelper.js +28 -0
  3. package/dist/helper/CommonHelper.js +10 -0
  4. package/dist/helper/DataHelper.js +241 -0
  5. package/dist/helper/ExpressHelper.js +728 -0
  6. package/dist/helper/FrontEndApiHelper.js +485 -0
  7. package/dist/helper/FrontEndReactApiHelper.js +483 -0
  8. package/dist/helper/MongoHelper.js +143 -0
  9. package/dist/helper/RNHelper.js +560 -0
  10. package/dist/helper/ReactHelper.js +524 -0
  11. package/dist/helper/SectionHelper.js +152 -0
  12. package/dist/helper/fileHelper.js +127 -0
  13. package/dist/helper/grammarHelper/BlendApiGrammarHelper.js +48 -0
  14. package/dist/helper/grammarHelper/BlendBasicGrammarHelper.js +98 -0
  15. package/dist/helper/grammarHelper/BlendDataGrammarHelper.js +47 -0
  16. package/dist/helper/grammarHelper/BlendMDPGrammarHelper.js +29 -0
  17. package/dist/helper/grammarHelper/BlendMongoGrammarHelper.js +51 -0
  18. package/dist/helper/grammarHelper/BlendRNGrammarHelper.js +56 -0
  19. package/dist/helper/grammarHelper/BlendReactGrammarHelper.js +55 -0
  20. package/dist/helper/grammarHelper/GrammarErrorHelper.js +16 -0
  21. package/dist/index.js +159 -0
  22. package/dist/parser/blendApi/src/grammar/BlendApiLexer.js +201 -0
  23. package/dist/parser/blendApi/src/grammar/BlendApiListener.js +3 -0
  24. package/dist/parser/blendApi/src/grammar/BlendApiParser.js +961 -0
  25. package/dist/parser/blendData/src/grammar/BlendDataLexer.js +154 -0
  26. package/dist/parser/blendData/src/grammar/BlendDataListener.js +3 -0
  27. package/dist/parser/blendData/src/grammar/BlendDataParser.js +641 -0
  28. package/dist/parser/blendMDP/src/grammar/BlendMDPLexer.js +151 -0
  29. package/dist/parser/blendMDP/src/grammar/BlendMDPListener.js +3 -0
  30. package/dist/parser/blendMDP/src/grammar/BlendMDPParser.js +490 -0
  31. package/dist/parser/blendMongo/src/grammar/BlendMongoLexer.js +187 -0
  32. package/dist/parser/blendMongo/src/grammar/BlendMongoListener.js +3 -0
  33. package/dist/parser/blendMongo/src/grammar/BlendMongoParser.js +848 -0
  34. package/dist/parser/blendRN/src/grammar/BlendRNLexer.js +172 -0
  35. package/dist/parser/blendRN/src/grammar/BlendRNListener.js +3 -0
  36. package/dist/parser/blendRN/src/grammar/BlendRNParser.js +657 -0
  37. package/dist/parser/blendReact/src/grammar/BlendReactLexer.js +159 -0
  38. package/dist/parser/blendReact/src/grammar/BlendReactListener.js +3 -0
  39. package/dist/parser/blendReact/src/grammar/BlendReactParser.js +644 -0
  40. package/dist/parser/blendbasic/src/grammar/BlendBasicLexer.js +147 -0
  41. package/dist/parser/blendbasic/src/grammar/BlendBasicListener.js +3 -0
  42. package/dist/parser/blendbasic/src/grammar/BlendBasicParser.js +747 -0
  43. package/dist/src/app.js +76 -0
  44. package/dist/src/app.ts +54 -0
  45. package/dist/types/apiOperationTypes.js +13 -0
  46. package/dist/types/basicOperationTypes.js +2 -0
  47. package/dist/types/dataOperationTypes.js +2 -0
  48. package/dist/types/frontendOperationTypes.js +4 -0
  49. package/dist/types/generalTypes.js +0 -0
  50. package/dist/types/mongoOperationTypes.js +12 -0
  51. package/package.json +29 -0
  52. package/src/grammar/.antlr/ApiModuleLexer.interp +71 -0
  53. package/src/grammar/.antlr/ApiModuleLexer.java +194 -0
  54. package/src/grammar/.antlr/ApiModuleLexer.tokens +32 -0
  55. package/src/grammar/.antlr/BlendApi.interp +70 -0
  56. package/src/grammar/.antlr/BlendApi.tokens +44 -0
  57. package/src/grammar/.antlr/BlendApiLexer.interp +89 -0
  58. package/src/grammar/.antlr/BlendApiLexer.java +237 -0
  59. package/src/grammar/.antlr/BlendApiLexer.tokens +44 -0
  60. package/src/grammar/.antlr/BlendApiParser.java +767 -0
  61. package/src/grammar/.antlr/BlendBasic.interp +41 -0
  62. package/src/grammar/.antlr/BlendBasic.tokens +20 -0
  63. package/src/grammar/.antlr/BlendBasicLexer.interp +50 -0
  64. package/src/grammar/.antlr/BlendBasicLexer.java +179 -0
  65. package/src/grammar/.antlr/BlendBasicLexer.tokens +20 -0
  66. package/src/grammar/.antlr/BlendBasicParser.java +599 -0
  67. package/src/grammar/.antlr/BlendData.interp +50 -0
  68. package/src/grammar/.antlr/BlendData.tokens +29 -0
  69. package/src/grammar/.antlr/BlendDataLexer.interp +65 -0
  70. package/src/grammar/.antlr/BlendDataLexer.java +181 -0
  71. package/src/grammar/.antlr/BlendDataLexer.tokens +29 -0
  72. package/src/grammar/.antlr/BlendDataParser.java +520 -0
  73. package/src/grammar/.antlr/BlendMDP.interp +45 -0
  74. package/src/grammar/.antlr/BlendMDP.tokens +25 -0
  75. package/src/grammar/.antlr/BlendMDPLexer.interp +59 -0
  76. package/src/grammar/.antlr/BlendMDPLexer.java +178 -0
  77. package/src/grammar/.antlr/BlendMDPLexer.tokens +25 -0
  78. package/src/grammar/.antlr/BlendMDPParser.java +386 -0
  79. package/src/grammar/.antlr/BlendMongo.interp +65 -0
  80. package/src/grammar/.antlr/BlendMongo.tokens +41 -0
  81. package/src/grammar/.antlr/BlendMongoLexer.interp +83 -0
  82. package/src/grammar/.antlr/BlendMongoLexer.java +219 -0
  83. package/src/grammar/.antlr/BlendMongoLexer.tokens +41 -0
  84. package/src/grammar/.antlr/BlendMongoParser.java +669 -0
  85. package/src/grammar/.antlr/BlendRN.interp +53 -0
  86. package/src/grammar/.antlr/BlendRN.tokens +31 -0
  87. package/src/grammar/.antlr/BlendRNLexer.interp +71 -0
  88. package/src/grammar/.antlr/BlendRNLexer.java +202 -0
  89. package/src/grammar/.antlr/BlendRNLexer.tokens +31 -0
  90. package/src/grammar/.antlr/BlendRNParser.java +542 -0
  91. package/src/grammar/.antlr/BlendReact.interp +49 -0
  92. package/src/grammar/.antlr/BlendReact.tokens +28 -0
  93. package/src/grammar/.antlr/BlendReactLexer.interp +65 -0
  94. package/src/grammar/.antlr/BlendReactLexer.java +188 -0
  95. package/src/grammar/.antlr/BlendReactLexer.tokens +28 -0
  96. package/src/grammar/.antlr/BlendReactParser.java +530 -0
  97. package/src/grammar/BlendApi.g4 +26 -0
  98. package/src/grammar/BlendBasic.g4 +16 -0
  99. package/src/grammar/BlendData.g4 +24 -0
  100. package/src/grammar/BlendMDP.g4 +12 -0
  101. package/src/grammar/BlendMongo.g4 +24 -0
  102. package/src/grammar/BlendRN.g4 +18 -0
  103. package/src/grammar/BlendReact.g4 +16 -0
  104. package/src/helper/BasicHelper.ts +35 -0
  105. package/src/helper/CommonHelper.ts +5 -0
  106. package/src/helper/DataHelper.ts +268 -0
  107. package/src/helper/ExpressHelper.ts +807 -0
  108. package/src/helper/FrontEndApiHelper.ts +526 -0
  109. package/src/helper/FrontEndReactApiHelper.ts +532 -0
  110. package/src/helper/MongoHelper.ts +165 -0
  111. package/src/helper/RNHelper.ts +651 -0
  112. package/src/helper/ReactHelper.ts +597 -0
  113. package/src/helper/SectionHelper.ts +154 -0
  114. package/src/helper/fileHelper.ts +111 -0
  115. package/src/helper/grammarHelper/BlendApiGrammarHelper.ts +45 -0
  116. package/src/helper/grammarHelper/BlendBasicGrammarHelper.ts +101 -0
  117. package/src/helper/grammarHelper/BlendDataGrammarHelper.ts +49 -0
  118. package/src/helper/grammarHelper/BlendMDPGrammarHelper.ts +33 -0
  119. package/src/helper/grammarHelper/BlendMongoGrammarHelper.ts +50 -0
  120. package/src/helper/grammarHelper/BlendRNGrammarHelper.ts +65 -0
  121. package/src/helper/grammarHelper/BlendReactGrammarHelper.ts +65 -0
  122. package/src/helper/grammarHelper/GrammarErrorHelper.ts +13 -0
  123. package/src/index.ts +168 -0
  124. package/src/parser/blendApi/src/grammar/BlendApi.interp +70 -0
  125. package/src/parser/blendApi/src/grammar/BlendApi.tokens +44 -0
  126. package/src/parser/blendApi/src/grammar/BlendApiLexer.interp +89 -0
  127. package/src/parser/blendApi/src/grammar/BlendApiLexer.tokens +44 -0
  128. package/src/parser/blendApi/src/grammar/BlendApiLexer.ts +193 -0
  129. package/src/parser/blendApi/src/grammar/BlendApiListener.ts +145 -0
  130. package/src/parser/blendApi/src/grammar/BlendApiParser.ts +968 -0
  131. package/src/parser/blendData/src/grammar/BlendData.interp +50 -0
  132. package/src/parser/blendData/src/grammar/BlendData.tokens +29 -0
  133. package/src/parser/blendData/src/grammar/BlendDataLexer.interp +65 -0
  134. package/src/parser/blendData/src/grammar/BlendDataLexer.tokens +29 -0
  135. package/src/parser/blendData/src/grammar/BlendDataLexer.ts +146 -0
  136. package/src/parser/blendData/src/grammar/BlendDataListener.ts +97 -0
  137. package/src/parser/blendData/src/grammar/BlendDataParser.ts +641 -0
  138. package/src/parser/blendMDP/src/grammar/BlendMDP.interp +45 -0
  139. package/src/parser/blendMDP/src/grammar/BlendMDP.tokens +25 -0
  140. package/src/parser/blendMDP/src/grammar/BlendMDPLexer.interp +59 -0
  141. package/src/parser/blendMDP/src/grammar/BlendMDPLexer.tokens +25 -0
  142. package/src/parser/blendMDP/src/grammar/BlendMDPLexer.ts +143 -0
  143. package/src/parser/blendMDP/src/grammar/BlendMDPListener.ts +85 -0
  144. package/src/parser/blendMDP/src/grammar/BlendMDPParser.ts +483 -0
  145. package/src/parser/blendMongo/src/grammar/BlendMongo.interp +65 -0
  146. package/src/parser/blendMongo/src/grammar/BlendMongo.tokens +41 -0
  147. package/src/parser/blendMongo/src/grammar/BlendMongoLexer.interp +83 -0
  148. package/src/parser/blendMongo/src/grammar/BlendMongoLexer.tokens +41 -0
  149. package/src/parser/blendMongo/src/grammar/BlendMongoLexer.ts +179 -0
  150. package/src/parser/blendMongo/src/grammar/BlendMongoListener.ts +133 -0
  151. package/src/parser/blendMongo/src/grammar/BlendMongoParser.ts +849 -0
  152. package/src/parser/blendRN/src/grammar/BlendRN.interp +53 -0
  153. package/src/parser/blendRN/src/grammar/BlendRN.tokens +31 -0
  154. package/src/parser/blendRN/src/grammar/BlendRNLexer.interp +71 -0
  155. package/src/parser/blendRN/src/grammar/BlendRNLexer.tokens +31 -0
  156. package/src/parser/blendRN/src/grammar/BlendRNLexer.ts +164 -0
  157. package/src/parser/blendRN/src/grammar/BlendRNListener.ts +85 -0
  158. package/src/parser/blendRN/src/grammar/BlendRNParser.ts +659 -0
  159. package/src/parser/blendReact/src/grammar/BlendReact.interp +49 -0
  160. package/src/parser/blendReact/src/grammar/BlendReact.tokens +28 -0
  161. package/src/parser/blendReact/src/grammar/BlendReactLexer.interp +65 -0
  162. package/src/parser/blendReact/src/grammar/BlendReactLexer.tokens +28 -0
  163. package/src/parser/blendReact/src/grammar/BlendReactLexer.ts +151 -0
  164. package/src/parser/blendReact/src/grammar/BlendReactListener.ts +85 -0
  165. package/src/parser/blendReact/src/grammar/BlendReactParser.ts +646 -0
  166. package/src/parser/blendbasic/src/grammar/BlendBasic.interp +41 -0
  167. package/src/parser/blendbasic/src/grammar/BlendBasic.tokens +20 -0
  168. package/src/parser/blendbasic/src/grammar/BlendBasicLexer.interp +50 -0
  169. package/src/parser/blendbasic/src/grammar/BlendBasicLexer.tokens +20 -0
  170. package/src/parser/blendbasic/src/grammar/BlendBasicLexer.ts +139 -0
  171. package/src/parser/blendbasic/src/grammar/BlendBasicListener.ts +109 -0
  172. package/src/parser/blendbasic/src/grammar/BlendBasicParser.ts +747 -0
  173. package/src/types/apiOperationTypes.ts +43 -0
  174. package/src/types/basicOperationTypes.ts +15 -0
  175. package/src/types/dataOperationTypes.ts +20 -0
  176. package/src/types/frontendOperationTypes.ts +92 -0
  177. package/src/types/generalTypes.ts +0 -0
  178. package/src/types/mongoOperationTypes.ts +36 -0
  179. package/template/.env.dev +1 -0
  180. package/template/package.json +36 -0
  181. package/template/src/app.js +76 -0
  182. package/template/src/app.ts +54 -0
  183. package/template/src/config/app.config.js +0 -0
  184. package/template/src/config/app.config.ts +0 -0
  185. package/template/src/config/database.config.js +6 -0
  186. package/template/src/config/database.config.ts +4 -0
  187. package/template/src/data/interfaces.js +2 -0
  188. package/template/src/data/interfaces.ts +23 -0
  189. package/template/src/middlewares/auth.js +22 -0
  190. package/template/src/middlewares/auth.ts +21 -0
  191. package/template/src/models/Database.js +10 -0
  192. package/template/src/models/Database.ts +8 -0
  193. package/template/src/models/User/Permission.model.js +13 -0
  194. package/template/src/models/User/Permission.model.ts +14 -0
  195. package/template/src/models/User/Role.model.js +13 -0
  196. package/template/src/models/User/Role.model.ts +14 -0
  197. package/template/src/models/User/User.model.js +17 -0
  198. package/template/src/models/User/User.model.ts +18 -0
  199. package/template/src/routes/User.routes.js +47 -0
  200. package/template/src/routes/User.routes.ts +41 -0
  201. package/template/src/routes/common/common.routes.config.js +14 -0
  202. package/template/src/routes/common/common.routes.config.ts +15 -0
  203. package/template/src/services/User/User.service.js +75 -0
  204. package/template/src/services/User/User.service.ts +68 -0
  205. package/template/src/services/User/api.data.js +72 -0
  206. package/template/src/services/User/api.data.ts +79 -0
  207. package/template/src/services/User/api.interface.js +3 -0
  208. package/template/src/services/User/api.interface.ts +10 -0
  209. package/template/tsconfig.json +10 -0
  210. package/tsconfig.json +13 -0
@@ -0,0 +1,560 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const fileHelper_1 = require("./fileHelper");
16
+ const path_1 = __importDefault(require("path"));
17
+ const BlendRNGrammarHelper_1 = __importDefault(require("./grammarHelper/BlendRNGrammarHelper"));
18
+ const { execSync } = require('child_process');
19
+ const runCommand = (command, cwd = process.cwd()) => {
20
+ try {
21
+ execSync(command, { stdio: 'inherit', cwd });
22
+ }
23
+ catch (error) {
24
+ console.error(`Failed to execute command: ${command}`);
25
+ process.exit(1);
26
+ }
27
+ };
28
+ class RNHelper {
29
+ constructor() {
30
+ this.folderPath = path_1.default.join(process.cwd());
31
+ this.folderName = path_1.default.basename(this.folderPath);
32
+ this.basicFilePath = path_1.default.join(this.folderPath, `${this.folderName}.basic`);
33
+ this.configPath = path_1.default.join(this.folderPath, '.basicConfig');
34
+ this.basicProjectContent = JSON.parse(fileHelper_1.FileHelper.readFile(`${this.configPath}/basicConfig.json`) || "{}");
35
+ }
36
+ doRNOperations() {
37
+ this.createRNSpec();
38
+ this.parseSpec();
39
+ }
40
+ doRNGenerations() {
41
+ this.buildComponents();
42
+ this.buildScreens();
43
+ }
44
+ createRNSpec() {
45
+ this.basicProjectContent.sectionList.forEach(section => {
46
+ const sectionName = section.name.trim();
47
+ const sectionFolderPath = path_1.default.join(this.folderPath, 'spec', sectionName);
48
+ const rnFolderPath = path_1.default.join(sectionFolderPath, 'frontend');
49
+ section.rnModuleList.forEach(dataModule => {
50
+ const dataFilePath = path_1.default.join(rnFolderPath, `${dataModule.name}.rn`);
51
+ if (!fileHelper_1.FileHelper.exists(dataFilePath)) {
52
+ fileHelper_1.FileHelper.writeFile(dataFilePath, `module ${dataModule.name}`);
53
+ }
54
+ });
55
+ });
56
+ }
57
+ parseScreenList(input) {
58
+ const screenRegex = /screen (.+?) under "(.+?)"/g;
59
+ const screens = [];
60
+ let match;
61
+ while ((match = screenRegex.exec(input)) !== null) {
62
+ const screenNames = match[1].split(",").map(name => name.trim());
63
+ const path = match[2];
64
+ screens.push(...screenNames.map(name => ({ name, path })));
65
+ }
66
+ if (screens.length === 0) {
67
+ throw new Error("Invalid screen syntax or no screens found.");
68
+ }
69
+ return screens;
70
+ }
71
+ parseLayouts(input) {
72
+ const layoutRegex = /layout (\w+)\("(.+?)"\) type\("(.+?)"\) {([\s\S]*?)}(?!\s*\})/g;
73
+ const pageRegex = /page (\w+)\("(.+?)"\) view\((\w+)\)/g;
74
+ const layouts = [];
75
+ const processedPages = new Set(); // Track pages to avoid duplicates
76
+ let match;
77
+ while ((match = layoutRegex.exec(input)) !== null) {
78
+ const [_, name, route, type, content] = match;
79
+ const children = [];
80
+ // Parse nested layouts first and collect pages from them
81
+ const nestedLayouts = this.parseLayouts(content);
82
+ const nestedPages = new Set();
83
+ // console.log(nestedLayouts,"Nested layouts")
84
+ for (const nested of nestedLayouts) {
85
+ children.push(nested); // Add the nested layout
86
+ // nested.children.forEach((child) => {
87
+ // if (child.element) {
88
+ // nestedPages.add(child.element);
89
+ // }
90
+ // });
91
+ }
92
+ // Parse pages in the current layout and check for duplicates
93
+ console.log(this.removeLayoutSection(content), `pages for section ${name}`);
94
+ const pagecontent = this.removeLayoutSection(content);
95
+ let pageMatch;
96
+ while ((pageMatch = pageRegex.exec(pagecontent)) !== null) {
97
+ const [__, pageName, pageRoute, viewName] = pageMatch;
98
+ // Only add the page if it hasn't been added already (either in nested layouts or previous iterations)
99
+ if (!nestedPages.has(pageName) && !processedPages.has(pageName)) {
100
+ children.push({
101
+ element: viewName,
102
+ name: pageName,
103
+ route: pageRoute,
104
+ parentLayout: name
105
+ });
106
+ processedPages.add(pageName); // Mark as processed
107
+ }
108
+ nestedPages.delete(pageName);
109
+ }
110
+ nestedPages.clear();
111
+ // Add the layout to the final list
112
+ layouts.push({
113
+ name,
114
+ route,
115
+ type,
116
+ children,
117
+ });
118
+ }
119
+ return layouts;
120
+ }
121
+ removeLayoutSection(spec) {
122
+ // Regular expression to match the layout section
123
+ const layoutRegex = /layout\s+\w+\(".*?"\)\s+type\(".*?"\)\s*{[^}]*}/;
124
+ return spec.replace(layoutRegex, "").trim();
125
+ }
126
+ parseSpec() {
127
+ const sectionRnList = [];
128
+ this.basicProjectContent.sectionList.forEach(section => {
129
+ const sectionName = section.name.trim();
130
+ let screenList = [];
131
+ let layout = [];
132
+ let projectName = "";
133
+ const sectionObj = {
134
+ name: sectionName,
135
+ rnModuleList: [],
136
+ };
137
+ section.rnModuleList.forEach(rnModule => {
138
+ const rnFilePath = path_1.default.join(this.folderPath, `spec/${sectionName}/frontend/${rnModule.name}.rn`);
139
+ const specCode = fileHelper_1.FileHelper.readFile(rnFilePath);
140
+ const rnHelper = new BlendRNGrammarHelper_1.default();
141
+ const json = rnHelper.parseBlendRN(specCode);
142
+ if (!json.valid) {
143
+ throw new Error("Error while parsing the react native screens");
144
+ }
145
+ else {
146
+ sectionObj.rnModuleList.push(json.json);
147
+ }
148
+ // Parse screenList and layout from the spec file
149
+ // screenList = this.parseScreenList(specCode);
150
+ // layout = this.parseLayouts(specCode);
151
+ // projectName = rnModule.name;
152
+ });
153
+ sectionRnList.push(sectionObj);
154
+ });
155
+ // Write the generated configuration to a file
156
+ fileHelper_1.FileHelper.writeFile(`${this.configPath}/rnConfig.json`, JSON.stringify(sectionRnList, null, 4));
157
+ }
158
+ //Generate
159
+ buildScreens() {
160
+ const rnSectionList = JSON.parse(fileHelper_1.FileHelper.readFile(`${this.configPath}/rnConfig.json`));
161
+ console.log(rnSectionList, "rnSectionList");
162
+ rnSectionList.forEach(rnSection => {
163
+ const rnFolderPath = path_1.default.join(this.folderPath, `module/${rnSection.name}/react-native`);
164
+ rnSection.rnModuleList.forEach(rnModule => {
165
+ // this.checkForFolderAndCreateReactNativeApp(rnFolderPath, rnModule.name).then(res => {
166
+ this.buildLayouts(rnSection, rnModule);
167
+ const rnProjectPath = path_1.default.join(rnFolderPath, rnModule.name);
168
+ rnModule.screenList.forEach(screen => {
169
+ const screenPath = `${rnProjectPath}/src/view/${screen.path}/`;
170
+ const screenCode = this.generateScreenCode(screen);
171
+ fileHelper_1.FileHelper.createFile(`${screenPath}${screen.name}.tsx`, screenCode);
172
+ });
173
+ // })
174
+ });
175
+ });
176
+ }
177
+ buildComponents() {
178
+ const reactSectionList = JSON.parse(fileHelper_1.FileHelper.readFile(`${this.configPath}/rnConfig.json`));
179
+ reactSectionList.forEach(reactSection => {
180
+ const reactFolderPath = path_1.default.join(this.folderPath, `module/${reactSection.name}/react-native`);
181
+ reactSection.rnModuleList.forEach(reactModule => {
182
+ this.buildLayouts(reactSection, reactModule);
183
+ const rnProjectPath = path_1.default.join(reactFolderPath, reactModule.name);
184
+ const mdpHookComponentPath = `${rnProjectPath}/src-gen/component/mdpHook.ts`;
185
+ const mdpPath = `${rnProjectPath}/src-gen/component/MDP.ts`;
186
+ const mdpHookCode = this.generateMDPHookCode(reactModule.componentList);
187
+ fileHelper_1.FileHelper.writeFile(`${mdpHookComponentPath}`, mdpHookCode);
188
+ fileHelper_1.FileHelper.writeFile(`${mdpPath}`, `export interface MDP {getMetaData:() => any;}\nexport interface IBasicComponent {value?: any;onInput?:(val: any) => any;}`);
189
+ reactModule.componentList.forEach(component => {
190
+ const componentPath = `${rnProjectPath}/src/component/${component.path}/`;
191
+ const componentCode = this.generateComponentCode(component);
192
+ const mdpCode = this.generateComponentMDPCode(component);
193
+ fileHelper_1.FileHelper.createFile(`${componentPath}/${component.name}/${component.name}.tsx`, componentCode);
194
+ fileHelper_1.FileHelper.createFile(`${componentPath}/${component.name}/${component.name}MDP.ts`, mdpCode);
195
+ fileHelper_1.FileHelper.createFile(`${componentPath}/${component.name}/index.ts`, `export {default} from './${component.name}';\nexport * from "./${component.name}MDP";`);
196
+ });
197
+ });
198
+ });
199
+ }
200
+ generateMDPHookCode(componentList) {
201
+ const importsCode = `
202
+ ${componentList.reduce((acc, component) => {
203
+ acc = acc + `import ${component.name} from '../../src/component/${component.path}/${component.name}';\n`;
204
+ return acc;
205
+ }, "")}`;
206
+ return `
207
+ import React, { useEffect, useState } from "react"
208
+ import { MDP } from "./MDP";
209
+ ${importsCode}
210
+
211
+
212
+ export const useMetaData: (props: { mdpClass: MDP, defaultInput?: any; onInput?: (val: any) => void; extraProps?: any }) => [element: React.ReactElement, input: any, setInput: any] = (props) => {
213
+ console.log(props.defaultInput, props.mdpClass, "defaultInput")
214
+ const [input, setInput] = useState(props.defaultInput);
215
+
216
+
217
+
218
+
219
+ return [generateElementFromMetaData({
220
+ componentClassMetaData: props.mdpClass.getMetaData(),
221
+ onInput: (val: any) => {
222
+ setInput(val);
223
+ props.onInput && props.onInput(val)
224
+ },
225
+ value: input,
226
+ extraProps: props.extraProps
227
+ }), input, setInput]
228
+ }
229
+
230
+
231
+ export const generateElementFromMetaData = ({ componentClassMetaData, value, onInput, extraProps }: {
232
+ componentClassMetaData: any;
233
+ value?: any;
234
+ onInput?: any;
235
+ extraProps?: object;
236
+ }) => {
237
+ return React.createElement((ComponentNameMap[componentClassMetaData.componentName] as any), {
238
+ ...componentClassMetaData.props,
239
+ value: value,
240
+ onInput: onInput,
241
+ ...extraProps
242
+ })
243
+ }
244
+
245
+
246
+ const ComponentNameMap: any = {
247
+ ${componentList.reduce((acc, component) => {
248
+ acc = acc + `"${component.name}": ${component.name},\n`;
249
+ return acc;
250
+ }, "")}
251
+ }
252
+
253
+ export interface IMetaDataHook {
254
+ element: React.ReactElement,
255
+ input?: any;
256
+ }
257
+
258
+ `;
259
+ }
260
+ checkForFolderAndCreateReactNativeApp() {
261
+ return new Promise((checkRes) => __awaiter(this, void 0, void 0, function* () {
262
+ const rnSectionList = JSON.parse(fileHelper_1.FileHelper.readFile(`${this.configPath}/rnConfig.json`));
263
+ const promises = [];
264
+ rnSectionList.forEach(rnSection => {
265
+ const rnFolderPath = path_1.default.join(this.folderPath, `module/${rnSection.name}/react-native`);
266
+ fileHelper_1.FileHelper.ensureDir(rnFolderPath);
267
+ rnSection.rnModuleList.forEach(rnModule => {
268
+ const modulePath = path_1.default.join(rnFolderPath, rnModule.name);
269
+ if (!fileHelper_1.FileHelper.exists(modulePath)) {
270
+ promises.push(new Promise(res => {
271
+ runCommand(`npx @react-native-community/cli@latest init ${rnModule.name} --version 0.78.0`, rnFolderPath);
272
+ runCommand(`npm install -D @tsconfig/react-native@3.0.5 @types/jest@29.5.14 @types/react@19.0.10 @types/react-test-renderer@19.0.0 typescript@5.0.4`, modulePath);
273
+ const dependencies = [
274
+ '@react-navigation/bottom-tabs@7.2.1',
275
+ '@react-navigation/drawer@7.1.2',
276
+ '@react-navigation/material-top-tabs@7.1.1',
277
+ '@react-navigation/native@7.0.15',
278
+ '@react-navigation/native-stack@7.2.1',
279
+ '@reduxjs/toolkit@2.6.0',
280
+ 'react-native-gesture-handler@2.24.0',
281
+ 'react-native-pager-view@6.7.0',
282
+ 'react-native-reanimated@3.17.1',
283
+ 'react-native-safe-area-context@5.3.0',
284
+ 'react-native-screens@4.9.1',
285
+ 'react-redux@9.2.0',
286
+ 'redux-saga@1.3.0',
287
+ "axios@1.8.1",
288
+ "react-native-dotenv@3.4.11"
289
+ ];
290
+ runCommand(`npm install ${dependencies.join(' ')}`, modulePath);
291
+ fileHelper_1.FileHelper.writeFile(`${modulePath}/tsconfig.json`, `{
292
+ "extends": "@tsconfig/react-native/tsconfig.json"
293
+ }`);
294
+ fileHelper_1.FileHelper.writeFile(`${modulePath}/App.tsx`, mainAppcode);
295
+ fileHelper_1.FileHelper.writeFile(`${modulePath}/babel.config.js`, `module.exports = {
296
+ presets: ['module:@react-native/babel-preset'],
297
+ plugins: [
298
+ ['module:react-native-dotenv']
299
+ ]
300
+ };`);
301
+ fileHelper_1.FileHelper.writeFile(`${modulePath}/.env.dev`, "");
302
+ fileHelper_1.FileHelper.writeFile(`${modulePath}/.env.prod`, "");
303
+ fileHelper_1.FileHelper.writeFile(`${modulePath}/env.d.ts`, `
304
+ declare module '@env' {
305
+ export const API_URL: string;
306
+ export const APP_ENV: string;
307
+ }`);
308
+ }));
309
+ }
310
+ });
311
+ });
312
+ yield Promise.all(promises);
313
+ checkRes(true);
314
+ }));
315
+ // return new Promise(res => {
316
+ // const modulePath = path.join(rnProjectPath, projectName);
317
+ // if(!FileHelper.exists(modulePath)) {
318
+ // runCommand(`npx @react-native-community/cli@latest init ${projectName}`,rnProjectPath);
319
+ // res(true);
320
+ // } else {
321
+ // res(true)
322
+ // }
323
+ // });
324
+ }
325
+ buildLayouts(rnSection, rnModule) {
326
+ const rnFolderPath = path_1.default.join(this.folderPath, `module/${rnSection.name}/react-native`);
327
+ // const path = `${projectPath}/frontend/${frontEnd.name}/src/layout`;
328
+ const rnLayoutPath = path_1.default.join(rnFolderPath, rnModule.name);
329
+ // rnModule.layout.forEach(lo => {
330
+ const lo = {
331
+ name: "BlendGenerated",
332
+ route: "/",
333
+ children: rnModule.layout,
334
+ type: "Stack",
335
+ };
336
+ this.traverseChildrenAndCreateLayout(rnLayoutPath, lo, rnModule);
337
+ fileHelper_1.FileHelper.createFile(`${rnLayoutPath}/src/layout/${lo.name}Layout.tsx`, `
338
+ ${this.generateLayoutCode(lo, rnModule)}
339
+ `);
340
+ fileHelper_1.FileHelper.writeFile(`${rnLayoutPath}/src-gen/router/config/${lo.name}LayoutConfig.tsx`, `
341
+ ${this.generateLayoutCodeInterface(lo)}
342
+ `);
343
+ // })
344
+ }
345
+ traverseChildrenAndCreateLayout(rnLayoutPath, lo, frontEnd) {
346
+ lo.children.forEach(loChild => {
347
+ if (loChild.children) {
348
+ fileHelper_1.FileHelper.createFile(`${rnLayoutPath}/src/layout/${loChild.name}Layout.tsx`, `
349
+ ${this.generateLayoutCode(loChild, frontEnd)}
350
+ `);
351
+ fileHelper_1.FileHelper.writeFile(`${rnLayoutPath}/src-gen/router/config/${loChild.name}LayoutConfig.tsx`, `
352
+ ${this.generateLayoutCodeInterface(loChild)}
353
+ `);
354
+ this.traverseChildrenAndCreateLayout(rnLayoutPath, loChild, frontEnd);
355
+ }
356
+ });
357
+ }
358
+ generateRouterConstant(children) {
359
+ let path = '';
360
+ const routeObj = generateRouterConstantObj(children);
361
+ function generateRouterConstantObj(children) {
362
+ return children.reduce((acc, child, index) => {
363
+ if (child.children) {
364
+ // path = path+"/"+child.route;
365
+ console.log(path, "Path With layout");
366
+ path = child.route && child.route != "" && child.route != "/" ? path + "/" + child.route : path;
367
+ acc[child.name] = generateRouterConstantObj(child.children);
368
+ console.log(child.name, index, children.length, "Path With layout After");
369
+ if (index == children.length - 1) {
370
+ path = path.split("/").slice(0, -1).join('/').toString();
371
+ // const pathNumToBeRemoved = child.route.split("/").length;
372
+ // path = path.split("/").slice(0,-pathNumToBeRemoved).join('/').toString();
373
+ }
374
+ }
375
+ else {
376
+ path = child.route && child.route != "" && child.route != "/" ? path + "/" + child.route : path;
377
+ acc[child.name] = path;
378
+ console.log(path, "Path Without layout");
379
+ const pathNumToBeRemoved = child.route.split("/").length;
380
+ console.log(pathNumToBeRemoved, index, children.length, "pathNumToBeRemoved..............");
381
+ path = path.split("/").slice(0, -pathNumToBeRemoved).join('/').toString();
382
+ if (index == children.length - 1) {
383
+ path = path.split("/").slice(0, -1).join('/').toString();
384
+ // const pathNumToBeRemoved = child.route.split("/").length;
385
+ // path = path.split("/").slice(0,-pathNumToBeRemoved).join('/').toString();
386
+ }
387
+ }
388
+ return acc;
389
+ }, {});
390
+ }
391
+ return JSON.stringify(routeObj);
392
+ }
393
+ generateLayoutCode(lo, frontEnd) {
394
+ const layoutChildName = lo.type == "Stack" ? `${lo.name}LayoutStack` : lo.type == "Drawer" ? `${lo.name}LayoutDrawer` : lo.type == "BottomTab" ? `${lo.name}LayoutBottomTab` : `${lo.name}LayoutTopTab`;
395
+ return (`
396
+ import { ${lo.name}LayoutNavigator,${layoutChildName} } from '../../src-gen/router/config/${lo.name}LayoutConfig';
397
+ ${lo.children.reduce((acc, item) => {
398
+ const importCode = ` ${item.children ? `
399
+ import ${item.name}Layout from './${item.name}Layout';\n
400
+ ` : `
401
+ import ${item.element} from '../view/${this.findScreenPath(frontEnd.screenList, ((item === null || item === void 0 ? void 0 : item.element) || ""))}/${item.element}';\n
402
+ `}`;
403
+ acc = acc + importCode;
404
+ return acc;
405
+ }, "")}
406
+
407
+ const ${lo.name}Layout = () => {
408
+ return (
409
+ <${lo.name}LayoutNavigator>
410
+ ${lo.children.reduce((acc, item) => {
411
+ acc = acc + `
412
+ <${layoutChildName}.Screen component={${item.element ? item.element : `${item.name}Layout`}} name={'${item.element ? item.name : `${item.name}Layout`}'}></${layoutChildName}.Screen>\n
413
+ `;
414
+ return acc;
415
+ }, "")}
416
+ </${lo.name}LayoutNavigator>
417
+ )
418
+ }
419
+
420
+ export default ${lo.name}Layout;
421
+ `);
422
+ }
423
+ generateLayoutCodeInterface(lo) {
424
+ const mainImportCode = lo.type == "TopTab" ? `import { createMaterialTopTabNavigator } from "@react-navigation/material-top-tabs";`
425
+ : lo.type == "Drawer" ?
426
+ `import { createDrawerNavigator } from '@react-navigation/drawer';`
427
+ : lo.type == "BottomTab" ?
428
+ `import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";`
429
+ : `import { createNativeStackNavigator } from "@react-navigation/native-stack";`;
430
+ const layoutChildName = lo.type == "TopTab" ? `${lo.name}LayoutTopTab` : lo.type == "Drawer" ? `${lo.name}LayoutDrawer` : lo.type == "BottomTab" ? `${lo.name}LayoutBottomTab` : `${lo.name}LayoutStack`;
431
+ const layoutNavigatorFunction = lo.type == "TopTab" ? `createMaterialTopTabNavigator`
432
+ : lo.type == "Drawer" ? `createDrawerNavigator`
433
+ : lo.type == "BottomTab" ? `createBottomTabNavigator`
434
+ : `createNativeStackNavigator`;
435
+ return (`
436
+ ${mainImportCode}
437
+ export type ${lo.name}LayoutScreenList = {\n
438
+ ${lo.children.reduce((acc, frontEndLayout) => {
439
+ var _a;
440
+ acc = acc + `${frontEndLayout.name}${(frontEndLayout.children && ((_a = frontEndLayout.children) === null || _a === void 0 ? void 0 : _a.length) > 0) ? 'Layout' : ''}: any,\n`;
441
+ return acc;
442
+ }, "")}
443
+ }
444
+
445
+ export type ${lo.name}LayoutChildren = ${lo.children && lo.children.length > 1 ? `[${new Array(lo.children.length).fill("React.ReactNode")}]` : "React.ReactNode"}
446
+
447
+ export const ${layoutChildName} = ${layoutNavigatorFunction}<${lo.name}LayoutScreenList>();
448
+ export const ${lo.name}LayoutNavigator: React.FC<{ children: ${lo.name}LayoutChildren }> = ({
449
+ children,
450
+ }) => {
451
+ return <${layoutChildName}.Navigator>{children}</${layoutChildName}.Navigator>;
452
+ };
453
+
454
+ /*const ${lo.name}Layout = () => {
455
+ return (
456
+ <${lo.name}LayoutNavigator>
457
+ ${lo.children.reduce((acc, item) => {
458
+ acc = acc + `
459
+ <${layoutChildName}.Screen component={${item.element ? item.element : `${item.name}Layout`}} name={'${item.name}'}></${layoutChildName}.Screen>\n
460
+ `;
461
+ return acc;
462
+ }, "")}
463
+ </${lo.name}LayoutNavigator>
464
+ )
465
+ }
466
+ */
467
+
468
+ `);
469
+ }
470
+ generateScreenCode(screen) {
471
+ return `
472
+ import React from "react";
473
+ import {Text} from "react-native";
474
+ const ${screen.name} = () => {
475
+ return(
476
+ <Text>
477
+ ${screen.name}
478
+ </Text>
479
+ )
480
+ }
481
+
482
+ export default ${screen.name};
483
+ `;
484
+ }
485
+ findScreenPath(screenList, screenName) {
486
+ const index = screenList.findIndex(screen => screen.name === screenName);
487
+ if (screenList[index]) {
488
+ return screenList[index].path;
489
+ }
490
+ else {
491
+ alert(`${screenName} not found`);
492
+ }
493
+ }
494
+ generateComponentCode(component) {
495
+ return `
496
+ import React from "react";
497
+ import {Text} from "react-native";
498
+ import {I${component.name}Props} from './${component.name}MDP';
499
+ const ${component.name} = (props: I${component.name}Props) => {
500
+ return(
501
+ <Text>
502
+ ${component.name}
503
+ </Text>
504
+ )
505
+ }
506
+
507
+ export default ${component.name};
508
+ `;
509
+ }
510
+ generateComponentMDPCode(component) {
511
+ const pathCode = '../../../' + component.path.split("/").reduce((acc, curVal) => {
512
+ acc = acc + '../';
513
+ return acc;
514
+ }, "");
515
+ return `
516
+ import { MDP,IBasicComponent } from "${pathCode}src-gen/component/MDP";
517
+
518
+ export class ${component.name}MDP implements I${component.name}MDP {
519
+ componentName: string = "${component.name}";
520
+
521
+ getMetaData() {
522
+ return {
523
+ componentName: this.componentName,
524
+ props: {
525
+ }
526
+
527
+ }
528
+ }
529
+ }
530
+
531
+ export interface I${component.name}Props extends IBasicComponent {
532
+ }
533
+ export interface I${component.name}MDP extends MDP {
534
+ getMetaData: () => {componentName: string, props: I${component.name}Props}
535
+ }
536
+ `;
537
+ }
538
+ }
539
+ exports.default = RNHelper;
540
+ const mainAppcode = `
541
+
542
+ import React from 'react';
543
+
544
+
545
+ import { NavigationContainer } from '@react-navigation/native';
546
+ import BlendGeneratedLayout from './src/layout/BlendGeneratedLayout';
547
+ function App(): React.JSX.Element {
548
+
549
+
550
+ return (
551
+ <NavigationContainer>
552
+ <BlendGeneratedLayout />
553
+ </NavigationContainer>
554
+ );
555
+ }
556
+
557
+
558
+ export default App;
559
+
560
+ `;