import * as ts from 'typescript' ; import { FileInfo , Constants } from '../types' ; import { isExpectedIdentifierVariableStatement , getVariableDeclarationFromVariableStatement , getMethodNamesFromVariableDeclaration } from './helpers' ; const getPropertySignature = ( fileInfo , utilityTypeName , variableDeclarationName , identifier , constants ) => ts . createPropertySignature ( undefined , ts . createIdentifier ( identifier ) , undefined , ts . createTypeReferenceNode ( ts . createIdentifier ( utilityTypeName ) , [ ts . createIndexedAccessTypeNode ( ts . createIndexedAccessTypeNode ( ts . createIndexedAccessTypeNode ( ts . createTypeReferenceNode ( ts . createIdentifier ( constants . MODULES ) , undefined ) , ts . createLiteralTypeNode ( ts . createStringLiteral ( fileInfo . nameSpace ) ) ) , ts . createLiteralTypeNode ( ts . createStringLiteral ( variableDeclarationName ) ) ) , ts . createLiteralTypeNode ( ts . createStringLiteral ( identifier ) ) ) ] ) , undefined ) ; const getPropertySignaturesFromSourceFile = ( sourceFile , fileInfo , utilityTypeName , variableDeclarationName , constants ) => sourceFile . getChildAt ( 0 ) . getChildren ( ) . filter ( ts . isVariableStatement ) . filter ( isExpectedIdentifierVariableStatement ( variableDeclarationName ) ) . map ( getVariableDeclarationFromVariableStatement ) . map ( getMethodNamesFromVariableDeclaration ) . map ( identifiers => identifiers . map ( identifier => getPropertySignature ( fileInfo , utilityTypeName , variableDeclarationName , identifier , constants ) ) ) [ 0 ] ; export const createInterfaceForLocal = ( sourceFile , fileInfo , distTypeName , utilityTypeName , variableDeclarationName , constants ) => ts . createInterfaceDeclaration ( undefined , undefined , ts . createIdentifier ( distTypeName ) , undefined , undefined , [ ts . createPropertySignature ( undefined , ts . createStringLiteral ( fileInfo . nameSpace ) , undefined , ts . createTypeLiteralNode ( getPropertySignaturesFromSourceFile ( sourceFile , fileInfo , utilityTypeName , variableDeclarationName , constants ) ) , undefined ) ] ) ;