-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactored prompts and tests messages
Co-authored-by: Thomas Lane <163203257+tlane25@users.noreply.github.com> Co-authored-by: Thomas Lane <tlane25@users.noreply.github.com>
- Loading branch information
1 parent
469691c
commit f6aa58d
Showing
15 changed files
with
206 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import { chalk, log } from '../command-helpers.js' | ||
|
||
import { confirmPrompt } from './confirm-prompt.js' | ||
import { destructiveCommandMessages } from './prompt-messages.js' | ||
|
||
export const promptBlobSetOverwrite = async (key: string, storeName: string): Promise<void> => { | ||
const { overwriteNoticeMessage } = destructiveCommandMessages | ||
const { generateWarningMessage, overwriteConfirmationMessage } = destructiveCommandMessages.blobSet | ||
|
||
const warningMessage = generateWarningMessage(storeName) | ||
|
||
const generateBlobWarningMessage = (key: string, storeName: string): void => { | ||
log() | ||
log(`${chalk.redBright('Warning')}: The following blob key already exists in store ${chalk.cyan(storeName)}:`) | ||
log(warningMessage) | ||
log() | ||
log(`${chalk.bold(key)}`) | ||
log() | ||
log(`This operation will ${chalk.redBright('overwrite')} the existing value.`) | ||
log(`${chalk.yellowBright('Notice')}: To overwrite without this warning, you can use the --force flag.`) | ||
} | ||
|
||
export const blobSetPrompts = async (key: string, storeName: string): Promise<void> => { | ||
generateBlobWarningMessage(key, storeName) | ||
await confirmPrompt('Do you want to proceed with overwriting this blob key existing value?') | ||
log(overwriteNoticeMessage) | ||
await confirmPrompt(overwriteConfirmationMessage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,34 @@ | ||
import { chalk, log } from '../command-helpers.js' | ||
import { log } from '../command-helpers.js' | ||
import { EnvVar } from '../types.js' | ||
|
||
import { confirmPrompt } from './confirm-prompt.js' | ||
import { destructiveCommandMessages } from './prompt-messages.js' | ||
|
||
type User = { | ||
id: string | ||
email: string | ||
avatar_url: string | ||
full_name: string | ||
} | ||
export const generateEnvVarsList = (envVarsToDelete: EnvVar[]) => envVarsToDelete.map((envVar) => envVar.key) | ||
|
||
type EnvVar = { | ||
key: string | ||
scopes: string[] | ||
values: Record<string, any>[] | ||
updated_at: string | ||
updated_by: User | ||
is_secret: boolean | ||
} | ||
/** | ||
* Prompts the user to confirm overwriting environment variables on a site. | ||
* | ||
* @param {string} siteId - The ID of the site. | ||
* @param {EnvVar[]} existingEnvVars - The environment variables that already exist on the site. | ||
* @returns {Promise<void>} A promise that resolves when the user has confirmed the overwriting of the variables. | ||
*/ | ||
export async function promptEnvCloneOverwrite(siteId: string, existingEnvVars: EnvVar[]): Promise<void> { | ||
const { overwriteNoticeMessage } = destructiveCommandMessages | ||
const { generateWarningMessage, noticeEnvVarsMessage, overwriteConfirmationMessage } = | ||
destructiveCommandMessages.envClone | ||
|
||
const existingEnvVarKeys = generateEnvVarsList(existingEnvVars) | ||
const warningMessage = generateWarningMessage(siteId) | ||
|
||
const generateSetMessage = (envVarsToDelete: EnvVar[], siteId: string): void => { | ||
log() | ||
log( | ||
`${chalk.redBright( | ||
'Warning', | ||
)}: The following environment variables are already set on the site with ID ${chalk.bgBlueBright( | ||
siteId, | ||
)}. They will be overwritten!`, | ||
) | ||
log(warningMessage) | ||
log() | ||
|
||
log(`${chalk.yellowBright('Notice')}: The following variables will be overwritten:`) | ||
log(noticeEnvVarsMessage) | ||
log() | ||
envVarsToDelete.forEach((envVar) => { | ||
log(envVar.key) | ||
}) | ||
|
||
existingEnvVarKeys.forEach(log) | ||
log() | ||
log( | ||
`${chalk.yellowBright( | ||
'Notice', | ||
)}: To overwrite the existing variables without confirmation prompts, pass the --force flag.`, | ||
) | ||
} | ||
log(overwriteNoticeMessage) | ||
|
||
export const envClonePrompts = async (siteId: string, envVarsToDelete: EnvVar[]): Promise<void> => { | ||
generateSetMessage(envVarsToDelete, siteId) | ||
await confirmPrompt('Do you want to proceed with overwriting these variables?') | ||
await confirmPrompt(overwriteConfirmationMessage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,23 @@ | ||
import { chalk, log } from '../command-helpers.js' | ||
import { log } from '../command-helpers.js' | ||
|
||
import { confirmPrompt } from './confirm-prompt.js' | ||
|
||
export const generateSetMessage = (variableName: string) => ({ | ||
warningMessage: `${chalk.redBright('Warning')}: The environment variable ${chalk.bgBlueBright( | ||
variableName, | ||
)} already exists!`, | ||
noticeMessage: `${chalk.yellowBright( | ||
'Notice', | ||
)}: To overwrite the existing variable without confirmation, pass the -f or --force flag.`, | ||
confirmMessage: 'The environment variable already exists. Do you want to overwrite it?', | ||
}) | ||
import { destructiveCommandMessages } from './prompt-messages.js' | ||
|
||
/** | ||
* Generates warning, notice and confirm messages when trying to set an env variable | ||
* that already exists. | ||
* Prompts the user to confirm overwriting an existing environment variable. | ||
* | ||
* @param {string} key - The key of the environment variable that already exists | ||
* @returns {Object} An object with the following properties: | ||
* - warning: A warning message to be displayed to the user | ||
* - notice: A notice message to be displayed to the user | ||
* - confirm: A confirmation prompt to ask the user if they want to overwrite the existing variable | ||
* @param {string} existingKey - The key of the existing environment variable. | ||
* @returns {Promise<void>} A promise that resolves when the user confirms overwriting the variable. | ||
*/ | ||
export const promptOverwriteEnvVariable = async (key: string): Promise<void> => { | ||
const { confirmMessage, noticeMessage, warningMessage } = generateSetMessage(key) | ||
export const promptOverwriteEnvVariable = async (existingKey: string): Promise<void> => { | ||
const { overwriteNoticeMessage } = destructiveCommandMessages | ||
const { generateWarningMessage, overwriteConfirmationMessage } = destructiveCommandMessages.envSet | ||
|
||
const warningMessage = generateWarningMessage(existingKey) | ||
|
||
log() | ||
log(warningMessage) | ||
log() | ||
log(noticeMessage) | ||
log() | ||
await confirmPrompt(confirmMessage) | ||
log(overwriteNoticeMessage) | ||
await confirmPrompt(overwriteConfirmationMessage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { chalk } from '../command-helpers.js' | ||
import { EnvVar } from '../types.js' | ||
|
||
export const destructiveCommandMessages = { | ||
overwriteNoticeMessage: `${chalk.yellowBright( | ||
'Notice', | ||
)}: To overwrite without this warning, you can use the --force flag.`, | ||
|
||
blobSet: { | ||
generateWarningMessage: (storeName: string) => | ||
`${chalk.redBright('Warning')}: The blob key already exists in store ${chalk.cyan(storeName)}.`, | ||
overwriteConfirmationMessage: 'Do you want to proceed with overwriting this blob key existing value?', | ||
}, | ||
|
||
envSet: { | ||
generateWarningMessage: (variableName: string) => | ||
`${chalk.redBright('Warning')}: The environment variable ${chalk.bgBlueBright(variableName)} already exists.`, | ||
overwriteConfirmationMessage: 'The environment variable already exists. Do you want to overwrite it?', | ||
}, | ||
|
||
envUnset: { | ||
generateWarningMessage: (variableName: string) => | ||
`${chalk.redBright('Warning')}: The environment variable ${chalk.bgBlueBright(variableName)} already exists!`, | ||
overwriteConfirmationMessage: 'The environment variable already exists. Do you want to overwrite it?', | ||
}, | ||
|
||
envClone: { | ||
generateWarningMessage: (siteId: string) => | ||
`${chalk.redBright( | ||
'Warning', | ||
)}: The following environment variables are already set on the site with ID ${chalk.bgBlueBright( | ||
siteId, | ||
)}. They will be overwritten!`, | ||
noticeEnvVarsMessage: `${chalk.yellowBright('Notice')}: The following variables will be overwritten:`, | ||
overwriteConfirmationMessage: 'The environment variables already exist. Do you want to overwrite them?', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,22 @@ | ||
import { chalk, log } from '../command-helpers.js' | ||
import { log } from '../command-helpers.js' | ||
|
||
import { confirmPrompt } from './confirm-prompt.js' | ||
|
||
export const generateUnsetMessage = (variableName: string) => ({ | ||
warningMessage: `${chalk.redBright('Warning')}: The environment variable ${chalk.bgBlueBright( | ||
variableName, | ||
)} already exists!`, | ||
noticeMessage: `${chalk.yellowBright( | ||
'Notice', | ||
)}: To overwrite the existing variable without confirmation, pass the -f or --force flag.`, | ||
confirmMessage: 'The environment variable already exists. Do you want to overwrite it?', | ||
}) | ||
import { destructiveCommandMessages } from './prompt-messages.js' | ||
|
||
/** | ||
* Logs a warning and prompts user to confirm overwriting an existing environment variable | ||
* | ||
* @param {string} key - The key of the environment variable that already exists | ||
* @returns {Promise<void>} A promise that resolves when the user has confirmed overwriting the variable | ||
*/ | ||
export const promptOverwriteEnvVariable = async (key: string): Promise<void> => { | ||
const { confirmMessage, noticeMessage, warningMessage } = generateUnsetMessage(key) | ||
export const promptOverwriteEnvVariable = async (existingKey: string): Promise<void> => { | ||
const { overwriteNoticeMessage } = destructiveCommandMessages | ||
const { generateWarningMessage, overwriteConfirmationMessage } = destructiveCommandMessages.envUnset | ||
|
||
const warningMessage = generateWarningMessage(existingKey) | ||
|
||
log(warningMessage) | ||
log() | ||
log(noticeMessage) | ||
await confirmPrompt(confirmMessage) | ||
log(overwriteNoticeMessage) | ||
await confirmPrompt(overwriteConfirmationMessage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.