Browse Source

add: volo pacakges proxy import map and resolve volo packages

pull/20035/head
masumulu28 2 years ago
parent
commit
1d42039bfb
  1. 3
      npm/ng-packs/packages/schematics/src/commands/api/index.ts
  2. 26
      npm/ng-packs/packages/schematics/src/constants/volo.ts
  3. 48
      npm/ng-packs/packages/schematics/src/utils/model.ts

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

@ -29,6 +29,7 @@ import {
sanitizeTypeNames,
sanitizeControllerTypeNames,
serializeParameters,
resolveAbpPackages,
} from '../../utils';
import * as cases from '../../utils/text';
@ -157,6 +158,8 @@ function createModelGenerator(params: ModelGeneratorParams) {
),
);
resolveAbpPackages(models);
return chain(
models.map(model =>
applyWithOverwrite(url('./files-model'), [

26
npm/ng-packs/packages/schematics/src/constants/volo.ts

@ -3,3 +3,29 @@ export const VOLO_REMOTE_STREAM_CONTENT = [
'Volo.Abp.Content.IRemoteStreamContent',
'Volo.Abp.Content.RemoteStreamContent',
];
export const VOLO_PACKAGE_PROXY_IMPORTS = new Map<string, string>([
['Volo.Abp.Identity.IdentityUserDto', '@volo/abp.ng.identity/proxy'],
['Volo.Abp.Identity.IdentityRoleDto', '@volo/abp.ng.identity/proxy'],
['Volo.Abp.FileManagement.FileDescriptorDto', '@volo/abp.ng.file-management/proxy'],
['Volo.Abp.FileManagement.DirectoryContentDto', '@volo/abp.ng.file-management/proxy'],
['Volo.Abp.AuditLogging.AuditLogDto', '@volo/abp.ng.audit-logging/proxy'],
['Volo.Abp.AuditLogging.AuditLogActionDto', '@volo/abp.ng.audit-logging/proxy'],
['Volo.Abp.AuditLogging.EntityChangeDto', '@volo/abp.ng.audit-logging/proxy'],
['Volo.Abp.AuditLogging.EntityPropertyChangeDto', '@volo/abp.ng.audit-logging/proxy'],
['Volo.Chat.Messages', '@volo/abp.ng.chat/proxy'],
['Volo.Chat.ChatMessageDto', '@volo/abp.ng.chat/proxy'],
['Volo.Chat.ChatConversationDto', '@volo/abp.ng.chat/proxy'],
['Volo.Abp.Gdpr.GdprRequestDto', '@volo/abp.ng.gdpr/proxy'],
['Volo.Saas.Tenants.TenantDto', '@volo/abp.ng.saas/proxy'],
['Volo.Saas.TenantConnectionStringsDto', '@volo/abp.ng.saas/proxy'],
['Volo.Saas.EditionDto', '@volo/abp.ng.saas/proxy'],
[
'Volo.Abp.TextTemplateManagement.TextTemplates.TextTemplateContentDto',
'@volo/abp.ng.saas/proxy',
],
[
'Volo.Abp.TextTemplateManagement.TextTemplates.TemplateDefinitionDto',
'@volo/abp.ng.saas/proxy',
],
]);

48
npm/ng-packs/packages/schematics/src/utils/model.ts

@ -1,5 +1,4 @@
import { VOLO_REGEX } from '../constants';
import { Interface, Model, Property, PropertyDef, Type, TypeWithEnum } from '../models';
import { Import, Interface, Model, Property, PropertyDef, Type, TypeWithEnum } from '../models';
import {
extractGenerics,
generateRefWithPlaceholders,
@ -17,6 +16,8 @@ import {
extendsSelf,
removeTypeModifiers,
} from './type';
import { VOLO_PACKAGE_PROXY_IMPORTS, VOLO_REGEX } from '../constants';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const shouldQuote = require('should-quote');
@ -201,3 +202,46 @@ export function parseBaseTypeWithGenericTypes(type: string): string[] {
return nodeToText(parsedTypeNode);
}
const tenantKey = 'tenant';
const saasNamespace = 'Volo.Saas';
export function resolveAbpPackages(models: Model[]) {
for (const model of models) {
renamePropForTenant(model.interfaces);
model.imports.forEach((imp, i) => {
fixImportName(imp);
for (const ref of imp.refs) {
const path = VOLO_PACKAGE_PROXY_IMPORTS.get(ref);
if (path) {
model.imports[i] = new Import({ ...imp, path });
}
}
});
}
}
function renamePropForTenant(interfaces: Interface[]) {
for (const inters of interfaces) {
for (const prop of inters.properties) {
const isTenant = prop.name.toLocaleLowerCase().includes(tenantKey);
const isSaasDto = prop.refs.filter(f => f.startsWith(saasNamespace)).length > 0;
if (isTenant && isSaasDto) {
prop.type = 'Saas' + prop.type;
}
}
}
}
function fixImportName(imp: Import) {
imp.specifiers.forEach((spe, index) => {
const isTenant = spe.toLocaleLowerCase().includes(tenantKey);
if (isTenant) {
imp.specifiers[index] = 'Saas' + spe;
}
});
}

Loading…
Cancel
Save