|
1 | 1 | import chalk from 'chalk' |
2 | | -import inquirer from 'inquirer' |
3 | | -import autocomplete from 'inquirer-autocomplete-prompt' |
4 | 2 | import { saveConfiguration } from '../../lib/configurations/index.js' |
5 | | -import { ConfigurationCreateAnswers } from '../../lib/types.js' |
6 | | -import { googleAlloyDbInstancePrompt } from './prompts/google-alloydb-instance.js' |
7 | | -import { configurationNamePrompt } from './prompts/configuration-name.js' |
8 | | -import { confirmationPrompt } from './prompts/confirmation.js' |
9 | | -import { databaseTypePrompt } from './prompts/database-type.js' |
10 | | -import { googleCloudProjectPrompt } from './prompts/google-cloud-project.js' |
11 | | -import { googleCloudSqlInstancePrompt } from './prompts/google-cloud-sql-instance.js' |
12 | | -import { kubernetesContextPrompt } from './prompts/kubernetes-context.js' |
13 | | -import { kubernetesNamespacePrompt } from './prompts/kubernetes-namespace.js' |
14 | | -import { kubernetesServiceAccountPrompt } from './prompts/kubernetes-service-account.js' |
15 | | -import { localPortPrompt } from './prompts/local-port.js' |
| 3 | +import { promptGoogleAlloyDbInstance } from './prompts/google-alloydb-instance.js' |
| 4 | +import { promptConfigurationName } from './prompts/configuration-name.js' |
| 5 | +import { promptConfirmation } from './prompts/confirmation.js' |
| 6 | +import { promptDatabaseType } from './prompts/database-type.js' |
| 7 | +import { promptGoogleCloudProject } from './prompts/google-cloud-project.js' |
| 8 | +import { promptGoogleCloudSqlInstance } from './prompts/google-cloud-sql-instance.js' |
| 9 | +import { promptKubernetesContext } from './prompts/kubernetes-context.js' |
| 10 | +import { promptKubernetesNamespace } from './prompts/kubernetes-namespace.js' |
| 11 | +import { promptKubernetesServiceAccount } from './prompts/kubernetes-service-account.js' |
| 12 | +import { promptLocalPort } from './prompts/local-port.js' |
16 | 13 |
|
17 | 14 | export const createConfiguration = async () => { |
18 | | - inquirer.registerPrompt('autocomplete', autocomplete) |
| 15 | + const googleCloudProject = await promptGoogleCloudProject() |
| 16 | + const databaseType = await promptDatabaseType() |
19 | 17 |
|
20 | | - const answers = await inquirer.prompt<ConfigurationCreateAnswers>([ |
21 | | - googleCloudProjectPrompt, |
22 | | - databaseTypePrompt, |
23 | | - googleCloudSqlInstancePrompt, |
24 | | - googleAlloyDbInstancePrompt, |
25 | | - kubernetesContextPrompt, |
26 | | - kubernetesNamespacePrompt, |
27 | | - kubernetesServiceAccountPrompt, |
28 | | - localPortPrompt, |
29 | | - configurationNamePrompt, |
30 | | - confirmationPrompt, |
31 | | - ]) |
| 18 | + const databaseInstance = databaseType === 'cloudsql' |
| 19 | + ? await promptGoogleCloudSqlInstance(googleCloudProject) |
| 20 | + : await promptGoogleAlloyDbInstance(googleCloudProject) |
32 | 21 |
|
33 | | - if (answers.confirmation) { |
34 | | - saveConfiguration(answers) |
| 22 | + const kubernetesContext = await promptKubernetesContext() |
| 23 | + const kubernetesNamespace = await promptKubernetesNamespace(kubernetesContext) |
| 24 | + const kubernetesServiceAccount = await promptKubernetesServiceAccount( |
| 25 | + kubernetesContext, |
| 26 | + kubernetesNamespace, |
| 27 | + ) |
| 28 | + const localPort = await promptLocalPort() |
| 29 | + const configurationName = await promptConfigurationName() |
| 30 | + const confirmation = await promptConfirmation() |
35 | 31 |
|
36 | | - console.log(chalk.green(`Saved configuration '${chalk.bold(answers.configurationName)}'.`)) |
| 32 | + if (confirmation) { |
| 33 | + saveConfiguration({ |
| 34 | + configurationName, |
| 35 | + databaseType, |
| 36 | + databaseInstance, |
| 37 | + kubernetesContext, |
| 38 | + kubernetesNamespace, |
| 39 | + kubernetesServiceAccount, |
| 40 | + localPort: localPort ?? 5432, |
| 41 | + }) |
| 42 | + |
| 43 | + console.log(chalk.green(`Saved configuration '${chalk.bold(configurationName)}'.`)) |
37 | 44 | } |
38 | 45 | else { |
39 | 46 | console.log(chalk.red('You are excused.')) |
|
0 commit comments