/
angular.ts
34 lines (28 loc) · 1.15 KB
/
angular.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { APIDefination } from './types/api-defination';
import { ServiceTemplates } from './templates/angular/service-templates';
import changeCase from 'change-case';
import fse from 'fs-extra';
export async function angular(data: APIDefination.Response, selectedModules: string[]) {
selectedModules.forEach(async module => {
const element = data.modules[module];
(Object.keys(element.controllers) || []).forEach(key => {
const controller = element.controllers[key];
const actions = element.controllers[key].actions;
const actionKeys = Object.keys(actions);
let contents = [] as string[];
actionKeys.forEach(key => {
const element = actions[key];
console.log(element);
switch (element.httpMethod) {
case 'GET':
contents.push(ServiceTemplates.getMethodTemplate(element.name, element.url));
break;
default:
break;
}
});
const service = ServiceTemplates.classTemplate(controller.controllerName, contents.join('\n'));
fse.writeFileSync(`dist/${changeCase.kebabCase(controller.controllerName)}.service.ts`, service);
});
});
}