Skip to content

Commit

Permalink
feat: auto-answer prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbrugger committed Apr 24, 2024
1 parent 8e3949f commit 4b86ca3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
40 changes: 21 additions & 19 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.posix.join(process.cwd(), '.flatfile')
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4b86ca3

Please sign in to comment.