import * as ts from 'typescript' ; import { FileInfo } from '../types' ; import { isExpectedIdentifierVariableStatement , getVariableDeclarationFromVariableStatement , getMethodNamesFromVariableDeclaration } from './helpers' ; function getStringLiteralIdentifier ( fileInfo , identifier ) { if ( fileInfo . nameSpace === '' ) return identifier ; return `${ fileInfo . nameSpace }/${ identifier }` ; } const getPropertySignature = ( fileInfo , identifier , aliasTypeName ) => ts . createPropertySignature ( undefined , ts . createStringLiteral ( getStringLiteralIdentifier ( fileInfo , identifier ) ) , undefined , ts . createIndexedAccessTypeNode ( ts . createIndexedAccessTypeNode ( ts . createTypeReferenceNode ( ts . createIdentifier ( aliasTypeName ) , undefined ) , ts . createLiteralTypeNode ( ts . createStringLiteral ( fileInfo . nameSpace ) ) ) , ts . createLiteralTypeNode ( ts . createStringLiteral ( identifier ) ) ) , undefined ) ; const getPropertySignaturesFromSourceFile = ( sourceFile , fileInfo , aliasTypeName , variableDeclarationName ) => sourceFile . getChildAt ( 0 ) . getChildren ( ) . filter ( ts . isVariableStatement ) . filter ( isExpectedIdentifierVariableStatement ( variableDeclarationName ) ) . map ( getVariableDeclarationFromVariableStatement ) . map ( getMethodNamesFromVariableDeclaration ) . map ( identifiers => identifiers . map ( identifier => getPropertySignature ( fileInfo , identifier , aliasTypeName ) ) ) [ 0 ] ; export const createInterfaceForRoot = ( sourceFile , fileInfo , distTypeName , aliasTypeName , variableDeclarationName ) => ts . createInterfaceDeclaration ( undefined , undefined , ts . createIdentifier ( distTypeName ) , undefined , undefined , getPropertySignaturesFromSourceFile ( sourceFile , fileInfo , aliasTypeName , variableDeclarationName ) ) ;