mirror of https://github.com/abpframework/abp.git
Browse Source
Introduced separate commands for adding, removing, and refreshing proxiespull/5240/head
committed by
GitHub
26 changed files with 425 additions and 108 deletions
@ -1,16 +0,0 @@ |
|||
export interface Schema { |
|||
/** |
|||
* Backend module to generate code for |
|||
*/ |
|||
module?: string; |
|||
|
|||
/** |
|||
* Angular project to resolve root namespace & API definition URL from |
|||
*/ |
|||
source?: string; |
|||
|
|||
/** |
|||
* Angular project to generate code in |
|||
*/ |
|||
target?: string; |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
import { strings } from '@angular-devkit/core'; |
|||
import { chain, SchematicContext, Tree } from '@angular-devkit/schematics'; |
|||
import { GenerateProxySchema } from '../../models'; |
|||
import { |
|||
buildDefaultPath, |
|||
chainAndMerge, |
|||
createApiDefinitionGetter, |
|||
createApisGenerator, |
|||
createProxyClearer, |
|||
createProxyConfigReader, |
|||
createProxyConfigSaver, |
|||
createProxyWarningSaver, |
|||
removeDefaultPlaceholders, |
|||
resolveProject, |
|||
} from '../../utils'; |
|||
|
|||
export default function(schema: GenerateProxySchema) { |
|||
const params = removeDefaultPlaceholders(schema); |
|||
const moduleName = strings.camelize(params.module || 'app'); |
|||
|
|||
return chain([ |
|||
async (host: Tree, _context: SchematicContext) => { |
|||
const target = await resolveProject(host, params.target!); |
|||
const targetPath = buildDefaultPath(target.definition); |
|||
const readProxyConfig = createProxyConfigReader(targetPath); |
|||
let generated: string[] = []; |
|||
|
|||
try { |
|||
generated = readProxyConfig(host).generated; |
|||
const index = generated.findIndex(m => m === moduleName); |
|||
if (index < 0) generated.push(moduleName); |
|||
} catch (_) { |
|||
generated.push(moduleName); |
|||
} |
|||
|
|||
const getApiDefinition = createApiDefinitionGetter(params); |
|||
const data = { generated, ...(await getApiDefinition(host)) }; |
|||
data.generated = []; |
|||
|
|||
const clearProxy = createProxyClearer(targetPath); |
|||
|
|||
const saveProxyConfig = createProxyConfigSaver(data, targetPath); |
|||
|
|||
const saveProxyWarning = createProxyWarningSaver(targetPath); |
|||
|
|||
const generateApis = createApisGenerator(schema, generated); |
|||
|
|||
return chainAndMerge([clearProxy, saveProxyConfig, saveProxyWarning, generateApis])(host); |
|||
}, |
|||
]); |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
import { SchematicContext, Tree } from '@angular-devkit/schematics'; |
|||
import { GenerateProxySchema } from '../../models'; |
|||
import { |
|||
buildDefaultPath, |
|||
chainAndMerge, |
|||
createApiDefinitionGetter, |
|||
createApisGenerator, |
|||
createProxyClearer, |
|||
createProxyConfigReader, |
|||
createProxyConfigSaver, |
|||
removeDefaultPlaceholders, |
|||
resolveProject, |
|||
} from '../../utils'; |
|||
|
|||
export default function(schema: GenerateProxySchema) { |
|||
const params = removeDefaultPlaceholders(schema); |
|||
|
|||
return async (host: Tree, _context: SchematicContext) => { |
|||
const target = await resolveProject(host, params.target!); |
|||
const targetPath = buildDefaultPath(target.definition); |
|||
|
|||
const readProxyConfig = createProxyConfigReader(targetPath); |
|||
const { generated } = readProxyConfig(host); |
|||
|
|||
const getApiDefinition = createApiDefinitionGetter(params); |
|||
const data = { generated, ...(await getApiDefinition(host)) }; |
|||
data.generated = []; |
|||
|
|||
const clearProxy = createProxyClearer(targetPath); |
|||
|
|||
const saveProxyConfig = createProxyConfigSaver(data, targetPath); |
|||
|
|||
const generateApis = createApisGenerator(schema, generated); |
|||
|
|||
return chainAndMerge([clearProxy, saveProxyConfig, generateApis])(host); |
|||
}; |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
{ |
|||
"$schema": "http://json-schema.org/schema", |
|||
"id": "SchematicsAbpGenerateProxy", |
|||
"title": "ABP Generate Proxy Schema", |
|||
"type": "object", |
|||
"properties": { |
|||
"module": { |
|||
"alias": "m", |
|||
"description": "Backend module name", |
|||
"type": "string", |
|||
"$default": { |
|||
"$source": "argv", |
|||
"index": 0 |
|||
}, |
|||
"x-prompt": "Please enter backend module name. (default: \"app\")" |
|||
}, |
|||
"source": { |
|||
"alias": "s", |
|||
"description": "Source Angular project for API definition URL & root namespace resolution", |
|||
"type": "string", |
|||
"$default": { |
|||
"$source": "argv", |
|||
"index": 1 |
|||
}, |
|||
"x-prompt": "Plese enter source Angular project for API definition URL & root namespace resolution. (default: workspace \"defaultProject\")" |
|||
}, |
|||
"target": { |
|||
"alias": "t", |
|||
"description": "Target Angular project to place the generated code", |
|||
"type": "string", |
|||
"$default": { |
|||
"$source": "argv", |
|||
"index": 2 |
|||
}, |
|||
"x-prompt": "Plese enter target Angular project to place the generated code. (default: workspace \"defaultProject\")" |
|||
} |
|||
}, |
|||
"required": [] |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
import { strings } from '@angular-devkit/core'; |
|||
import { SchematicContext, Tree } from '@angular-devkit/schematics'; |
|||
import { GenerateProxySchema } from '../../models'; |
|||
import { |
|||
buildDefaultPath, |
|||
chainAndMerge, |
|||
createApiDefinitionGetter, |
|||
createApisGenerator, |
|||
createProxyClearer, |
|||
createProxyConfigReader, |
|||
createProxyConfigSaver, |
|||
removeDefaultPlaceholders, |
|||
resolveProject, |
|||
} from '../../utils'; |
|||
|
|||
export default function(schema: GenerateProxySchema) { |
|||
const params = removeDefaultPlaceholders(schema); |
|||
const moduleName = strings.camelize(params.module || 'app'); |
|||
|
|||
return async (host: Tree, _context: SchematicContext) => { |
|||
const target = await resolveProject(host, params.target!); |
|||
const targetPath = buildDefaultPath(target.definition); |
|||
|
|||
const readProxyConfig = createProxyConfigReader(targetPath); |
|||
const { generated } = readProxyConfig(host); |
|||
|
|||
const index = generated.findIndex(m => m === moduleName); |
|||
if (index < 0) return host; |
|||
generated.splice(index, 1); |
|||
|
|||
const getApiDefinition = createApiDefinitionGetter(params); |
|||
const data = { generated, ...(await getApiDefinition(host)) }; |
|||
data.generated = []; |
|||
|
|||
const clearProxy = createProxyClearer(targetPath); |
|||
|
|||
const saveProxyConfig = createProxyConfigSaver(data, targetPath); |
|||
|
|||
const generateApis = createApisGenerator(schema, generated); |
|||
|
|||
return chainAndMerge([clearProxy, saveProxyConfig, generateApis])(host); |
|||
}; |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
{ |
|||
"$schema": "http://json-schema.org/schema", |
|||
"id": "SchematicsAbpGenerateProxy", |
|||
"title": "ABP Generate Proxy Schema", |
|||
"type": "object", |
|||
"properties": { |
|||
"module": { |
|||
"alias": "m", |
|||
"description": "Backend module name", |
|||
"type": "string", |
|||
"$default": { |
|||
"$source": "argv", |
|||
"index": 0 |
|||
}, |
|||
"x-prompt": "Please enter backend module name. (default: \"app\")" |
|||
}, |
|||
"source": { |
|||
"alias": "s", |
|||
"description": "Source Angular project for API definition URL & root namespace resolution", |
|||
"type": "string", |
|||
"$default": { |
|||
"$source": "argv", |
|||
"index": 1 |
|||
}, |
|||
"x-prompt": "Plese enter source Angular project for API definition URL & root namespace resolution. (default: workspace \"defaultProject\")" |
|||
}, |
|||
"target": { |
|||
"alias": "t", |
|||
"description": "Target Angular project to place the generated code", |
|||
"type": "string", |
|||
"$default": { |
|||
"$source": "argv", |
|||
"index": 2 |
|||
}, |
|||
"x-prompt": "Plese enter target Angular project to place the generated code. (default: workspace \"defaultProject\")" |
|||
} |
|||
}, |
|||
"required": [] |
|||
} |
|||
@ -1,42 +0,0 @@ |
|||
import { strings } from '@angular-devkit/core'; |
|||
import { |
|||
branchAndMerge, |
|||
chain, |
|||
schematic, |
|||
SchematicContext, |
|||
Tree, |
|||
} from '@angular-devkit/schematics'; |
|||
import { API_DEFINITION_ENDPOINT } from '../../constants'; |
|||
import { ApiDefinition } from '../../models'; |
|||
import { |
|||
buildDefaultPath, |
|||
createApiDefinitionSaver, |
|||
getApiDefinition, |
|||
getSourceUrl, |
|||
removeDefaultPlaceholders, |
|||
resolveProject, |
|||
} from '../../utils'; |
|||
import { Schema as GenerateProxySchema } from './schema'; |
|||
|
|||
export default function(schema: GenerateProxySchema) { |
|||
const params = removeDefaultPlaceholders(schema); |
|||
const moduleName = strings.camelize(params.module || 'app'); |
|||
|
|||
return chain([ |
|||
async (tree: Tree, _context: SchematicContext) => { |
|||
const source = await resolveProject(tree, params.source!); |
|||
const target = await resolveProject(tree, params.target!); |
|||
const sourceUrl = getSourceUrl(tree, source, moduleName); |
|||
const targetPath = buildDefaultPath(target.definition); |
|||
const data: ApiDefinition = await getApiDefinition(sourceUrl + API_DEFINITION_ENDPOINT); |
|||
|
|||
const saveApiDefinition = createApiDefinitionSaver( |
|||
data, |
|||
`${targetPath}/shared/api-definition.json`, |
|||
); |
|||
const createApi = schematic('api', schema); |
|||
|
|||
return branchAndMerge(chain([saveApiDefinition, createApi])); |
|||
}, |
|||
]); |
|||
} |
|||
@ -1,16 +0,0 @@ |
|||
export interface Schema { |
|||
/** |
|||
* Backend module to generate code for |
|||
*/ |
|||
module?: string; |
|||
|
|||
/** |
|||
* Angular project to resolve root namespace & API definition URL from |
|||
*/ |
|||
source?: string; |
|||
|
|||
/** |
|||
* Angular project to generate code in |
|||
*/ |
|||
target?: string; |
|||
} |
|||
@ -1,3 +1,4 @@ |
|||
export * from './api'; |
|||
export * from './proxy'; |
|||
export * from './system-types'; |
|||
export * from './volo'; |
|||
|
|||
@ -0,0 +1,18 @@ |
|||
export const PROXY_PATH = '/proxy'; |
|||
export const PROXY_CONFIG_PATH = `${PROXY_PATH}/generate-proxy.json`; |
|||
export const PROXY_WARNING_PATH = `${PROXY_PATH}/README.md`; |
|||
|
|||
export const PROXY_WARNING = `# Proxy Generation Output
|
|||
|
|||
This directory includes the output of the latest proxy generation. |
|||
The \`services\`, \`models\`, and \`enums\` folders will be overwritten when proxy generation is run again.
|
|||
Therefore, please do not place your own content in those folders. |
|||
|
|||
In addition, \`generate-proxy.json\` works like a lock file.
|
|||
It includes information used by the proxy generator, so please do not delete or modify it. |
|||
|
|||
Finally, the name of this folder should not be changed for two reasons: |
|||
- Proxy generator will keep creating this folder and you will have multiple copies of the same content. |
|||
- ABP Suite generates imports from this folder and uses the path \`/proxy\` when doing so.
|
|||
|
|||
`;
|
|||
@ -0,0 +1,16 @@ |
|||
export interface GenerateProxySchema { |
|||
/** |
|||
* Backend module name |
|||
*/ |
|||
module?: string; |
|||
|
|||
/** |
|||
* Source Angular project for API definition URL & root namespace resolution |
|||
*/ |
|||
source?: string; |
|||
|
|||
/** |
|||
* Target Angular project to place the generated code |
|||
*/ |
|||
target?: string; |
|||
} |
|||
@ -1,7 +1,10 @@ |
|||
export * from './api-definition'; |
|||
export * from './generate-proxy-schema'; |
|||
export * from './import'; |
|||
export * from './method'; |
|||
export * from './model'; |
|||
export * from './project'; |
|||
export * from './proxy-config'; |
|||
export * from './service'; |
|||
export * from './tree'; |
|||
export * from './util'; |
|||
|
|||
@ -0,0 +1,5 @@ |
|||
import { ApiDefinition } from './api-definition'; |
|||
|
|||
export interface ProxyConfig extends ApiDefinition { |
|||
generated: string[]; |
|||
} |
|||
@ -0,0 +1 @@ |
|||
export type WriteOp = 'create' | 'overwrite'; |
|||
@ -0,0 +1,11 @@ |
|||
import { chain, schematic } from '@angular-devkit/schematics'; |
|||
import { GenerateProxySchema } from '../models'; |
|||
|
|||
export function createApisGenerator(schema: GenerateProxySchema, generated: string[]) { |
|||
return chain( |
|||
generated.map(m => { |
|||
const apiSchema = { ...schema, source: schema.target, module: m }; |
|||
return schematic('api', apiSchema); |
|||
}), |
|||
); |
|||
} |
|||
Loading…
Reference in new issue