mirror of https://github.com/abpframework/abp.git
12 changed files with 273 additions and 94 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,48 @@ |
|||||
|
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, |
||||
|
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 generateApis = createApisGenerator(schema, generated); |
||||
|
|
||||
|
return chainAndMerge([clearProxy, saveProxyConfig, 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,39 +0,0 @@ |
|||||
import { strings } from '@angular-devkit/core'; |
|
||||
import { |
|
||||
branchAndMerge, |
|
||||
chain, |
|
||||
schematic, |
|
||||
SchematicContext, |
|
||||
Tree, |
|
||||
} from '@angular-devkit/schematics'; |
|
||||
import { API_DEFINITION_ENDPOINT, PROXY_CONFIG_PATH } from '../../constants'; |
|
||||
import { ApiDefinition } from '../../models'; |
|
||||
import { |
|
||||
buildDefaultPath, |
|
||||
createProxyConfigSaver, |
|
||||
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 saveProxyConfig = createProxyConfigSaver(data, targetPath + PROXY_CONFIG_PATH); |
|
||||
const createApi = schematic('api', schema); |
|
||||
|
|
||||
return branchAndMerge(chain([saveProxyConfig, 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; |
|
||||
} |
|
||||
Loading…
Reference in new issue