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.
- package/dist/helper/ApiHelper.js +0 -0
- package/dist/helper/BasicHelper.js +28 -0
- package/dist/helper/CommonHelper.js +10 -0
- package/dist/helper/DataHelper.js +241 -0
- package/dist/helper/ExpressHelper.js +728 -0
- package/dist/helper/FrontEndApiHelper.js +485 -0
- package/dist/helper/FrontEndReactApiHelper.js +483 -0
- package/dist/helper/MongoHelper.js +143 -0
- package/dist/helper/RNHelper.js +560 -0
- package/dist/helper/ReactHelper.js +524 -0
- package/dist/helper/SectionHelper.js +152 -0
- package/dist/helper/fileHelper.js +127 -0
- package/dist/helper/grammarHelper/BlendApiGrammarHelper.js +48 -0
- package/dist/helper/grammarHelper/BlendBasicGrammarHelper.js +98 -0
- package/dist/helper/grammarHelper/BlendDataGrammarHelper.js +47 -0
- package/dist/helper/grammarHelper/BlendMDPGrammarHelper.js +29 -0
- package/dist/helper/grammarHelper/BlendMongoGrammarHelper.js +51 -0
- package/dist/helper/grammarHelper/BlendRNGrammarHelper.js +56 -0
- package/dist/helper/grammarHelper/BlendReactGrammarHelper.js +55 -0
- package/dist/helper/grammarHelper/GrammarErrorHelper.js +16 -0
- package/dist/index.js +159 -0
- package/dist/parser/blendApi/src/grammar/BlendApiLexer.js +201 -0
- package/dist/parser/blendApi/src/grammar/BlendApiListener.js +3 -0
- package/dist/parser/blendApi/src/grammar/BlendApiParser.js +961 -0
- package/dist/parser/blendData/src/grammar/BlendDataLexer.js +154 -0
- package/dist/parser/blendData/src/grammar/BlendDataListener.js +3 -0
- package/dist/parser/blendData/src/grammar/BlendDataParser.js +641 -0
- package/dist/parser/blendMDP/src/grammar/BlendMDPLexer.js +151 -0
- package/dist/parser/blendMDP/src/grammar/BlendMDPListener.js +3 -0
- package/dist/parser/blendMDP/src/grammar/BlendMDPParser.js +490 -0
- package/dist/parser/blendMongo/src/grammar/BlendMongoLexer.js +187 -0
- package/dist/parser/blendMongo/src/grammar/BlendMongoListener.js +3 -0
- package/dist/parser/blendMongo/src/grammar/BlendMongoParser.js +848 -0
- package/dist/parser/blendRN/src/grammar/BlendRNLexer.js +172 -0
- package/dist/parser/blendRN/src/grammar/BlendRNListener.js +3 -0
- package/dist/parser/blendRN/src/grammar/BlendRNParser.js +657 -0
- package/dist/parser/blendReact/src/grammar/BlendReactLexer.js +159 -0
- package/dist/parser/blendReact/src/grammar/BlendReactListener.js +3 -0
- package/dist/parser/blendReact/src/grammar/BlendReactParser.js +644 -0
- package/dist/parser/blendbasic/src/grammar/BlendBasicLexer.js +147 -0
- package/dist/parser/blendbasic/src/grammar/BlendBasicListener.js +3 -0
- package/dist/parser/blendbasic/src/grammar/BlendBasicParser.js +747 -0
- package/dist/src/app.js +76 -0
- package/dist/src/app.ts +54 -0
- package/dist/types/apiOperationTypes.js +13 -0
- package/dist/types/basicOperationTypes.js +2 -0
- package/dist/types/dataOperationTypes.js +2 -0
- package/dist/types/frontendOperationTypes.js +4 -0
- package/dist/types/generalTypes.js +0 -0
- package/dist/types/mongoOperationTypes.js +12 -0
- package/package.json +29 -0
- package/src/grammar/.antlr/ApiModuleLexer.interp +71 -0
- package/src/grammar/.antlr/ApiModuleLexer.java +194 -0
- package/src/grammar/.antlr/ApiModuleLexer.tokens +32 -0
- package/src/grammar/.antlr/BlendApi.interp +70 -0
- package/src/grammar/.antlr/BlendApi.tokens +44 -0
- package/src/grammar/.antlr/BlendApiLexer.interp +89 -0
- package/src/grammar/.antlr/BlendApiLexer.java +237 -0
- package/src/grammar/.antlr/BlendApiLexer.tokens +44 -0
- package/src/grammar/.antlr/BlendApiParser.java +767 -0
- package/src/grammar/.antlr/BlendBasic.interp +41 -0
- package/src/grammar/.antlr/BlendBasic.tokens +20 -0
- package/src/grammar/.antlr/BlendBasicLexer.interp +50 -0
- package/src/grammar/.antlr/BlendBasicLexer.java +179 -0
- package/src/grammar/.antlr/BlendBasicLexer.tokens +20 -0
- package/src/grammar/.antlr/BlendBasicParser.java +599 -0
- package/src/grammar/.antlr/BlendData.interp +50 -0
- package/src/grammar/.antlr/BlendData.tokens +29 -0
- package/src/grammar/.antlr/BlendDataLexer.interp +65 -0
- package/src/grammar/.antlr/BlendDataLexer.java +181 -0
- package/src/grammar/.antlr/BlendDataLexer.tokens +29 -0
- package/src/grammar/.antlr/BlendDataParser.java +520 -0
- package/src/grammar/.antlr/BlendMDP.interp +45 -0
- package/src/grammar/.antlr/BlendMDP.tokens +25 -0
- package/src/grammar/.antlr/BlendMDPLexer.interp +59 -0
- package/src/grammar/.antlr/BlendMDPLexer.java +178 -0
- package/src/grammar/.antlr/BlendMDPLexer.tokens +25 -0
- package/src/grammar/.antlr/BlendMDPParser.java +386 -0
- package/src/grammar/.antlr/BlendMongo.interp +65 -0
- package/src/grammar/.antlr/BlendMongo.tokens +41 -0
- package/src/grammar/.antlr/BlendMongoLexer.interp +83 -0
- package/src/grammar/.antlr/BlendMongoLexer.java +219 -0
- package/src/grammar/.antlr/BlendMongoLexer.tokens +41 -0
- package/src/grammar/.antlr/BlendMongoParser.java +669 -0
- package/src/grammar/.antlr/BlendRN.interp +53 -0
- package/src/grammar/.antlr/BlendRN.tokens +31 -0
- package/src/grammar/.antlr/BlendRNLexer.interp +71 -0
- package/src/grammar/.antlr/BlendRNLexer.java +202 -0
- package/src/grammar/.antlr/BlendRNLexer.tokens +31 -0
- package/src/grammar/.antlr/BlendRNParser.java +542 -0
- package/src/grammar/.antlr/BlendReact.interp +49 -0
- package/src/grammar/.antlr/BlendReact.tokens +28 -0
- package/src/grammar/.antlr/BlendReactLexer.interp +65 -0
- package/src/grammar/.antlr/BlendReactLexer.java +188 -0
- package/src/grammar/.antlr/BlendReactLexer.tokens +28 -0
- package/src/grammar/.antlr/BlendReactParser.java +530 -0
- package/src/grammar/BlendApi.g4 +26 -0
- package/src/grammar/BlendBasic.g4 +16 -0
- package/src/grammar/BlendData.g4 +24 -0
- package/src/grammar/BlendMDP.g4 +12 -0
- package/src/grammar/BlendMongo.g4 +24 -0
- package/src/grammar/BlendRN.g4 +18 -0
- package/src/grammar/BlendReact.g4 +16 -0
- package/src/helper/BasicHelper.ts +35 -0
- package/src/helper/CommonHelper.ts +5 -0
- package/src/helper/DataHelper.ts +268 -0
- package/src/helper/ExpressHelper.ts +807 -0
- package/src/helper/FrontEndApiHelper.ts +526 -0
- package/src/helper/FrontEndReactApiHelper.ts +532 -0
- package/src/helper/MongoHelper.ts +165 -0
- package/src/helper/RNHelper.ts +651 -0
- package/src/helper/ReactHelper.ts +597 -0
- package/src/helper/SectionHelper.ts +154 -0
- package/src/helper/fileHelper.ts +111 -0
- package/src/helper/grammarHelper/BlendApiGrammarHelper.ts +45 -0
- package/src/helper/grammarHelper/BlendBasicGrammarHelper.ts +101 -0
- package/src/helper/grammarHelper/BlendDataGrammarHelper.ts +49 -0
- package/src/helper/grammarHelper/BlendMDPGrammarHelper.ts +33 -0
- package/src/helper/grammarHelper/BlendMongoGrammarHelper.ts +50 -0
- package/src/helper/grammarHelper/BlendRNGrammarHelper.ts +65 -0
- package/src/helper/grammarHelper/BlendReactGrammarHelper.ts +65 -0
- package/src/helper/grammarHelper/GrammarErrorHelper.ts +13 -0
- package/src/index.ts +168 -0
- package/src/parser/blendApi/src/grammar/BlendApi.interp +70 -0
- package/src/parser/blendApi/src/grammar/BlendApi.tokens +44 -0
- package/src/parser/blendApi/src/grammar/BlendApiLexer.interp +89 -0
- package/src/parser/blendApi/src/grammar/BlendApiLexer.tokens +44 -0
- package/src/parser/blendApi/src/grammar/BlendApiLexer.ts +193 -0
- package/src/parser/blendApi/src/grammar/BlendApiListener.ts +145 -0
- package/src/parser/blendApi/src/grammar/BlendApiParser.ts +968 -0
- package/src/parser/blendData/src/grammar/BlendData.interp +50 -0
- package/src/parser/blendData/src/grammar/BlendData.tokens +29 -0
- package/src/parser/blendData/src/grammar/BlendDataLexer.interp +65 -0
- package/src/parser/blendData/src/grammar/BlendDataLexer.tokens +29 -0
- package/src/parser/blendData/src/grammar/BlendDataLexer.ts +146 -0
- package/src/parser/blendData/src/grammar/BlendDataListener.ts +97 -0
- package/src/parser/blendData/src/grammar/BlendDataParser.ts +641 -0
- package/src/parser/blendMDP/src/grammar/BlendMDP.interp +45 -0
- package/src/parser/blendMDP/src/grammar/BlendMDP.tokens +25 -0
- package/src/parser/blendMDP/src/grammar/BlendMDPLexer.interp +59 -0
- package/src/parser/blendMDP/src/grammar/BlendMDPLexer.tokens +25 -0
- package/src/parser/blendMDP/src/grammar/BlendMDPLexer.ts +143 -0
- package/src/parser/blendMDP/src/grammar/BlendMDPListener.ts +85 -0
- package/src/parser/blendMDP/src/grammar/BlendMDPParser.ts +483 -0
- package/src/parser/blendMongo/src/grammar/BlendMongo.interp +65 -0
- package/src/parser/blendMongo/src/grammar/BlendMongo.tokens +41 -0
- package/src/parser/blendMongo/src/grammar/BlendMongoLexer.interp +83 -0
- package/src/parser/blendMongo/src/grammar/BlendMongoLexer.tokens +41 -0
- package/src/parser/blendMongo/src/grammar/BlendMongoLexer.ts +179 -0
- package/src/parser/blendMongo/src/grammar/BlendMongoListener.ts +133 -0
- package/src/parser/blendMongo/src/grammar/BlendMongoParser.ts +849 -0
- package/src/parser/blendRN/src/grammar/BlendRN.interp +53 -0
- package/src/parser/blendRN/src/grammar/BlendRN.tokens +31 -0
- package/src/parser/blendRN/src/grammar/BlendRNLexer.interp +71 -0
- package/src/parser/blendRN/src/grammar/BlendRNLexer.tokens +31 -0
- package/src/parser/blendRN/src/grammar/BlendRNLexer.ts +164 -0
- package/src/parser/blendRN/src/grammar/BlendRNListener.ts +85 -0
- package/src/parser/blendRN/src/grammar/BlendRNParser.ts +659 -0
- package/src/parser/blendReact/src/grammar/BlendReact.interp +49 -0
- package/src/parser/blendReact/src/grammar/BlendReact.tokens +28 -0
- package/src/parser/blendReact/src/grammar/BlendReactLexer.interp +65 -0
- package/src/parser/blendReact/src/grammar/BlendReactLexer.tokens +28 -0
- package/src/parser/blendReact/src/grammar/BlendReactLexer.ts +151 -0
- package/src/parser/blendReact/src/grammar/BlendReactListener.ts +85 -0
- package/src/parser/blendReact/src/grammar/BlendReactParser.ts +646 -0
- package/src/parser/blendbasic/src/grammar/BlendBasic.interp +41 -0
- package/src/parser/blendbasic/src/grammar/BlendBasic.tokens +20 -0
- package/src/parser/blendbasic/src/grammar/BlendBasicLexer.interp +50 -0
- package/src/parser/blendbasic/src/grammar/BlendBasicLexer.tokens +20 -0
- package/src/parser/blendbasic/src/grammar/BlendBasicLexer.ts +139 -0
- package/src/parser/blendbasic/src/grammar/BlendBasicListener.ts +109 -0
- package/src/parser/blendbasic/src/grammar/BlendBasicParser.ts +747 -0
- package/src/types/apiOperationTypes.ts +43 -0
- package/src/types/basicOperationTypes.ts +15 -0
- package/src/types/dataOperationTypes.ts +20 -0
- package/src/types/frontendOperationTypes.ts +92 -0
- package/src/types/generalTypes.ts +0 -0
- package/src/types/mongoOperationTypes.ts +36 -0
- package/template/.env.dev +1 -0
- package/template/package.json +36 -0
- package/template/src/app.js +76 -0
- package/template/src/app.ts +54 -0
- package/template/src/config/app.config.js +0 -0
- package/template/src/config/app.config.ts +0 -0
- package/template/src/config/database.config.js +6 -0
- package/template/src/config/database.config.ts +4 -0
- package/template/src/data/interfaces.js +2 -0
- package/template/src/data/interfaces.ts +23 -0
- package/template/src/middlewares/auth.js +22 -0
- package/template/src/middlewares/auth.ts +21 -0
- package/template/src/models/Database.js +10 -0
- package/template/src/models/Database.ts +8 -0
- package/template/src/models/User/Permission.model.js +13 -0
- package/template/src/models/User/Permission.model.ts +14 -0
- package/template/src/models/User/Role.model.js +13 -0
- package/template/src/models/User/Role.model.ts +14 -0
- package/template/src/models/User/User.model.js +17 -0
- package/template/src/models/User/User.model.ts +18 -0
- package/template/src/routes/User.routes.js +47 -0
- package/template/src/routes/User.routes.ts +41 -0
- package/template/src/routes/common/common.routes.config.js +14 -0
- package/template/src/routes/common/common.routes.config.ts +15 -0
- package/template/src/services/User/User.service.js +75 -0
- package/template/src/services/User/User.service.ts +68 -0
- package/template/src/services/User/api.data.js +72 -0
- package/template/src/services/User/api.data.ts +79 -0
- package/template/src/services/User/api.interface.js +3 -0
- package/template/src/services/User/api.interface.ts +10 -0
- package/template/tsconfig.json +10 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
import { IApiMainSection, IApiSection } from "../types/apiOperationTypes";
|
|
2
|
+
import { IBasicProject, IBasicSection } from "../types/basicOperationTypes";
|
|
3
|
+
import { FileHelper } from "./fileHelper";
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import BlendReactGrammarHelper from "./grammarHelper/BlendReactGrammarHelper";
|
|
6
|
+
import { IFrontEndScreen, IReactComponent, IReactLayout, IReactModule, IReactScreen, IReactSection } from "../types/frontendOperationTypes";
|
|
7
|
+
import BlendMDPGrammarHelper from "./grammarHelper/BlendMDPGrammarHelper";
|
|
8
|
+
|
|
9
|
+
const { execSync } = require('child_process');
|
|
10
|
+
|
|
11
|
+
const runCommand = (command, cwd = process.cwd()) => {
|
|
12
|
+
try {
|
|
13
|
+
execSync(command, { stdio: 'inherit', cwd });
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.error(`Failed to execute command: ${command}`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default class ReactHelper {
|
|
21
|
+
basicFilePath: string;
|
|
22
|
+
folderName: string;
|
|
23
|
+
folderPath: string;
|
|
24
|
+
basicFileContent: string;
|
|
25
|
+
configPath: string;
|
|
26
|
+
basicProjectContent: IBasicProject;
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
this.folderPath = path.join(process.cwd());
|
|
30
|
+
this.folderName = path.basename(this.folderPath);
|
|
31
|
+
this.basicFilePath = path.join(this.folderPath, `${this.folderName}.basic`);
|
|
32
|
+
this.configPath = path.join(this.folderPath, '.basicConfig');
|
|
33
|
+
this.basicProjectContent = JSON.parse(FileHelper.readFile(`${this.configPath}/basicConfig.json`) || "{}");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
doReactOperations() {
|
|
37
|
+
this.createReactSpec();
|
|
38
|
+
this.parseSpec();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
doReactGenerations() {
|
|
42
|
+
this.buildComponents();
|
|
43
|
+
this.buildScreens();
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
createReactSpec() {
|
|
48
|
+
this.basicProjectContent.sectionList.forEach(section => {
|
|
49
|
+
const sectionName = section.name.trim();
|
|
50
|
+
const sectionFolderPath = path.join(this.folderPath, 'spec', sectionName);
|
|
51
|
+
const reactFolderPath = path.join(sectionFolderPath, 'frontend');
|
|
52
|
+
section.reactModuleList.forEach(reactModule => {
|
|
53
|
+
const dataFilePath = path.join(reactFolderPath, `${reactModule.name}.react`);
|
|
54
|
+
if (!FileHelper.exists(dataFilePath)) {
|
|
55
|
+
FileHelper.writeFile(dataFilePath, `module ${reactModule.name}`);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
parseSpec() {
|
|
68
|
+
const sectionReactList: IReactSection[] = [];
|
|
69
|
+
this.basicProjectContent.sectionList.forEach(section => {
|
|
70
|
+
const sectionName = section.name.trim();
|
|
71
|
+
const sectionObj: IReactSection = {
|
|
72
|
+
name: sectionName,
|
|
73
|
+
reactModuleList: [],
|
|
74
|
+
};
|
|
75
|
+
section.reactModuleList.forEach(reactModule => {
|
|
76
|
+
const rnFilePath = path.join(this.folderPath, `spec/${sectionName}/frontend/${reactModule.name}.react`);
|
|
77
|
+
const specCode = FileHelper.readFile(rnFilePath);
|
|
78
|
+
const reactHelper = new BlendReactGrammarHelper();
|
|
79
|
+
const json = reactHelper.parseBlendReact(specCode);
|
|
80
|
+
if (!json.valid) {
|
|
81
|
+
throw new Error("Error while parsing the react native screens");
|
|
82
|
+
} else {
|
|
83
|
+
sectionObj.reactModuleList.push(json.json);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
sectionReactList.push(sectionObj);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Write the generated configuration to a file
|
|
92
|
+
FileHelper.writeFile(`${this.configPath}/reactConfig.json`, JSON.stringify(sectionReactList, null, 4));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
generateMDPCode(component: IReactComponent) {
|
|
96
|
+
return `module ${component.name}\nprops {}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
//Generate
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
buildScreens() {
|
|
105
|
+
const reactSectionList: IReactSection[] = JSON.parse(FileHelper.readFile(`${this.configPath}/reactConfig.json`));
|
|
106
|
+
reactSectionList.forEach(reactSection => {
|
|
107
|
+
const reactFolderPath = path.join(this.folderPath, `module/${reactSection.name}/react`);
|
|
108
|
+
|
|
109
|
+
reactSection.reactModuleList.forEach(reactModule => {
|
|
110
|
+
this.buildLayouts(reactSection, reactModule);
|
|
111
|
+
const rnProjectPath = path.join(reactFolderPath, reactModule.name);
|
|
112
|
+
reactModule.screenList.forEach(screen => {
|
|
113
|
+
const screenPath = `${rnProjectPath}/src/view/${screen.path}/`;
|
|
114
|
+
const screenCode = this.generateScreenCode(screen);
|
|
115
|
+
FileHelper.createFile(`${screenPath}${screen.name}.tsx`, screenCode
|
|
116
|
+
)
|
|
117
|
+
});
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
buildComponents() {
|
|
124
|
+
const reactSectionList: IReactSection[] = JSON.parse(FileHelper.readFile(`${this.configPath}/reactConfig.json`));
|
|
125
|
+
reactSectionList.forEach(reactSection => {
|
|
126
|
+
const reactFolderPath = path.join(this.folderPath, `module/${reactSection.name}/react`);
|
|
127
|
+
|
|
128
|
+
reactSection.reactModuleList.forEach(reactModule => {
|
|
129
|
+
this.buildLayouts(reactSection, reactModule);
|
|
130
|
+
const rnProjectPath = path.join(reactFolderPath, reactModule.name);
|
|
131
|
+
const mdpHookComponentPath = `${rnProjectPath}/src/src-gen/component/mdpHook.ts`;
|
|
132
|
+
const mdpPath = `${rnProjectPath}/src/src-gen/component/MDP.ts`;
|
|
133
|
+
const mdpHookCode = this.generateMDPHookCode(reactModule.componentList);
|
|
134
|
+
FileHelper.writeFile(`${mdpHookComponentPath}`, mdpHookCode);
|
|
135
|
+
FileHelper.writeFile(`${mdpPath}`, `export interface MDP {getMetaData:() => any;}\nexport interface IBasicComponent {value?: any;onInput?:(val: any) => any;}`);
|
|
136
|
+
reactModule.componentList.forEach(component => {
|
|
137
|
+
const componentPath = `${rnProjectPath}/src/component/${component.path}/`;
|
|
138
|
+
const componentCode = this.generateComponentCode(component);
|
|
139
|
+
const mdpCode = this.generateComponentMDPCode(component);
|
|
140
|
+
FileHelper.createFile(`${componentPath}/${component.name}/${component.name}.tsx`, componentCode);
|
|
141
|
+
FileHelper.createFile(`${componentPath}/${component.name}/${component.name}MDP.ts`, mdpCode);
|
|
142
|
+
FileHelper.createFile(`${componentPath}/${component.name}/index.ts`, `export {default} from './${component.name}';\nexport * from "./${component.name}MDP";`);
|
|
143
|
+
|
|
144
|
+
});
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
generateMDPHookCode(componentList: IReactComponent[]) {
|
|
149
|
+
const importsCode = `
|
|
150
|
+
${componentList.reduce((acc, component) => {
|
|
151
|
+
acc = acc + `import ${component.name} from '../../component/${component.path}/${component.name}';\n`
|
|
152
|
+
return acc;
|
|
153
|
+
}, "")}`
|
|
154
|
+
return `
|
|
155
|
+
import React, { useCallback, useRef, useState } from "react";
|
|
156
|
+
import { MDP } from "./MDP";
|
|
157
|
+
${importsCode}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
export const useMetaData = (props: {
|
|
161
|
+
mdpClass: MDP;
|
|
162
|
+
defaultInput?: any;
|
|
163
|
+
onInput?: (val: any) => void;
|
|
164
|
+
extraProps?: any;
|
|
165
|
+
memoize?: boolean;
|
|
166
|
+
}): [React.ReactElement, any, React.Dispatch<any>] => {
|
|
167
|
+
|
|
168
|
+
console.log(props.defaultInput, props.mdpClass, "defaultInput");
|
|
169
|
+
|
|
170
|
+
const [input, setInput] = useState(props.defaultInput);
|
|
171
|
+
const componentRef: any = useRef<React.ReactElement | null>(null);
|
|
172
|
+
|
|
173
|
+
// useEffect(() => {
|
|
174
|
+
// setInput(props.defaultInput);
|
|
175
|
+
// }, [props.defaultInput]);
|
|
176
|
+
|
|
177
|
+
const handleInputChange = useCallback((val: any) => {
|
|
178
|
+
setInput(val);
|
|
179
|
+
props.onInput?.(val);
|
|
180
|
+
}, [props.onInput]);
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
if (!componentRef.current || props.mdpClass !== componentRef.current.props.mdpClass || props.extraProps !== componentRef.current.props.extraProps) {
|
|
184
|
+
componentRef.current = generateElementFromMetaData({
|
|
185
|
+
componentClassMetaData: props.mdpClass.getMetaData(),
|
|
186
|
+
onInput: handleInputChange,
|
|
187
|
+
value: input,
|
|
188
|
+
extraProps: props.extraProps
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return [componentRef.current, input, setInput];
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export const generateElementFromMetaData = ({ componentClassMetaData, value, onInput, extraProps }: {
|
|
196
|
+
componentClassMetaData: any;
|
|
197
|
+
value?: any;
|
|
198
|
+
onInput?: any;
|
|
199
|
+
extraProps?: object;
|
|
200
|
+
}) => {
|
|
201
|
+
return React.createElement((ComponentNameMap[componentClassMetaData.componentName] as any), {
|
|
202
|
+
...componentClassMetaData.props,
|
|
203
|
+
value: value,
|
|
204
|
+
onInput: onInput,
|
|
205
|
+
...extraProps
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
const ComponentNameMap: any = {
|
|
212
|
+
${componentList.reduce((acc, component) => {
|
|
213
|
+
acc = acc + `"${component.name}": ${component.name},\n`
|
|
214
|
+
return acc;
|
|
215
|
+
}, "")}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export interface IMetaDataHook {
|
|
219
|
+
element: React.ReactElement,
|
|
220
|
+
input?: any;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
`;
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
checkForFolderAndCreateReactApp() {
|
|
227
|
+
return new Promise(async (checkRes) => {
|
|
228
|
+
const reactSectionList: IReactSection[] = JSON.parse(FileHelper.readFile(`${this.configPath}/reactConfig.json`));
|
|
229
|
+
const promises: Promise<void>[] = [];
|
|
230
|
+
reactSectionList.forEach(reactSection => {
|
|
231
|
+
const reactFolderPath = path.join(this.folderPath, `module/${reactSection.name}/react`);
|
|
232
|
+
FileHelper.ensureDir(reactFolderPath);
|
|
233
|
+
|
|
234
|
+
reactSection.reactModuleList.forEach(rnModule => {
|
|
235
|
+
const modulePath = path.join(reactFolderPath, rnModule.name);
|
|
236
|
+
if (!FileHelper.exists(modulePath)) {
|
|
237
|
+
promises.push(new Promise(res => {
|
|
238
|
+
|
|
239
|
+
runCommand(`npm create vite@6.2.0 ${rnModule.name} -- --template react-ts `, reactFolderPath);
|
|
240
|
+
// runCommand(`npm install -D typescript @types/node @types/react @types/react-dom @types/jest`, modulePath);
|
|
241
|
+
|
|
242
|
+
const dependencies = [
|
|
243
|
+
'@reduxjs/toolkit@2.6.0',
|
|
244
|
+
'react-redux@9.2.0',
|
|
245
|
+
'redux-saga@1.3.0',
|
|
246
|
+
"axios@1.8.1",
|
|
247
|
+
"react-router-dom@7.2.0",
|
|
248
|
+
"tailwindcss@4.0.9",
|
|
249
|
+
"tailwindcss@4.0.9",
|
|
250
|
+
"@tailwindcss/vite@4.0.9"
|
|
251
|
+
|
|
252
|
+
];
|
|
253
|
+
runCommand(`npm install ${dependencies.join(' ')}`, modulePath);
|
|
254
|
+
|
|
255
|
+
FileHelper.writeFile(`${modulePath}/src/App.tsx`, mainAppcode);
|
|
256
|
+
FileHelper.writeFile(`${modulePath}/src/index.css`, `@import "tailwindcss";`);
|
|
257
|
+
FileHelper.writeFile(`${modulePath}/tsconfig.json`, tsConfigJsonCode);
|
|
258
|
+
FileHelper.writeFile(`${modulePath}/tsconfig.app.json`, tsConfigAppJsonCode);
|
|
259
|
+
FileHelper.writeFile(`${modulePath}/src/index.css`, `@import "tailwindcss";`);
|
|
260
|
+
runCommand(`npm install -D @types/node`, modulePath);
|
|
261
|
+
FileHelper.writeFile(`${modulePath}/vite.config.ts`, viteConfigCode);
|
|
262
|
+
runCommand(`npx shadcn@latest init`, modulePath);
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
}))
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
})
|
|
271
|
+
await Promise.all(promises);
|
|
272
|
+
checkRes(true)
|
|
273
|
+
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
buildLayouts(rnSection: IReactSection, reactModule: IReactModule) {
|
|
280
|
+
const reactFolderPath = path.join(this.folderPath, `module/${rnSection.name}/react`);
|
|
281
|
+
const rnLayoutPath = path.join(reactFolderPath, reactModule.name);
|
|
282
|
+
const lo: IReactLayout = {
|
|
283
|
+
name: "BlendGenerated",
|
|
284
|
+
route: "/",
|
|
285
|
+
children: reactModule.layout,
|
|
286
|
+
}
|
|
287
|
+
const routerCode = this.generateRouterCode(lo, reactModule);
|
|
288
|
+
FileHelper.writeFile(`${rnLayoutPath}/src/src-gen/router/blend-router.tsx`, routerCode)
|
|
289
|
+
this.traverseChildrenAndCreateLayout(rnLayoutPath, lo, reactModule);
|
|
290
|
+
FileHelper.createFile(`${rnLayoutPath}/src/layout/${lo.name}Layout.tsx`, `
|
|
291
|
+
${this.generateLayoutCode(lo, reactModule)}
|
|
292
|
+
`)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
traverseChildrenAndCreateLayout(reactLayoutPath: string, lo: IReactLayout, frontEnd: IReactModule) {
|
|
297
|
+
lo.children.forEach(loChild => {
|
|
298
|
+
if (loChild.children) {
|
|
299
|
+
FileHelper.createFile(`${reactLayoutPath}/src/layout/${loChild.name}Layout.tsx`, `
|
|
300
|
+
${this.generateLayoutCode(loChild, frontEnd)}
|
|
301
|
+
`)
|
|
302
|
+
this.traverseChildrenAndCreateLayout(reactLayoutPath, loChild, frontEnd)
|
|
303
|
+
}
|
|
304
|
+
})
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
findScreenPath(screenList: IReactScreen[], screenName: string) {
|
|
308
|
+
const index = screenList.findIndex(screen => screen.name === screenName);
|
|
309
|
+
if (screenList[index]) {
|
|
310
|
+
return screenList[index].path;
|
|
311
|
+
} else {
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
generateFlattenedArray(children: IReactLayout[]) {
|
|
316
|
+
let uniqueElements: any[] = [];
|
|
317
|
+
let flatenedArray: any[] = [];
|
|
318
|
+
generateFlattenedArrayFun(children);
|
|
319
|
+
function generateFlattenedArrayFun(children: IReactLayout[]) {
|
|
320
|
+
return children.forEach((child) => {
|
|
321
|
+
flatenedArray.push(child);
|
|
322
|
+
if (child.children) {
|
|
323
|
+
generateFlattenedArrayFun(child.children);
|
|
324
|
+
} else {
|
|
325
|
+
if (!uniqueElements.includes(child.element)) {
|
|
326
|
+
uniqueElements.push(child.element);
|
|
327
|
+
} else {
|
|
328
|
+
flatenedArray.pop();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return flatenedArray;
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
generateRouterCode(mainLayout: IReactLayout, frontEnd: IReactModule) {
|
|
340
|
+
const defaultImportCode = `
|
|
341
|
+
import { createBrowserRouter } from 'react-router-dom';\n
|
|
342
|
+
import React from 'react';\n
|
|
343
|
+
import BlendGeneratedLayout from '../../layout/BlendGeneratedLayout';
|
|
344
|
+
`;
|
|
345
|
+
|
|
346
|
+
console.log([mainLayout],JSON.stringify([mainLayout]),"Main layout///////////////")
|
|
347
|
+
const routerJsonCode = `const router = createBrowserRouter([${this.generateLayoutRouterJSONCode([mainLayout])}])\nexport default router;`
|
|
348
|
+
console.log(this.generateFlattenedArray(mainLayout.children), "this.generateFlattenedArray(mainLayout.children)");
|
|
349
|
+
const importCode = `${this.generateFlattenedArray(mainLayout.children).reduce((acc, item) => {
|
|
350
|
+
const importCode = ` ${item.children ? `
|
|
351
|
+
import ${item.name}Layout from '../../layout/${item.name}Layout';\n
|
|
352
|
+
`: `
|
|
353
|
+
import ${item.element} from '../../view/${this.findScreenPath(frontEnd.screenList, (item?.element || ""))}/${item.element}';\n
|
|
354
|
+
`}`
|
|
355
|
+
acc = acc + importCode;
|
|
356
|
+
return acc;
|
|
357
|
+
}, "")}`;
|
|
358
|
+
return importCode + defaultImportCode + routerJsonCode;
|
|
359
|
+
}
|
|
360
|
+
generateLayoutRouterJSONCode(layoutList: IReactLayout[]) {
|
|
361
|
+
return layoutList.reduce((acc, layout) => {
|
|
362
|
+
acc = acc + `{element: ${layout.children ? `<${layout.name}Layout/>,` : `<${layout.element} />,`}
|
|
363
|
+
path: "${layout.route}",
|
|
364
|
+
${layout.children ? `children: [${this.generateLayoutRouterJSONCode(layout.children)}],` : ``}
|
|
365
|
+
},
|
|
366
|
+
`
|
|
367
|
+
return acc;
|
|
368
|
+
}, '')
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
generateRouterConstant(children: IReactLayout[]) {
|
|
373
|
+
let path = '';
|
|
374
|
+
const routeObj = generateRouterConstantObj(children);
|
|
375
|
+
function generateRouterConstantObj(children: IReactLayout[]): any {
|
|
376
|
+
|
|
377
|
+
return children.reduce((acc: any, child: any, index: number) => {
|
|
378
|
+
if (child.children) {
|
|
379
|
+
path = child.route && child.route != "" && child.route != "/" ? path + "/" + child.route : path;
|
|
380
|
+
acc[child.name] = generateRouterConstantObj(child.children);
|
|
381
|
+
console.log(child.name, index, children.length, "Path With layout After")
|
|
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
|
+
} else {
|
|
388
|
+
path = child.route && child.route != "" && child.route != "/" ? path + "/" + child.route : path;
|
|
389
|
+
acc[child.name] = path;
|
|
390
|
+
console.log(path, "Path Without layout")
|
|
391
|
+
const pathNumToBeRemoved = child.route.split("/").length;
|
|
392
|
+
console.log(pathNumToBeRemoved, index, children.length, "pathNumToBeRemoved..............")
|
|
393
|
+
path = path.split("/").slice(0, -pathNumToBeRemoved).join('/').toString();
|
|
394
|
+
|
|
395
|
+
if (index == children.length - 1) {
|
|
396
|
+
path = path.split("/").slice(0, -1).join('/').toString();
|
|
397
|
+
// const pathNumToBeRemoved = child.route.split("/").length;
|
|
398
|
+
// path = path.split("/").slice(0,-pathNumToBeRemoved).join('/').toString();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return acc;
|
|
404
|
+
}, {})
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
return JSON.stringify(routeObj);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
generateLayoutCode(lo: IReactLayout, frontEnd: IReactModule) {
|
|
411
|
+
|
|
412
|
+
return (
|
|
413
|
+
`
|
|
414
|
+
import { Outlet } from "react-router-dom"
|
|
415
|
+
const ${lo.name}Layout = () => {
|
|
416
|
+
return (
|
|
417
|
+
<div>
|
|
418
|
+
${lo.name}Layout
|
|
419
|
+
<Outlet />
|
|
420
|
+
</div>
|
|
421
|
+
)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export default ${lo.name}Layout;
|
|
425
|
+
`
|
|
426
|
+
)
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
generateScreenCode(screen: IReactScreen) {
|
|
432
|
+
return `
|
|
433
|
+
import React from "react";
|
|
434
|
+
const ${screen.name} = () => {
|
|
435
|
+
return(
|
|
436
|
+
<div>
|
|
437
|
+
${screen.name}
|
|
438
|
+
</div>
|
|
439
|
+
)
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export default ${screen.name};
|
|
443
|
+
`
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
generateComponentCode(component: IReactComponent) {
|
|
447
|
+
return `
|
|
448
|
+
import React from "react";
|
|
449
|
+
import {I${component.name}Props} from './${component.name}MDP';
|
|
450
|
+
const ${component.name} = (props: I${component.name}Props) => {
|
|
451
|
+
return(
|
|
452
|
+
<div>
|
|
453
|
+
${component.name}
|
|
454
|
+
</div>
|
|
455
|
+
)
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export default ${component.name};
|
|
459
|
+
`
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
generateComponentMDPCode(component: IReactComponent) {
|
|
466
|
+
const pathCode = '../../' + component.path.split("/").reduce((acc,curVal) => {
|
|
467
|
+
acc = acc + '../'
|
|
468
|
+
return acc;
|
|
469
|
+
},"")
|
|
470
|
+
return `
|
|
471
|
+
import { MDP,IBasicComponent } from "${pathCode}src-gen/component/MDP";
|
|
472
|
+
|
|
473
|
+
export class ${component.name}MDP implements I${component.name}MDP {
|
|
474
|
+
componentName: string = "${component.name}";
|
|
475
|
+
|
|
476
|
+
getMetaData() {
|
|
477
|
+
return {
|
|
478
|
+
componentName: this.componentName,
|
|
479
|
+
props: {
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export interface I${component.name}Props extends IBasicComponent {
|
|
487
|
+
}
|
|
488
|
+
export interface I${component.name}MDP extends MDP {
|
|
489
|
+
getMetaData: () => {componentName: string, props: I${component.name}Props}
|
|
490
|
+
}
|
|
491
|
+
`
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
const mainAppcode = `
|
|
504
|
+
|
|
505
|
+
import { Provider } from 'react-redux';
|
|
506
|
+
import './App.css';
|
|
507
|
+
import { store } from './redux/store/store';
|
|
508
|
+
import { RouterProvider } from 'react-router-dom';
|
|
509
|
+
import router from './src-gen/router/blend-router'
|
|
510
|
+
function App() {
|
|
511
|
+
|
|
512
|
+
return (
|
|
513
|
+
<div className="App">
|
|
514
|
+
<Provider store={store}>
|
|
515
|
+
<RouterProvider router={router}/>
|
|
516
|
+
</Provider>
|
|
517
|
+
</div>
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
export default App;
|
|
522
|
+
`
|
|
523
|
+
|
|
524
|
+
const tsConfigJsonCode = `
|
|
525
|
+
{
|
|
526
|
+
"files": [],
|
|
527
|
+
"references": [
|
|
528
|
+
{
|
|
529
|
+
"path": "./tsconfig.app.json"
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
"path": "./tsconfig.node.json"
|
|
533
|
+
}
|
|
534
|
+
],
|
|
535
|
+
"compilerOptions": {
|
|
536
|
+
"baseUrl": ".",
|
|
537
|
+
"paths": {
|
|
538
|
+
"@/*": ["./src/*"]
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
`
|
|
544
|
+
|
|
545
|
+
const tsConfigAppJsonCode = `
|
|
546
|
+
{
|
|
547
|
+
"compilerOptions": {
|
|
548
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
549
|
+
"target": "ES2020",
|
|
550
|
+
"useDefineForClassFields": true,
|
|
551
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
552
|
+
"module": "ESNext",
|
|
553
|
+
"skipLibCheck": true,
|
|
554
|
+
|
|
555
|
+
/* Bundler mode */
|
|
556
|
+
"moduleResolution": "bundler",
|
|
557
|
+
"allowImportingTsExtensions": true,
|
|
558
|
+
"isolatedModules": true,
|
|
559
|
+
"moduleDetection": "force",
|
|
560
|
+
"noEmit": true,
|
|
561
|
+
"jsx": "react-jsx",
|
|
562
|
+
|
|
563
|
+
/* Linting */
|
|
564
|
+
"strict": true,
|
|
565
|
+
"noUnusedLocals": true,
|
|
566
|
+
"noUnusedParameters": true,
|
|
567
|
+
"noFallthroughCasesInSwitch": true,
|
|
568
|
+
"noUncheckedSideEffectImports": true,
|
|
569
|
+
"baseUrl": ".",
|
|
570
|
+
"paths": {
|
|
571
|
+
"@/*": [
|
|
572
|
+
"./src/*"
|
|
573
|
+
]
|
|
574
|
+
}
|
|
575
|
+
},
|
|
576
|
+
"include": ["src"]
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
`
|
|
581
|
+
|
|
582
|
+
const viteConfigCode = `
|
|
583
|
+
import path from "path"
|
|
584
|
+
import tailwindcss from "@tailwindcss/vite"
|
|
585
|
+
import react from "@vitejs/plugin-react"
|
|
586
|
+
import { defineConfig } from "vite"
|
|
587
|
+
|
|
588
|
+
// https://vite.dev/config/
|
|
589
|
+
export default defineConfig({
|
|
590
|
+
plugins: [react(), tailwindcss()],
|
|
591
|
+
resolve: {
|
|
592
|
+
alias: {
|
|
593
|
+
"@": path.resolve(__dirname, "./src"),
|
|
594
|
+
},
|
|
595
|
+
},
|
|
596
|
+
})
|
|
597
|
+
`
|