From 80588c7759180b5bc9ddbec08b92b043b44dea9b Mon Sep 17 00:00:00 2001 From: Carl Brugger Date: Wed, 24 Apr 2024 14:24:29 -0500 Subject: [PATCH 1/3] feat: auto-answer prompt --- packages/cli/README.md | 1 + packages/cli/src/index.ts | 8 +++- packages/cli/src/x/actions/develop.action.ts | 40 ++++++++++---------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/packages/cli/README.md b/packages/cli/README.md index a048574f..1663701d 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -45,6 +45,7 @@ Options: -k, --token the authentication token to use (or set env FLATFILE_API_KEY or FLATFILE_BEARER_TOKEN) -h, --api-url (optional) the API URL to use (or set env FLATFILE_API_URL) -e, --env (optional) the Environment to use (or set env FLATFILE_ENVIRONMENT_ID) + --skip-deployed-check (optional) skip check for deployed agents --help display help for command ``` diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 5cd8a601..a7537d48 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -10,13 +10,13 @@ import { writeErrorToFile } from './shared/utils/error' import { switchInit } from './switch.init' import { switchVersion } from './switch.version' import { createEnvironmentAction } from './x/actions/create.environment.action' -import { deployAction } from './x/actions/deploy.action' import { deleteAction } from './x/actions/delete.action' +import { deployAction } from './x/actions/deploy.action' import { developAction } from './x/actions/develop.action' +import { listAgentsAction } from './x/actions/list-agents.action' import { publishAction } from './x/actions/publish.action' import { publishPubSub } from './x/actions/publish.pubsub' import { quickstartAction } from './x/actions/quickstart.action' -import { listAgentsAction } from './x/actions/list-agents.action' dotenv.config() @@ -78,6 +78,10 @@ program '-e, --env ', '(optional) the Environment to use (or set env FLATFILE_ENVIRONMENT_ID)' ) + .option( + '--skip-deployed-check', + '(optional) bypass check for deployed agents' + ) .action(developAction) program diff --git a/packages/cli/src/x/actions/develop.action.ts b/packages/cli/src/x/actions/develop.action.ts index 22ae5dec..c31b2106 100644 --- a/packages/cli/src/x/actions/develop.action.ts +++ b/packages/cli/src/x/actions/develop.action.ts @@ -1,6 +1,6 @@ import { Client } from '@flatfile/listener' -import { program } from 'commander' import { PubSubDriver } from '@flatfile/listener-driver-pubsub' +import { program } from 'commander' import fs from 'fs' // @ts-expect-error import ncc from '@vercel/ncc' @@ -8,10 +8,10 @@ import ora from 'ora' import path from 'path' import prompts from 'prompts' -import { apiKeyClient } from './auth.action' import { getAuth } from '../../shared/get-auth' import { getEntryFile } from '../../shared/get-entry-file' import { messages } from '../../shared/messages' +import { apiKeyClient } from './auth.action' export async function developAction( file?: string | null | undefined, @@ -19,6 +19,7 @@ export async function developAction( apiUrl: string token: string env: string + skipDeployedCheck: boolean }> ): Promise { const outDir = path.join(process.cwd(), '.flatfile') @@ -54,25 +55,26 @@ export async function developAction( // Check if any agents are listed for environment const apiClient = apiKeyClient({ apiUrl, apiKey: apiKey! }) - const agents = await apiClient.agents.list({ - environmentId: environment.id, - }) - if (agents?.data && agents?.data?.length > 0) { - console.error(messages.warnDeployedAgents(agents.data)) - - const { developLocally } = await prompts({ - type: 'confirm', - name: 'developLocally', - message: 'Would you like to proceed listening locally? (y/n)', + if (!options?.skipDeployedCheck) { + const agents = await apiClient.agents.list({ + environmentId: environment.id, }) - - if (!developLocally) { - ora({ - text: `Local development aborted`, - }).fail() - process.exit(1) + if (agents?.data && agents?.data?.length > 0) { + console.error(messages.warnDeployedAgents(agents.data)) + + const { developLocally } = await prompts({ + type: 'confirm', + name: 'developLocally', + message: 'Would you like to proceed listening locally? (y/n)', + }) + + if (!developLocally) { + ora({ + text: `Local development aborted`, + }).fail() + process.exit(1) + } } - } const driver = new PubSubDriver(environment.id) From e75df90b6a11baaec414440d2bb0d920374452cc Mon Sep 17 00:00:00 2001 From: Carl Brugger Date: Wed, 24 Apr 2024 15:51:52 -0500 Subject: [PATCH 2/3] feat: add env var --- packages/cli/src/x/actions/develop.action.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/x/actions/develop.action.ts b/packages/cli/src/x/actions/develop.action.ts index c31b2106..6aa33017 100644 --- a/packages/cli/src/x/actions/develop.action.ts +++ b/packages/cli/src/x/actions/develop.action.ts @@ -55,7 +55,12 @@ export async function developAction( // Check if any agents are listed for environment const apiClient = apiKeyClient({ apiUrl, apiKey: apiKey! }) - if (!options?.skipDeployedCheck) { + const skipDeployedCheck = + options?.skipDeployedCheck ?? + (process.env.FLATFILE_SKIP_DEPLOYED_CHECK ?? '').trim().toLowerCase() === + 'true' + + if (!skipDeployedCheck) { const agents = await apiClient.agents.list({ environmentId: environment.id, }) From 1f157d570697fa55fd6678d2c5d585c260c41f29 Mon Sep 17 00:00:00 2001 From: Carl Brugger Date: Thu, 31 Oct 2024 13:19:32 -0500 Subject: [PATCH 3/3] still print warning --- packages/cli/src/x/actions/develop.action.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/cli/src/x/actions/develop.action.ts b/packages/cli/src/x/actions/develop.action.ts index 6aa33017..94ed8692 100644 --- a/packages/cli/src/x/actions/develop.action.ts +++ b/packages/cli/src/x/actions/develop.action.ts @@ -60,13 +60,12 @@ export async function developAction( (process.env.FLATFILE_SKIP_DEPLOYED_CHECK ?? '').trim().toLowerCase() === 'true' - if (!skipDeployedCheck) { - const agents = await apiClient.agents.list({ - environmentId: environment.id, - }) - if (agents?.data && agents?.data?.length > 0) { - console.error(messages.warnDeployedAgents(agents.data)) - + const agents = await apiClient.agents.list({ + environmentId: environment.id, + }) + if (agents?.data && agents?.data?.length > 0) { + console.error(messages.warnDeployedAgents(agents.data)) + if (!skipDeployedCheck) { const { developLocally } = await prompts({ type: 'confirm', name: 'developLocally',