import { readdirSync , writeFileSync } from 'fs' ; import { join } from 'path' ; import { PromptObject } from 'prompts' ; import { cliPrint , IntegrationInfo , promptQuestions , runAndHandleErrors } from '../src' ; const createCliOption = ( name ) => ( { title : name , value : name , } ) ; const questions = [ { type : 'select' , name : 'integration' , message : 'Choose integration' , choices : readdirSync ( join ( __dirname , '../integrations' ) , { withFileTypes : true } ) . filter ( ( integration ) => integration . isDirectory ( ) ) . map ( ( integration ) => integration . name ) . map ( createCliOption ) , } , { type : 'select' , name : 'airnodeType' , message : 'Choose Airnode type' , choices : [ createCliOption ( 'local' ) , createCliOption ( 'aws' ) , createCliOption ( 'gcp' ) ] , } , { type : ( _prev , values ) => { return values . airnodeType === 'gcp' ? 'text' : null ; } , name : 'gcpProjectId' , message : 'Enter a GCP project ID' , } , { type : 'select' , name : 'network' , message : 'Select target blockchain network' , choices : ( prev ) => { const options = [ createCliOption ( 'rinkeby' ) ] ; if ( prev === 'local' ) options . push ( createCliOption ( 'localhost' ) ) ; return options ; } , } , { type : 'text' , name : 'mnemonic' , message : [ 'Since you chose testnet network, we need an account with testnet funds to connect to the blockchain.' , '' , 'IMPORTANT: DO NOT ENTER A MNEMONIC LINKED WITH MAINNET ACCOUNTS!!!' , '' , 'Enter the testnet mnemonic phrase' , ] . join ( '\n' ) , initial : ( _prev , values ) => values . network === 'localhost' ? 'test test test test test test test test test test test junk' : '' , } , { type : 'text' , name : 'providerUrl' , message : 'Enter a provider URL' , initial : ( _prev , values ) => { if ( values . network === 'localhost' ) return 'http://127.0.0.1:8545/' ; if ( values . network === 'rinkeby' ) return 'https://eth-rinkeby.gateway.pokt.network/v1/lb/<APP_ID>' ; return '' ; } , } , ] ; /**
 * Ask the user for the integration choice and return them as an object.
 */ const chooseIntegration = async ( ) : Promise < IntegrationInfo > => { const response = await promptQuestions ( questions ) ; return response as IntegrationInfo ; } ; const main = async ( ) => { const integration = await chooseIntegration ( ) ; writeFileSync ( join ( __dirname , '../integration-info.json' ) , JSON . stringify ( integration , null , 2 ) ) ; cliPrint . info ( `A file 'integration-info.json' was created!` ) ; } ; runAndHandleErrors ( main ) ;