mirror of https://github.com/abpframework/abp.git
10 changed files with 145 additions and 39 deletions
@ -0,0 +1,48 @@ |
|||
import { normalize, strings } from '@angular-devkit/core'; |
|||
import { applyTemplates, branchAndMerge, chain, move, SchematicContext, Tree, url } from '@angular-devkit/schematics'; |
|||
import app from '../../mocks/app.gitignore'; |
|||
import { applyWithOverwrite, buildDefaultPath, createApiDefinitionReader, resolveProject } from '../../utils'; |
|||
import * as cases from '../../utils/text'; |
|||
import type { Schema as GenerateProxySchema } from './schema'; |
|||
|
|||
export default function(params: GenerateProxySchema) { |
|||
const solution = params.solution; |
|||
const moduleName = strings.camelize(params.module || 'app'); |
|||
|
|||
return chain([ |
|||
async (tree: Tree, _context: SchematicContext) => { |
|||
const target = await resolveProject(tree, params.target!); |
|||
const targetPath = buildDefaultPath(target.definition); |
|||
const readApiDefinition = createApiDefinitionReader(`${targetPath}/shared/api-definition.json`); |
|||
const data = readApiDefinition(tree); |
|||
data.modules.app = app; |
|||
|
|||
const controllers = Object.values(data.modules[moduleName]?.controllers || {}); |
|||
|
|||
const createServiceFiles = chain( |
|||
controllers.map(controller => { |
|||
const {controllerName: name, type, actions, interfaces} = controller; |
|||
const namespaceRegex = new RegExp('^' + solution + '\.(Controllers\.)?'); |
|||
const namespace = type.replace(namespaceRegex, '').split('.').slice(0, -1).join('.'); |
|||
|
|||
return applyWithOverwrite(url('./files-service'), [ |
|||
applyTemplates({ |
|||
...cases, |
|||
solution, |
|||
namespace, |
|||
name, |
|||
apiName: data.modules[moduleName].remoteServiceName, |
|||
apiUrl: controller.actions[0]?.url, |
|||
actions, |
|||
interfaces, |
|||
}), |
|||
move(normalize(targetPath)), |
|||
]); |
|||
} |
|||
), |
|||
); |
|||
|
|||
return branchAndMerge(chain([createServiceFiles])); |
|||
}, |
|||
]); |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
{ |
|||
"$schema": "http://json-schema.org/schema", |
|||
"id": "SchematicsAbpGenerateAPI", |
|||
"title": "ABP Generate API Schema", |
|||
"type": "object", |
|||
"properties": { |
|||
"solution": { |
|||
"alias": "x", |
|||
"description": "Solution name", |
|||
"type": "string", |
|||
"$default": { |
|||
"$source": "argv", |
|||
"index": 0 |
|||
}, |
|||
"x-prompt": "Please enter the solution name. (case-sensitive, eg. Acme.BookStore)" |
|||
}, |
|||
"target": { |
|||
"alias": "t", |
|||
"description": "Angular project to generate code in", |
|||
"type": "string", |
|||
"$default": { |
|||
"$source": "argv", |
|||
"index": 1 |
|||
}, |
|||
"x-prompt": "Plese enter Angular project name to place generated code in. (default: workspace \"defaultProject\")" |
|||
}, |
|||
"module": { |
|||
"alias": "m", |
|||
"description": "Backend module to generate code for", |
|||
"type": "string", |
|||
"$default": { |
|||
"$source": "argv", |
|||
"index": 2 |
|||
}, |
|||
"x-prompt": "Please enter name of the backend module you wish to generate proxies for. (default: \"app\")" |
|||
} |
|||
}, |
|||
"required": ["solution"] |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
export interface Schema { |
|||
/** |
|||
* Solution name |
|||
*/ |
|||
solution: string; |
|||
|
|||
/** |
|||
* Angular project to generate code in |
|||
*/ |
|||
target?: string; |
|||
|
|||
/** |
|||
* Backend module to generate code for |
|||
*/ |
|||
module?: string; |
|||
} |
|||
Loading…
Reference in new issue