Merge pull request #14968 from abpframework/issue/14540

Filter controller by service-type  on ABP Schematics
pull/14992/head
Mahmut Gundogdu 3 years ago committed by GitHub
commit 9466214014
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -76,11 +76,9 @@ public class AngularServiceProxyGenerator : ServiceProxyGeneratorBase<AngularSer
commandBuilder.Append($" --url {url}");
}
var serviceType = GetServiceType(args);
if (args.ServiceType != null)
{
commandBuilder.Append($" --service-type {serviceType.ToString().ToLower()}");
}
var serviceType = GetServiceType(args) ?? Volo.Abp.Cli.ServiceProxying.ServiceType.Application;
commandBuilder.Append($" --service-type {serviceType.ToString().ToLower()}");
_cmdhelper.RunCmd(commandBuilder.ToString());
}

@ -37,7 +37,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": {

@ -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,
);
}

@ -45,10 +45,42 @@
"type": "string",
"$default": {
"$source": "argv",
"index": 5
"index": 4
},
"x-prompt": "Please enter target Angular project to place the generated code. (default: workspace \"defaultProject\")"
},
"serviceType": {
"description": "Service type to the generated code",
"type": "string",
"$default": {
"$source": "argv",
"index": 5
},
"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"
}
]
}
}
},
"required": []
}

@ -48,6 +48,37 @@
"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": {
"$source": "argv",
"index": 5
},
"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": {

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

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

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

@ -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;
}

@ -17,6 +17,7 @@ const packageMap = {
'tenant-management': 'ng.tenant-management',
'theme-basic': 'ng.theme.basic',
'theme-shared': 'ng.theme.shared',
'schematics':'ng.schematics'
};
program.option('-t, --templates <templates>', 'template dirs', false);
program.option('-p, --template-path <templatePath>', 'root template path', false);

Loading…
Cancel
Save