diff --git a/frontend-frame/src/router.ts b/frontend-frame/src/router.ts index 7fc9967..3bd2e5f 100644 --- a/frontend-frame/src/router.ts +++ b/frontend-frame/src/router.ts @@ -8,56 +8,5 @@ export default new Router({ base: process.env.BASE_URL, routes: [ // SYSTE-BUILDER-routes - - { - path: '/about', - name: 'about', - // route level code-splitting - // this generates a separate chunk (about.[hash].js) for this route - // which is lazy-loaded when the route is visited. - component: () => import(/* webpackChunkName: "about" */ './views/About.vue') - }, - { - path: '/organizations', - name: 'organizations', - - component: () => import(/* webpackChunkName: "organizations" */ './views/Organizations.vue') - }, - { - path: '/organization/:orgId/:tab', - name: 'Organization', - - component: () => import(/* webpackChunkName: "organizations" */ './views/Organization.vue') - }, - { - path: '/users/:appId', - name: 'Users', - - component: () => import(/* webpackChunkName: "organizations" */ './views/Users.vue') - }, - { - path: '/access/:appId', - name: 'Access', - - component: () => import(/* webpackChunkName: "organizations" */ './views/Access.vue') - }, - { - path: '/bandit/:appId', - name: 'Bandit', - - component: () => import(/* webpackChunkName: "organizations" */ './views/Bandit.vue') - }, - { - path: '/switches/:appId', - name: 'Switches', - - component: () => import(/* webpackChunkName: "organizations" */ './views/Switches.vue') - }, - { - path: '/createOrg', - name: 'organization creation', - - component: () => import(/* webpackChunkName: "organizations" */ './views/CreateOrganization.vue') - }, ] }); diff --git a/src/frontend-services/app-view-builder.ts b/src/frontend-services/app-view-builder.ts new file mode 100644 index 0000000..aa5af17 --- /dev/null +++ b/src/frontend-services/app-view-builder.ts @@ -0,0 +1,29 @@ +import {ComponentDef, EndpointDef, SystemDef} from "../systemGenService"; +import path from "path"; +import fs from "fs"; + +export function buildAppLinks(component: ComponentDef, outDir: string, systemDef: SystemDef): Promise { + let listEndpoints: EndpointDef[] = component.endpoints.filter((epd: EndpointDef) => { + return epd.type === 'list'; + }); + if (listEndpoints.length) { + return new Promise((resolve) => { + const separator: string = ``; + let fileLocation = path.join(process.cwd(), `frontend-${systemDef.name}`, 'src', 'App.vue'); + let initServiceFile: string = fs.readFileSync(fileLocation, 'utf8'); + let parts = initServiceFile.split(separator); + parts[0] = parts[0] + createLinksMarkup(component, systemDef); + let newServiceFile = parts.join(separator); + fs.writeFileSync(fileLocation, newServiceFile, 'utf8'); + resolve(); + }); + } + return Promise.resolve(); +} + +function createLinksMarkup(component: ComponentDef, systemDef: SystemDef): string { + let out = `${component.component} List + `; + + return out; +} \ No newline at end of file diff --git a/src/frontend-services/fe-service-creator.ts b/src/frontend-services/fe-service-creator.ts index 4712f90..f858b17 100644 --- a/src/frontend-services/fe-service-creator.ts +++ b/src/frontend-services/fe-service-creator.ts @@ -1,6 +1,12 @@ import {ComponentDef, EndpointDef, SystemDef} from "../systemGenService"; import path from "path"; -import {initializeComponentFile, removeTemplateFiles, removeTemplateFolder, uppercaseFirstLetter} from "../helpers"; +import { + componentDestination, + initializeComponentFile, + removeTemplateFiles, + removeTemplateFolder, + uppercaseFirstLetter +} from "../helpers"; import fs from "fs"; import {buildServiceFunctionName, getFuncParams} from "../views/service-creator"; import {METHOD, URL} from "../views/routes-creator"; @@ -8,16 +14,23 @@ import {buildDetailsView} from "./details-view-builder"; import {buildListView} from "./list-view-builder"; import {buildEditorView} from "./editor-view-builder"; import {buildTypesView} from "./types-view-builder"; +import {buildRoute} from "./route-view-builder"; +import {buildAppLinks} from "./app-view-builder"; const ncp = require('ncp').ncp; export function createFrontend(systemDef: SystemDef): Promise { let fePromises = []; for (let i in systemDef.components) { fePromises.push(createComponent(systemDef.components[i], systemDef).then(() => { + // build app router logic + return buildRoute(systemDef.components[i], componentDestination(systemDef.name, systemDef.components[i].component), systemDef); + }).then(() => { + // add a vue view and add it to App.vue + return buildAppLinks(systemDef.components[i], componentDestination(systemDef.name, systemDef.components[i].component), systemDef); + }).then(() => { return removeTemplateFiles(componentDestination(systemDef.name, systemDef.components[i].component)); })); - // TODO: add a vue view and add it to App.vue - // TODO: build app router logic + } // TODO: after all is done clean up the template files return Promise.all(fePromises).then((res: void[]) => { @@ -31,9 +44,7 @@ function componentSource() { return path.join(process.cwd(), 'frontend-frame', 'src', 'components', '{{component}}'); } -function componentDestination(systemDefName: string, componentName: string) { - return path.join(process.cwd(), `frontend-${systemDefName}`, 'src', 'components', componentName); -} + function createComponent(component: ComponentDef, systemDef: SystemDef) { return new Promise((componentResolve, componentReject) => { diff --git a/src/frontend-services/route-view-builder.ts b/src/frontend-services/route-view-builder.ts new file mode 100644 index 0000000..2a04ffb --- /dev/null +++ b/src/frontend-services/route-view-builder.ts @@ -0,0 +1,33 @@ +import {ComponentDef, EndpointDef, SystemDef} from "../systemGenService"; +import path from "path"; +import fs from "fs"; + +export function buildRoute(component: ComponentDef, outDir: string, systemDef: SystemDef): Promise { + let listEndpoints: EndpointDef[] = component.endpoints.filter((epd: EndpointDef) => { + return epd.type === 'list'; + }); + if (listEndpoints.length) { + return new Promise((resolve) => { + const separator: string = `// SYSTE-BUILDER-routes`; + let fileLocation = path.join(process.cwd(), `frontend-${systemDef.name}`, 'src', 'router.ts'); + let initServiceFile: string = fs.readFileSync(fileLocation, 'utf8'); + let parts = initServiceFile.split(separator); + parts[0] = parts[0] + createRouteCode(component, systemDef); + let newServiceFile = parts.join(separator); + fs.writeFileSync(fileLocation, newServiceFile, 'utf8'); + resolve(); + }); + } + return Promise.resolve(); +} + +function createRouteCode(component: ComponentDef, systemDef: SystemDef): string { + let out = `{ + path: '/${component.component}', + name: '${component.component}', + component: () => import(/* webpackChunkName: "${component.component}" */ './components/${component.component}/${component.component}List.vue') + }, + `; + + return out; +} \ No newline at end of file diff --git a/src/helpers.ts b/src/helpers.ts index 8bc7d11..48f6cc7 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -190,7 +190,12 @@ function createDetailsTypeValues(view: EndpointDef, systemDef: SystemDef) { return out; } +function componentDestination(systemDefName: string, componentName: string) { + return path.join(process.cwd(), `frontend-${systemDefName}`, 'src', 'components', componentName); +} + export { + componentDestination, createDetailsInitValues, createDetailsTypeValues, findColumn,