diff --git a/npm/ng-packs/packages/schematics/src/utils/namespace.ts b/npm/ng-packs/packages/schematics/src/utils/namespace.ts index bbee41aa6f..003198adcb 100644 --- a/npm/ng-packs/packages/schematics/src/utils/namespace.ts +++ b/npm/ng-packs/packages/schematics/src/utils/namespace.ts @@ -1,5 +1,8 @@ +import { createTypeParser } from './type'; + export function parseNamespace(solution: string, type: string) { - let namespace = type + const parseType = createTypeParser(); + let namespace = parseType(type) .split('.') .slice(0, -1) .join('.'); diff --git a/npm/ng-packs/packages/schematics/src/utils/type.ts b/npm/ng-packs/packages/schematics/src/utils/type.ts index b365e0e4ad..5a56e2e445 100644 --- a/npm/ng-packs/packages/schematics/src/utils/type.ts +++ b/npm/ng-packs/packages/schematics/src/utils/type.ts @@ -7,28 +7,37 @@ import { relativePathToModel } from './path'; import { parseGenerics } from './tree'; export function createTypeSimplifier(solution: string) { - const optionalRegex = /\?/g; const solutionRegex = new RegExp(solution.replace(/\./g, `\.`) + `\.`); const voloRegex = /^Volo\.(Abp\.?)(Application\.?)/; + return createTypeParser( + type => + type + .replace(voloRegex, '') + .replace(solutionRegex, '') + .split('.') + .pop()!, + ); +} + +export function createTypeParser(replacerFn = (t: string) => t) { + const optionalRegex = /\?/g; + return (originalType: string) => { - const union = originalType + const unionType = originalType .replace(/^{/, '') .replace(/}$/, '') .split(':'); - return union + + return unionType .map(type => { type = type.startsWith('[') ? type.slice(1, -1) + '[]' : type; - type = type.replace(voloRegex, ''); - type = type.replace(solutionRegex, ''); type = type.replace(optionalRegex, ''); type = type.replace( /System\.([0-9A-Za-z]+)/g, (_, match) => SYSTEM_TYPES.get(match) ?? strings.camelize(match), ); - type = type.split('.').pop()!; - console.log(type); - return type; + return replacerFn(type); }) .join(' | '); };