-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5222 from abpframework/feat/5202
Introduced separate commands for adding, removing, and refreshing proxies
- Loading branch information
Showing
26 changed files
with
425 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
npm/ng-packs/packages/schematics/src/commands/api/schema.ts
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
npm/ng-packs/packages/schematics/src/commands/proxy-add/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}, | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
npm/ng-packs/packages/schematics/src/commands/proxy-refresh/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; | ||
} |
39 changes: 39 additions & 0 deletions
39
npm/ng-packs/packages/schematics/src/commands/proxy-refresh/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": [] | ||
} |
43 changes: 43 additions & 0 deletions
43
npm/ng-packs/packages/schematics/src/commands/proxy-remove/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; | ||
} |
39 changes: 39 additions & 0 deletions
39
npm/ng-packs/packages/schematics/src/commands/proxy-remove/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": [] | ||
} |
42 changes: 0 additions & 42 deletions
42
npm/ng-packs/packages/schematics/src/commands/proxy/index.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.