Skip to content

Commit

Permalink
chore: remove deprecated inquirerer usage in sync-file
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-run committed Dec 18, 2024
1 parent e0e160a commit b7867cc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 38 deletions.
Binary file modified bun.lockb
Binary file not shown.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@
"postinstall": "bun x prettier package.json --write && echo \"Prettiered package.json\""
},
"dependencies": {
"@inquirer/prompts": "^7.0.1",
"@inquirer/prompts": "^7.2.0",
"chalk": "^5.3.0",
"date-fns": "^4.1.0",
"fs-extra": "^11.2.0",
"inquirer": "^9.2.21",
"octokit": "^3.2.0",
"open": "^10.1.0",
"remeda": "^2.17.0",
"remeda": "^2.18.0",
"simple-git": "^3.27.0",
"yargs": "^17.7.2"
},
"devDependencies": {
"@navikt/eslint-config-teamsykmelding": "^7.0.0",
"@types/bun": "^1.1.13",
"@navikt/eslint-config-teamsykmelding": "^7.1.0",
"@types/bun": "^1.1.14",
"@types/fs-extra": "^11.0.4",
"@types/inquirer": "^9.0.7",
"@types/yargs": "^17.0.33",
"@typescript-eslint/eslint-plugin": "^8.13.0",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"eslint": "^8.54.0",
"husky": "^9.1.6",
"husky": "^9.1.7",
"interactive-cli-tester": "^0.3.0",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"lint-staged": "^15.2.11",
"prettier": "^3.4.2",
"rimraf": "^6.0.1",
"semver": "^7.6.3"
},
Expand Down
1 change: 0 additions & 1 deletion src/actions/kafka.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import fs from 'fs-extra'

import { CACHE_DIR } from '../common/cache.ts'
import { log } from '../common/log.ts'
import inquirer from '../common/inquirer.ts'
import { getAllAppNames, promptForAppName } from '../common/kubectl.ts'

function saveSecretToPath(secretData: any, path: string): void {
Expand Down
45 changes: 16 additions & 29 deletions src/actions/sync-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import path from 'node:path'
import * as R from 'remeda'
import chalk from 'chalk'
import { PushResult } from 'simple-git'
import { search } from '@inquirer/prompts'
import { search, input, checkbox, confirm } from '@inquirer/prompts'

import { BaseRepoNode } from '../common/octokit.ts'
import { log } from '../common/log.ts'
import { Gitter } from '../common/git.ts'
import inquirer, { hackilyFixBackToBackPrompt } from '../common/inquirer.ts'
import { GIT_CACHE_DIR } from '../common/cache.ts'
import { getTeam } from '../common/config.ts'
import { getAllRepos } from '../common/repos.ts'
Expand Down Expand Up @@ -36,9 +35,7 @@ function queryRepo(query: string, repo: string): boolean {
}

async function getTargetRepos<Repo extends { name: string }>(otherRepos: Repo[]): Promise<Repo[]> {
const checkboxResponse = await inquirer.prompt<{ target: string[] }>({
type: 'checkbox',
name: 'target',
const checkboxResponse = await checkbox({
message: 'Select repos to copy file to',
choices: [
{ value: 'all', name: 'All repos' },
Expand All @@ -49,10 +46,10 @@ async function getTargetRepos<Repo extends { name: string }>(otherRepos: Repo[])
],
})

if (checkboxResponse.target.includes('all')) {
if (checkboxResponse.includes('all')) {
return otherRepos
} else if (checkboxResponse.target.length !== 0) {
return otherRepos.filter((it) => checkboxResponse.target.includes(it.name))
} else if (checkboxResponse.length !== 0) {
return otherRepos.filter((it) => checkboxResponse.includes(it.name))
} else {
log(chalk.red('You must select at least one repo'))
return getTargetRepos(otherRepos)
Expand Down Expand Up @@ -89,58 +86,48 @@ 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)

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

// Step 4, writing commit message
await hackilyFixBackToBackPrompt()
const commitMessage = await inquirer.prompt<{ message: string }>({
type: 'input',
name: 'message',
const commitMessage = await input({
message: 'Commit message for sync commits',
})

log(`The file "${chalk.yellow(fileToSync)}" will be synced across the following repos:`)
log(targetRepos.map((it) => ` - ${it.name}`).join('\n'))
log(`The commit message will be "${chalk.yellow(commitMessage.message)}"`)
log(`The commit message will be "${chalk.yellow(commitMessage)}"`)

// Step 5, confirm
await hackilyFixBackToBackPrompt()
const confirmResult = await inquirer.prompt({
name: 'confirm',
type: 'confirm',
const confirmResult = await confirm({
message: `Do you want to continue? This will create ${otherRepos.length} commits, one for each repo.`,
})

if (confirmResult.confirm) {
await copyFileToRepos(sourceRepo, targetRepos, fileToSync, commitMessage.message)
if (confirmResult) {
await copyFileToRepos(sourceRepo, targetRepos, fileToSync, commitMessage)
} else {
log(chalk.red('Aborting!'))
}
}

async function getValidFileInSource(sourceRepo: string, initialValue?: string): Promise<string> {
const file = await inquirer.prompt<{ file: string }>({
type: 'input',
name: 'file',
const file = await input({
default: initialValue,
message: `Which file in ${sourceRepo} should be synced across? \n (Path should be root in repo)`,
})

const bunFile = Bun.file(path.join(GIT_CACHE_DIR, sourceRepo, file.file))
log(path.join(GIT_CACHE_DIR, sourceRepo, file.file))
const bunFile = Bun.file(path.join(GIT_CACHE_DIR, sourceRepo, file))
log(path.join(GIT_CACHE_DIR, sourceRepo, file))
if (await bunFile.exists()) {
return file.file
return file
}

log(chalk.red(`Could not find file ${file.file} in ${sourceRepo}`))
log(chalk.red(`Could not find file ${file} in ${sourceRepo}`))

return getValidFileInSource(sourceRepo, file.file)
return getValidFileInSource(sourceRepo, file)
}

async function copyFileToRepos(
Expand Down

0 comments on commit b7867cc

Please sign in to comment.