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,
url,
} from '@angular-devkit/schematics';
import { PROXY_CONFIG_PATH } from '../../constants';
import { Exception } from '../../enums';
import { ServiceGeneratorParams } from '../../models';
import {
applyWithOverwrite,
buildDefaultPath,
createApiDefinitionReader,
createControllerToServiceMapper,
createImportRefsToModelReducer,
createImportRefToEnumMapper,
createProxyConfigReader,
EnumGeneratorParams,
getEnumNamesFromImports,
getRootNamespace,
@ -40,9 +41,9 @@ export default function(schema: GenerateProxySchema) {
const target = await resolveProject(tree, params.target!);
const solution = getRootNamespace(tree, source, moduleName);
const targetPath = buildDefaultPath(target.definition);
const definitionPath = `${targetPath}/shared/api-definition.json`;
const readApiDefinition = createApiDefinitionReader(definitionPath);
const data = readApiDefinition(tree);
const definitionPath = targetPath + PROXY_CONFIG_PATH;
const readProxyConfig = createProxyConfigReader(definitionPath);
const data = readProxyConfig(tree);
const types = data.types;
const modules = data.modules;
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,
Tree,
} from '@angular-devkit/schematics';
import { API_DEFINITION_ENDPOINT } from '../../constants';
import { API_DEFINITION_ENDPOINT, PROXY_CONFIG_PATH } from '../../constants';
import { ApiDefinition } from '../../models';
import {
buildDefaultPath,
createApiDefinitionSaver,
createProxyConfigSaver,
getApiDefinition,
getSourceUrl,
removeDefaultPlaceholders,
@ -30,13 +30,10 @@ export default function(schema: GenerateProxySchema) {
const targetPath = buildDefaultPath(target.definition);
const data: ApiDefinition = await getApiDefinition(sourceUrl + API_DEFINITION_ENDPOINT);
const saveApiDefinition = createApiDefinitionSaver(
data,
`${targetPath}/shared/api-definition.json`,
);
const saveProxyConfig = createProxyConfigSaver(data, targetPath + PROXY_CONFIG_PATH);
const createApi = schematic('api', schema);
return branchAndMerge(chain([saveApiDefinition, createApi]));
return branchAndMerge(chain([saveProxyConfig, createApi]));
},
]);
}

Loading…
Cancel
Save