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,154 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { FileHelper } from "./fileHelper";
|
|
3
|
+
|
|
4
|
+
export default class SectionHelper {
|
|
5
|
+
static createProject(basicFileContent: string) {
|
|
6
|
+
const folderPath = process.cwd(); // Current working directory
|
|
7
|
+
const sectionRegex = /section\s+([a-zA-Z0-9_]+)\s*{\s*data-module\s+([a-zA-Z0-9,]+)\s*}/g;
|
|
8
|
+
|
|
9
|
+
let match;
|
|
10
|
+
while ((match = sectionRegex.exec(basicFileContent)) !== null) {
|
|
11
|
+
const sectionName = match[1];
|
|
12
|
+
// Path for the section folder inside `spec`
|
|
13
|
+
const sectionFolderPath = path.join(folderPath, 'module', sectionName);
|
|
14
|
+
const packageFilePath = path.join(sectionFolderPath,"package.json");
|
|
15
|
+
const tsConfigFilePath = path.join(sectionFolderPath,"tsconfig.json");
|
|
16
|
+
const appTsPath = path.join(sectionFolderPath,"src/app.ts");
|
|
17
|
+
const envPath = path.join(sectionFolderPath,".env.dev");
|
|
18
|
+
const routesPath = path.join(sectionFolderPath,"src/routes/common/common.routes.config.ts");
|
|
19
|
+
const packageFileCode = packageJSON;
|
|
20
|
+
packageFileCode.name = sectionName;
|
|
21
|
+
FileHelper.createFile(packageFilePath,JSON.stringify(packageFileCode));
|
|
22
|
+
FileHelper.createFile(tsConfigFilePath,JSON.stringify(tsconfigJson));
|
|
23
|
+
FileHelper.createFile(appTsPath,appTsCode);
|
|
24
|
+
FileHelper.createFile(envPath,envFileCode);
|
|
25
|
+
FileHelper.createFile(routesPath,routesCode);
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const tsconfigJson = {
|
|
32
|
+
"compilerOptions": {
|
|
33
|
+
"target": "es2016",
|
|
34
|
+
"module": "commonjs",
|
|
35
|
+
"outDir": "./dist",
|
|
36
|
+
"strict": true,
|
|
37
|
+
"esModuleInterop": true,
|
|
38
|
+
"inlineSourceMap": true
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const packageJSON = {
|
|
43
|
+
"name": "",
|
|
44
|
+
"version": "1.0.0",
|
|
45
|
+
"description": "",
|
|
46
|
+
"main": "index.js",
|
|
47
|
+
"scripts": {
|
|
48
|
+
"start": "tsc && NODE_ENV=dev node ./dist/app.js",
|
|
49
|
+
"debug": "export DEBUG=* && npm run start",
|
|
50
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
51
|
+
},
|
|
52
|
+
"author": "Govind",
|
|
53
|
+
"license": "ISC",
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"bcrypt": "^5.1.0",
|
|
56
|
+
"body-parser": "^1.20.1",
|
|
57
|
+
"cors": "^2.8.5",
|
|
58
|
+
"crypto": "^1.0.1",
|
|
59
|
+
"debug": "^4.3.4",
|
|
60
|
+
"express": "^4.18.2",
|
|
61
|
+
"express-jwt": "^8.4.1",
|
|
62
|
+
"express-winston": "^4.2.0",
|
|
63
|
+
"jsonwebtoken": "^9.0.0",
|
|
64
|
+
"mongoose": "^6.8.1",
|
|
65
|
+
"winston": "^3.8.2",
|
|
66
|
+
"dotenv": "^16.3.1"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@types/bcrypt": "^5.0.0",
|
|
70
|
+
"@types/cors": "^2.8.13",
|
|
71
|
+
"@types/debug": "^4.1.7",
|
|
72
|
+
"@types/express": "^4.17.15",
|
|
73
|
+
"source-map-support": "^0.5.21",
|
|
74
|
+
"tslint": "^6.1.3",
|
|
75
|
+
"typescript": "^4.9.4"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const envFileCode = "";
|
|
80
|
+
|
|
81
|
+
const appTsCode = `
|
|
82
|
+
import express from 'express';
|
|
83
|
+
import * as http from 'http';
|
|
84
|
+
|
|
85
|
+
import * as winston from 'winston';
|
|
86
|
+
import * as expressWinston from 'express-winston';
|
|
87
|
+
import cors from 'cors';
|
|
88
|
+
import debug from 'debug';
|
|
89
|
+
|
|
90
|
+
import bodyParser, {json, urlencoded} from 'body-parser';
|
|
91
|
+
import mongoose from 'mongoose';
|
|
92
|
+
import { CommonRoutesConfig } from './routes/common/common.routes.config';
|
|
93
|
+
import dotenv from "dotenv";
|
|
94
|
+
|
|
95
|
+
const app: express.Application = express();
|
|
96
|
+
|
|
97
|
+
const port = 3000;
|
|
98
|
+
const routes: Array<CommonRoutesConfig> = [];
|
|
99
|
+
const debugLog: debug.IDebugger = debug('app');
|
|
100
|
+
app.use((err: any, req:express.Request, res:express.Response, next:any) => {
|
|
101
|
+
console.error(err.stack)
|
|
102
|
+
res.status(500).send('Something broke!')
|
|
103
|
+
});
|
|
104
|
+
app.use(express.json());
|
|
105
|
+
|
|
106
|
+
app.use(cors());
|
|
107
|
+
app.use(urlencoded());
|
|
108
|
+
app.use(json());
|
|
109
|
+
dotenv.config({ path: ".env.\${process.env.NODE_ENV}" });
|
|
110
|
+
mongoose.set('strictQuery', false);
|
|
111
|
+
|
|
112
|
+
const runningMessage = "Server running ats http://localhost:\${port}";
|
|
113
|
+
app.get('/', (req: express.Request, res: express.Response) => {
|
|
114
|
+
|
|
115
|
+
res.send("Hello World")
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
const server: http.Server = http.createServer(app);
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
server.listen(port, () => {
|
|
123
|
+
if(process.env.MONGO_DB_URL) {
|
|
124
|
+
mongoose.connect(process.env.MONGO_DB_URL).then(mongoConnection => {
|
|
125
|
+
console.log("Succesfully connected to the data base",routes)
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
console.log(runningMessage);
|
|
129
|
+
routes.forEach((route: CommonRoutesConfig) => {
|
|
130
|
+
|
|
131
|
+
});
|
|
132
|
+
// our only exception to avoiding console.log(), because we
|
|
133
|
+
// always want to know when the server is done starting up
|
|
134
|
+
|
|
135
|
+
});
|
|
136
|
+
`
|
|
137
|
+
|
|
138
|
+
const routesCode = `
|
|
139
|
+
import express from 'express';
|
|
140
|
+
export abstract class CommonRoutesConfig {
|
|
141
|
+
app: express.Application;
|
|
142
|
+
name: string;
|
|
143
|
+
|
|
144
|
+
constructor(app: express.Application, name: string) {
|
|
145
|
+
this.app = app;
|
|
146
|
+
this.name = name;
|
|
147
|
+
this.configureRoutes();
|
|
148
|
+
}
|
|
149
|
+
getName() {
|
|
150
|
+
return this.name;
|
|
151
|
+
}
|
|
152
|
+
abstract configureRoutes(): express.Application;
|
|
153
|
+
}
|
|
154
|
+
`
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// fileHelper.ts
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export class FileHelper {
|
|
6
|
+
// Ensure a directory exists, create it if it doesn't
|
|
7
|
+
static ensureDir(folderPath: string): void {
|
|
8
|
+
try {
|
|
9
|
+
fs.ensureDirSync(folderPath);
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error(`Error ensuring directory: ${error.message}`);
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static writeFile(filePath: string, content: string): void {
|
|
17
|
+
try {
|
|
18
|
+
// Ensure the folder exists
|
|
19
|
+
const folderPath = path.dirname(filePath);
|
|
20
|
+
this.ensureDir(folderPath);
|
|
21
|
+
|
|
22
|
+
// Write the file
|
|
23
|
+
fs.writeFileSync(filePath, content);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error(`Error writing file at ${filePath}: ${error.message}`);
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static createFile(filePath: string, content: string): void {
|
|
31
|
+
try {
|
|
32
|
+
// Ensure the folder exists
|
|
33
|
+
const folderPath = path.dirname(filePath);
|
|
34
|
+
this.ensureDir(folderPath);
|
|
35
|
+
if (!fs.existsSync(filePath)) {
|
|
36
|
+
fs.writeFileSync(filePath, content);
|
|
37
|
+
}
|
|
38
|
+
// Write the file
|
|
39
|
+
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error(`Error writing file at ${filePath}: ${error.message}`);
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Read content from a file
|
|
47
|
+
static readFile(filePath: string): string {
|
|
48
|
+
try {
|
|
49
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error(`Error reading file at ${filePath}: ${error.message}`);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Write a JSON object to a file, ensuring the folder exists
|
|
56
|
+
static writeJson(filePath: string, jsonContent: object): void {
|
|
57
|
+
try {
|
|
58
|
+
// Ensure the folder exists
|
|
59
|
+
const folderPath = path.dirname(filePath);
|
|
60
|
+
this.ensureDir(folderPath);
|
|
61
|
+
|
|
62
|
+
// Write the JSON file
|
|
63
|
+
fs.writeJsonSync(filePath, jsonContent, { spaces: 2 });
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(`Error writing JSON to ${filePath}: ${error.message}`);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Check if a file or directory exists
|
|
71
|
+
static exists(filePath: string): boolean {
|
|
72
|
+
try {
|
|
73
|
+
return fs.existsSync(filePath);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error(`Error checking existence of ${filePath}: ${error.message}`);
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Copy a file from source to destination, ensuring the destination folder exists
|
|
81
|
+
static async copyFile(srcPath: string, destPath: string): Promise<void> {
|
|
82
|
+
try {
|
|
83
|
+
// Ensure the destination folder exists
|
|
84
|
+
await fs.ensureDir(path.dirname(destPath));
|
|
85
|
+
|
|
86
|
+
// Copy the file
|
|
87
|
+
await fs.copyFile(srcPath, destPath);
|
|
88
|
+
console.log(`File copied from ${srcPath} to ${destPath}`);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error(`Error copying file from ${srcPath} to ${destPath}: ${error.message}`);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Copies an entire folder from source to destination, including its contents.
|
|
98
|
+
* @param srcFolder The path to the source folder.
|
|
99
|
+
* @param destFolder The path to the destination folder.
|
|
100
|
+
*/
|
|
101
|
+
static async copyFolder(srcFolder: string, destFolder: string): Promise<void> {
|
|
102
|
+
try {
|
|
103
|
+
// Copy the folder recursively
|
|
104
|
+
await fs.copy(srcFolder, destFolder, { overwrite: true });
|
|
105
|
+
console.log(`Folder copied from ${srcFolder} to ${destFolder}`);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error(`Error copying folder from ${srcFolder} to ${destFolder}: ${error.message}`);
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CharStreams, CommonTokenStream } from "antlr4ts";
|
|
2
|
+
import { BlendApiLexer } from "../../parser/blendApi/src/grammar/BlendApiLexer";
|
|
3
|
+
import { BlendApiParser } from "../../parser/blendApi/src/grammar/BlendApiParser";
|
|
4
|
+
import { IApiMainSection, IApiSection, IApiSpec, IExpressSection } from "../../types/apiOperationTypes";
|
|
5
|
+
|
|
6
|
+
export default class BlendApiGrammarHelper {
|
|
7
|
+
parseBlendApi(code: string) {
|
|
8
|
+
const inputStream = CharStreams.fromString(code);
|
|
9
|
+
const lexer = new BlendApiLexer(inputStream);
|
|
10
|
+
const tokenStream = new CommonTokenStream(lexer);
|
|
11
|
+
const parser = new BlendApiParser(tokenStream);
|
|
12
|
+
|
|
13
|
+
const mainModule = parser.program();
|
|
14
|
+
const json: IExpressSection = {
|
|
15
|
+
name: mainModule.moduleDefinition().CAPITAL_IDENTIFIER().text,
|
|
16
|
+
apiSectionList: mainModule.sectionDefinition().map(item => {
|
|
17
|
+
const apiSection: IApiSection = {
|
|
18
|
+
name: item.CAPITAL_IDENTIFIER().text, apiList: item.apiDefinition().map(api => {
|
|
19
|
+
const apiSpec: IApiSpec = {
|
|
20
|
+
input: {},
|
|
21
|
+
output: {},
|
|
22
|
+
name: api.IDENTIFIER().text,
|
|
23
|
+
type: api.HTTP_METHOD().text,
|
|
24
|
+
directOutput: api.outputDefinition()?.directOutputDefenition()?.type()? {
|
|
25
|
+
required: !api.outputDefinition()?.directOutputDefenition()?.type().text.includes("?"),
|
|
26
|
+
name: api.outputDefinition()?.directOutputDefenition()?.type().text?.replace("?", ""),
|
|
27
|
+
}:{},
|
|
28
|
+
authenticated: api?.authenticated()?.text=="authenticated"
|
|
29
|
+
}
|
|
30
|
+
api.inputDefinition()?.field()?.forEach(field => {
|
|
31
|
+
apiSpec.input[field.IDENTIFIER().text] = { type: field.type().text?.replace("?", ""), required: !field?.type().text.includes("?") };
|
|
32
|
+
})
|
|
33
|
+
api.outputDefinition()?.field()?.forEach(field => {
|
|
34
|
+
apiSpec.output[field.IDENTIFIER().text] = { type: field.type().text?.replace("?", ""), required: !field?.type().text.includes("?") };
|
|
35
|
+
})
|
|
36
|
+
return apiSpec;
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
return apiSection;
|
|
40
|
+
}),
|
|
41
|
+
includedDataModuleList: []
|
|
42
|
+
}
|
|
43
|
+
return { isValid: parser.numberOfSyntaxErrors === 0, json };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { CharStreams, CommonTokenStream } from "antlr4ts";
|
|
2
|
+
import { BlendBasicLexer } from "../../parser/blendbasic/src/grammar/BlendBasicLexer";
|
|
3
|
+
import { BlendBasicParser, SectionContext, ModuleContext, DataModuleContext, ExpressModuleContext, RnModuleContext, MongoModuleContext, ReactModuleContext } from "../../parser/blendbasic/src/grammar/BlendBasicParser";
|
|
4
|
+
import { AbstractParseTreeVisitor } from "antlr4ts/tree/AbstractParseTreeVisitor";
|
|
5
|
+
import GrammarErrorHelper from "./GrammarErrorHelper";
|
|
6
|
+
|
|
7
|
+
export default class BlendBasicGrammarHelper extends AbstractParseTreeVisitor<any> {
|
|
8
|
+
protected defaultResult() {
|
|
9
|
+
return {}; // Avoid errors if visitChildren returns nothing
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
parseBlendBasic(code: string) {
|
|
13
|
+
const inputStream = CharStreams.fromString(code);
|
|
14
|
+
const lexer = new BlendBasicLexer(inputStream);
|
|
15
|
+
const tokenStream = new CommonTokenStream(lexer);
|
|
16
|
+
const parser = new BlendBasicParser(tokenStream);
|
|
17
|
+
const sectionsList = parser.sections(); // Assuming the root rule is "program" that contains multiple sections
|
|
18
|
+
const sections = sectionsList.section().map(section => this.visitSection(section));
|
|
19
|
+
const basicJson = {
|
|
20
|
+
name: "BlendBasicConfig",
|
|
21
|
+
description: "Basic config for swing",
|
|
22
|
+
createdAt: new Date().toISOString(),
|
|
23
|
+
sectionList: sections
|
|
24
|
+
};
|
|
25
|
+
return {valid: parser.numberOfSyntaxErrors===0,basicJson};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
visitSection(ctx: SectionContext): any {
|
|
29
|
+
const sectionName = ctx.IDENTIFIER().text;
|
|
30
|
+
|
|
31
|
+
// Lists for categorized modules
|
|
32
|
+
const dataModuleList: string[] = [];
|
|
33
|
+
const expressModuleList: any[] = [];
|
|
34
|
+
const rnModuleList: any[] = [];
|
|
35
|
+
const mongoModuleList: any[] = [];
|
|
36
|
+
const reactModuleList: any[] = [];
|
|
37
|
+
|
|
38
|
+
ctx.module().forEach(mod => {
|
|
39
|
+
const resultList = this.visitModule(mod);
|
|
40
|
+
console.log(resultList,"resultList")
|
|
41
|
+
if (!resultList) return;
|
|
42
|
+
resultList.map(result => {
|
|
43
|
+
if (result.type === "data-module") {
|
|
44
|
+
dataModuleList.push(result.name);
|
|
45
|
+
} else if (result.type === "express-module") {
|
|
46
|
+
expressModuleList.push({ name: result.name });
|
|
47
|
+
} else if (result.type === "rn-module") {
|
|
48
|
+
rnModuleList.push({ name: result.name });
|
|
49
|
+
} else if (result.type === "mongo-module") {
|
|
50
|
+
mongoModuleList.push({ name: result.name });
|
|
51
|
+
}
|
|
52
|
+
else if (result.type === "react-module") {
|
|
53
|
+
reactModuleList.push({ name: result.name });
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
name: sectionName,
|
|
62
|
+
dataModuleList,
|
|
63
|
+
expressModuleList,
|
|
64
|
+
rnModuleList,
|
|
65
|
+
mongoModuleList,
|
|
66
|
+
reactModuleList
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
visitModule(ctx: ModuleContext): any {
|
|
71
|
+
// Handle multiple identifiers
|
|
72
|
+
const moduleType = ctx.children?.[0].text; // First token is the type (e.g., data-module)
|
|
73
|
+
console.log(moduleType,"moduleType")
|
|
74
|
+
if(ctx.dataModule()) return this.visitDataModule(ctx.dataModule())
|
|
75
|
+
if(ctx.expressModule()) return this.visitExpressModule(ctx.expressModule())
|
|
76
|
+
if(ctx.rnModule()) return this.visitRnModule(ctx.rnModule())
|
|
77
|
+
if(ctx.mongoModule()) return this.visitMongoModule(ctx.mongoModule())
|
|
78
|
+
if(ctx.reactModule()) return this.visitReactModule(ctx.reactModule())
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
visitDataModule(ctx: DataModuleContext): any {
|
|
82
|
+
return ctx.IDENTIFIER().map(id => ({ type: "data-module", name: id.text }));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
visitExpressModule(ctx: ExpressModuleContext): any {
|
|
86
|
+
return ctx.IDENTIFIER().map(id => ({ type: "express-module", name: id.text }));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
visitRnModule(ctx: RnModuleContext): any {
|
|
90
|
+
return ctx.IDENTIFIER().map(id => ({ type: "rn-module", name: id.text }));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
visitMongoModule(ctx: MongoModuleContext): any {
|
|
94
|
+
return ctx.IDENTIFIER().map(id => ({ type: "mongo-module", name: id.text }));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
visitReactModule(ctx: ReactModuleContext): any {
|
|
98
|
+
return ctx.IDENTIFIER().map(id => ({ type: "react-module", name: id.text }));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CharStreams, CommonTokenStream } from "antlr4ts";
|
|
2
|
+
import { BlendDataLexer } from "../../parser/blendData/src/grammar/BlendDataLexer";
|
|
3
|
+
import { BlendDataParser, DataDefinitionContext, FieldContext } from "../../parser/blendData/src/grammar/BlendDataParser";
|
|
4
|
+
|
|
5
|
+
export default class BlendDataGrammarHelper {
|
|
6
|
+
parseBlendData(code: string) {
|
|
7
|
+
const inputStream = CharStreams.fromString(code);
|
|
8
|
+
const lexer = new BlendDataLexer(inputStream);
|
|
9
|
+
const tokenStream = new CommonTokenStream(lexer);
|
|
10
|
+
const parser = new BlendDataParser(tokenStream);
|
|
11
|
+
const mainSection = parser.program(); // Assuming the root rule is "program" that contains multiple sections
|
|
12
|
+
const dataDefenitionList = mainSection.dataDefinition();
|
|
13
|
+
let hasError = false;
|
|
14
|
+
|
|
15
|
+
const dataSet = new Set();
|
|
16
|
+
const moduleDataObject = {
|
|
17
|
+
name: mainSection.moduleDefinition().CAPITAL_IDENTIFIER().text,
|
|
18
|
+
dataList: dataDefenitionList.map((dataDefinition: DataDefinitionContext) => {
|
|
19
|
+
const dataName = dataDefinition.CAPITAL_IDENTIFIER().text;
|
|
20
|
+
if(dataSet.has(dataName)) {
|
|
21
|
+
hasError = true;
|
|
22
|
+
console.log(`Duplicate Data ${dataName} found`)
|
|
23
|
+
}
|
|
24
|
+
dataSet.add(dataDefinition.CAPITAL_IDENTIFIER().text)
|
|
25
|
+
const fieldSet = new Set();
|
|
26
|
+
return {
|
|
27
|
+
name: dataDefinition.CAPITAL_IDENTIFIER().text,
|
|
28
|
+
fields: dataDefinition.field().map((field: FieldContext) => {
|
|
29
|
+
const fieldName = field.IDENTIFIER().text;
|
|
30
|
+
if(fieldSet.has(fieldName)) {
|
|
31
|
+
hasError = true;
|
|
32
|
+
console.log(`Field Data ${fieldName} found in ${dataName}`)
|
|
33
|
+
}
|
|
34
|
+
fieldSet.add(fieldName);
|
|
35
|
+
return {
|
|
36
|
+
name: fieldName,
|
|
37
|
+
requred: !field.type().text.includes("?"),
|
|
38
|
+
type: field.type().text.replace("?",""),
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {valid: parser.numberOfSyntaxErrors===0&&!hasError,moduleDataObject};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CharStreams, CommonTokenStream } from "antlr4ts";
|
|
2
|
+
import { } from "../../parser/blendbasic/src/grammar/BlendBasicLexer";
|
|
3
|
+
import { SectionContext, ModuleContext, DataModuleContext, ExpressModuleContext, RnModuleContext, MongoModuleContext, ReactModuleContext } from "../../parser/blendbasic/src/grammar/BlendBasicParser";
|
|
4
|
+
import { AbstractParseTreeVisitor } from "antlr4ts/tree/AbstractParseTreeVisitor";
|
|
5
|
+
import { BlendMDPLexer } from "../../parser/blendMDP/src/grammar/BlendMDPLexer";
|
|
6
|
+
import { BlendMDPParser } from "../../parser/blendMDP/src/grammar/BlendMDPParser";
|
|
7
|
+
|
|
8
|
+
export default class BlendMDPGrammarHelper extends AbstractParseTreeVisitor<any> {
|
|
9
|
+
protected defaultResult() {
|
|
10
|
+
return {}; // Avoid errors if visitChildren returns nothing
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
parseBlendMDP(code: string) {
|
|
14
|
+
const inputStream = CharStreams.fromString(code);
|
|
15
|
+
const lexer = new BlendMDPLexer(inputStream);
|
|
16
|
+
const tokenStream = new CommonTokenStream(lexer);
|
|
17
|
+
const parser = new BlendMDPParser(tokenStream);
|
|
18
|
+
const program = parser.program();
|
|
19
|
+
|
|
20
|
+
const mdpJson = {
|
|
21
|
+
name: program.moduleDefinition().CAPITAL_IDENTIFIER().text,
|
|
22
|
+
propsList: program.propsDefinition().propsBodyDefinition().map(propsBody => {
|
|
23
|
+
return {
|
|
24
|
+
name: propsBody.IDENTIFIER().text,
|
|
25
|
+
type: propsBody.CAPITAL_IDENTIFIER().text
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
};
|
|
29
|
+
return {valid: parser.numberOfSyntaxErrors===0,mdpJson};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { CharStreams, CommonTokenStream } from "antlr4ts";
|
|
2
|
+
import { BlendMongoLexer } from "../../parser/blendMongo/src/grammar/BlendMongoLexer";
|
|
3
|
+
import { BlendMongoParser } from "../../parser/blendMongo/src/grammar/BlendMongoParser";
|
|
4
|
+
import { IDataBase } from "../../types/mongoOperationTypes";
|
|
5
|
+
|
|
6
|
+
export default class BlendMongoGrammarHelper {
|
|
7
|
+
parseBlendMongo(code: string){
|
|
8
|
+
const inputStream = CharStreams.fromString(code);
|
|
9
|
+
const lexer = new BlendMongoLexer(inputStream);
|
|
10
|
+
const tokenStream = new CommonTokenStream(lexer);
|
|
11
|
+
const parser = new BlendMongoParser(tokenStream);
|
|
12
|
+
const program = parser.program();
|
|
13
|
+
const moduleDefinition = program.moduleDefinition();
|
|
14
|
+
const collectionDefinitionList = program.collectionDefinition();
|
|
15
|
+
const json: IDataBase = {
|
|
16
|
+
dbName: moduleDefinition.CAPITAL_IDENTIFIER().text,
|
|
17
|
+
collectionList: collectionDefinitionList.map(collectionDefinition => {
|
|
18
|
+
const propertyFields = collectionDefinition.property().map(property => {
|
|
19
|
+
return {
|
|
20
|
+
name: property.IDENTIFIER().text,
|
|
21
|
+
type: property.type().text,
|
|
22
|
+
unique: property.propertyChars()?.mongoChars()?property.propertyChars()?.mongoChars()?.findIndex(item => item.text === "unique") !=-1: undefined,
|
|
23
|
+
index: property.propertyChars()?.mongoChars()?property.propertyChars()?.mongoChars()?.findIndex(item => item.text === "index") !=-1: undefined,
|
|
24
|
+
// ref: collectionDefinition.reference()?collectionDefinition.reference()?.CAPITAL_IDENTIFIER().text:undefined,
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const referenceFields = collectionDefinition.reference()?.map(reference => {
|
|
29
|
+
return {
|
|
30
|
+
name: reference.IDENTIFIER().text,
|
|
31
|
+
type: 'Types.ObjectId',
|
|
32
|
+
unique: reference.propertyChars()?.mongoChars()?reference.propertyChars()?.mongoChars()?.findIndex(item => item.text === "unique") !=-1: undefined,
|
|
33
|
+
index: reference.propertyChars()?.mongoChars()?reference.propertyChars()?.mongoChars()?.findIndex(item => item.text === "index") !=-1: undefined,
|
|
34
|
+
ref: reference?.CAPITAL_IDENTIFIER().text,
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
name: collectionDefinition.CAPITAL_IDENTIFIER().text,
|
|
39
|
+
fields: [...propertyFields,...referenceFields]
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
isValid: parser.numberOfSyntaxErrors>0,
|
|
47
|
+
json: json
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CharStreams, CommonTokenStream } from "antlr4ts";
|
|
2
|
+
import { BlendMongoLexer } from "../../parser/blendMongo/src/grammar/BlendMongoLexer";
|
|
3
|
+
import { BlendMongoParser } from "../../parser/blendMongo/src/grammar/BlendMongoParser";
|
|
4
|
+
import { IDataBase } from "../../types/mongoOperationTypes";
|
|
5
|
+
import { BlendRNLexer } from "../../parser/blendRN/src/grammar/BlendRNLexer";
|
|
6
|
+
import { BlendRNParser, LayoutDefinitionContext, ProgramContext } from "../../parser/blendRN/src/grammar/BlendRNParser";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { IRNComponent, IRNLayout, IRNModule, IRNScreen } from "../../types/frontendOperationTypes";
|
|
9
|
+
|
|
10
|
+
export default class BlendRNGrammarHelper {
|
|
11
|
+
parseBlendRN(code: string){
|
|
12
|
+
const inputStream = CharStreams.fromString(code);
|
|
13
|
+
const lexer = new BlendRNLexer(inputStream);
|
|
14
|
+
const tokenStream = new CommonTokenStream(lexer);
|
|
15
|
+
const parser = new BlendRNParser(tokenStream);
|
|
16
|
+
const program = parser.program();
|
|
17
|
+
let screenList: IRNScreen[] = [];
|
|
18
|
+
let componentList: IRNComponent[] = [];
|
|
19
|
+
program.screenDefenition().forEach(screen => {
|
|
20
|
+
screen.CAPITAL_IDENTIFIER().forEach(screenName => {
|
|
21
|
+
screenList.push({name: screenName.text,path: screen.PATH_IDENTIFIER().text.replace(/"/g, '')});
|
|
22
|
+
})
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
program.componentDefenition().forEach(component => {
|
|
26
|
+
component.CAPITAL_IDENTIFIER().forEach(componentName => {
|
|
27
|
+
componentList.push({name: componentName.text,path: component.PATH_IDENTIFIER().text.replace(/"/g, '')});
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
const layout: IRNLayout[] = parseAndCreateLayoutAndScreen(program);
|
|
31
|
+
function parseAndCreateLayoutAndScreen(prgrm: ProgramContext|LayoutDefinitionContext): IRNLayout[] {
|
|
32
|
+
return prgrm.layoutDefinition().map(layout => {
|
|
33
|
+
const layoutList = parseAndCreateLayoutAndScreen(layout);
|
|
34
|
+
const pageList: IRNLayout[] = layout.pageDefinition().map(page => {
|
|
35
|
+
return {
|
|
36
|
+
name: page.CAPITAL_IDENTIFIER()[0].text,
|
|
37
|
+
route: page.PATH_IDENTIFIER().text.replace(/"/g, ''),
|
|
38
|
+
element: page.CAPITAL_IDENTIFIER()[1].text
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
return {
|
|
42
|
+
name: layout.CAPITAL_IDENTIFIER().text,
|
|
43
|
+
route: layout.PATH_IDENTIFIER().text.replace(/"/g, ''),
|
|
44
|
+
children: [...layoutList,...pageList],
|
|
45
|
+
type: layout.LAYOUT_TYPE().text
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const json:IRNModule = {
|
|
51
|
+
componentList,
|
|
52
|
+
screenList,
|
|
53
|
+
layout,
|
|
54
|
+
name: program.moduleDefinition().CAPITAL_IDENTIFIER().text
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
valid: parser.numberOfSyntaxErrors==0,
|
|
59
|
+
json
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CharStreams, CommonTokenStream } from "antlr4ts";
|
|
2
|
+
import { BlendMongoLexer } from "../../parser/blendMongo/src/grammar/BlendMongoLexer";
|
|
3
|
+
import { BlendMongoParser } from "../../parser/blendMongo/src/grammar/BlendMongoParser";
|
|
4
|
+
import { IDataBase } from "../../types/mongoOperationTypes";
|
|
5
|
+
import { BlendRNLexer } from "../../parser/blendRN/src/grammar/BlendRNLexer";
|
|
6
|
+
import { LayoutDefinitionContext, ProgramContext } from "../../parser/blendReact/src/grammar/BlendReactParser";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { BlendReactLexer } from "../../parser/blendReact/src/grammar/BlendReactLexer";
|
|
9
|
+
import { BlendReactParser } from "../../parser/blendReact/src/grammar/BlendReactParser";
|
|
10
|
+
import { IReactLayout, IReactModule, IReactScreen } from "../../types/frontendOperationTypes";
|
|
11
|
+
|
|
12
|
+
export default class BlendReactGrammarHelper {
|
|
13
|
+
parseBlendReact(code: string){
|
|
14
|
+
const inputStream = CharStreams.fromString(code);
|
|
15
|
+
const lexer = new BlendReactLexer(inputStream);
|
|
16
|
+
const tokenStream = new CommonTokenStream(lexer);
|
|
17
|
+
const parser = new BlendReactParser(tokenStream);
|
|
18
|
+
const program = parser.program();
|
|
19
|
+
let screenList: IReactScreen[] = [];
|
|
20
|
+
let componentList: IReactScreen[] = [];
|
|
21
|
+
program.screenDefenition().forEach(screen => {
|
|
22
|
+
screen.CAPITAL_IDENTIFIER().forEach(screenName => {
|
|
23
|
+
screenList.push({name: screenName.text,path: screen.PATH_IDENTIFIER().text.replace(/"/g, '')});
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
program.componentDefenition().forEach(screen => {
|
|
27
|
+
screen.CAPITAL_IDENTIFIER().forEach(screenName => {
|
|
28
|
+
componentList.push({name: screenName.text,path: screen.PATH_IDENTIFIER().text.replace(/"/g, '')});
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
const layout: IReactLayout[] = parseAndCreateLayoutAndScreen(program);
|
|
32
|
+
function parseAndCreateLayoutAndScreen(prgrm: ProgramContext|LayoutDefinitionContext): IReactLayout[] {
|
|
33
|
+
return prgrm.layoutDefinition().map(layout => {
|
|
34
|
+
const layoutList = parseAndCreateLayoutAndScreen(layout);
|
|
35
|
+
const pageList: IReactLayout[] = layout.pageDefinition().map(page => {
|
|
36
|
+
return {
|
|
37
|
+
name: page.CAPITAL_IDENTIFIER()[0].text,
|
|
38
|
+
route: page.PATH_IDENTIFIER().text.replace(/"/g, ''),
|
|
39
|
+
element: page.CAPITAL_IDENTIFIER()[1].text
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
return {
|
|
43
|
+
name: layout.CAPITAL_IDENTIFIER().text,
|
|
44
|
+
route: layout.PATH_IDENTIFIER().text.replace(/"/g, ''),
|
|
45
|
+
children: [...layoutList,...pageList],
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const json:IReactModule = {
|
|
51
|
+
componentList,
|
|
52
|
+
screenList,
|
|
53
|
+
layout,
|
|
54
|
+
name: program.moduleDefinition().CAPITAL_IDENTIFIER().text.toLocaleLowerCase()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
valid: parser.numberOfSyntaxErrors==0,
|
|
59
|
+
json
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
}
|