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,526 @@
|
|
|
1
|
+
import { IApiMainSection, IApiSection, IExpressSection } from "../types/apiOperationTypes";
|
|
2
|
+
import { IBasicProject, IBasicSection } from "../types/basicOperationTypes";
|
|
3
|
+
import { IDataSection } from "../types/dataOperationTypes";
|
|
4
|
+
import { IRNSection } from "../types/frontendOperationTypes";
|
|
5
|
+
import ExpressHelper from "./ExpressHelper";
|
|
6
|
+
import { FileHelper } from "./fileHelper";
|
|
7
|
+
import path from 'path';
|
|
8
|
+
|
|
9
|
+
export default class FrontEndApiHelper {
|
|
10
|
+
basicFilePath: string;
|
|
11
|
+
folderName: string;
|
|
12
|
+
folderPath: string;
|
|
13
|
+
basicFileContent: string;
|
|
14
|
+
configPath: string;
|
|
15
|
+
basicProjectContent: IBasicProject;
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
this.folderPath = path.join(process.cwd());
|
|
19
|
+
this.folderName = path.basename(this.folderPath);
|
|
20
|
+
this.basicFilePath = path.join(this.folderPath, `${this.folderName}.basic`);
|
|
21
|
+
this.configPath = path.join(this.folderPath, '.basicConfig');
|
|
22
|
+
this.basicProjectContent = JSON.parse(FileHelper.readFile(`${this.configPath}/basicConfig.json`) || "{}");
|
|
23
|
+
}
|
|
24
|
+
doFrontEndApiGenerations() {
|
|
25
|
+
this.writeStoreFiles();
|
|
26
|
+
this.createRequiredFiles();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
createRequiredFiles() {
|
|
30
|
+
const apiMainSectionList: IApiMainSection[] = JSON.parse(FileHelper.readFile(`${this.configPath}/apiConfig.json`));
|
|
31
|
+
const rnSectionList: IRNSection[] = JSON.parse(FileHelper.readFile(`${this.configPath}/rnConfig.json`));
|
|
32
|
+
rnSectionList.forEach(rnSection => {
|
|
33
|
+
const rnFolderPath = path.join(this.folderPath, `module/${rnSection.name}/react-native`);
|
|
34
|
+
rnSection.rnModuleList.forEach(rnModule => {
|
|
35
|
+
let currentApiSection: IApiMainSection = apiMainSectionList.find(item => item.name === rnSection.name)
|
|
36
|
+
const rnProjectPath = path.join(rnFolderPath, rnModule.name);
|
|
37
|
+
const rapcode = this.generateRmoteApiPointsCode(currentApiSection);
|
|
38
|
+
FileHelper.createFile(`${rnProjectPath}/src/remote-api-point.ts`, rapcode);
|
|
39
|
+
FileHelper.createFile(`${rnProjectPath}/src-gen/data/common.ts`, commonApiDataCode);
|
|
40
|
+
FileHelper.createFile(`${rnProjectPath}/src/redux/store/store.ts`, mainStoreCode);
|
|
41
|
+
FileHelper.createFile(`${rnProjectPath}/src/redux/store/saga.ts`, mainSagaCode);
|
|
42
|
+
FileHelper.createFile(`${rnProjectPath}/src/redux/store/snackbar/snackbarSlice.ts`, snackbarSliceCode);
|
|
43
|
+
FileHelper.createFile(`${rnProjectPath}/src/redux/hooks.ts`, hooksCode);
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
generateRmoteApiPointsCode(currentApiSection: IApiMainSection) {
|
|
51
|
+
let code = `
|
|
52
|
+
import axios from 'axios';
|
|
53
|
+
import { API_URL } from '@env';
|
|
54
|
+
${currentApiSection.expressSectionList.reduce((acc, curVal) => {
|
|
55
|
+
acc = acc + `export const ${curVal.name}Api = axios.create({
|
|
56
|
+
baseURL: API_URL||'http://localhost:8000', // Replace with your API base URL
|
|
57
|
+
headers: {
|
|
58
|
+
// Authorization: localStorage.getItem("authToken")||""
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
\n
|
|
62
|
+
`
|
|
63
|
+
return acc;
|
|
64
|
+
}, "")}
|
|
65
|
+
`;
|
|
66
|
+
return code;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
writeStoreFiles() {
|
|
70
|
+
const apiMainSectionList: IApiMainSection[] = JSON.parse(FileHelper.readFile(`${this.configPath}/apiConfig.json`));
|
|
71
|
+
const rnSectionList: IRNSection[] = JSON.parse(FileHelper.readFile(`${this.configPath}/rnConfig.json`));
|
|
72
|
+
console.log(rnSectionList, "rnSectionList")
|
|
73
|
+
rnSectionList.forEach(rnSection => {
|
|
74
|
+
const rnFolderPath = path.join(this.folderPath, `module/${rnSection.name}/react-native`);
|
|
75
|
+
let currentApiSection: IApiMainSection = apiMainSectionList.find(item => item.name === rnSection.name)
|
|
76
|
+
rnSection.rnModuleList.forEach(rnModule => {
|
|
77
|
+
const rnProjectPath = path.join(rnFolderPath, rnModule.name);
|
|
78
|
+
currentApiSection.expressSectionList.forEach(expressSection => {
|
|
79
|
+
const rnApiPath = path.join(rnProjectPath, `src-gen/redux/${expressSection.name}`);
|
|
80
|
+
const rnReducerPath = path.join(rnProjectPath, `src-gen/redux/gen-reducers.ts`);
|
|
81
|
+
const reducerCode = this.generateReducersCode(expressSection.apiSectionList, expressSection.name);
|
|
82
|
+
const rnSagaPath = path.join(rnProjectPath, `src-gen/redux/gen-root-saga.ts`);
|
|
83
|
+
const rootSagaCode = this.generateRootSagaCode(expressSection.apiSectionList, expressSection.name);
|
|
84
|
+
FileHelper.writeFile(rnReducerPath, reducerCode);
|
|
85
|
+
FileHelper.writeFile(rnSagaPath, rootSagaCode);
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
expressSection.apiSectionList.forEach(apiSection => {
|
|
89
|
+
const apiSectionSlicePath = path.join(rnApiPath, apiSection.name, `${apiSection.name}Slice.ts`);
|
|
90
|
+
const apiSectionDataPath = path.join(rnApiPath, apiSection.name, `data.ts`);
|
|
91
|
+
const apiSectionActionPath = path.join(rnApiPath, apiSection.name, `action.ts`);
|
|
92
|
+
const apiSectionSagaPath = path.join(rnApiPath, apiSection.name, `${apiSection.name}Saga.ts`);
|
|
93
|
+
const sliceCode = this.generateSliceCode(apiSection);
|
|
94
|
+
const dataCode = this.generateApiDatacode(apiSection);
|
|
95
|
+
const actionCode = this.generateApiActioncode(apiSection, expressSection);
|
|
96
|
+
const sagaCode = this.generateSagaCode(apiSection);
|
|
97
|
+
FileHelper.writeFile(apiSectionSlicePath, sliceCode);
|
|
98
|
+
FileHelper.writeFile(apiSectionDataPath, dataCode);
|
|
99
|
+
FileHelper.writeFile(apiSectionActionPath, actionCode);
|
|
100
|
+
FileHelper.writeFile(apiSectionSagaPath, sagaCode);
|
|
101
|
+
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
generateSliceCode(apiSection: IApiSection) {
|
|
112
|
+
const filteredApiListForData = apiSection.apiList.filter(api => {
|
|
113
|
+
const inputKeyList = Object.keys(api.input);
|
|
114
|
+
const outputKeyList = Object.keys(api.output);
|
|
115
|
+
return inputKeyList.length>0||outputKeyList.length>0
|
|
116
|
+
})
|
|
117
|
+
const code = `
|
|
118
|
+
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
${filteredApiListForData.length>0?`import { ${apiSection.apiList.reduce((acc, curVal) => {
|
|
122
|
+
const inputKeyList = Object.keys(curVal.input);
|
|
123
|
+
const outputKeyList = Object.keys(curVal.output);
|
|
124
|
+
const inputDataTypeName: string = (`${apiSection.name}_${curVal.name}_Input`).toUpperCase();
|
|
125
|
+
const outputDataTypeName: string = (`${apiSection.name}_${curVal.name}_Output`).toUpperCase();
|
|
126
|
+
acc = acc + `${inputKeyList.length > 0 ? inputDataTypeName + ',' : ''}`;
|
|
127
|
+
acc = acc + `${outputKeyList.length > 0 ? outputDataTypeName + ',' : ''}`;
|
|
128
|
+
return acc
|
|
129
|
+
}, '')} } from "./data";
|
|
130
|
+
|
|
131
|
+
${apiSection.apiList.reduce((acc, curVal) => {
|
|
132
|
+
if (curVal?.directOutput?.name) {
|
|
133
|
+
const [moduleName, dataName] = curVal?.directOutput?.name?.split("->");
|
|
134
|
+
acc = acc + `import {${dataName?.replace("[]","")}} from "../../../data/${moduleName}";`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return acc
|
|
138
|
+
}, '')} `:''}
|
|
139
|
+
|
|
140
|
+
${apiSection.apiList.reduce((acc, curVal) => {
|
|
141
|
+
if (curVal?.directOutput?.name) {
|
|
142
|
+
const [moduleName, dataName] = curVal?.directOutput?.name?.split("->");
|
|
143
|
+
acc = acc + `import {${dataName?.replace("[]","")}} from "../../../data/${moduleName}";`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return acc
|
|
147
|
+
}, '')}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
import { ApiStatus } from "../../../data/common";
|
|
152
|
+
interface ${apiSection.name}State {
|
|
153
|
+
${apiSection.apiList.reduce((acc, curVal) => {
|
|
154
|
+
const [moduleName, dataName] = curVal?.directOutput?.name?.split("->")||[];
|
|
155
|
+
acc = acc + `${curVal.name}: {
|
|
156
|
+
data: ${Object.keys(curVal.output).length > 0 ? `${apiSection.name.toUpperCase()}_${curVal.name.toUpperCase()}_OUTPUT` :dataName?dataName: "any"},\n
|
|
157
|
+
status: ApiStatus,
|
|
158
|
+
error:string|null
|
|
159
|
+
}
|
|
160
|
+
`
|
|
161
|
+
return acc
|
|
162
|
+
}, "")}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const initialState: ${apiSection.name}State = {
|
|
166
|
+
${apiSection.apiList.reduce((acc, curVal) => {
|
|
167
|
+
const [moduleName, dataName] = curVal?.directOutput?.name?.split("->")||[];
|
|
168
|
+
|
|
169
|
+
const isOutputDataArray = (dataName || "").includes("[]")
|
|
170
|
+
|
|
171
|
+
acc = acc + `${curVal.name}:{
|
|
172
|
+
data: ${Object.keys(curVal.output).length > 0 ? `new ${apiSection.name.toUpperCase()}_${curVal.name.toUpperCase()}_OUTPUT()` :(dataName&&!isOutputDataArray)?`new ${dataName}()`:(dataName&&isOutputDataArray)?'[]': "null"},
|
|
173
|
+
status: ApiStatus.Idle,
|
|
174
|
+
error: null
|
|
175
|
+
},\n`
|
|
176
|
+
return acc
|
|
177
|
+
}, "")}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export const ${apiSection.name}Slice = createSlice({
|
|
181
|
+
name: "${apiSection.name}",
|
|
182
|
+
initialState,
|
|
183
|
+
reducers: {
|
|
184
|
+
reset${apiSection.name}Reducer: () => initialState,
|
|
185
|
+
${apiSection.apiList.reduce((acc, curVal, currentIndex) => {
|
|
186
|
+
const inputKeyList = Object.keys(curVal.input);
|
|
187
|
+
const inputDataTypeName: string = (`${apiSection.name}_${curVal.name}_Input`).toUpperCase();
|
|
188
|
+
acc = acc + `
|
|
189
|
+
${curVal.name}Action:(state:any, ${inputKeyList.length > 0 ? `payload:PayloadAction<${inputDataTypeName}>` : ``}) => {
|
|
190
|
+
state.${curVal.name}.status = ApiStatus.Loading;
|
|
191
|
+
state.${curVal.name}.error = '';
|
|
192
|
+
},
|
|
193
|
+
${curVal.name}SuccessAction:(state:any, payload:any) => {
|
|
194
|
+
state.${curVal.name}.status = ApiStatus.Success;
|
|
195
|
+
state.${curVal.name}.data = payload.payload;
|
|
196
|
+
},
|
|
197
|
+
${curVal.name}ErrorAction:(state:any, payload:any) => {
|
|
198
|
+
state.${curVal.name}.status = ApiStatus.Failed;
|
|
199
|
+
state.${curVal.name}.error = payload.error;
|
|
200
|
+
},
|
|
201
|
+
`
|
|
202
|
+
return acc;
|
|
203
|
+
}, '')
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
export const {reset${apiSection.name}Reducer,${apiSection.apiList.reduce((acc, curVal, currentIndex) => {
|
|
210
|
+
acc = acc + `
|
|
211
|
+
${curVal.name}Action,${curVal.name}SuccessAction,${curVal.name}ErrorAction,
|
|
212
|
+
`; return acc
|
|
213
|
+
}, '')}} = ${apiSection.name}Slice.actions;
|
|
214
|
+
export default ${apiSection.name}Slice.reducer;
|
|
215
|
+
`
|
|
216
|
+
return code;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
generateSagaCode(apiSection: IApiSection) {
|
|
221
|
+
const code = `
|
|
222
|
+
import { put, takeLatest } from "redux-saga/effects";
|
|
223
|
+
import { PayloadAction } from "@reduxjs/toolkit";
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
import { ${apiSection.apiList.reduce((acc, curVal) => {
|
|
227
|
+
acc = acc + `${curVal.name}Api,`;
|
|
228
|
+
return acc
|
|
229
|
+
}, '')} }from './action';
|
|
230
|
+
|
|
231
|
+
import { ${apiSection.apiList.reduce((acc, curVal) => {
|
|
232
|
+
|
|
233
|
+
acc = acc + `${curVal.name}SuccessAction,${curVal.name}ErrorAction,`;
|
|
234
|
+
return acc
|
|
235
|
+
}, '')} } from "./${apiSection.name}Slice";
|
|
236
|
+
|
|
237
|
+
${apiSection.apiList.reduce((acc, curVal) => {
|
|
238
|
+
const inputKeyList = Object.keys(curVal.input);
|
|
239
|
+
acc = acc + `
|
|
240
|
+
function* ${curVal.name}Saga(action: PayloadAction<any>): any {
|
|
241
|
+
try {
|
|
242
|
+
const response: any = yield ${curVal.name}Api(${inputKeyList.length > 0 ? `action.payload` : ``})
|
|
243
|
+
yield put(${curVal.name}SuccessAction(response.data))
|
|
244
|
+
} catch(e: any) {
|
|
245
|
+
yield put(${curVal.name}ErrorAction(e));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function* watch${apiSection.name}${curVal.name}() {
|
|
250
|
+
yield takeLatest("${apiSection.name}/${curVal.name}Action", ${curVal.name}Saga);
|
|
251
|
+
}
|
|
252
|
+
`
|
|
253
|
+
return acc
|
|
254
|
+
|
|
255
|
+
}, '')}
|
|
256
|
+
|
|
257
|
+
`
|
|
258
|
+
|
|
259
|
+
return code;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
generateReducersCode(apiSectionList: IApiSection[], sectionName: string) {
|
|
263
|
+
const code = `
|
|
264
|
+
${apiSectionList.reduce((acc, curVal) => {
|
|
265
|
+
acc = acc + `
|
|
266
|
+
import ${curVal.name}Reducer from './${sectionName}/${curVal.name}/${curVal.name}Slice';\n`
|
|
267
|
+
return acc;
|
|
268
|
+
}, '')}
|
|
269
|
+
|
|
270
|
+
export const GeneratedReducers = {
|
|
271
|
+
${apiSectionList.reduce((acc, curVal) => {
|
|
272
|
+
acc = acc + `${curVal.name.toLowerCase()}: ${curVal.name}Reducer,`
|
|
273
|
+
return acc;
|
|
274
|
+
}, '')}
|
|
275
|
+
}
|
|
276
|
+
`;
|
|
277
|
+
return code;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
generateApiActioncode(apiSection: IApiSection, expressSection: IExpressSection) {
|
|
281
|
+
const filteredApiListForData = apiSection.apiList.filter(api => {
|
|
282
|
+
const inputKeyList = Object.keys(api.input);
|
|
283
|
+
const outputKeyList = Object.keys(api.output);
|
|
284
|
+
return inputKeyList.length>0||outputKeyList.length>0
|
|
285
|
+
})
|
|
286
|
+
console.log(filteredApiListForData,"filteredApiListForDatafilteredApiListForData")
|
|
287
|
+
const code = `
|
|
288
|
+
import { createAsyncThunk } from "@reduxjs/toolkit";
|
|
289
|
+
import axios, { AxiosError } from 'axios';
|
|
290
|
+
import {${expressSection.name}Api} from "../../../../src/remote-api-point";
|
|
291
|
+
${filteredApiListForData.length>0?`import { ${filteredApiListForData.reduce((acc, curVal) => {
|
|
292
|
+
const inputKeyList = Object.keys(curVal.input);
|
|
293
|
+
const outputKeyList = Object.keys(curVal.output);
|
|
294
|
+
// const directOutputName = curVal.directOutput?.name;
|
|
295
|
+
const inputDataTypeName: string = (`${apiSection.name}_${curVal.name}_Input`).toUpperCase();
|
|
296
|
+
const outputDataTypeName: string = (`${apiSection.name}_${curVal.name}_Output`).toUpperCase();
|
|
297
|
+
// const directOutputDataTypeName: string = (`${apiSection.name}_${curVal.name}_Output`).toUpperCase();
|
|
298
|
+
acc = acc + `${inputKeyList.length > 0 ? inputDataTypeName + ',' : ''}`;
|
|
299
|
+
acc = acc + `${outputKeyList.length > 0 ? outputDataTypeName + ',' : ''}`;
|
|
300
|
+
return acc
|
|
301
|
+
}, '')} } from "./data";`:''}
|
|
302
|
+
|
|
303
|
+
${apiSection.apiList.reduce((acc, curVal) => {
|
|
304
|
+
if (curVal?.directOutput?.name) {
|
|
305
|
+
const [moduleName, dataName] = curVal?.directOutput?.name?.split("->");
|
|
306
|
+
acc = acc + `import {${dataName?.replace("[]","")}} from "../../../data/${moduleName}";`;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return acc
|
|
310
|
+
}, '')}
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
const showError = (err: AxiosError) => {
|
|
316
|
+
const errorResponse: any = err.response?.data || {};
|
|
317
|
+
if (err.response?.data) {
|
|
318
|
+
if (typeof (err.response?.data) == "string") {
|
|
319
|
+
return err.response?.data
|
|
320
|
+
} else {
|
|
321
|
+
return Object.keys(err.response?.data).reduce((acc, currVal) => {
|
|
322
|
+
acc = acc + errorResponse[currVal];
|
|
323
|
+
return acc;
|
|
324
|
+
}, "")
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
return err.message
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
${apiSection.apiList.reduce((acc, curVal) => {
|
|
334
|
+
const inputKeyList = Object.keys(curVal.input);
|
|
335
|
+
const outputKeyList = Object.keys(curVal.output);
|
|
336
|
+
const inputDataTypeName: string = (`${apiSection.name}_${curVal.name}_Input`).toUpperCase();
|
|
337
|
+
const outputDataTypeName: string = (`${apiSection.name}_${curVal.name}_Output`).toUpperCase();
|
|
338
|
+
const [moduleName, dataName] = curVal?.directOutput?.name?.split("->")||[];
|
|
339
|
+
acc = acc + `
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
export const ${curVal.name}Api = async (${inputKeyList.length > 0 ? `input: ${inputDataTypeName},` : ``} ) => {
|
|
343
|
+
return ${expressSection.name}Api.${curVal.type.toLowerCase()}('${this.getApiName(expressSection.name)}/${this.getApiName(apiSection.name)}/${this.getApiName(curVal.name)}',${inputKeyList.length > 0 ? `${curVal.type == 'post' ? 'input' : '{params: input.toJSON()}'}` : ''});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export const call${this.capitalizeFirstLetter(curVal.name)}Api = async (${inputKeyList.length > 0 ? `input: ${inputDataTypeName},` : ``} output: (output: ${outputKeyList.length > 0 ? outputDataTypeName :dataName?dataName: 'any'}) => any,error: (errMsg: any) => void) => {
|
|
347
|
+
try {
|
|
348
|
+
//const { data } = await ${expressSection.name}Api.${curVal.type.toLowerCase()}('${this.getApiName(apiSection.name)}/${this.getApiName(curVal.name)}',${inputKeyList.length > 0 ? `${curVal.type == 'post' ? 'input' : '{params: input.toJSON()}'}` : ''});
|
|
349
|
+
const { data } = await ${curVal.name}Api(${inputKeyList.length > 0 ? `${curVal.type == 'post' ? 'input' : 'input'}` : ''});
|
|
350
|
+
return output(data);
|
|
351
|
+
} catch (err: any) {
|
|
352
|
+
return error(showError(err));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
`
|
|
356
|
+
return acc
|
|
357
|
+
}, '')}
|
|
358
|
+
|
|
359
|
+
`
|
|
360
|
+
|
|
361
|
+
return code;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
generateRootSagaCode(apiSectionList: IApiSection[], expressSectionName: string) {
|
|
366
|
+
const code = `
|
|
367
|
+
import { all, fork } from "redux-saga/effects";
|
|
368
|
+
${apiSectionList.reduce((acc, curVal) => {
|
|
369
|
+
acc = acc + `
|
|
370
|
+
import{
|
|
371
|
+
${curVal.apiList.reduce((apiAcc, apiCurVal) => {
|
|
372
|
+
apiAcc = apiAcc + `
|
|
373
|
+
watch${curVal.name}${apiCurVal.name},
|
|
374
|
+
`;
|
|
375
|
+
return apiAcc
|
|
376
|
+
}, '')
|
|
377
|
+
}
|
|
378
|
+
} from './${expressSectionName}/${curVal.name}/${curVal.name}Saga';\n
|
|
379
|
+
`
|
|
380
|
+
return acc;
|
|
381
|
+
}, '')}
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
const genRootSaga = [
|
|
387
|
+
|
|
388
|
+
${apiSectionList.reduce((acc, curVal) => {
|
|
389
|
+
acc = acc + `
|
|
390
|
+
|
|
391
|
+
${curVal.apiList.reduce((apiAcc, apiCurVal) => {
|
|
392
|
+
apiAcc = apiAcc + `
|
|
393
|
+
watch${curVal.name}${apiCurVal.name}()
|
|
394
|
+
,
|
|
395
|
+
`;
|
|
396
|
+
return apiAcc
|
|
397
|
+
}, '')
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
`
|
|
401
|
+
return acc;
|
|
402
|
+
}, '')}
|
|
403
|
+
|
|
404
|
+
];
|
|
405
|
+
|
|
406
|
+
export default genRootSaga;
|
|
407
|
+
`;
|
|
408
|
+
return code;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
getApiName(apiName: string) {
|
|
412
|
+
return apiName.replace(/[A-Z]/g, m => "-" + m.toLowerCase()).replace(/^-/, '');
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
capitalizeFirstLetter(val: string) {
|
|
416
|
+
return val.charAt(0).toUpperCase() + val.slice(1);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
generateApiDatacode(apiSection: IApiSection) {
|
|
420
|
+
const expressHelper = new ExpressHelper();
|
|
421
|
+
return expressHelper.generateSampleApiDataCode(apiSection, "react-native");
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const commonApiDataCode = `
|
|
428
|
+
export enum ApiStatus {
|
|
429
|
+
Success="Success",
|
|
430
|
+
Loading="Loading",
|
|
431
|
+
Failed="Failed",
|
|
432
|
+
Idle="Idle"
|
|
433
|
+
}
|
|
434
|
+
`;
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
const snackbarSliceCode = `
|
|
438
|
+
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
export interface SnackbarRequest {
|
|
442
|
+
type: SnackbarType,
|
|
443
|
+
message: string,
|
|
444
|
+
timing: number
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export enum SnackbarType {
|
|
448
|
+
Success="success",
|
|
449
|
+
Error="error",
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
interface SnackbarState {
|
|
454
|
+
snackbarRequestList: SnackbarRequest[]
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const initialState:SnackbarState = {
|
|
458
|
+
snackbarRequestList: []
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
export const snackbarSlice= createSlice({
|
|
463
|
+
name: "Snackbar",
|
|
464
|
+
initialState: initialState,
|
|
465
|
+
reducers: {
|
|
466
|
+
addSnackbar: (state, action: {type:String,payload: SnackbarRequest}) => {
|
|
467
|
+
state.snackbarRequestList.push(action.payload);
|
|
468
|
+
},
|
|
469
|
+
removeLastSnackbar: (state) => {
|
|
470
|
+
state.snackbarRequestList.pop();
|
|
471
|
+
},
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
export const {addSnackbar,removeLastSnackbar} = snackbarSlice.actions;
|
|
477
|
+
|
|
478
|
+
export default snackbarSlice.reducer;
|
|
479
|
+
`
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
const mainStoreCode = `
|
|
483
|
+
|
|
484
|
+
import { configureStore } from '@reduxjs/toolkit'
|
|
485
|
+
import { GeneratedReducers } from '../../../src-gen/redux/gen-reducers'
|
|
486
|
+
import SnackbarReducer from './snackbar/snackbarSlice'
|
|
487
|
+
import createSagaMiddleware from 'redux-saga';
|
|
488
|
+
import rootSaga from '../../../src-gen/redux/gen-root-saga';
|
|
489
|
+
import { mySaga } from './saga';
|
|
490
|
+
const reduxSagaMiddleWareOptions = {};
|
|
491
|
+
const sagaMiddleWare = createSagaMiddleware(reduxSagaMiddleWareOptions);
|
|
492
|
+
export const store = configureStore({
|
|
493
|
+
reducer: {
|
|
494
|
+
...GeneratedReducers,
|
|
495
|
+
snackbar: SnackbarReducer,
|
|
496
|
+
},
|
|
497
|
+
middleware: (getDefaultMiddleware) =>
|
|
498
|
+
getDefaultMiddleware().concat([sagaMiddleWare]),
|
|
499
|
+
|
|
500
|
+
})
|
|
501
|
+
sagaMiddleWare.run(mySaga)
|
|
502
|
+
|
|
503
|
+
export type RootState = ReturnType<typeof store.getState>
|
|
504
|
+
|
|
505
|
+
export type AppDispatch = typeof store.dispatch;
|
|
506
|
+
|
|
507
|
+
`;
|
|
508
|
+
|
|
509
|
+
const mainSagaCode = `
|
|
510
|
+
import { all, takeEvery } from "redux-saga/effects";
|
|
511
|
+
import genRootSaga from "../../../src-gen/redux/gen-root-saga";
|
|
512
|
+
|
|
513
|
+
export function* mySaga() {
|
|
514
|
+
yield all([...genRootSaga])
|
|
515
|
+
}
|
|
516
|
+
`
|
|
517
|
+
|
|
518
|
+
const hooksCode = `
|
|
519
|
+
import { useDispatch, useSelector } from 'react-redux'
|
|
520
|
+
import type { TypedUseSelectorHook } from 'react-redux'
|
|
521
|
+
import type { RootState, AppDispatch } from './store/store'
|
|
522
|
+
|
|
523
|
+
// Use throughout your app instead of plain useDispatch and useSelector
|
|
524
|
+
export const useAppDispatch: () => AppDispatch = useDispatch
|
|
525
|
+
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
|
|
526
|
+
`;
|