Skip to content

Commit

Permalink
fix: prompt bug in web and sync-file
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-run committed Nov 22, 2023
1 parent b582b55 commit 527d00a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/actions/sync-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../common/octokit.ts'
import { log } from '../common/log.ts'
import { Gitter } from '../common/git.ts'
import inquirer from '../common/inquirer.ts'
import inquirer, { hackilyFixBackToBackPrompt } from '../common/inquirer.ts'
import { GIT_CACHE_DIR } from '../common/cache.ts'

const reposQuery = /* GraphQL */ `
Expand Down Expand Up @@ -122,13 +122,16 @@ export async function syncFileAcrossRepos(query: string): Promise<void> {
])

// Step 2, selecting a valid file in the source repo
await hackilyFixBackToBackPrompt()
const fileToSync = await getValidFileInSource(sourceRepo.source)

// Step 3, selecting target repos
await hackilyFixBackToBackPrompt()
const otherRepos = relevantRepos.filter((it) => it.name !== sourceRepo.source)
const targetRepos = await getTargetRepos(otherRepos)

// Step 4, writing commit message
await hackilyFixBackToBackPrompt()
const commitMessage = await inquirer.prompt<{ message: string }>({
type: 'input',
name: 'message',
Expand All @@ -140,6 +143,7 @@ export async function syncFileAcrossRepos(query: string): Promise<void> {
log(`The commit message will be "${chalk.yellow(commitMessage.message)}"`)

// Step 5, confirm
await hackilyFixBackToBackPrompt()
const confirmResult = await inquirer.prompt({
type: 'confirm',
message: `Do you want to continue? This will create ${otherRepos.length} commits, one for each repo.`,
Expand Down
3 changes: 2 additions & 1 deletion src/actions/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as R from 'remeda'
import open from 'open'
import chalk from 'chalk'

import inquirer from '../common/inquirer.ts'
import inquirer, { hackilyFixBackToBackPrompt } from '../common/inquirer.ts'
import { log } from '../common/log.ts'

type Envs = {
Expand Down Expand Up @@ -105,6 +105,7 @@ export async function openResource(what: string | null, env: string | null): Pro
return
}

await hackilyFixBackToBackPrompt()
const selectedEnv = await getAppEnv(cleanItem)
await openApp(cleanItem, selectedEnv)
}
Expand Down
8 changes: 8 additions & 0 deletions src/common/inquirer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ import inquirer from 'inquirer'

inquirer.registerPrompt('autocomplete', autocomplete)

/**
* Sometimes when inquirer propmts are invoked back to back, the second prompt
* will not be able to receive input. This is a hacky workaround to fix that.
*/
export async function hackilyFixBackToBackPrompt(): Promise<void> {
await new Promise((resolve) => setTimeout(resolve, 369))
}

export default inquirer

0 comments on commit 527d00a

Please sign in to comment.