blend-r 1.1.6

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 (30) hide show
  1. package/README.md +213 -0
  2. package/dist/helper/ApiHelper.js +766 -0
  3. package/dist/helper/BasicHelper.js +43 -0
  4. package/dist/helper/DataHelper.js +231 -0
  5. package/dist/helper/FrontEndHelper.js +201 -0
  6. package/dist/helper/fileHelper.js +127 -0
  7. package/dist/helper/grammarHelper/BlendApiGrammarHelper.js +90 -0
  8. package/dist/helper/grammarHelper/BlendBasicGrammarHelper.js +135 -0
  9. package/dist/helper/grammarHelper/BlendDataGrammarHelper.js +47 -0
  10. package/dist/helper/grammarHelper/GrammarErrorHelper.js +16 -0
  11. package/dist/index.js +87 -0
  12. package/dist/parser/blendApi/src/grammar/BlendApiLexer.js +207 -0
  13. package/dist/parser/blendApi/src/grammar/BlendApiListener.js +3 -0
  14. package/dist/parser/blendApi/src/grammar/BlendApiParser.js +978 -0
  15. package/dist/parser/blendData/src/grammar/BlendDataLexer.js +154 -0
  16. package/dist/parser/blendData/src/grammar/BlendDataListener.js +3 -0
  17. package/dist/parser/blendData/src/grammar/BlendDataParser.js +642 -0
  18. package/dist/parser/blendRBasic/src/grammar/BlendRBasicListener.js +3 -0
  19. package/dist/parser/blendRBasic/src/grammar/blendRBasicLexer.js +184 -0
  20. package/dist/parser/blendRBasic/src/grammar/blendRBasicParser.js +993 -0
  21. package/dist/parser/blendRnBasic/src/grammar/BlendRnBasicLexer.js +214 -0
  22. package/dist/parser/blendRnBasic/src/grammar/BlendRnBasicListener.js +3 -0
  23. package/dist/parser/blendRnBasic/src/grammar/BlendRnBasicParser.js +1224 -0
  24. package/dist/types/apiOperationTypes.js +20 -0
  25. package/dist/types/basicOperationTypes.js +3 -0
  26. package/dist/types/dataOperationTypes.js +2 -0
  27. package/dist/types/frontendOperationTypes.js +4 -0
  28. package/dist/types/generalTypes.js +0 -0
  29. package/dist/types/mongoOperationTypes.js +12 -0
  30. package/package.json +36 -0
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fileHelper_1 = require("./fileHelper");
7
+ const path_1 = __importDefault(require("path"));
8
+ const BlendBasicGrammarHelper_1 = __importDefault(require("./grammarHelper/BlendBasicGrammarHelper"));
9
+ class BasicHelper {
10
+ constructor() {
11
+ this.folderPath = path_1.default.join(process.cwd());
12
+ this.folderName = path_1.default.basename(this.folderPath);
13
+ this.basicFilePath = path_1.default.join(this.folderPath, `${this.folderName}.basic`);
14
+ this.configPath = path_1.default.join(this.folderPath, '.basicConfig');
15
+ this.specPath = path_1.default.join(this.folderPath, 'spec');
16
+ }
17
+ parseSpec(spec) {
18
+ const blendbasic = new BlendBasicGrammarHelper_1.default();
19
+ const basicParsedJSON = blendbasic.parseBlendBasic(spec);
20
+ if (basicParsedJSON.valid) {
21
+ basicParsedJSON.basicJson.name = this.folderName;
22
+ fileHelper_1.FileHelper.ensureDir(this.configPath);
23
+ fileHelper_1.FileHelper.writeFile(`${this.configPath}/basicConfig.json`, JSON.stringify(basicParsedJSON.basicJson));
24
+ }
25
+ else {
26
+ }
27
+ }
28
+ createRequiredFile(spec) {
29
+ const blendbasic = new BlendBasicGrammarHelper_1.default();
30
+ const basicParsedJSON = blendbasic.parseBlendBasic(spec);
31
+ if (basicParsedJSON.valid) {
32
+ basicParsedJSON.basicJson.dataModuleList.map(item => {
33
+ fileHelper_1.FileHelper.createFile(`${this.specPath}/data/${item}.data`, `module ${item}`);
34
+ });
35
+ basicParsedJSON.basicJson.apiModuleList.map(item => {
36
+ fileHelper_1.FileHelper.createFile(`${this.specPath}/api/${item}.api`, `module ${item}`);
37
+ });
38
+ }
39
+ else {
40
+ }
41
+ }
42
+ }
43
+ exports.default = BasicHelper;
@@ -0,0 +1,231 @@
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 path_1 = __importDefault(require("path"));
16
+ const fileHelper_1 = require("./fileHelper");
17
+ const BlendDataGrammarHelper_1 = __importDefault(require("./grammarHelper/BlendDataGrammarHelper"));
18
+ const basicDataTypes = ["string", "object", "boolean", "number", "any"];
19
+ class DataHelper {
20
+ constructor() {
21
+ this.folderPath = path_1.default.join(process.cwd());
22
+ this.folderName = path_1.default.basename(this.folderPath);
23
+ this.basicFilePath = path_1.default.join(this.folderPath, `${this.folderName}.basic`);
24
+ this.configPath = path_1.default.join(this.folderPath, '.basicConfig');
25
+ this.specPath = path_1.default.join(this.folderPath, 'spec');
26
+ }
27
+ parseSpec() {
28
+ const basicFile = JSON.parse(fileHelper_1.FileHelper.readFile(`${this.configPath}/basicConfig.json`));
29
+ let mainDataObjList = [];
30
+ const dataFolderPath = path_1.default.join(this.folderPath, 'spec/data');
31
+ basicFile.dataModuleList.forEach(module => {
32
+ const filePath = path_1.default.join(dataFolderPath, `${module}.data`);
33
+ const specCode = fileHelper_1.FileHelper.readFile(filePath);
34
+ const json = new BlendDataGrammarHelper_1.default().parseBlendData(specCode);
35
+ console.log(json, "json");
36
+ if (!json.valid) {
37
+ throw new Error("Error while parsing the syntax");
38
+ }
39
+ const moduleDataObject = json.moduleDataObject;
40
+ mainDataObjList.push(moduleDataObject);
41
+ });
42
+ // sectionDataObjList.push({
43
+ // name: sectionName,
44
+ // sectionDataList: mainDataObjList
45
+ // });
46
+ fileHelper_1.FileHelper.writeFile(`${this.configPath}/dataConfig.json`, JSON.stringify(mainDataObjList));
47
+ }
48
+ parseJSONAndGenerateFiles() {
49
+ try {
50
+ const moduleDataList = JSON.parse(fileHelper_1.FileHelper.readFile(`${this.configPath}/dataConfig.json`));
51
+ moduleDataList.forEach((moduleData) => __awaiter(this, void 0, void 0, function* () {
52
+ const dataPath = path_1.default.join(this.folderPath, `src-gen/data/${moduleData.name}.ts`);
53
+ const imports = new Set(); // Collect unique imports
54
+ // Generate class definitions
55
+ const classesCode = moduleData.dataList
56
+ .map((curItem) => {
57
+ // Collect imports for fields with types like "Module->ClassName"
58
+ curItem.fields.forEach((field) => {
59
+ const typeParts = field.type.split("->");
60
+ if (typeParts.length === 2) {
61
+ const [module, typeName] = typeParts;
62
+ const baseTypeName = typeName.endsWith("[]") ? typeName.slice(0, -2) : typeName;
63
+ imports.add(`import { ${baseTypeName} } from './${module}';`);
64
+ }
65
+ });
66
+ // Generate the class code
67
+ return `
68
+ export class ${curItem.name} {
69
+ constructor(
70
+ ${curItem.fields
71
+ .map((field) => ` public ${field.name}: ${this.resolveType(field.type)}${!field.required ? '|undefined' : ''} = ${this.getDefaultValue(field, moduleData)},`)
72
+ .join('\n')}
73
+ ) {}
74
+
75
+ static fromJSON(jsonObj: any): ${curItem.name} {
76
+ return new ${curItem.name}(
77
+ ${curItem.fields
78
+ .map((field) => this.generateFromJSONField(field))
79
+ .join(',\n')}
80
+ );
81
+ }
82
+
83
+ public toJSON(): any {
84
+ return {
85
+ ${curItem.fields
86
+ .map((field) => this.generateToJSONField(field, moduleData))
87
+ .join('\n')}
88
+ };
89
+ }
90
+ }
91
+
92
+
93
+ export interface I_${curItem.name} {
94
+ ${curItem.fields
95
+ .map((field) => ` ${field.name}: ${this.resolveType(field.type)}${field.required ? '|undefined' : ''},`)
96
+ .join('\n')}
97
+ }
98
+ `;
99
+ })
100
+ .join('\n');
101
+ // Combine imports and class definitions
102
+ const finalCode = `
103
+ ${Array.from(imports).join('\n')}
104
+
105
+ ${classesCode}
106
+ `;
107
+ fileHelper_1.FileHelper.writeFile(dataPath, finalCode);
108
+ // this.basicProjectContent.sectionList.forEach(section => {
109
+ // section.expressModuleList.forEach(expressModule => {
110
+ // // if (expressModule.includedDataModuleList.includes(moduleData.name)) {
111
+ // if(section.name==sectionData.name) {
112
+ // const expressDataPath = `${this.folderPath}/module/${section.name}/express/${section.name}-api/src-gen/data/${expressModule.name}/${moduleData.name}.ts`
113
+ // FileHelper.writeFile(expressDataPath, finalCode);
114
+ // }
115
+ // // }
116
+ // });
117
+ // })
118
+ }));
119
+ }
120
+ catch (e) {
121
+ }
122
+ }
123
+ resolveType(type) {
124
+ const typeParts = type.split("->");
125
+ const baseType = typeParts.length === 2 ? typeParts[1] : type;
126
+ return baseType.endsWith("[]") ? `${baseType.slice(0, -2)}[]` : baseType; // Handle array types
127
+ }
128
+ getDefaultValue(field, curItem) {
129
+ const typeParts = field.type.split("->");
130
+ const baseType = typeParts.length === 2 ? typeParts[1] : field.type;
131
+ if (baseType.endsWith("[]")) {
132
+ return "[]"; // Default value for arrays
133
+ }
134
+ if (typeParts.length === 2) {
135
+ const [, typeName] = typeParts;
136
+ const baseTypeName = typeName.endsWith("[]") ? typeName.slice(0, -2) : typeName;
137
+ return `new ${baseTypeName}()`; // Instantiate the imported class
138
+ }
139
+ if (!basicDataTypes.includes(field.type)) {
140
+ const currentFieldType = curItem.dataList.find(item => item.name == field.type);
141
+ if (!currentFieldType) {
142
+ throw new Error(`unable to find out ${currentFieldType}`);
143
+ }
144
+ else {
145
+ if (field.required) {
146
+ return `new ${currentFieldType.name}()`;
147
+ }
148
+ else {
149
+ return undefined;
150
+ }
151
+ }
152
+ }
153
+ else {
154
+ switch (field.type) {
155
+ case "string":
156
+ return field.required ? "''" : "undefined";
157
+ case "object":
158
+ return field.required ? "{}" : "undefined";
159
+ case "boolean":
160
+ return field.required ? "false" : "undefined";
161
+ case "number":
162
+ return field.required ? "0" : "undefined";
163
+ default:
164
+ return "null";
165
+ }
166
+ }
167
+ }
168
+ generateFromJSONField(field) {
169
+ const typeParts = field.type.split("->");
170
+ const baseType = typeParts.length === 2 ? typeParts[1] : field.type;
171
+ if (baseType.endsWith("[]")) {
172
+ const elementType = baseType.slice(0, -2);
173
+ if (["string", "number", "boolean"].includes(elementType)) {
174
+ return ` jsonObj.${field.name} ?? []`;
175
+ }
176
+ return ` (jsonObj.${field.name} != null) ? jsonObj.${field.name}.map((item: any) => ${elementType}.fromJSON(item)) : []`;
177
+ }
178
+ if (typeParts.length === 2) {
179
+ const [, typeName] = typeParts;
180
+ const baseTypeName = typeName.endsWith("[]") ? typeName.slice(0, -2) : typeName;
181
+ return ` (jsonObj.${field.name} != null) ? ${baseTypeName}.fromJSON(jsonObj.${field.name}) : new ${baseTypeName}()`;
182
+ }
183
+ if (!basicDataTypes.includes(baseType)) {
184
+ const baseTypeName = baseType.endsWith("[]") ? baseType.slice(0, -2) : baseType;
185
+ return ` (jsonObj.${field.name} != null) ? ${baseTypeName}.fromJSON(jsonObj.${field.name}) : new ${baseTypeName}()`;
186
+ }
187
+ return ` (jsonObj.${field.name} !== null) ? jsonObj?.${field.name} : undefined`;
188
+ }
189
+ // generateToJSONField(field: IDataField): string {
190
+ // const typeParts = field.type.split("->");
191
+ // const baseType = typeParts.length === 2 ? typeParts[1] : field.type;
192
+ // if (baseType.endsWith("[]")) {
193
+ // const elementType = baseType.slice(0, -2);
194
+ // if (["string", "number", "boolean"].includes(elementType)) {
195
+ // return ` ${field.name}: this.${field.name} ?? [],`;
196
+ // }
197
+ // return ` ${field.name}: (this.${field.name} != null) ? this.${field.name}.map((x) => x.toJSON()) : [],`;
198
+ // }
199
+ // return ` ${field.name}: this.${field.name} != null ? this.${field.name} : undefined,`;
200
+ // }
201
+ generateToJSONField(field, curItem) {
202
+ // const typeParts = field.type.split("->");
203
+ // const baseType = typeParts.length === 2 ? typeParts[1] : field.type;
204
+ // if (baseType.endsWith("[]")) {
205
+ // const elementType = baseType.slice(0, -2);
206
+ // if (["string", "number", "boolean"].includes(elementType)) {
207
+ // return ` ${field.name}: this.${field.name} ?? [],`;
208
+ // }
209
+ // return ` ${field.name}: (this.${field.name} != null) ? this.${field.name}.map((x) => x.toJson()) : [],`;
210
+ // }
211
+ // return ` ${field.name}: this.${field.name} != null ? this.${field.name} : undefined,`;
212
+ const typeParts = field.type.split("->");
213
+ const baseType = typeParts.length === 2 ? typeParts[1] : field.type;
214
+ if (baseType.endsWith("[]")) {
215
+ const elementType = baseType.slice(0, -2);
216
+ if (["string", "number", "boolean", "object", "any"].includes(elementType)) {
217
+ return ` ${field.name}: this.${field.name} ?? [],`;
218
+ }
219
+ return ` ${field.name}: (this.${field.name} != null) ? this.${field.name}.map((x) => x.toJSON()) : [],`;
220
+ }
221
+ else {
222
+ if (["string", "number", "boolean", "object", "any"].includes(baseType)) {
223
+ return `${field.name}: this.${field.name} != null ? this.${field.name} : ${this.getDefaultValue(field, curItem)},`;
224
+ }
225
+ else {
226
+ return ` ${field.name}: this.${field.name} != null ? this.${field.name}.toJSON() : ${this.getDefaultValue(field, curItem)}.toJSON(),`;
227
+ }
228
+ }
229
+ }
230
+ }
231
+ exports.default = DataHelper;
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const fileHelper_1 = require("./fileHelper");
8
+ class FrontEndHelper {
9
+ constructor() {
10
+ this.folderPath = path_1.default.join(process.cwd());
11
+ this.folderName = path_1.default.basename(this.folderPath);
12
+ this.basicFilePath = path_1.default.join(this.folderPath, `${this.folderName}.basic`);
13
+ this.configPath = path_1.default.join(this.folderPath, '.basicConfig');
14
+ this.specPath = path_1.default.join(this.folderPath, 'spec');
15
+ }
16
+ buildFrontEnd() {
17
+ this.generateFrontEndScreen();
18
+ this.buildLayouts();
19
+ this.generateComponents();
20
+ }
21
+ generateFrontEndScreen() {
22
+ const basicFile = JSON.parse(fileHelper_1.FileHelper.readFile(`${this.configPath}/basicConfig.json`));
23
+ basicFile.frontend.screenList.map(screen => {
24
+ const screenPath = `${this.folderPath}/src/view/${screen.path}/${screen.name}/`;
25
+ const screenCode = this.generateScreenCode(screen);
26
+ fileHelper_1.FileHelper.createFile(`${screenPath}${screen.name}View.tsx`, screenCode);
27
+ fileHelper_1.FileHelper.createFile(`${screenPath}${screen.name}Style.css`, `
28
+ `);
29
+ fileHelper_1.FileHelper.ensureDir(`${screenPath}/components`);
30
+ });
31
+ }
32
+ // createTestCaseCode() {
33
+ // }
34
+ generateComponents() {
35
+ const basicFile = JSON.parse(fileHelper_1.FileHelper.readFile(`${this.configPath}/basicConfig.json`));
36
+ basicFile.frontend.componentList.map(component => {
37
+ const screenPath = `${this.folderPath}/src/components/${component.path}/${component.name}/`;
38
+ const screenCode = this.generateScreenCode(component);
39
+ fileHelper_1.FileHelper.createFile(`${screenPath}${component.name}Comp.tsx`, screenCode);
40
+ fileHelper_1.FileHelper.createFile(`${screenPath}${component.name}Style.ts`, `
41
+ import { StyleSheet } from 'react-native';
42
+ const styles = StyleSheet.create({})
43
+ export default styles;
44
+ `);
45
+ });
46
+ }
47
+ generateScreenCode(screen) {
48
+ return `
49
+ import "./${screen.name}Style.css"
50
+ const ${screen.name} = () => {
51
+ return(
52
+ <div>
53
+ ${screen.name}
54
+ </div>
55
+ )
56
+ }
57
+
58
+ export default ${screen.name};
59
+ `;
60
+ }
61
+ buildLayouts() {
62
+ const basicFile = JSON.parse(fileHelper_1.FileHelper.readFile(`${this.configPath}/basicConfig.json`));
63
+ const lo = {
64
+ name: "BlendGenerated",
65
+ route: "/",
66
+ children: basicFile.frontend.layout,
67
+ };
68
+ const routerCode = this.generateRouterCode(lo, basicFile);
69
+ fileHelper_1.FileHelper.writeFile(`${this.folderPath}/src-gen/router/blend-router.tsx`, routerCode);
70
+ this.traverseChildrenAndCreateLayout(lo, basicFile.frontend);
71
+ const routerConstant = this.generateRouterConstant(basicFile.frontend.layout);
72
+ fileHelper_1.FileHelper.createFile(`${this.folderPath}/src/layout/${lo.name}Layout.tsx`, `
73
+ ${this.generateLayoutCode(lo)}
74
+ `);
75
+ fileHelper_1.FileHelper.writeFile(`${this.folderPath}/src-gen/router/routerConstant.ts`, `
76
+ ${routerConstant}
77
+ `);
78
+ // })
79
+ }
80
+ traverseChildrenAndCreateLayout(lo, frontEnd) {
81
+ lo.children.forEach(loChild => {
82
+ if (loChild.children) {
83
+ fileHelper_1.FileHelper.createFile(`${this.folderPath}/src/layout/${loChild.name}Layout.tsx`, `
84
+ ${this.generateLayoutCode(loChild)}
85
+ `);
86
+ this.traverseChildrenAndCreateLayout(loChild, frontEnd);
87
+ }
88
+ });
89
+ }
90
+ findScreenPath(screenList, screenName) {
91
+ const index = screenList.findIndex(screen => screen.name === screenName);
92
+ if (screenList[index]) {
93
+ return `${screenList[index].path}`;
94
+ }
95
+ else {
96
+ // alert(`${screenName} not found`)
97
+ }
98
+ }
99
+ generateRouterConstant(children) {
100
+ let path = '';
101
+ const routeObj = generateRouterConstantObj(children);
102
+ function generateRouterConstantObj(children) {
103
+ return children.reduce((acc, child, index) => {
104
+ if (child.children) {
105
+ path = child.route && child.route != "" && child.route != "/" ? path + "/" + child.route : path;
106
+ acc[child.name] = generateRouterConstantObj(child.children);
107
+ console.log(child.name, index, children.length, "Path With layout After");
108
+ if (index == children.length - 1) {
109
+ path = path.split("/").slice(0, -1).join('_').toString();
110
+ // const pathNumToBeRemoved = child.route.split("/").length;
111
+ // path = path.split("/").slice(0,-pathNumToBeRemoved).join('/').toString();
112
+ }
113
+ }
114
+ else {
115
+ path = child.route && child.route != "" && child.route != "/" ? path + "/" + child.route : path;
116
+ acc[child.name] = path;
117
+ console.log(path, "Path Without layout");
118
+ const pathNumToBeRemoved = child.route.split("/").length;
119
+ console.log(pathNumToBeRemoved, index, children.length, "pathNumToBeRemoved..............");
120
+ path = path.split("/").slice(0, -pathNumToBeRemoved).join('_').toString();
121
+ if (index == children.length - 1) {
122
+ path = path.split("/").slice(0, -1).join('_').toString();
123
+ // const pathNumToBeRemoved = child.route.split("/").length;
124
+ // path = path.split("/").slice(0,-pathNumToBeRemoved).join('/').toString();
125
+ }
126
+ }
127
+ return acc;
128
+ }, {});
129
+ }
130
+ return `export const RouterConstant = ${JSON.stringify(routeObj)}`;
131
+ }
132
+ generateLayoutCode(lo) {
133
+ return (`
134
+ import { Outlet } from "react-router-dom"
135
+ const ${lo.name}Layout = () => {
136
+ return (
137
+ <div>
138
+ ${lo.name}Layout
139
+ <Outlet />
140
+ </div>
141
+ )
142
+ }
143
+
144
+ export default ${lo.name}Layout;
145
+ `);
146
+ }
147
+ generateFlattenedArray(children) {
148
+ let uniqueElements = [];
149
+ let flatenedArray = [];
150
+ generateFlattenedArrayFun(children);
151
+ function generateFlattenedArrayFun(children) {
152
+ return children.forEach((child) => {
153
+ flatenedArray.push(child);
154
+ if (child.children) {
155
+ generateFlattenedArrayFun(child.children);
156
+ }
157
+ else {
158
+ if (!uniqueElements.includes(child.element)) {
159
+ uniqueElements.push(child.element);
160
+ }
161
+ else {
162
+ flatenedArray.pop();
163
+ }
164
+ }
165
+ });
166
+ }
167
+ return flatenedArray;
168
+ }
169
+ generateRouterCode(mainLayout, basicFile) {
170
+ const defaultImportCode = `
171
+ import { createBrowserRouter } from 'react-router-dom';\n
172
+ import React from 'react';\n
173
+ import BlendGeneratedLayout from '../../src/layout/BlendGeneratedLayout';
174
+ `;
175
+ console.log([mainLayout], JSON.stringify([mainLayout]), "Main layout///////////////");
176
+ const routerJsonCode = `const router = createBrowserRouter([${this.generateLayoutRouterJSONCode([mainLayout])}])\nexport default router;`;
177
+ const routerConstant = this.generateRouterConstant([mainLayout]);
178
+ console.log(this.generateFlattenedArray(mainLayout.children), "this.generateFlattenedArray(mainLayout.children)");
179
+ const importCode = `${this.generateFlattenedArray(mainLayout.children).reduce((acc, item) => {
180
+ const importCode = ` ${item.children ? `
181
+ import ${item.name}Layout from '../../src/layout/${item.name}Layout';\n
182
+ ` : `
183
+ import ${item.element} from '../../src/view/${this.findScreenPath(basicFile.frontend.screenList, ((item === null || item === void 0 ? void 0 : item.element) || ""))}/${item.element}/${item.element}View';\n
184
+ `}`;
185
+ acc = acc + importCode;
186
+ return acc;
187
+ }, "")}`;
188
+ return importCode + defaultImportCode + routerJsonCode + '\n' + routerConstant;
189
+ }
190
+ generateLayoutRouterJSONCode(layoutList) {
191
+ return layoutList.reduce((acc, layout) => {
192
+ acc = acc + `{element: ${layout.children ? `<${layout.name}Layout/>,` : `<${layout.element} />,`}
193
+ path: "${layout.route}",
194
+ ${layout.children ? `children: [${this.generateLayoutRouterJSONCode(layout.children)}],` : ``}
195
+ },
196
+ `;
197
+ return acc;
198
+ }, '');
199
+ }
200
+ }
201
+ exports.default = FrontEndHelper;
@@ -0,0 +1,127 @@
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
+ exports.FileHelper = void 0;
16
+ // fileHelper.ts
17
+ const fs_extra_1 = __importDefault(require("fs-extra"));
18
+ const path_1 = __importDefault(require("path"));
19
+ class FileHelper {
20
+ // Ensure a directory exists, create it if it doesn't
21
+ static ensureDir(folderPath) {
22
+ try {
23
+ fs_extra_1.default.ensureDirSync(folderPath);
24
+ }
25
+ catch (error) {
26
+ console.error(`Error ensuring directory: ${error.message}`);
27
+ throw error;
28
+ }
29
+ }
30
+ static writeFile(filePath, content) {
31
+ try {
32
+ // Ensure the folder exists
33
+ const folderPath = path_1.default.dirname(filePath);
34
+ this.ensureDir(folderPath);
35
+ // Write the file
36
+ fs_extra_1.default.writeFileSync(filePath, content);
37
+ }
38
+ catch (error) {
39
+ console.error(`Error writing file at ${filePath}: ${error.message}`);
40
+ throw error;
41
+ }
42
+ }
43
+ static createFile(filePath, content) {
44
+ try {
45
+ // Ensure the folder exists
46
+ const folderPath = path_1.default.dirname(filePath);
47
+ this.ensureDir(folderPath);
48
+ if (!fs_extra_1.default.existsSync(filePath)) {
49
+ fs_extra_1.default.writeFileSync(filePath, content);
50
+ }
51
+ // Write the file
52
+ }
53
+ catch (error) {
54
+ console.error(`Error writing file at ${filePath}: ${error.message}`);
55
+ throw error;
56
+ }
57
+ }
58
+ // Read content from a file
59
+ static readFile(filePath) {
60
+ try {
61
+ return fs_extra_1.default.readFileSync(filePath, 'utf-8');
62
+ }
63
+ catch (error) {
64
+ console.error(`Error reading file at ${filePath}: ${error.message}`);
65
+ throw error;
66
+ }
67
+ }
68
+ // Write a JSON object to a file, ensuring the folder exists
69
+ static writeJson(filePath, jsonContent) {
70
+ try {
71
+ // Ensure the folder exists
72
+ const folderPath = path_1.default.dirname(filePath);
73
+ this.ensureDir(folderPath);
74
+ // Write the JSON file
75
+ fs_extra_1.default.writeJsonSync(filePath, jsonContent, { spaces: 2 });
76
+ }
77
+ catch (error) {
78
+ console.error(`Error writing JSON to ${filePath}: ${error.message}`);
79
+ throw error;
80
+ }
81
+ }
82
+ // Check if a file or directory exists
83
+ static exists(filePath) {
84
+ try {
85
+ return fs_extra_1.default.existsSync(filePath);
86
+ }
87
+ catch (error) {
88
+ console.error(`Error checking existence of ${filePath}: ${error.message}`);
89
+ throw error;
90
+ }
91
+ }
92
+ // Copy a file from source to destination, ensuring the destination folder exists
93
+ static copyFile(srcPath, destPath) {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ try {
96
+ // Ensure the destination folder exists
97
+ yield fs_extra_1.default.ensureDir(path_1.default.dirname(destPath));
98
+ // Copy the file
99
+ yield fs_extra_1.default.copyFile(srcPath, destPath);
100
+ console.log(`File copied from ${srcPath} to ${destPath}`);
101
+ }
102
+ catch (error) {
103
+ console.error(`Error copying file from ${srcPath} to ${destPath}: ${error.message}`);
104
+ throw error;
105
+ }
106
+ });
107
+ }
108
+ /**
109
+ * Copies an entire folder from source to destination, including its contents.
110
+ * @param srcFolder The path to the source folder.
111
+ * @param destFolder The path to the destination folder.
112
+ */
113
+ static copyFolder(srcFolder, destFolder) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ try {
116
+ // Copy the folder recursively
117
+ yield fs_extra_1.default.copy(srcFolder, destFolder, { overwrite: true });
118
+ console.log(`Folder copied from ${srcFolder} to ${destFolder}`);
119
+ }
120
+ catch (error) {
121
+ console.error(`Error copying folder from ${srcFolder} to ${destFolder}: ${error.message}`);
122
+ throw error;
123
+ }
124
+ });
125
+ }
126
+ }
127
+ exports.FileHelper = FileHelper;