XYOracleNetwork/clients

View on GitHub
packages/cli/src/terminal/commands/handlers/showConfig.ts

Summary

Maintainability
A
3 hrs
Test Coverage
import type { ModuleConfig } from '@xyo-network/module-model'

import {
  printLine, printTitle, readFileDeep,
} from '../../../lib/index.js'

export const showConfig = async () => {
  const [config, path] = readFileDeep(['xyo-config.json', 'xyo-config.js'])
  let configObj: ModuleConfig | undefined
  printTitle(`Config found at: ${path}`)
  if (config) {
    if (path?.endsWith('.json')) {
      configObj = JSON.parse(config) as ModuleConfig
    } else if (path?.endsWith('.cjs') || path?.endsWith('.js')) {
      configObj = (await import(path)) as ModuleConfig
    }
  }
  printLine(JSON.stringify(configObj ?? {}))
}