Browse Source

feat: add a warning about generated proxies in markdown

pull/5222/head
Arman Ozak 6 years ago
parent
commit
47b1aa13fb
  1. 5
      npm/ng-packs/packages/schematics/src/commands/proxy-add/index.ts
  2. 16
      npm/ng-packs/packages/schematics/src/constants/proxy.ts
  3. 25
      npm/ng-packs/packages/schematics/src/utils/source.ts

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

@ -9,6 +9,7 @@ import {
createProxyClearer,
createProxyConfigReader,
createProxyConfigSaver,
createProxyWarningSaver,
removeDefaultPlaceholders,
resolveProject,
} from '../../utils';
@ -40,9 +41,11 @@ export default function(schema: GenerateProxySchema) {
const saveProxyConfig = createProxyConfigSaver(data, targetPath);
const saveProxyWarning = createProxyWarningSaver(targetPath);
const generateApis = createApisGenerator(schema, generated);
return chainAndMerge([clearProxy, saveProxyConfig, generateApis])(host);
return chainAndMerge([clearProxy, saveProxyConfig, saveProxyWarning, generateApis])(host);
},
]);
}

16
npm/ng-packs/packages/schematics/src/constants/proxy.ts

@ -1,2 +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.
`;

25
npm/ng-packs/packages/schematics/src/utils/source.ts

@ -1,7 +1,13 @@
import { strings } from '@angular-devkit/core';
import { SchematicsException, Tree } from '@angular-devkit/schematics';
import got from 'got';
import { API_DEFINITION_ENDPOINT, PROXY_CONFIG_PATH, PROXY_PATH } from '../constants';
import {
API_DEFINITION_ENDPOINT,
PROXY_CONFIG_PATH,
PROXY_PATH,
PROXY_WARNING,
PROXY_WARNING_PATH,
} from '../constants';
import { Exception } from '../enums';
import { ApiDefinition, GenerateProxySchema, Project, ProxyConfig, WriteOp } from '../models';
import { getAssignedPropertyFromObjectliteral } from './ast';
@ -116,6 +122,19 @@ export function createProxyClearer(targetPath: string) {
};
}
export function createProxyWarningSaver(targetPath: string) {
targetPath += PROXY_WARNING_PATH;
const createFileWriter = createFileWriterCreator(targetPath);
return (tree: Tree) => {
const op = tree.exists(targetPath) ? 'overwrite' : 'create';
const writeWarningMD = createFileWriter(op, PROXY_WARNING);
writeWarningMD(tree);
return tree;
};
}
export function createProxyConfigSaver(apiDefinition: ApiDefinition, targetPath: string) {
const createProxyConfigJson = createProxyConfigJsonCreator(apiDefinition);
const readPreviousConfig = createProxyConfigReader(targetPath);
@ -145,6 +164,10 @@ export function createProxyConfigSaver(apiDefinition: ApiDefinition, targetPath:
export function createProxyConfigWriterCreator(targetPath: string) {
targetPath += PROXY_CONFIG_PATH;
return createFileWriterCreator(targetPath);
}
export function createFileWriterCreator(targetPath: string) {
return (op: WriteOp, data: string) => (tree: Tree) => {
try {
tree[op](targetPath, data);

Loading…
Cancel
Save