import fs from "fs" ; import { internalEnums , VERSION } from "../src/protos/index" ; import { FILES } from "./path" ; export async function compileEnums ( ) { const stream = fs . createWriteStream ( FILES . enums ) ; stream . write ( `/* Autogenerated File! Do Not Edit */\n` ) ; stream . write ( "\n// eslint-disable-next-line\n" ) ; stream . write ( "export namespace enums {\n" ) ; for ( const [ fullName , def ] of Object . entries ( internalEnums ) ) { const [ name ] = fullName . split ( "Enum" ) ; const values = ( def as any ) [ name ] ; const pairs = Object . keys ( values ) . map ( ( key ) => { const protoVal = values [ key ] ; return `${ key } = ${ protoVal }, // ${ key }` ; } ) ; const enumStr = `export enum ${ name } {
      ${ pairs . join ( "\n" ) }
    }` ; const docsLink = buildEnumLink ( VERSION , fullName , name ) ; stream . write ( `\n/**
    * @name ${ fullName }.${ name }
    * @link ${ docsLink }
    */` ) ; stream . write ( `\n${ enumStr }\n` ) ; } stream . write ( "}\n" ) ; stream . end ( ) ; return Promise . resolve ( ) ; } function buildEnumLink ( version , fullName , shortName ) { return `https://developers.google.com/google-ads/api/reference/rpc/${ version }/${ fullName }.${ shortName } ` ; }