diff --git a/src/commands/add.ts b/src/commands/add.ts index d0d6127..870f60b 100644 --- a/src/commands/add.ts +++ b/src/commands/add.ts @@ -11,6 +11,7 @@ import { compareUIConfig } from "../utils/compareUIConfig"; import { addModuleToConfig, getNuxtConfig, getUIConfig, updateConfig } from "../utils/config"; import { fileExists } from "../utils/fileExists"; import { installPackages } from "../utils/installPackages"; +import { installValidator } from "../utils/installValidator"; import { printFancyBoxMessage } from "../utils/printFancyBoxMessage"; import { promptUserForComponents } from "../utils/promptForComponents"; import { writeFile } from "../utils/writeFile"; @@ -281,6 +282,21 @@ export const add = new Command() } } + // check if any of the components has the `askValidator` property set to true + let shouldAskValidator = false; + // Check if any component has askValidator set to true + for (const component of found) { + if (component.askValidator) { + shouldAskValidator = true; + break; + } + } + + if (shouldAskValidator) { + // Ask the user for their choice of validator + await installValidator(uiConfig.packageManager); + } + printFancyBoxMessage( "All Done!", { title: "Components Added" }, diff --git a/src/utils/installValidator.ts b/src/utils/installValidator.ts new file mode 100644 index 0000000..1808c9a --- /dev/null +++ b/src/utils/installValidator.ts @@ -0,0 +1,35 @@ +import prompts from "prompts"; + +import { installPackages } from "./installPackages"; + +export const installValidator = async (packageManager: string) => { + // Depending on the selected validator, install the corresponding packages + const validatorPackages = { + yup: ["yup", "@vee-validate/yup"], + zod: ["zod", "@vee-validate/zod"], + joi: ["joi", "@vee-validate/joi"], + valibot: ["valibot", "@vee-validate/valibot"], + }; + + const { validator }: { validator: keyof typeof validatorPackages } = await prompts({ + type: "select", + name: "validator", + message: "Choose the validator package to use with Vee Validate: ", + choices: [ + { title: "Yup", value: "yup" }, + { title: "Zod", value: "zod" }, + { title: "Joi", value: "joi" }, + { title: "Valibot", value: "valibot" }, + ], + }); + if (!validator) { + console.log("No validator package selected"); + return; + } + console.log(`Selected ${validator} as the validator package`); + + if (validatorPackages[validator]) { + await installPackages(packageManager, validatorPackages[validator]); + } + return validator; +};