blend-r 1.1.6 → 1.1.7
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 +69 -41
- package/dist/helper/DataHelper.js +0 -1
- package/dist/helper/FrontEndHelper.js +3 -8
- package/dist/helper/fileHelper.js +0 -2
- package/dist/helper/grammarHelper/BlendApiGrammarHelper.js +6 -7
- package/dist/helper/grammarHelper/BlendBasicGrammarHelper.js +1 -3
- package/dist/helper/grammarHelper/BlendDataGrammarHelper.js +2 -2
- package/dist/helper/grammarHelper/GrammarErrorHelper.js +0 -1
- package/dist/index.js +38 -27
- package/dist/parser/blendApi/src/grammar/BlendApiLexer.js +95 -90
- package/dist/parser/blendApi/src/grammar/BlendApiParser.js +220 -157
- package/dist/parser/blendApi/src/grammar/src/grammar/BlendApiLexer.js +212 -0
- package/dist/parser/blendApi/src/grammar/src/grammar/BlendApiListener.js +3 -0
- package/dist/parser/blendApi/src/grammar/src/grammar/BlendApiParser.js +1149 -0
- package/dist/parser/blendApi/src/grammar/src/grammar/BlendApiVisitor.js +3 -0
- package/dist/parser/blendRBasic/src/grammar/blendRBasicLexer.js +2 -2
- package/package.json +1 -1
package/dist/helper/ApiHelper.js
CHANGED
|
@@ -112,18 +112,19 @@ Authorization: localStorage.getItem("authToken")||""
|
|
|
112
112
|
return code;
|
|
113
113
|
}
|
|
114
114
|
generateRolesGetterCode() {
|
|
115
|
+
var _a, _b;
|
|
115
116
|
const code = `
|
|
116
117
|
import type { RootState } from "@/redux/store/store";
|
|
117
|
-
import type { Role } from "./type";
|
|
118
|
-
export const selectRoles = (state: RootState) => state.roles.roles;
|
|
119
118
|
|
|
120
|
-
|
|
119
|
+
${(((_b = (_a = this.basicProjectContent) === null || _a === void 0 ? void 0 : _a.frontend) === null || _b === void 0 ? void 0 : _b.roleList) || []).length > 0 ? `// Generic checker
|
|
120
|
+
import type { Role } from "./type";
|
|
121
|
+
export const selectRoles = (state: RootState) => state.roles.roles;
|
|
121
122
|
export const hasRole = (role: Role) => (state: RootState) =>
|
|
122
123
|
state.roles.roles.includes(role);
|
|
123
124
|
export const hasAnyRole = (roles: Role[]) => (state: RootState) =>
|
|
124
|
-
roles.some(role => state.roles.roles.includes(role))
|
|
125
|
+
roles.some(role => state.roles.roles.includes(role));` : ''}
|
|
125
126
|
|
|
126
|
-
${this.basicProjectContent.frontend.roleList.reduce((acc, role) => {
|
|
127
|
+
${(this.basicProjectContent.frontend.roleList || []).reduce((acc, role) => {
|
|
127
128
|
acc = acc + `
|
|
128
129
|
export const has${role}Role = (state: RootState) =>
|
|
129
130
|
state.roles.roles.includes("${role}");
|
|
@@ -134,10 +135,11 @@ ${this.basicProjectContent.frontend.roleList.reduce((acc, role) => {
|
|
|
134
135
|
return code;
|
|
135
136
|
}
|
|
136
137
|
generateRolesTypeCode() {
|
|
137
|
-
const code = `
|
|
138
|
-
export type Role = ${this.basicProjectContent.frontend.roleList.map(role => `"${role}"`).join(' | ')};
|
|
139
|
-
|
|
140
|
-
return this.basicProjectContent.frontend.roleList.length
|
|
138
|
+
const code = (this.basicProjectContent.frontend.roleList || []).length > 0 ? `
|
|
139
|
+
export type Role = ${(this.basicProjectContent.frontend.roleList || []).map(role => `"${role}"`).join(' | ')};
|
|
140
|
+
` : `export type Role = 'admin';`;
|
|
141
|
+
// return (this.basicProjectContent.frontend.roleList||[]).length>0?code:'';
|
|
142
|
+
return code;
|
|
141
143
|
}
|
|
142
144
|
generateRoleRelatedFiles() {
|
|
143
145
|
const roleSliceCode = this.generateRoleSliceCode();
|
|
@@ -171,7 +173,7 @@ ${this.basicProjectContent.frontend.roleList.reduce((acc, role) => {
|
|
|
171
173
|
const sliceCode = this.generateSliceCode(apiSection);
|
|
172
174
|
const dataCode = this.generateApiDatacode(apiSection);
|
|
173
175
|
const actionCode = this.generateApiActioncode(apiSection, expressSection);
|
|
174
|
-
const selectorCode = this.generateApiSelectorCode(apiSection);
|
|
176
|
+
const selectorCode = this.generateApiSelectorCode(expressSection, apiSection);
|
|
175
177
|
// const sagaCode = this.generateSagaCode(apiSection);
|
|
176
178
|
fileHelper_1.FileHelper.writeFile(apiSectionSlicePath, sliceCode);
|
|
177
179
|
fileHelper_1.FileHelper.writeFile(apiSectionSelectorPath, selectorCode);
|
|
@@ -195,19 +197,24 @@ import * as ${apiSection.name}Selector from "src-gen/redux/${expressSection.name
|
|
|
195
197
|
const outputKeyList = Object.keys(api.output);
|
|
196
198
|
return inputKeyList.length > 0 || outputKeyList.length > 0;
|
|
197
199
|
});
|
|
200
|
+
const inputStoreApis = apiSection.apiList.filter(api => api.inputStore && Object.keys(api.input).length > 0);
|
|
198
201
|
const code = `
|
|
199
202
|
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
|
200
203
|
import {${apiSection.apiList.reduce((acc, curVal) => {
|
|
201
204
|
acc = acc + `${curVal.name}AsyncThunk,`;
|
|
202
205
|
return acc;
|
|
203
|
-
}, '')}
|
|
206
|
+
}, '')}${inputStoreApis.reduce((acc, curVal) => {
|
|
207
|
+
acc = acc + `set${this.capitalizeFirstLetter(curVal.name)}Input,`;
|
|
208
|
+
return acc;
|
|
209
|
+
}, '')}
|
|
210
|
+
} from './action';
|
|
204
211
|
|
|
205
212
|
${filteredApiListForData.length > 0 ? `import { ${filteredApiListForData.reduce((acc, curVal) => {
|
|
206
213
|
const inputKeyList = Object.keys(curVal.input);
|
|
207
214
|
const outputKeyList = Object.keys(curVal.output);
|
|
208
|
-
|
|
215
|
+
const inputDataTypeName = (`${apiSection.name}_${curVal.name}_Input`).toUpperCase();
|
|
209
216
|
const outputDataTypeName = (`${apiSection.name}_${curVal.name}_Output`).toUpperCase();
|
|
210
|
-
|
|
217
|
+
acc = acc + `${curVal.inputStore && inputKeyList.length > 0 ? `I_${inputDataTypeName},` : ''}`;
|
|
211
218
|
acc = acc + `${outputKeyList.length > 0 ? outputDataTypeName + `,I_${outputDataTypeName}` + ',' : ''}`;
|
|
212
219
|
return acc;
|
|
213
220
|
}, '')} } from "./data";` : ''}
|
|
@@ -216,14 +223,13 @@ ${filteredApiListForData.length > 0 ? `import { ${filteredApiListForData.reduce(
|
|
|
216
223
|
var _a, _b, _c;
|
|
217
224
|
if ((_a = curVal === null || curVal === void 0 ? void 0 : curVal.directOutput) === null || _a === void 0 ? void 0 : _a.name) {
|
|
218
225
|
const [moduleName, dataName] = (_c = (_b = curVal === null || curVal === void 0 ? void 0 : curVal.directOutput) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.split("->");
|
|
219
|
-
console.log(dataName, moduleName, "DataName...........");
|
|
220
226
|
if (dataName) {
|
|
221
227
|
const dataTypeName = `${dataName === null || dataName === void 0 ? void 0 : dataName.replace("[]", "")}`;
|
|
222
228
|
acc = acc + `import {${dataTypeName},I_${dataTypeName}} from "../../../data/${moduleName}";`;
|
|
223
229
|
}
|
|
224
230
|
}
|
|
225
231
|
return acc;
|
|
226
|
-
}, '')}
|
|
232
|
+
}, '')}
|
|
227
233
|
|
|
228
234
|
|
|
229
235
|
import { ApiStatus } from "../../../data/common";
|
|
@@ -231,12 +237,16 @@ interface ${apiSection.name}State {
|
|
|
231
237
|
${apiSection.apiList.reduce((acc, curVal) => {
|
|
232
238
|
var _a, _b;
|
|
233
239
|
const [moduleName, dataName] = ((_b = (_a = curVal === null || curVal === void 0 ? void 0 : curVal.directOutput) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.split("->")) || [];
|
|
240
|
+
const inputDataTypeName = (`${apiSection.name}_${curVal.name}_Input`).toUpperCase();
|
|
234
241
|
acc = acc + `${curVal.name}: {
|
|
235
242
|
data: ${Object.keys(curVal.output).length > 0 ? `I_${apiSection.name.toUpperCase()}_${curVal.name.toUpperCase()}_OUTPUT` : dataName ? `I_${dataName}` : "any"},\n
|
|
236
243
|
status: ApiStatus,
|
|
237
244
|
error:string|null
|
|
238
245
|
}
|
|
239
246
|
`;
|
|
247
|
+
if (curVal.inputStore && Object.keys(curVal.input).length > 0) {
|
|
248
|
+
acc = acc + `${curVal.name}Input: I_${inputDataTypeName} | null\n`;
|
|
249
|
+
}
|
|
240
250
|
return acc;
|
|
241
251
|
}, "")}
|
|
242
252
|
}
|
|
@@ -251,6 +261,9 @@ const initialState: ${apiSection.name}State = {
|
|
|
251
261
|
status: ApiStatus.Idle,
|
|
252
262
|
error: null
|
|
253
263
|
},\n`;
|
|
264
|
+
if (curVal.inputStore && Object.keys(curVal.input).length > 0) {
|
|
265
|
+
acc = acc + `${curVal.name}Input: null,\n`;
|
|
266
|
+
}
|
|
254
267
|
return acc;
|
|
255
268
|
}, "")}
|
|
256
269
|
}
|
|
@@ -260,7 +273,7 @@ export const ${apiSection.name}Slice = createSlice({
|
|
|
260
273
|
initialState,
|
|
261
274
|
reducers: {
|
|
262
275
|
reset${apiSection.name}Reducer: () => initialState
|
|
263
|
-
},
|
|
276
|
+
},
|
|
264
277
|
extraReducers: (builder) =>{
|
|
265
278
|
builder.
|
|
266
279
|
${apiSection.apiList.reduce((acc, curVal, currentIndex) => {
|
|
@@ -274,12 +287,14 @@ export const ${apiSection.name}Slice = createSlice({
|
|
|
274
287
|
})\n\t\t.addCase(${curVal.name}AsyncThunk.rejected, (state, action) => {
|
|
275
288
|
state.${curVal.name}.status = ApiStatus.Failed;
|
|
276
289
|
state.${curVal.name}.error = action.payload as string;
|
|
277
|
-
})\n\t\t${
|
|
290
|
+
})\n\t\t${curVal.inputStore && Object.keys(curVal.input).length > 0 ? `.addCase(set${this.capitalizeFirstLetter(curVal.name)}Input, (state, action) => {
|
|
291
|
+
state.${curVal.name}Input = action.payload;
|
|
292
|
+
})\n\t\t` : ''}${currentIndex < apiSection.apiList.length - 1 ? '.' : ''}`;
|
|
278
293
|
return acc;
|
|
279
294
|
}, "")}
|
|
280
295
|
}
|
|
281
296
|
});
|
|
282
|
-
|
|
297
|
+
|
|
283
298
|
export const {reset${apiSection.name}Reducer} = ${apiSection.name}Slice.actions;
|
|
284
299
|
export default ${apiSection.name}Slice.reducer;
|
|
285
300
|
`;
|
|
@@ -326,7 +341,6 @@ export default ${apiSection.name}Slice.reducer;
|
|
|
326
341
|
generateReducersCode(apiSectionList) {
|
|
327
342
|
const code = `
|
|
328
343
|
${apiSectionList.reduce((acc, curVal) => {
|
|
329
|
-
console.log(curVal.name, "APINAME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
330
344
|
acc = acc + `
|
|
331
345
|
import ${curVal.name}Reducer from './${curVal.sectionName}/${curVal.name}/${curVal.name}Slice';\n`;
|
|
332
346
|
return acc;
|
|
@@ -334,7 +348,7 @@ export default ${apiSection.name}Slice.reducer;
|
|
|
334
348
|
|
|
335
349
|
export const GeneratedReducers = {
|
|
336
350
|
${apiSectionList.reduce((acc, curVal) => {
|
|
337
|
-
acc = acc + `${curVal.name.toLowerCase()}: ${curVal.name}Reducer,`;
|
|
351
|
+
acc = acc + `${curVal.sectionName}_${curVal.name.toLowerCase()}: ${curVal.name}Reducer,`;
|
|
338
352
|
return acc;
|
|
339
353
|
}, '')}
|
|
340
354
|
}
|
|
@@ -347,8 +361,9 @@ export const GeneratedReducers = {
|
|
|
347
361
|
const outputKeyList = Object.keys(api.output);
|
|
348
362
|
return inputKeyList.length > 0 || outputKeyList.length > 0;
|
|
349
363
|
});
|
|
364
|
+
const inputStoreApis = apiSection.apiList.filter(api => api.inputStore && Object.keys(api.input).length > 0);
|
|
350
365
|
const code = `
|
|
351
|
-
import { createAsyncThunk } from "@reduxjs/toolkit";
|
|
366
|
+
import { createAsyncThunk${inputStoreApis.length > 0 ? ', createAction' : ''} } from "@reduxjs/toolkit";
|
|
352
367
|
import axios, { AxiosError } from 'axios';
|
|
353
368
|
import {${expressSection.name}Api} from "../../../../src/remote-api-point";
|
|
354
369
|
${filteredApiListForData.length > 0 ? `import { ${filteredApiListForData.reduce((acc, curVal) => {
|
|
@@ -365,19 +380,14 @@ export const GeneratedReducers = {
|
|
|
365
380
|
var _a, _b, _c;
|
|
366
381
|
if ((_a = curVal === null || curVal === void 0 ? void 0 : curVal.directOutput) === null || _a === void 0 ? void 0 : _a.name) {
|
|
367
382
|
const [moduleName, dataName] = (_c = (_b = curVal === null || curVal === void 0 ? void 0 : curVal.directOutput) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.split("->");
|
|
368
|
-
// console.log(dataName,moduleName,"DataName...........")
|
|
369
383
|
if (dataName) {
|
|
370
384
|
acc = acc + `import * as ${moduleName} from "../../../data/${moduleName}";`;
|
|
371
385
|
}
|
|
372
386
|
}
|
|
373
387
|
return acc;
|
|
374
|
-
}, '')}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
388
|
+
}, '')}
|
|
379
389
|
|
|
380
|
-
|
|
390
|
+
const showError = (err: AxiosError) => {
|
|
381
391
|
const errorResponse: any = err.response?.data;
|
|
382
392
|
if (errorResponse) {
|
|
383
393
|
return {status: err.status,data: errorResponse}
|
|
@@ -387,10 +397,14 @@ export const GeneratedReducers = {
|
|
|
387
397
|
}
|
|
388
398
|
}
|
|
389
399
|
|
|
400
|
+
${inputStoreApis.reduce((acc, curVal) => {
|
|
401
|
+
const inputDataTypeName = (`${apiSection.name}_${curVal.name}_Input`).toUpperCase();
|
|
402
|
+
acc = acc + `
|
|
403
|
+
export const set${this.capitalizeFirstLetter(curVal.name)}Input = createAction<${inputDataTypeName} | null>('${apiSection.name}/set${this.capitalizeFirstLetter(curVal.name)}Input');
|
|
404
|
+
`;
|
|
405
|
+
return acc;
|
|
406
|
+
}, '')}
|
|
390
407
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
408
|
${apiSection.apiList.reduce((acc, curVal) => {
|
|
395
409
|
var _a, _b;
|
|
396
410
|
const inputKeyList = Object.keys(curVal.input);
|
|
@@ -398,13 +412,15 @@ export const GeneratedReducers = {
|
|
|
398
412
|
const inputDataTypeName = (`${apiSection.name}_${curVal.name}_Input`).toUpperCase();
|
|
399
413
|
const outputDataTypeName = (`${apiSection.name}_${curVal.name}_Output`).toUpperCase();
|
|
400
414
|
const [moduleName, dataName] = ((_b = (_a = curVal === null || curVal === void 0 ? void 0 : curVal.directOutput) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.split("->")) || [];
|
|
415
|
+
const hasInputStore = curVal.inputStore && inputKeyList.length > 0;
|
|
401
416
|
acc = acc + `
|
|
402
|
-
|
|
417
|
+
|
|
403
418
|
|
|
404
419
|
export const ${curVal.name}Api = async (${inputKeyList.length > 0 ? `input: ${inputDataTypeName},` : ``} ) => {
|
|
405
420
|
return ${expressSection.name}Api.${curVal.type.toLowerCase()}('${curVal.url}',${inputKeyList.length > 0 ? `${curVal.type == 'POST' ? 'input' : '{params: input.toJSON()}'}` : ''});
|
|
406
421
|
}
|
|
407
|
-
export const ${curVal.name}AsyncThunk = createAsyncThunk<${outputKeyList.length > 0 ? outputDataTypeName : dataName ? `${moduleName}.${dataName}` : 'any'},${inputKeyList.length > 0 ? `${inputDataTypeName}` : `void`},any>('${apiSection.name}/${curVal.name}', async (${inputKeyList.length > 0 ? `input: ${inputDataTypeName}` : `_`}, { rejectWithValue }) => {
|
|
422
|
+
export const ${curVal.name}AsyncThunk = createAsyncThunk<${outputKeyList.length > 0 ? outputDataTypeName : dataName ? `${moduleName}.${dataName}` : 'any'},${inputKeyList.length > 0 ? `${inputDataTypeName}` : `void`},any>('${apiSection.name}/${curVal.name}', async (${inputKeyList.length > 0 ? `input: ${inputDataTypeName}` : `_`}, { rejectWithValue${hasInputStore ? ', dispatch' : ''} }) => {
|
|
423
|
+
${hasInputStore ? `dispatch(set${this.capitalizeFirstLetter(curVal.name)}Input(input.toJSON()));` : ''}
|
|
408
424
|
return call${this.capitalizeFirstLetter(curVal.name)}Api(${inputKeyList.length > 0 ? `input,` : ''} output => {
|
|
409
425
|
return output
|
|
410
426
|
},error=> {
|
|
@@ -415,30 +431,43 @@ export const GeneratedReducers = {
|
|
|
415
431
|
|
|
416
432
|
export const call${this.capitalizeFirstLetter(curVal.name)}Api = async (${inputKeyList.length > 0 ? `input: ${inputDataTypeName},` : ``} output: (output: ${outputKeyList.length > 0 ? outputDataTypeName : dataName ? `${moduleName}.${dataName}` : 'any'}) => any,error?: (errMsg: any) => void) => {
|
|
417
433
|
try {
|
|
418
|
-
//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()}'}` : ''});
|
|
419
434
|
const { data } = await ${curVal.name}Api(${inputKeyList.length > 0 ? `${curVal.type == 'POST' ? 'input' : 'input'}` : ''});
|
|
420
435
|
return output(data);
|
|
421
436
|
} catch (err: any) {
|
|
422
437
|
if(error) {
|
|
423
438
|
return error(showError(err));
|
|
424
439
|
}
|
|
425
|
-
|
|
440
|
+
|
|
426
441
|
}
|
|
427
442
|
}
|
|
443
|
+
|
|
444
|
+
${(inputKeyList.length > 0 && inputKeyList.length < 5) ?
|
|
445
|
+
`export const call${this.capitalizeFirstLetter(curVal.name)}ApiWithParams = async (${inputKeyList.length > 0 ? `${inputKeyList.reduce((acc, inputCurVal) => {
|
|
446
|
+
const inputCurValType = curVal.input[inputCurVal].type;
|
|
447
|
+
acc = acc + `${inputCurVal}: ${['string', 'number', 'boolean'].indexOf(inputCurValType) !== -1 ? inputCurValType : 'any'},`;
|
|
448
|
+
return acc;
|
|
449
|
+
}, "")}` : ``} output: (output: ${outputKeyList.length > 0 ? outputDataTypeName : dataName ? `${moduleName}.${dataName}` : 'any'}) => any,error?: (errMsg: any) => void) => {
|
|
450
|
+
return call${this.capitalizeFirstLetter(curVal.name)}Api(${inputDataTypeName}.fromJSON({${inputKeyList.reduce((acc, cur) => { acc = acc + cur + ','; return acc; }, "")}}), output, error);
|
|
451
|
+
}` : ''}
|
|
452
|
+
|
|
428
453
|
`;
|
|
429
454
|
return acc;
|
|
430
455
|
}, '')}
|
|
431
|
-
|
|
456
|
+
|
|
432
457
|
`;
|
|
433
458
|
return code;
|
|
434
459
|
}
|
|
435
|
-
generateApiSelectorCode(apiSection) {
|
|
460
|
+
generateApiSelectorCode(expressSection, apiSection) {
|
|
436
461
|
const code = `
|
|
437
462
|
import { RootState } from "@/redux/store/store";
|
|
438
463
|
|
|
439
464
|
${apiSection.apiList.reduce((acc, curVal) => {
|
|
440
465
|
acc = acc +
|
|
441
|
-
`export const select${this.capitalizeFirstLetter(curVal.name)}Data = (state: RootState) => state.${apiSection.name.toLocaleLowerCase()}.${curVal.name}.data;\n`;
|
|
466
|
+
`export const select${this.capitalizeFirstLetter(curVal.name)}Data = (state: RootState) => state.${expressSection.name}_${apiSection.name.toLocaleLowerCase()}.${curVal.name}.data;\n`;
|
|
467
|
+
if (curVal.inputStore && Object.keys(curVal.input).length > 0) {
|
|
468
|
+
acc = acc +
|
|
469
|
+
`export const select${this.capitalizeFirstLetter(curVal.name)}Input = (state: RootState) => state.${expressSection.name}_${apiSection.name.toLocaleLowerCase()}.${curVal.name}Input;\n`;
|
|
470
|
+
}
|
|
442
471
|
return acc;
|
|
443
472
|
}, '')}
|
|
444
473
|
`;
|
|
@@ -513,7 +542,7 @@ export default genRootSaga;
|
|
|
513
542
|
imports.add(`import { ${baseTypeName} } from '../data/${module}';`);
|
|
514
543
|
}
|
|
515
544
|
else {
|
|
516
|
-
imports.add(`import { ${baseTypeName} } from '
|
|
545
|
+
imports.add(`import { ${baseTypeName} } from '../../../data/${module}';`);
|
|
517
546
|
}
|
|
518
547
|
}
|
|
519
548
|
});
|
|
@@ -526,7 +555,7 @@ export default genRootSaga;
|
|
|
526
555
|
imports.add(`import { ${baseTypeName} } from '../data/${module}';`);
|
|
527
556
|
}
|
|
528
557
|
else {
|
|
529
|
-
imports.add(`import { ${baseTypeName} } from '
|
|
558
|
+
imports.add(`import { ${baseTypeName} } from '../../../data/${module}';`);
|
|
530
559
|
}
|
|
531
560
|
}
|
|
532
561
|
});
|
|
@@ -636,7 +665,6 @@ ${outputKeyList
|
|
|
636
665
|
}
|
|
637
666
|
}
|
|
638
667
|
generateFromJSONField(field) {
|
|
639
|
-
console.log(field, "field");
|
|
640
668
|
const typeParts = field.type.split("->");
|
|
641
669
|
const baseType = typeParts.length === 2 ? typeParts[1] : field.type;
|
|
642
670
|
if (baseType.endsWith("[]")) {
|
|
@@ -32,7 +32,6 @@ class DataHelper {
|
|
|
32
32
|
const filePath = path_1.default.join(dataFolderPath, `${module}.data`);
|
|
33
33
|
const specCode = fileHelper_1.FileHelper.readFile(filePath);
|
|
34
34
|
const json = new BlendDataGrammarHelper_1.default().parseBlendData(specCode);
|
|
35
|
-
console.log(json, "json");
|
|
36
35
|
if (!json.valid) {
|
|
37
36
|
throw new Error("Error while parsing the syntax");
|
|
38
37
|
}
|
|
@@ -104,9 +104,8 @@ ${this.generateLayoutCode(loChild)}
|
|
|
104
104
|
if (child.children) {
|
|
105
105
|
path = child.route && child.route != "" && child.route != "/" ? path + "/" + child.route : path;
|
|
106
106
|
acc[child.name] = generateRouterConstantObj(child.children);
|
|
107
|
-
console.log(child.name, index, children.length, "Path With layout After");
|
|
108
107
|
if (index == children.length - 1) {
|
|
109
|
-
path = path.split("/").slice(0, -1).join('
|
|
108
|
+
path = path.split("/").slice(0, -1).join('/').toString();
|
|
110
109
|
// const pathNumToBeRemoved = child.route.split("/").length;
|
|
111
110
|
// path = path.split("/").slice(0,-pathNumToBeRemoved).join('/').toString();
|
|
112
111
|
}
|
|
@@ -114,12 +113,10 @@ ${this.generateLayoutCode(loChild)}
|
|
|
114
113
|
else {
|
|
115
114
|
path = child.route && child.route != "" && child.route != "/" ? path + "/" + child.route : path;
|
|
116
115
|
acc[child.name] = path;
|
|
117
|
-
console.log(path, "Path Without layout");
|
|
118
116
|
const pathNumToBeRemoved = child.route.split("/").length;
|
|
119
|
-
|
|
120
|
-
path = path.split("/").slice(0, -pathNumToBeRemoved).join('_').toString();
|
|
117
|
+
path = path.split("/").slice(0, -pathNumToBeRemoved).join('/').toString();
|
|
121
118
|
if (index == children.length - 1) {
|
|
122
|
-
path = path.split("/").slice(0, -1).join('
|
|
119
|
+
path = path.split("/").slice(0, -1).join('/').toString();
|
|
123
120
|
// const pathNumToBeRemoved = child.route.split("/").length;
|
|
124
121
|
// path = path.split("/").slice(0,-pathNumToBeRemoved).join('/').toString();
|
|
125
122
|
}
|
|
@@ -172,10 +169,8 @@ export default ${lo.name}Layout;
|
|
|
172
169
|
import React from 'react';\n
|
|
173
170
|
import BlendGeneratedLayout from '../../src/layout/BlendGeneratedLayout';
|
|
174
171
|
`;
|
|
175
|
-
console.log([mainLayout], JSON.stringify([mainLayout]), "Main layout///////////////");
|
|
176
172
|
const routerJsonCode = `const router = createBrowserRouter([${this.generateLayoutRouterJSONCode([mainLayout])}])\nexport default router;`;
|
|
177
173
|
const routerConstant = this.generateRouterConstant([mainLayout]);
|
|
178
|
-
console.log(this.generateFlattenedArray(mainLayout.children), "this.generateFlattenedArray(mainLayout.children)");
|
|
179
174
|
const importCode = `${this.generateFlattenedArray(mainLayout.children).reduce((acc, item) => {
|
|
180
175
|
const importCode = ` ${item.children ? `
|
|
181
176
|
import ${item.name}Layout from '../../src/layout/${item.name}Layout';\n
|
|
@@ -97,7 +97,6 @@ class FileHelper {
|
|
|
97
97
|
yield fs_extra_1.default.ensureDir(path_1.default.dirname(destPath));
|
|
98
98
|
// Copy the file
|
|
99
99
|
yield fs_extra_1.default.copyFile(srcPath, destPath);
|
|
100
|
-
console.log(`File copied from ${srcPath} to ${destPath}`);
|
|
101
100
|
}
|
|
102
101
|
catch (error) {
|
|
103
102
|
console.error(`Error copying file from ${srcPath} to ${destPath}: ${error.message}`);
|
|
@@ -115,7 +114,6 @@ class FileHelper {
|
|
|
115
114
|
try {
|
|
116
115
|
// Copy the folder recursively
|
|
117
116
|
yield fs_extra_1.default.copy(srcFolder, destFolder, { overwrite: true });
|
|
118
|
-
console.log(`Folder copied from ${srcFolder} to ${destFolder}`);
|
|
119
117
|
}
|
|
120
118
|
catch (error) {
|
|
121
119
|
console.error(`Error copying folder from ${srcFolder} to ${destFolder}: ${error.message}`);
|
|
@@ -28,7 +28,7 @@ class BlendApiGrammarHelper {
|
|
|
28
28
|
const apiNameList = new Set();
|
|
29
29
|
const apiSection = {
|
|
30
30
|
name: item.CAPITAL_IDENTIFIER().text, apiList: item.apiDefinition().map(api => {
|
|
31
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
31
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
32
32
|
const apiName = api.IDENTIFIER().text;
|
|
33
33
|
if (apiNameList.has(apiName)) {
|
|
34
34
|
duplicateApis[apiName] = true;
|
|
@@ -47,24 +47,23 @@ class BlendApiGrammarHelper {
|
|
|
47
47
|
name: (_g = (_f = (_e = api.outputDefinition()) === null || _e === void 0 ? void 0 : _e.directOutputDefenition()) === null || _f === void 0 ? void 0 : _f.type().text) === null || _g === void 0 ? void 0 : _g.replace("?", ""),
|
|
48
48
|
} : {},
|
|
49
49
|
authenticated: ((_h = api === null || api === void 0 ? void 0 : api.authenticated()) === null || _h === void 0 ? void 0 : _h.text) == "authenticated",
|
|
50
|
-
url: api === null || api === void 0 ? void 0 : api.URL_IDENTIFIER().text.replace(/"/g, '')
|
|
50
|
+
url: api === null || api === void 0 ? void 0 : api.URL_IDENTIFIER().text.replace(/"/g, ''),
|
|
51
|
+
inputStore: !!((_j = api.inputDefinition()) === null || _j === void 0 ? void 0 : _j.store())
|
|
51
52
|
};
|
|
52
|
-
(
|
|
53
|
+
(_l = (_k = api.inputDefinition()) === null || _k === void 0 ? void 0 : _k.field()) === null || _l === void 0 ? void 0 : _l.forEach(field => {
|
|
53
54
|
var _a, _b, _c;
|
|
54
55
|
const fieldName = ((_a = field.IDENTIFIER()) === null || _a === void 0 ? void 0 : _a.text) || ((_b = field.CAPITAL_IDENTIFIER()) === null || _b === void 0 ? void 0 : _b.text);
|
|
55
56
|
apiSpec.input[fieldName] = { type: (_c = field.type().text) === null || _c === void 0 ? void 0 : _c.replace("?", ""), required: !(field === null || field === void 0 ? void 0 : field.type().text.includes("?")) };
|
|
56
57
|
});
|
|
57
|
-
|
|
58
|
-
const customData = (_m = (_l = api.outputDefinition()) === null || _l === void 0 ? void 0 : _l.directOutputDefenition()) === null || _m === void 0 ? void 0 : _m.type().text;
|
|
58
|
+
const customData = (_o = (_m = api.outputDefinition()) === null || _m === void 0 ? void 0 : _m.directOutputDefenition()) === null || _o === void 0 ? void 0 : _o.type().text;
|
|
59
59
|
if (customData && !dataModuleList.includes(customData === null || customData === void 0 ? void 0 : customData.split("->")[0])) {
|
|
60
60
|
console.error(`No Data Module '${customData.split("->")[0]}' Found in section '${item.CAPITAL_IDENTIFIER().text}' at line ${api.start.line}`);
|
|
61
61
|
haveNoDataFoundError = true;
|
|
62
62
|
}
|
|
63
|
-
(
|
|
63
|
+
(_q = (_p = api.outputDefinition()) === null || _p === void 0 ? void 0 : _p.field()) === null || _q === void 0 ? void 0 : _q.forEach(field => {
|
|
64
64
|
var _a, _b, _c;
|
|
65
65
|
if (field.type().text.includes("->")) {
|
|
66
66
|
const customDataSplit = field.type().text.split("->");
|
|
67
|
-
console.log(dataModuleList, "dataModuleList....");
|
|
68
67
|
if (!dataModuleList.includes(customDataSplit[0])) {
|
|
69
68
|
console.error(`No Data Module '${customDataSplit[0]}' Found in section '${item.CAPITAL_IDENTIFIER().text}' at line ${api.start.line}`);
|
|
70
69
|
haveNoDataFoundError = true;
|
|
@@ -78,7 +78,6 @@ class BlendBasicGrammarHelper extends AbstractParseTreeVisitor_1.AbstractParseTr
|
|
|
78
78
|
let screenList = [];
|
|
79
79
|
let componentList = [];
|
|
80
80
|
let roleList = [];
|
|
81
|
-
console.log("program", program.screenDefenition());
|
|
82
81
|
program.screenDefenition().forEach(screen => {
|
|
83
82
|
screen.CAPITAL_IDENTIFIER().forEach(screenName => {
|
|
84
83
|
screenList.push({ name: screenName.text, path: screen.PATH_IDENTIFIER().text.replace(/"/g, '') });
|
|
@@ -102,7 +101,7 @@ class BlendBasicGrammarHelper extends AbstractParseTreeVisitor_1.AbstractParseTr
|
|
|
102
101
|
var _a;
|
|
103
102
|
if (screenList.findIndex(item => item.name == page.CAPITAL_IDENTIFIER()[1].text) == -1) {
|
|
104
103
|
haveNoDataFoundError = true;
|
|
105
|
-
console.
|
|
104
|
+
console.error(`❌ Screen '${(_a = page.CAPITAL_IDENTIFIER()[1]) === null || _a === void 0 ? void 0 : _a.text}' not found inside layout '${layout.CAPITAL_IDENTIFIER().text}' at line ${page.start.line}`);
|
|
106
105
|
}
|
|
107
106
|
return {
|
|
108
107
|
name: page.CAPITAL_IDENTIFIER()[0].text,
|
|
@@ -124,7 +123,6 @@ class BlendBasicGrammarHelper extends AbstractParseTreeVisitor_1.AbstractParseTr
|
|
|
124
123
|
layout,
|
|
125
124
|
roleList
|
|
126
125
|
};
|
|
127
|
-
console.log("json", json);
|
|
128
126
|
return {
|
|
129
127
|
valid: parser.numberOfSyntaxErrors == 0 && !haveNoDataFoundError,
|
|
130
128
|
json
|
|
@@ -19,7 +19,7 @@ class BlendDataGrammarHelper {
|
|
|
19
19
|
const dataName = dataDefinition.CAPITAL_IDENTIFIER().text;
|
|
20
20
|
if (dataSet.has(dataName)) {
|
|
21
21
|
hasError = true;
|
|
22
|
-
console.
|
|
22
|
+
console.error(`❌ Duplicate Data '${dataName}' found`);
|
|
23
23
|
}
|
|
24
24
|
dataSet.add(dataDefinition.CAPITAL_IDENTIFIER().text);
|
|
25
25
|
const fieldSet = new Set();
|
|
@@ -29,7 +29,7 @@ class BlendDataGrammarHelper {
|
|
|
29
29
|
const fieldName = field.IDENTIFIER().text;
|
|
30
30
|
if (fieldSet.has(fieldName)) {
|
|
31
31
|
hasError = true;
|
|
32
|
-
console.
|
|
32
|
+
console.error(`❌ Duplicate field '${fieldName}' in '${dataName}'`);
|
|
33
33
|
}
|
|
34
34
|
fieldSet.add(fieldName);
|
|
35
35
|
return {
|
package/dist/index.js
CHANGED
|
@@ -47,41 +47,52 @@ program.command('init')
|
|
|
47
47
|
program.command('prepare')
|
|
48
48
|
.description('Prepare the environment (e.g., validating setup, etc.)')
|
|
49
49
|
.action(() => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
try {
|
|
51
|
+
const dataHelper = new DataHelper_1.default();
|
|
52
|
+
const apiHelper = new ApiHelper_1.default();
|
|
53
|
+
dataHelper.parseSpec();
|
|
54
|
+
apiHelper.parseSpec();
|
|
55
|
+
console.log(`✅ Prepare complete — apiConfig.json and dataConfig.json updated.`);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
console.error(`❌ Prepare failed: ${e.message}`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
58
61
|
});
|
|
59
62
|
// Command 3: blend-generate (add your logic here)
|
|
60
63
|
program.command('serve')
|
|
61
64
|
.description('Generate files or configurations based on existing ones')
|
|
62
65
|
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
try {
|
|
67
|
+
const frontEndHelper = new FrontEndHelper_1.default();
|
|
68
|
+
const apiHelper = new ApiHelper_1.default();
|
|
69
|
+
const dataHelper = new DataHelper_1.default();
|
|
70
|
+
frontEndHelper.buildFrontEnd();
|
|
71
|
+
dataHelper.parseJSONAndGenerateFiles();
|
|
72
|
+
apiHelper.doFrontEndApiGenerations();
|
|
73
|
+
console.log(`✅ Serve complete — frontend, data models, and Redux files generated.`);
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
console.error(`❌ Serve failed: ${e.message}`);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
75
79
|
}));
|
|
76
80
|
program.command('chop')
|
|
77
81
|
.description('Generate files or configurations based on existing ones')
|
|
78
82
|
.action(() => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
try {
|
|
84
|
+
const folderPath = path_1.default.join(process.cwd());
|
|
85
|
+
const folderName = path_1.default.basename(folderPath);
|
|
86
|
+
const basicFilePath = path_1.default.join(folderPath, `${folderName}.rbasic`);
|
|
87
|
+
const basicFileContent = fileHelper_1.FileHelper.readFile(basicFilePath);
|
|
88
|
+
const basicHelper = new BasicHelper_1.default();
|
|
89
|
+
basicHelper.parseSpec(basicFileContent);
|
|
90
|
+
basicHelper.createRequiredFile(basicFileContent);
|
|
91
|
+
console.log(`✅ Chop complete — spec files created from ${folderName}.rbasic.`);
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
console.error(`❌ Chop failed: ${e.message}`);
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
86
97
|
});
|
|
87
98
|
program.parse(process.argv);
|