working frontend build
This commit is contained in:
@ -1,18 +1,27 @@
|
||||
import {ComponentDef, EndpointDef, SystemDef} from "../systemGenService";
|
||||
import path from "path";
|
||||
import {initializeComponentFile} from "../helpers";
|
||||
import {initializeComponentFile, removeTemplateFiles} from "../helpers";
|
||||
import fs from "fs";
|
||||
import {buildServiceFunctionName, getFuncParams} from "../views/service-creator";
|
||||
import {METHOD, URL} from "../views/routes-creator";
|
||||
import {buildDetailsView} from "./details-view-builder";
|
||||
import {buildListView} from "./list-view-builder";
|
||||
import {buildEditorView} from "./editor-view-builder";
|
||||
import {buildTypesView} from "./types-view-builder";
|
||||
const ncp = require('ncp').ncp;
|
||||
|
||||
export function createFrontend(systemDef: SystemDef) {
|
||||
export function createFrontend(systemDef: SystemDef): Promise<void[]> {
|
||||
let fePromises = [];
|
||||
for (let i in systemDef.components) {
|
||||
fePromises.push(createComponent(systemDef.components[i], systemDef));
|
||||
// TODO: add a vue view and add it to App.vue
|
||||
// TODO: build app router logic
|
||||
}
|
||||
return Promise.all(fePromises);
|
||||
// TODO: after all is done clean up the template files
|
||||
return Promise.all(fePromises).then((res: void[]) => {
|
||||
removeTemplateFiles(componentSource())
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
function componentSource() {
|
||||
@ -38,12 +47,57 @@ function createComponent(component: ComponentDef, systemDef: SystemDef) {
|
||||
return insertFEServiceCode(component.endpoints[i], componentDest);
|
||||
});
|
||||
// TODO: use templates for Details, Editor, List and Types view based on the endpoints provided
|
||||
// servicePromise = servicePromise.then(() => {
|
||||
//
|
||||
// return initializeComponentFile(path.join(componentDest, '{{component}}Service.ets'), path.join(componentDest, `${component.component}Service.ts`), component.component, systemDef.name);
|
||||
// });
|
||||
}
|
||||
if (componentContains('list', component)) {
|
||||
servicePromise = servicePromise.then(() => {
|
||||
return initializeComponentFile(path.join(componentDest, '{{component}}List.vue'), path.join(componentDest, `${component.component}List.vue`), component.component, systemDef.name);
|
||||
}).then(() => {
|
||||
// TODO: build list contents based on the list endpoint
|
||||
return buildListView(component, componentDest, systemDef);
|
||||
});
|
||||
}
|
||||
if (componentContains('item', component)) {
|
||||
servicePromise = servicePromise.then(() => {
|
||||
return initializeComponentFile(path.join(componentDest, '{{component}}Details.vue'), path.join(componentDest, `${component.component}Details.vue`), component.component, systemDef.name);
|
||||
}).then(() => {
|
||||
// build list contents based on the item endpoint
|
||||
return buildDetailsView(component, componentDest, systemDef);
|
||||
});
|
||||
}
|
||||
if (componentContains('update', component) || componentContains('create', component)) {
|
||||
servicePromise = servicePromise.then(() => {
|
||||
return initializeComponentFile(path.join(componentDest, '{{component}}Editor.vue'), path.join(componentDest, `${component.component}Editor.vue`), component.component, systemDef.name);
|
||||
}).then(() => {
|
||||
// build list contents based on the item endpoint
|
||||
return buildEditorView(component, componentDest, systemDef);
|
||||
});
|
||||
}
|
||||
if (component.endpoints.length) {
|
||||
// add a types file to power the whole component
|
||||
servicePromise = servicePromise.then(() => {
|
||||
return initializeComponentFile(path.join(componentDest, '{{component}}Types.ets'), path.join(componentDest, `${component.component}Types.ts`), component.component, systemDef.name);
|
||||
}).then(() => {
|
||||
return buildTypesView(component, componentDest, systemDef);
|
||||
});
|
||||
}
|
||||
servicePromise.then(() => {
|
||||
componentResolve();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function componentContains(type: string, component: ComponentDef) {
|
||||
return component.endpoints.some((epd: EndpointDef) => {
|
||||
return epd.type === type;
|
||||
});
|
||||
}
|
||||
|
||||
function insertFEServiceCode(view: EndpointDef, outDir: string) {
|
||||
return new Promise<void>((resolve) => {
|
||||
const separator: string = `// SYSTEM-BUILDER-service-functions`;
|
||||
|
Reference in New Issue
Block a user