From c766dc72d9038a3082bbfe9b0a5a7ad276038707 Mon Sep 17 00:00:00 2001 From: fainashalts Date: Tue, 30 Mar 2021 09:55:28 -0700 Subject: [PATCH] Add support for custom config in db-kit --- packages/db-kit/src/cli/App.tsx | 12 ++++++++---- packages/db-kit/src/cli/hooks/useConfig.ts | 8 ++++++-- packages/db-kit/src/cli/index.ts | 9 +++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/db-kit/src/cli/App.tsx b/packages/db-kit/src/cli/App.tsx index ae998221027..169068ae5df 100644 --- a/packages/db-kit/src/cli/App.tsx +++ b/packages/db-kit/src/cli/App.tsx @@ -12,17 +12,19 @@ import { Menu } from "./menu"; export interface Props { network?: Pick, "name">; + configPath?: string; } export const App = ({ network = { name: "development" - } + }, + configPath }: Props) => { const { exit } = useApp(); const [shouldQuit, setShouldQuit] = useState(false); - const config = useConfig({ network }); + const config = useConfig({ network, configPath }); const { db, project, error } = useDb({ config }); useEffect(() => { @@ -54,8 +56,10 @@ export const App = ({ {" Reading truffle-config and connecting to network..."} )} - {error && - error instanceof DbNotEnabledError && // specific error case + { + error && error instanceof DbNotEnabledError && ( + + ) // specific error case } {error && !(error instanceof DbNotEnabledError) && ( // unknown error case diff --git a/packages/db-kit/src/cli/hooks/useConfig.ts b/packages/db-kit/src/cli/hooks/useConfig.ts index 9ea806e2153..4c6840a703d 100644 --- a/packages/db-kit/src/cli/hooks/useConfig.ts +++ b/packages/db-kit/src/cli/hooks/useConfig.ts @@ -6,14 +6,18 @@ import type { Resources } from "@truffle/db"; export interface UseConfigOptions { network: Pick, "name">; + configPath?: string; } -export function useConfig({ network: { name } }) { +export function useConfig({ network: { name }, configPath }) { const [config, setConfig] = useState(undefined); useEffect(() => { setImmediate(() => { - const config = TruffleConfig.detect({ network: name }); + const config = TruffleConfig.detect({ + network: name, + config: configPath + }); Environment.detect(config).then(() => setConfig(config)); }); diff --git a/packages/db-kit/src/cli/index.ts b/packages/db-kit/src/cli/index.ts index 6d4eb329119..65458698261 100644 --- a/packages/db-kit/src/cli/index.ts +++ b/packages/db-kit/src/cli/index.ts @@ -11,24 +11,29 @@ const cli = meow( Options --network Name of network to connect to + --config Path to configuration file `, { flags: { network: { type: "string" + }, + config: { + type: "string" } } } ); export async function start() { - const { network: name } = cli.flags; + const { network: name, config: configPath } = cli.flags; const { waitUntilExit } = render( React.createElement(App, { network: { name - } + }, + configPath }) );