Browse Source

Filter controller by service-type

pull/14968/head
Mahmut Gundogdu 4 years ago
parent
commit
1885d865d4
  1. 2
      npm/ng-packs/package.json
  2. 18
      npm/ng-packs/packages/schematics/src/commands/api/index.ts
  3. 28
      npm/ng-packs/packages/schematics/src/commands/proxy-add/schema.json
  4. 1
      npm/ng-packs/packages/schematics/src/enums/index.ts
  5. 7
      npm/ng-packs/packages/schematics/src/enums/service-types.ts
  6. 2
      npm/ng-packs/packages/schematics/src/models/api-definition.ts
  7. 3
      npm/ng-packs/packages/schematics/src/models/generate-proxy-schema.ts

2
npm/ng-packs/package.json

@ -36,7 +36,7 @@
"lerna": "lerna",
"migrate-nx": "yarn nx migrate --run-migrations",
"mock:schematics": "cd scripts/mock-schematic && yarn && yarn start",
"debug:schematics": "./node_modules/.bin/ng g ./packages/schematics/src/collection.json:proxy-add --module __default --apiName __default --source __default --target __default --url http://localhost:4300"
"debug:schematics": "./node_modules/.bin/ng g ./packages/schematics/src/collection.json:proxy-add --module __default --apiName __default --source __default --target __default --url https://localhost:44305 --serviceType application"
},
"private": true,
"devDependencies": {

18
npm/ng-packs/packages/schematics/src/commands/api/index.ts

@ -8,8 +8,8 @@ import {
Tree,
url,
} from '@angular-devkit/schematics';
import { Exception } from '../../enums';
import { GenerateProxySchema, ServiceGeneratorParams } from '../../models';
import { defaultEServiceType, eServiceType, Exception } from '../../enums';
import { Controller, GenerateProxySchema, ServiceGeneratorParams } from '../../models';
import {
applyWithOverwrite,
buildTargetPath,
@ -47,6 +47,7 @@ export default function (schema: GenerateProxySchema) {
const data = readProxyConfig(tree);
const types = data.types;
const modules = data.modules;
const serviceType = schema.serviceType || defaultEServiceType;
if (!types || !modules) throw new SchematicsException(Exception.InvalidApiDefinition);
const definition = data.modules[moduleName];
@ -54,7 +55,7 @@ export default function (schema: GenerateProxySchema) {
throw new SchematicsException(interpolate(Exception.InvalidModule, moduleName));
const apiName = definition.remoteServiceName;
const controllers = Object.values(definition.controllers || {});
const controllers = filterControllersByServiceType(serviceType, definition.controllers);
const serviceImports: Record<string, string[]> = {};
const generateServices = createServiceGenerator({
targetPath,
@ -170,3 +171,14 @@ function createServiceGenerator(params: ServiceGeneratorParams) {
}),
);
}
function filterControllersByServiceType(
serviceType: eServiceType,
controllers: Record<string, Controller>,
): Controller[] {
const itShouldBeIntegratedService = serviceType === eServiceType.Integration;
const skipFilter = serviceType === eServiceType.All;
return Object.values(controllers || {}).filter(
x => x.isIntegrationService === itShouldBeIntegratedService || skipFilter,
);
}

28
npm/ng-packs/packages/schematics/src/commands/proxy-add/schema.json

@ -48,6 +48,34 @@
"index": 4
},
"x-prompt": "Please enter URL for API definition (default: API Name's url in environment file)"
},
"serviceType": {
"description": "Service type to the generated code",
"type": "string",
"$default": "application",
"enum": [
"application",
"integration",
"all"
],
"x-prompt": {
"message": "Specifies the service type to generate. `application`, `integration` and `all`, Default value: `application`",
"type": "list",
"items": [
{
"value": "all",
"label": "All"
},
{
"value": "application",
"label": "Application"
},
{
"value": "integration",
"label": "Integration"
}
]
}
}
},
"entryPoint": {

1
npm/ng-packs/packages/schematics/src/enums/index.ts

@ -2,3 +2,4 @@ export * from './binding-source-id';
export * from './exception';
export * from './import-keyword';
export * from './method-modifier';
export * from './service-types';

7
npm/ng-packs/packages/schematics/src/enums/service-types.ts

@ -0,0 +1,7 @@
export enum eServiceType {
All = 'all',
Application = 'application',
Integration = 'integration',
}
export const defaultEServiceType = eServiceType.Application;

2
npm/ng-packs/packages/schematics/src/models/api-definition.ts

@ -31,6 +31,8 @@ export interface Module {
export interface Controller {
controllerName: string;
type: string;
isRemoteService: boolean;
isIntegrationService: boolean;
interfaces: InterfaceDef[];
actions: Record<string, Action>;
}

3
npm/ng-packs/packages/schematics/src/models/generate-proxy-schema.ts

@ -1,3 +1,5 @@
import { eServiceType } from '../enums';
export interface GenerateProxySchema {
/**
* Backend module name
@ -28,4 +30,5 @@ export interface GenerateProxySchema {
* Secondary entrypoint for proxy generation
*/
entryPoint?: string;
serviceType?: eServiceType;
}

Loading…
Cancel
Save