Browse Source

feat: use proxy config reader and saver in commands

pull/5222/head
Arman Ozak 6 years ago
parent
commit
a4d9df215c
  1. 9
      npm/ng-packs/packages/schematics/src/commands/api/index.ts
  2. 11
      npm/ng-packs/packages/schematics/src/commands/proxy/index.ts

9
npm/ng-packs/packages/schematics/src/commands/api/index.ts

@ -9,15 +9,16 @@ import {
Tree, Tree,
url, url,
} from '@angular-devkit/schematics'; } from '@angular-devkit/schematics';
import { PROXY_CONFIG_PATH } from '../../constants';
import { Exception } from '../../enums'; import { Exception } from '../../enums';
import { ServiceGeneratorParams } from '../../models'; import { ServiceGeneratorParams } from '../../models';
import { import {
applyWithOverwrite, applyWithOverwrite,
buildDefaultPath, buildDefaultPath,
createApiDefinitionReader,
createControllerToServiceMapper, createControllerToServiceMapper,
createImportRefsToModelReducer, createImportRefsToModelReducer,
createImportRefToEnumMapper, createImportRefToEnumMapper,
createProxyConfigReader,
EnumGeneratorParams, EnumGeneratorParams,
getEnumNamesFromImports, getEnumNamesFromImports,
getRootNamespace, getRootNamespace,
@ -40,9 +41,9 @@ export default function(schema: GenerateProxySchema) {
const target = await resolveProject(tree, params.target!); const target = await resolveProject(tree, params.target!);
const solution = getRootNamespace(tree, source, moduleName); const solution = getRootNamespace(tree, source, moduleName);
const targetPath = buildDefaultPath(target.definition); const targetPath = buildDefaultPath(target.definition);
const definitionPath = `${targetPath}/shared/api-definition.json`; const definitionPath = targetPath + PROXY_CONFIG_PATH;
const readApiDefinition = createApiDefinitionReader(definitionPath); const readProxyConfig = createProxyConfigReader(definitionPath);
const data = readApiDefinition(tree); const data = readProxyConfig(tree);
const types = data.types; const types = data.types;
const modules = data.modules; const modules = data.modules;
if (!types || !modules) throw new SchematicsException(Exception.InvalidApiDefinition); if (!types || !modules) throw new SchematicsException(Exception.InvalidApiDefinition);

11
npm/ng-packs/packages/schematics/src/commands/proxy/index.ts

@ -6,11 +6,11 @@ import {
SchematicContext, SchematicContext,
Tree, Tree,
} from '@angular-devkit/schematics'; } from '@angular-devkit/schematics';
import { API_DEFINITION_ENDPOINT } from '../../constants'; import { API_DEFINITION_ENDPOINT, PROXY_CONFIG_PATH } from '../../constants';
import { ApiDefinition } from '../../models'; import { ApiDefinition } from '../../models';
import { import {
buildDefaultPath, buildDefaultPath,
createApiDefinitionSaver, createProxyConfigSaver,
getApiDefinition, getApiDefinition,
getSourceUrl, getSourceUrl,
removeDefaultPlaceholders, removeDefaultPlaceholders,
@ -30,13 +30,10 @@ export default function(schema: GenerateProxySchema) {
const targetPath = buildDefaultPath(target.definition); const targetPath = buildDefaultPath(target.definition);
const data: ApiDefinition = await getApiDefinition(sourceUrl + API_DEFINITION_ENDPOINT); const data: ApiDefinition = await getApiDefinition(sourceUrl + API_DEFINITION_ENDPOINT);
const saveApiDefinition = createApiDefinitionSaver( const saveProxyConfig = createProxyConfigSaver(data, targetPath + PROXY_CONFIG_PATH);
data,
`${targetPath}/shared/api-definition.json`,
);
const createApi = schematic('api', schema); const createApi = schematic('api', schema);
return branchAndMerge(chain([saveApiDefinition, createApi])); return branchAndMerge(chain([saveProxyConfig, createApi]));
}, },
]); ]);
} }

Loading…
Cancel
Save