refactor and add some new endpoint defs
This commit is contained in:
@ -1,9 +1,14 @@
|
||||
import {
|
||||
BelongsToDef,
|
||||
ColumnDef,
|
||||
Filter, JoinDef, Order,
|
||||
SystemDef, TableDef,
|
||||
EndpointDef, ComponentDef, ColumnRef
|
||||
ColumnRef,
|
||||
ComponentDef,
|
||||
EndpointDef,
|
||||
Filter,
|
||||
JoinDef,
|
||||
Order,
|
||||
SystemDef,
|
||||
TableDef
|
||||
} from '../systemGenService';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
@ -21,7 +26,7 @@ export function createViews(systemDef: SystemDef) {
|
||||
}
|
||||
|
||||
function createComponent(component: ComponentDef, systemDef: SystemDef) {
|
||||
let componentPromise = new Promise<void>((componentResolve, componentReject) => {
|
||||
return new Promise<void>((componentResolve, componentReject) => {
|
||||
ncp(path.join(process.cwd(), 'frame', 'src', 'components', '{{component}}'), path.join(process.cwd(), systemDef.name, 'src', 'components', component.component), (err: any) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
@ -44,11 +49,10 @@ function createComponent(component: ComponentDef, systemDef: SystemDef) {
|
||||
}
|
||||
});
|
||||
});
|
||||
return componentPromise;
|
||||
}
|
||||
|
||||
function initializeComponentFile(sourceFile: string, destinationFile: string, component: string, outDir: string) {
|
||||
let filePromise = new Promise<void>((resolve, reject) => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
fs.rename(sourceFile, destinationFile, (err: any) => {
|
||||
let fileContents = fs.readFileSync(destinationFile, 'utf8');
|
||||
var uppercaseFirstLetterComponentName = uppercaseFirstLetter(component);
|
||||
@ -58,8 +62,7 @@ function initializeComponentFile(sourceFile: string, destinationFile: string, co
|
||||
fs.writeFileSync(destinationFile, newFileContents, 'utf8');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
return filePromise
|
||||
})
|
||||
}
|
||||
|
||||
function addInitializeServiceCode(component: string, outDir: string) {
|
||||
@ -91,7 +94,7 @@ function addInitializeRoutesCode(component: string, outDir: string) {
|
||||
}
|
||||
|
||||
function insertMapperCode(view: EndpointDef, outDir: string): Promise<void> {
|
||||
const filePromise: Promise<void> = new Promise<void>((resolve) => {
|
||||
return new Promise<void>((resolve) => {
|
||||
const separator: string = `// SYSTEM-BUILDER-${view.component}-mapper`;
|
||||
let fileLocation = path.join(process.cwd(), outDir, 'src', 'components', view.component, `${view.component}Mapper.ts`);
|
||||
let initMapperFile: string = fs.readFileSync(fileLocation, 'utf8');
|
||||
@ -102,7 +105,6 @@ function insertMapperCode(view: EndpointDef, outDir: string): Promise<void> {
|
||||
fs.writeFileSync(fileLocation, newMapperFile, 'utf8');
|
||||
resolve();
|
||||
});
|
||||
return filePromise;
|
||||
}
|
||||
|
||||
function createMapperFunc(view: EndpointDef): string {
|
||||
@ -116,6 +118,8 @@ function createMapperFunc(view: EndpointDef): string {
|
||||
funcName = `update${uppercaseFirstLetter(view.component)}`;
|
||||
} else if (view.type.indexOf('create') !== -1) {
|
||||
func = buildCreateFunc(view);
|
||||
} else if (view.type.indexOf('delete') !== -1) {
|
||||
funcName = `delete${uppercaseFirstLetter(view.component)}`;
|
||||
}
|
||||
return func;
|
||||
}
|
||||
|
Reference in New Issue
Block a user