diff --git a/npm/ng-packs/packages/schematics/src/utils/model.ts b/npm/ng-packs/packages/schematics/src/utils/model.ts index 79efea320c..f76133552b 100644 --- a/npm/ng-packs/packages/schematics/src/utils/model.ts +++ b/npm/ng-packs/packages/schematics/src/utils/model.ts @@ -4,7 +4,7 @@ import { parseNamespace } from './namespace'; import { createTypeSimplifier } from './type'; export function createImportRefsToModelMapper(solution: string, types: Record) { - const simplifyType = createTypeSimplifier(solution); + const mapImportRefToInterface = createImportRefToInterfaceMapper(solution, types); return (importRefs: string[]) => { const model = new Model({ @@ -12,28 +12,36 @@ export function createImportRefsToModelMapper(solution: string, types: Record { - const typeDef = types[ref]; - let identifier = simplifyType(ref); - (typeDef.genericArguments ?? []).forEach((t, i) => { - identifier = identifier.replace(`T${i}`, t); - }); + model.interfaces.push(mapImportRefToInterface(ref)); + }); + + model.interfaces.sort((a, b) => (a.identifier > b.identifier ? 1 : -1)); + + return model; + }; +} - const base = typeDef.baseType ? simplifyType(typeDef.baseType) : null; - const _interface = new Interface({ identifier, base }); +export function createImportRefToInterfaceMapper(solution: string, types: Record) { + const simplifyType = createTypeSimplifier(solution); - typeDef.properties?.forEach(({ name, typeSimple }) => { - name = strings.camelize(name); - const type = simplifyType(typeSimple); - const optional = typeSimple.endsWith('?') ? '?' : ''; + return (ref: string) => { + const typeDef = types[ref]; + let identifier = simplifyType(ref); + (typeDef.genericArguments ?? []).forEach((t, i) => { + identifier = identifier.replace(`T${i}`, t); + }); - _interface.properties.push(new Property({ name, type, optional })); - }); + const base = typeDef.baseType ? simplifyType(typeDef.baseType) : null; + const _interface = new Interface({ identifier, base }); - console.log(_interface); + typeDef.properties?.forEach(({ name, typeSimple }) => { + name = strings.camelize(name); + const optional = typeSimple.endsWith('?') ? '?' : ''; + const type = simplifyType(typeSimple); - model.interfaces.push(_interface); + _interface.properties.push(new Property({ name, optional, type })); }); - return model; + return _interface; }; }