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,524 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const fileHelper_1 = require("./fileHelper");
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const BlendReactGrammarHelper_1 = __importDefault(require("./grammarHelper/BlendReactGrammarHelper"));
|
|
18
|
+
const { execSync } = require('child_process');
|
|
19
|
+
const runCommand = (command, cwd = process.cwd()) => {
|
|
20
|
+
try {
|
|
21
|
+
execSync(command, { stdio: 'inherit', cwd });
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error(`Failed to execute command: ${command}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
class ReactHelper {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.folderPath = path_1.default.join(process.cwd());
|
|
31
|
+
this.folderName = path_1.default.basename(this.folderPath);
|
|
32
|
+
this.basicFilePath = path_1.default.join(this.folderPath, `${this.folderName}.basic`);
|
|
33
|
+
this.configPath = path_1.default.join(this.folderPath, '.basicConfig');
|
|
34
|
+
this.basicProjectContent = JSON.parse(fileHelper_1.FileHelper.readFile(`${this.configPath}/basicConfig.json`) || "{}");
|
|
35
|
+
}
|
|
36
|
+
doReactOperations() {
|
|
37
|
+
this.createReactSpec();
|
|
38
|
+
this.parseSpec();
|
|
39
|
+
}
|
|
40
|
+
doReactGenerations() {
|
|
41
|
+
this.buildComponents();
|
|
42
|
+
this.buildScreens();
|
|
43
|
+
}
|
|
44
|
+
createReactSpec() {
|
|
45
|
+
this.basicProjectContent.sectionList.forEach(section => {
|
|
46
|
+
const sectionName = section.name.trim();
|
|
47
|
+
const sectionFolderPath = path_1.default.join(this.folderPath, 'spec', sectionName);
|
|
48
|
+
const reactFolderPath = path_1.default.join(sectionFolderPath, 'frontend');
|
|
49
|
+
section.reactModuleList.forEach(reactModule => {
|
|
50
|
+
const dataFilePath = path_1.default.join(reactFolderPath, `${reactModule.name}.react`);
|
|
51
|
+
if (!fileHelper_1.FileHelper.exists(dataFilePath)) {
|
|
52
|
+
fileHelper_1.FileHelper.writeFile(dataFilePath, `module ${reactModule.name}`);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
parseSpec() {
|
|
58
|
+
const sectionReactList = [];
|
|
59
|
+
this.basicProjectContent.sectionList.forEach(section => {
|
|
60
|
+
const sectionName = section.name.trim();
|
|
61
|
+
const sectionObj = {
|
|
62
|
+
name: sectionName,
|
|
63
|
+
reactModuleList: [],
|
|
64
|
+
};
|
|
65
|
+
section.reactModuleList.forEach(reactModule => {
|
|
66
|
+
const rnFilePath = path_1.default.join(this.folderPath, `spec/${sectionName}/frontend/${reactModule.name}.react`);
|
|
67
|
+
const specCode = fileHelper_1.FileHelper.readFile(rnFilePath);
|
|
68
|
+
const reactHelper = new BlendReactGrammarHelper_1.default();
|
|
69
|
+
const json = reactHelper.parseBlendReact(specCode);
|
|
70
|
+
if (!json.valid) {
|
|
71
|
+
throw new Error("Error while parsing the react native screens");
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
sectionObj.reactModuleList.push(json.json);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
sectionReactList.push(sectionObj);
|
|
78
|
+
});
|
|
79
|
+
// Write the generated configuration to a file
|
|
80
|
+
fileHelper_1.FileHelper.writeFile(`${this.configPath}/reactConfig.json`, JSON.stringify(sectionReactList, null, 4));
|
|
81
|
+
}
|
|
82
|
+
generateMDPCode(component) {
|
|
83
|
+
return `module ${component.name}\nprops {}`;
|
|
84
|
+
}
|
|
85
|
+
//Generate
|
|
86
|
+
buildScreens() {
|
|
87
|
+
const reactSectionList = JSON.parse(fileHelper_1.FileHelper.readFile(`${this.configPath}/reactConfig.json`));
|
|
88
|
+
reactSectionList.forEach(reactSection => {
|
|
89
|
+
const reactFolderPath = path_1.default.join(this.folderPath, `module/${reactSection.name}/react`);
|
|
90
|
+
reactSection.reactModuleList.forEach(reactModule => {
|
|
91
|
+
this.buildLayouts(reactSection, reactModule);
|
|
92
|
+
const rnProjectPath = path_1.default.join(reactFolderPath, reactModule.name);
|
|
93
|
+
reactModule.screenList.forEach(screen => {
|
|
94
|
+
const screenPath = `${rnProjectPath}/src/view/${screen.path}/`;
|
|
95
|
+
const screenCode = this.generateScreenCode(screen);
|
|
96
|
+
fileHelper_1.FileHelper.createFile(`${screenPath}${screen.name}.tsx`, screenCode);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
buildComponents() {
|
|
102
|
+
const reactSectionList = JSON.parse(fileHelper_1.FileHelper.readFile(`${this.configPath}/reactConfig.json`));
|
|
103
|
+
reactSectionList.forEach(reactSection => {
|
|
104
|
+
const reactFolderPath = path_1.default.join(this.folderPath, `module/${reactSection.name}/react`);
|
|
105
|
+
reactSection.reactModuleList.forEach(reactModule => {
|
|
106
|
+
this.buildLayouts(reactSection, reactModule);
|
|
107
|
+
const rnProjectPath = path_1.default.join(reactFolderPath, reactModule.name);
|
|
108
|
+
const mdpHookComponentPath = `${rnProjectPath}/src/src-gen/component/mdpHook.ts`;
|
|
109
|
+
const mdpPath = `${rnProjectPath}/src/src-gen/component/MDP.ts`;
|
|
110
|
+
const mdpHookCode = this.generateMDPHookCode(reactModule.componentList);
|
|
111
|
+
fileHelper_1.FileHelper.writeFile(`${mdpHookComponentPath}`, mdpHookCode);
|
|
112
|
+
fileHelper_1.FileHelper.writeFile(`${mdpPath}`, `export interface MDP {getMetaData:() => any;}\nexport interface IBasicComponent {value?: any;onInput?:(val: any) => any;}`);
|
|
113
|
+
reactModule.componentList.forEach(component => {
|
|
114
|
+
const componentPath = `${rnProjectPath}/src/component/${component.path}/`;
|
|
115
|
+
const componentCode = this.generateComponentCode(component);
|
|
116
|
+
const mdpCode = this.generateComponentMDPCode(component);
|
|
117
|
+
fileHelper_1.FileHelper.createFile(`${componentPath}/${component.name}/${component.name}.tsx`, componentCode);
|
|
118
|
+
fileHelper_1.FileHelper.createFile(`${componentPath}/${component.name}/${component.name}MDP.ts`, mdpCode);
|
|
119
|
+
fileHelper_1.FileHelper.createFile(`${componentPath}/${component.name}/index.ts`, `export {default} from './${component.name}';\nexport * from "./${component.name}MDP";`);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
generateMDPHookCode(componentList) {
|
|
125
|
+
const importsCode = `
|
|
126
|
+
${componentList.reduce((acc, component) => {
|
|
127
|
+
acc = acc + `import ${component.name} from '../../component/${component.path}/${component.name}';\n`;
|
|
128
|
+
return acc;
|
|
129
|
+
}, "")}`;
|
|
130
|
+
return `
|
|
131
|
+
import React, { useCallback, useRef, useState } from "react";
|
|
132
|
+
import { MDP } from "./MDP";
|
|
133
|
+
${importsCode}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
export const useMetaData = (props: {
|
|
137
|
+
mdpClass: MDP;
|
|
138
|
+
defaultInput?: any;
|
|
139
|
+
onInput?: (val: any) => void;
|
|
140
|
+
extraProps?: any;
|
|
141
|
+
memoize?: boolean;
|
|
142
|
+
}): [React.ReactElement, any, React.Dispatch<any>] => {
|
|
143
|
+
|
|
144
|
+
console.log(props.defaultInput, props.mdpClass, "defaultInput");
|
|
145
|
+
|
|
146
|
+
const [input, setInput] = useState(props.defaultInput);
|
|
147
|
+
const componentRef: any = useRef<React.ReactElement | null>(null);
|
|
148
|
+
|
|
149
|
+
// useEffect(() => {
|
|
150
|
+
// setInput(props.defaultInput);
|
|
151
|
+
// }, [props.defaultInput]);
|
|
152
|
+
|
|
153
|
+
const handleInputChange = useCallback((val: any) => {
|
|
154
|
+
setInput(val);
|
|
155
|
+
props.onInput?.(val);
|
|
156
|
+
}, [props.onInput]);
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
if (!componentRef.current || props.mdpClass !== componentRef.current.props.mdpClass || props.extraProps !== componentRef.current.props.extraProps) {
|
|
160
|
+
componentRef.current = generateElementFromMetaData({
|
|
161
|
+
componentClassMetaData: props.mdpClass.getMetaData(),
|
|
162
|
+
onInput: handleInputChange,
|
|
163
|
+
value: input,
|
|
164
|
+
extraProps: props.extraProps
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return [componentRef.current, input, setInput];
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export const generateElementFromMetaData = ({ componentClassMetaData, value, onInput, extraProps }: {
|
|
172
|
+
componentClassMetaData: any;
|
|
173
|
+
value?: any;
|
|
174
|
+
onInput?: any;
|
|
175
|
+
extraProps?: object;
|
|
176
|
+
}) => {
|
|
177
|
+
return React.createElement((ComponentNameMap[componentClassMetaData.componentName] as any), {
|
|
178
|
+
...componentClassMetaData.props,
|
|
179
|
+
value: value,
|
|
180
|
+
onInput: onInput,
|
|
181
|
+
...extraProps
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
const ComponentNameMap: any = {
|
|
188
|
+
${componentList.reduce((acc, component) => {
|
|
189
|
+
acc = acc + `"${component.name}": ${component.name},\n`;
|
|
190
|
+
return acc;
|
|
191
|
+
}, "")}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface IMetaDataHook {
|
|
195
|
+
element: React.ReactElement,
|
|
196
|
+
input?: any;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
`;
|
|
200
|
+
}
|
|
201
|
+
checkForFolderAndCreateReactApp() {
|
|
202
|
+
return new Promise((checkRes) => __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
const reactSectionList = JSON.parse(fileHelper_1.FileHelper.readFile(`${this.configPath}/reactConfig.json`));
|
|
204
|
+
const promises = [];
|
|
205
|
+
reactSectionList.forEach(reactSection => {
|
|
206
|
+
const reactFolderPath = path_1.default.join(this.folderPath, `module/${reactSection.name}/react`);
|
|
207
|
+
fileHelper_1.FileHelper.ensureDir(reactFolderPath);
|
|
208
|
+
reactSection.reactModuleList.forEach(rnModule => {
|
|
209
|
+
const modulePath = path_1.default.join(reactFolderPath, rnModule.name);
|
|
210
|
+
if (!fileHelper_1.FileHelper.exists(modulePath)) {
|
|
211
|
+
promises.push(new Promise(res => {
|
|
212
|
+
runCommand(`npm create vite@6.2.0 ${rnModule.name} -- --template react-ts `, reactFolderPath);
|
|
213
|
+
// runCommand(`npm install -D typescript @types/node @types/react @types/react-dom @types/jest`, modulePath);
|
|
214
|
+
const dependencies = [
|
|
215
|
+
'@reduxjs/toolkit@2.6.0',
|
|
216
|
+
'react-redux@9.2.0',
|
|
217
|
+
'redux-saga@1.3.0',
|
|
218
|
+
"axios@1.8.1",
|
|
219
|
+
"react-router-dom@7.2.0",
|
|
220
|
+
"tailwindcss@4.0.9",
|
|
221
|
+
"tailwindcss@4.0.9",
|
|
222
|
+
"@tailwindcss/vite@4.0.9"
|
|
223
|
+
];
|
|
224
|
+
runCommand(`npm install ${dependencies.join(' ')}`, modulePath);
|
|
225
|
+
fileHelper_1.FileHelper.writeFile(`${modulePath}/src/App.tsx`, mainAppcode);
|
|
226
|
+
fileHelper_1.FileHelper.writeFile(`${modulePath}/src/index.css`, `@import "tailwindcss";`);
|
|
227
|
+
fileHelper_1.FileHelper.writeFile(`${modulePath}/tsconfig.json`, tsConfigJsonCode);
|
|
228
|
+
fileHelper_1.FileHelper.writeFile(`${modulePath}/tsconfig.app.json`, tsConfigAppJsonCode);
|
|
229
|
+
fileHelper_1.FileHelper.writeFile(`${modulePath}/src/index.css`, `@import "tailwindcss";`);
|
|
230
|
+
runCommand(`npm install -D @types/node`, modulePath);
|
|
231
|
+
fileHelper_1.FileHelper.writeFile(`${modulePath}/vite.config.ts`, viteConfigCode);
|
|
232
|
+
runCommand(`npx shadcn@latest init`, modulePath);
|
|
233
|
+
}));
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
yield Promise.all(promises);
|
|
238
|
+
checkRes(true);
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
241
|
+
buildLayouts(rnSection, reactModule) {
|
|
242
|
+
const reactFolderPath = path_1.default.join(this.folderPath, `module/${rnSection.name}/react`);
|
|
243
|
+
const rnLayoutPath = path_1.default.join(reactFolderPath, reactModule.name);
|
|
244
|
+
const lo = {
|
|
245
|
+
name: "BlendGenerated",
|
|
246
|
+
route: "/",
|
|
247
|
+
children: reactModule.layout,
|
|
248
|
+
};
|
|
249
|
+
const routerCode = this.generateRouterCode(lo, reactModule);
|
|
250
|
+
fileHelper_1.FileHelper.writeFile(`${rnLayoutPath}/src/src-gen/router/blend-router.tsx`, routerCode);
|
|
251
|
+
this.traverseChildrenAndCreateLayout(rnLayoutPath, lo, reactModule);
|
|
252
|
+
fileHelper_1.FileHelper.createFile(`${rnLayoutPath}/src/layout/${lo.name}Layout.tsx`, `
|
|
253
|
+
${this.generateLayoutCode(lo, reactModule)}
|
|
254
|
+
`);
|
|
255
|
+
}
|
|
256
|
+
traverseChildrenAndCreateLayout(reactLayoutPath, lo, frontEnd) {
|
|
257
|
+
lo.children.forEach(loChild => {
|
|
258
|
+
if (loChild.children) {
|
|
259
|
+
fileHelper_1.FileHelper.createFile(`${reactLayoutPath}/src/layout/${loChild.name}Layout.tsx`, `
|
|
260
|
+
${this.generateLayoutCode(loChild, frontEnd)}
|
|
261
|
+
`);
|
|
262
|
+
this.traverseChildrenAndCreateLayout(reactLayoutPath, loChild, frontEnd);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
findScreenPath(screenList, screenName) {
|
|
267
|
+
const index = screenList.findIndex(screen => screen.name === screenName);
|
|
268
|
+
if (screenList[index]) {
|
|
269
|
+
return screenList[index].path;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
generateFlattenedArray(children) {
|
|
275
|
+
let uniqueElements = [];
|
|
276
|
+
let flatenedArray = [];
|
|
277
|
+
generateFlattenedArrayFun(children);
|
|
278
|
+
function generateFlattenedArrayFun(children) {
|
|
279
|
+
return children.forEach((child) => {
|
|
280
|
+
flatenedArray.push(child);
|
|
281
|
+
if (child.children) {
|
|
282
|
+
generateFlattenedArrayFun(child.children);
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
if (!uniqueElements.includes(child.element)) {
|
|
286
|
+
uniqueElements.push(child.element);
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
flatenedArray.pop();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
return flatenedArray;
|
|
295
|
+
}
|
|
296
|
+
generateRouterCode(mainLayout, frontEnd) {
|
|
297
|
+
const defaultImportCode = `
|
|
298
|
+
import { createBrowserRouter } from 'react-router-dom';\n
|
|
299
|
+
import React from 'react';\n
|
|
300
|
+
import BlendGeneratedLayout from '../../layout/BlendGeneratedLayout';
|
|
301
|
+
`;
|
|
302
|
+
console.log([mainLayout], JSON.stringify([mainLayout]), "Main layout///////////////");
|
|
303
|
+
const routerJsonCode = `const router = createBrowserRouter([${this.generateLayoutRouterJSONCode([mainLayout])}])\nexport default router;`;
|
|
304
|
+
console.log(this.generateFlattenedArray(mainLayout.children), "this.generateFlattenedArray(mainLayout.children)");
|
|
305
|
+
const importCode = `${this.generateFlattenedArray(mainLayout.children).reduce((acc, item) => {
|
|
306
|
+
const importCode = ` ${item.children ? `
|
|
307
|
+
import ${item.name}Layout from '../../layout/${item.name}Layout';\n
|
|
308
|
+
` : `
|
|
309
|
+
import ${item.element} from '../../view/${this.findScreenPath(frontEnd.screenList, ((item === null || item === void 0 ? void 0 : item.element) || ""))}/${item.element}';\n
|
|
310
|
+
`}`;
|
|
311
|
+
acc = acc + importCode;
|
|
312
|
+
return acc;
|
|
313
|
+
}, "")}`;
|
|
314
|
+
return importCode + defaultImportCode + routerJsonCode;
|
|
315
|
+
}
|
|
316
|
+
generateLayoutRouterJSONCode(layoutList) {
|
|
317
|
+
return layoutList.reduce((acc, layout) => {
|
|
318
|
+
acc = acc + `{element: ${layout.children ? `<${layout.name}Layout/>,` : `<${layout.element} />,`}
|
|
319
|
+
path: "${layout.route}",
|
|
320
|
+
${layout.children ? `children: [${this.generateLayoutRouterJSONCode(layout.children)}],` : ``}
|
|
321
|
+
},
|
|
322
|
+
`;
|
|
323
|
+
return acc;
|
|
324
|
+
}, '');
|
|
325
|
+
}
|
|
326
|
+
generateRouterConstant(children) {
|
|
327
|
+
let path = '';
|
|
328
|
+
const routeObj = generateRouterConstantObj(children);
|
|
329
|
+
function generateRouterConstantObj(children) {
|
|
330
|
+
return children.reduce((acc, child, index) => {
|
|
331
|
+
if (child.children) {
|
|
332
|
+
path = child.route && child.route != "" && child.route != "/" ? path + "/" + child.route : path;
|
|
333
|
+
acc[child.name] = generateRouterConstantObj(child.children);
|
|
334
|
+
console.log(child.name, index, children.length, "Path With layout After");
|
|
335
|
+
if (index == children.length - 1) {
|
|
336
|
+
path = path.split("/").slice(0, -1).join('/').toString();
|
|
337
|
+
// const pathNumToBeRemoved = child.route.split("/").length;
|
|
338
|
+
// path = path.split("/").slice(0,-pathNumToBeRemoved).join('/').toString();
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
path = child.route && child.route != "" && child.route != "/" ? path + "/" + child.route : path;
|
|
343
|
+
acc[child.name] = path;
|
|
344
|
+
console.log(path, "Path Without layout");
|
|
345
|
+
const pathNumToBeRemoved = child.route.split("/").length;
|
|
346
|
+
console.log(pathNumToBeRemoved, index, children.length, "pathNumToBeRemoved..............");
|
|
347
|
+
path = path.split("/").slice(0, -pathNumToBeRemoved).join('/').toString();
|
|
348
|
+
if (index == children.length - 1) {
|
|
349
|
+
path = path.split("/").slice(0, -1).join('/').toString();
|
|
350
|
+
// const pathNumToBeRemoved = child.route.split("/").length;
|
|
351
|
+
// path = path.split("/").slice(0,-pathNumToBeRemoved).join('/').toString();
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return acc;
|
|
355
|
+
}, {});
|
|
356
|
+
}
|
|
357
|
+
return JSON.stringify(routeObj);
|
|
358
|
+
}
|
|
359
|
+
generateLayoutCode(lo, frontEnd) {
|
|
360
|
+
return (`
|
|
361
|
+
import { Outlet } from "react-router-dom"
|
|
362
|
+
const ${lo.name}Layout = () => {
|
|
363
|
+
return (
|
|
364
|
+
<div>
|
|
365
|
+
${lo.name}Layout
|
|
366
|
+
<Outlet />
|
|
367
|
+
</div>
|
|
368
|
+
)
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export default ${lo.name}Layout;
|
|
372
|
+
`);
|
|
373
|
+
}
|
|
374
|
+
generateScreenCode(screen) {
|
|
375
|
+
return `
|
|
376
|
+
import React from "react";
|
|
377
|
+
const ${screen.name} = () => {
|
|
378
|
+
return(
|
|
379
|
+
<div>
|
|
380
|
+
${screen.name}
|
|
381
|
+
</div>
|
|
382
|
+
)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export default ${screen.name};
|
|
386
|
+
`;
|
|
387
|
+
}
|
|
388
|
+
generateComponentCode(component) {
|
|
389
|
+
return `
|
|
390
|
+
import React from "react";
|
|
391
|
+
import {I${component.name}Props} from './${component.name}MDP';
|
|
392
|
+
const ${component.name} = (props: I${component.name}Props) => {
|
|
393
|
+
return(
|
|
394
|
+
<div>
|
|
395
|
+
${component.name}
|
|
396
|
+
</div>
|
|
397
|
+
)
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export default ${component.name};
|
|
401
|
+
`;
|
|
402
|
+
}
|
|
403
|
+
generateComponentMDPCode(component) {
|
|
404
|
+
const pathCode = '../../' + component.path.split("/").reduce((acc, curVal) => {
|
|
405
|
+
acc = acc + '../';
|
|
406
|
+
return acc;
|
|
407
|
+
}, "");
|
|
408
|
+
return `
|
|
409
|
+
import { MDP,IBasicComponent } from "${pathCode}src-gen/component/MDP";
|
|
410
|
+
|
|
411
|
+
export class ${component.name}MDP implements I${component.name}MDP {
|
|
412
|
+
componentName: string = "${component.name}";
|
|
413
|
+
|
|
414
|
+
getMetaData() {
|
|
415
|
+
return {
|
|
416
|
+
componentName: this.componentName,
|
|
417
|
+
props: {
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export interface I${component.name}Props extends IBasicComponent {
|
|
425
|
+
}
|
|
426
|
+
export interface I${component.name}MDP extends MDP {
|
|
427
|
+
getMetaData: () => {componentName: string, props: I${component.name}Props}
|
|
428
|
+
}
|
|
429
|
+
`;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
exports.default = ReactHelper;
|
|
433
|
+
const mainAppcode = `
|
|
434
|
+
|
|
435
|
+
import { Provider } from 'react-redux';
|
|
436
|
+
import './App.css';
|
|
437
|
+
import { store } from './redux/store/store';
|
|
438
|
+
import { RouterProvider } from 'react-router-dom';
|
|
439
|
+
import router from './src-gen/router/blend-router'
|
|
440
|
+
function App() {
|
|
441
|
+
|
|
442
|
+
return (
|
|
443
|
+
<div className="App">
|
|
444
|
+
<Provider store={store}>
|
|
445
|
+
<RouterProvider router={router}/>
|
|
446
|
+
</Provider>
|
|
447
|
+
</div>
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export default App;
|
|
452
|
+
`;
|
|
453
|
+
const tsConfigJsonCode = `
|
|
454
|
+
{
|
|
455
|
+
"files": [],
|
|
456
|
+
"references": [
|
|
457
|
+
{
|
|
458
|
+
"path": "./tsconfig.app.json"
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
"path": "./tsconfig.node.json"
|
|
462
|
+
}
|
|
463
|
+
],
|
|
464
|
+
"compilerOptions": {
|
|
465
|
+
"baseUrl": ".",
|
|
466
|
+
"paths": {
|
|
467
|
+
"@/*": ["./src/*"]
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
`;
|
|
473
|
+
const tsConfigAppJsonCode = `
|
|
474
|
+
{
|
|
475
|
+
"compilerOptions": {
|
|
476
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
477
|
+
"target": "ES2020",
|
|
478
|
+
"useDefineForClassFields": true,
|
|
479
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
480
|
+
"module": "ESNext",
|
|
481
|
+
"skipLibCheck": true,
|
|
482
|
+
|
|
483
|
+
/* Bundler mode */
|
|
484
|
+
"moduleResolution": "bundler",
|
|
485
|
+
"allowImportingTsExtensions": true,
|
|
486
|
+
"isolatedModules": true,
|
|
487
|
+
"moduleDetection": "force",
|
|
488
|
+
"noEmit": true,
|
|
489
|
+
"jsx": "react-jsx",
|
|
490
|
+
|
|
491
|
+
/* Linting */
|
|
492
|
+
"strict": true,
|
|
493
|
+
"noUnusedLocals": true,
|
|
494
|
+
"noUnusedParameters": true,
|
|
495
|
+
"noFallthroughCasesInSwitch": true,
|
|
496
|
+
"noUncheckedSideEffectImports": true,
|
|
497
|
+
"baseUrl": ".",
|
|
498
|
+
"paths": {
|
|
499
|
+
"@/*": [
|
|
500
|
+
"./src/*"
|
|
501
|
+
]
|
|
502
|
+
}
|
|
503
|
+
},
|
|
504
|
+
"include": ["src"]
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
`;
|
|
509
|
+
const viteConfigCode = `
|
|
510
|
+
import path from "path"
|
|
511
|
+
import tailwindcss from "@tailwindcss/vite"
|
|
512
|
+
import react from "@vitejs/plugin-react"
|
|
513
|
+
import { defineConfig } from "vite"
|
|
514
|
+
|
|
515
|
+
// https://vite.dev/config/
|
|
516
|
+
export default defineConfig({
|
|
517
|
+
plugins: [react(), tailwindcss()],
|
|
518
|
+
resolve: {
|
|
519
|
+
alias: {
|
|
520
|
+
"@": path.resolve(__dirname, "./src"),
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
})
|
|
524
|
+
`;
|
|
@@ -0,0 +1,152 @@
|
|
|
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 SectionHelper {
|
|
9
|
+
static createProject(basicFileContent) {
|
|
10
|
+
const folderPath = process.cwd(); // Current working directory
|
|
11
|
+
const sectionRegex = /section\s+([a-zA-Z0-9_]+)\s*{\s*data-module\s+([a-zA-Z0-9,]+)\s*}/g;
|
|
12
|
+
let match;
|
|
13
|
+
while ((match = sectionRegex.exec(basicFileContent)) !== null) {
|
|
14
|
+
const sectionName = match[1];
|
|
15
|
+
// Path for the section folder inside `spec`
|
|
16
|
+
const sectionFolderPath = path_1.default.join(folderPath, 'module', sectionName);
|
|
17
|
+
const packageFilePath = path_1.default.join(sectionFolderPath, "package.json");
|
|
18
|
+
const tsConfigFilePath = path_1.default.join(sectionFolderPath, "tsconfig.json");
|
|
19
|
+
const appTsPath = path_1.default.join(sectionFolderPath, "src/app.ts");
|
|
20
|
+
const envPath = path_1.default.join(sectionFolderPath, ".env.dev");
|
|
21
|
+
const routesPath = path_1.default.join(sectionFolderPath, "src/routes/common/common.routes.config.ts");
|
|
22
|
+
const packageFileCode = packageJSON;
|
|
23
|
+
packageFileCode.name = sectionName;
|
|
24
|
+
fileHelper_1.FileHelper.createFile(packageFilePath, JSON.stringify(packageFileCode));
|
|
25
|
+
fileHelper_1.FileHelper.createFile(tsConfigFilePath, JSON.stringify(tsconfigJson));
|
|
26
|
+
fileHelper_1.FileHelper.createFile(appTsPath, appTsCode);
|
|
27
|
+
fileHelper_1.FileHelper.createFile(envPath, envFileCode);
|
|
28
|
+
fileHelper_1.FileHelper.createFile(routesPath, routesCode);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.default = SectionHelper;
|
|
33
|
+
const tsconfigJson = {
|
|
34
|
+
"compilerOptions": {
|
|
35
|
+
"target": "es2016",
|
|
36
|
+
"module": "commonjs",
|
|
37
|
+
"outDir": "./dist",
|
|
38
|
+
"strict": true,
|
|
39
|
+
"esModuleInterop": true,
|
|
40
|
+
"inlineSourceMap": true
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const packageJSON = {
|
|
44
|
+
"name": "",
|
|
45
|
+
"version": "1.0.0",
|
|
46
|
+
"description": "",
|
|
47
|
+
"main": "index.js",
|
|
48
|
+
"scripts": {
|
|
49
|
+
"start": "tsc && NODE_ENV=dev node ./dist/app.js",
|
|
50
|
+
"debug": "export DEBUG=* && npm run start",
|
|
51
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
52
|
+
},
|
|
53
|
+
"author": "Govind",
|
|
54
|
+
"license": "ISC",
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"bcrypt": "^5.1.0",
|
|
57
|
+
"body-parser": "^1.20.1",
|
|
58
|
+
"cors": "^2.8.5",
|
|
59
|
+
"crypto": "^1.0.1",
|
|
60
|
+
"debug": "^4.3.4",
|
|
61
|
+
"express": "^4.18.2",
|
|
62
|
+
"express-jwt": "^8.4.1",
|
|
63
|
+
"express-winston": "^4.2.0",
|
|
64
|
+
"jsonwebtoken": "^9.0.0",
|
|
65
|
+
"mongoose": "^6.8.1",
|
|
66
|
+
"winston": "^3.8.2",
|
|
67
|
+
"dotenv": "^16.3.1"
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@types/bcrypt": "^5.0.0",
|
|
71
|
+
"@types/cors": "^2.8.13",
|
|
72
|
+
"@types/debug": "^4.1.7",
|
|
73
|
+
"@types/express": "^4.17.15",
|
|
74
|
+
"source-map-support": "^0.5.21",
|
|
75
|
+
"tslint": "^6.1.3",
|
|
76
|
+
"typescript": "^4.9.4"
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const envFileCode = "";
|
|
80
|
+
const appTsCode = `
|
|
81
|
+
import express from 'express';
|
|
82
|
+
import * as http from 'http';
|
|
83
|
+
|
|
84
|
+
import * as winston from 'winston';
|
|
85
|
+
import * as expressWinston from 'express-winston';
|
|
86
|
+
import cors from 'cors';
|
|
87
|
+
import debug from 'debug';
|
|
88
|
+
|
|
89
|
+
import bodyParser, {json, urlencoded} from 'body-parser';
|
|
90
|
+
import mongoose from 'mongoose';
|
|
91
|
+
import { CommonRoutesConfig } from './routes/common/common.routes.config';
|
|
92
|
+
import dotenv from "dotenv";
|
|
93
|
+
|
|
94
|
+
const app: express.Application = express();
|
|
95
|
+
|
|
96
|
+
const port = 3000;
|
|
97
|
+
const routes: Array<CommonRoutesConfig> = [];
|
|
98
|
+
const debugLog: debug.IDebugger = debug('app');
|
|
99
|
+
app.use((err: any, req:express.Request, res:express.Response, next:any) => {
|
|
100
|
+
console.error(err.stack)
|
|
101
|
+
res.status(500).send('Something broke!')
|
|
102
|
+
});
|
|
103
|
+
app.use(express.json());
|
|
104
|
+
|
|
105
|
+
app.use(cors());
|
|
106
|
+
app.use(urlencoded());
|
|
107
|
+
app.use(json());
|
|
108
|
+
dotenv.config({ path: ".env.\${process.env.NODE_ENV}" });
|
|
109
|
+
mongoose.set('strictQuery', false);
|
|
110
|
+
|
|
111
|
+
const runningMessage = "Server running ats http://localhost:\${port}";
|
|
112
|
+
app.get('/', (req: express.Request, res: express.Response) => {
|
|
113
|
+
|
|
114
|
+
res.send("Hello World")
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
const server: http.Server = http.createServer(app);
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
server.listen(port, () => {
|
|
122
|
+
if(process.env.MONGO_DB_URL) {
|
|
123
|
+
mongoose.connect(process.env.MONGO_DB_URL).then(mongoConnection => {
|
|
124
|
+
console.log("Succesfully connected to the data base",routes)
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
console.log(runningMessage);
|
|
128
|
+
routes.forEach((route: CommonRoutesConfig) => {
|
|
129
|
+
|
|
130
|
+
});
|
|
131
|
+
// our only exception to avoiding console.log(), because we
|
|
132
|
+
// always want to know when the server is done starting up
|
|
133
|
+
|
|
134
|
+
});
|
|
135
|
+
`;
|
|
136
|
+
const routesCode = `
|
|
137
|
+
import express from 'express';
|
|
138
|
+
export abstract class CommonRoutesConfig {
|
|
139
|
+
app: express.Application;
|
|
140
|
+
name: string;
|
|
141
|
+
|
|
142
|
+
constructor(app: express.Application, name: string) {
|
|
143
|
+
this.app = app;
|
|
144
|
+
this.name = name;
|
|
145
|
+
this.configureRoutes();
|
|
146
|
+
}
|
|
147
|
+
getName() {
|
|
148
|
+
return this.name;
|
|
149
|
+
}
|
|
150
|
+
abstract configureRoutes(): express.Application;
|
|
151
|
+
}
|
|
152
|
+
`;
|