Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auto-answer prompt #96

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Options:
-k, --token <string> the authentication token to use (or set env FLATFILE_API_KEY or FLATFILE_BEARER_TOKEN)
-h, --api-url <url> (optional) the API URL to use (or set env FLATFILE_API_URL)
-e, --env <string> (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
```

Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -78,6 +78,10 @@ program
'-e, --env <env-id>',
'(optional) the Environment to use (or set env FLATFILE_ENVIRONMENT_ID)'
)
.option(
'--skip-deployed-check',
'(optional) bypass check for deployed agents'
)
.action(developAction)

program
Expand Down
36 changes: 21 additions & 15 deletions packages/cli/src/x/actions/develop.action.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
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'
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,
options?: Partial<{
apiUrl: string
token: string
env: string
skipDeployedCheck: boolean
}>
): Promise<void> {
const outDir = path.join(process.cwd(), '.flatfile')
Expand Down Expand Up @@ -54,25 +55,30 @@ export async function developAction(
// Check if any agents are listed for environment
const apiClient = apiKeyClient({ apiUrl, apiKey: apiKey! })

const skipDeployedCheck =
options?.skipDeployedCheck ??
(process.env.FLATFILE_SKIP_DEPLOYED_CHECK ?? '').trim().toLowerCase() ===
'true'

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 (!developLocally) {
ora({
text: `Local development aborted`,
}).fail()
process.exit(1)
if (!skipDeployedCheck) {
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)
}
}
Comment on lines +68 to 81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Several improvements needed in the deployment check logic

  1. The indentation in the if block seems inconsistent with the rest of the file
  2. Consider a more informative message on abort
  3. Consider using a more graceful shutdown approach

Apply these improvements:

     if (!skipDeployedCheck) {
       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`,
+          text: `Local development aborted - deployed agents will remain active`,
         }).fail()
-        process.exit(1)
+        // Allow proper cleanup of resources
+        await driver.stop()
+        return
       }
     }

Committable suggestion skipped: line range outside the PR's diff.


}

const driver = new PubSubDriver(environment.id)
Expand Down
Loading