create_vue_monorepo_rs/dialoguers/
dialoguer_work.rs1use console::Term;
2use dialoguer::{theme::ColorfulTheme, Confirm, Input};
3use crate::utils::util::{is_valid_package_name, to_valid_package_name};
4
5use crate::ConfiguresSelected;
6
7pub fn work(configures: &mut ConfiguresSelected) -> (String, &ConfiguresSelected) {
8 let term = Term::buffered_stderr();
9 let theme = ColorfulTheme::default();
10
11 let mut project_name: String = Input::with_theme(&theme)
12 .with_prompt("projectName")
13 .default("vue-monorepo-project".to_string())
14 .interact_on(&term)
15 .unwrap();
16
17 if !is_valid_package_name(&project_name) {
18 println!(
19 "! Invalid package.json name `{}`, Automatically converted to a valid name.",
20 project_name
21 );
22 project_name = to_valid_package_name(&project_name)
23 }
24 println!("! Current project name: {}", project_name);
25
26 let config_value: bool = Confirm::with_theme(&theme)
27 .with_prompt("Add ESLint for code quality & Add Prettier for code formatting?")
28 .interact_on(&term)
29 .unwrap();
30 configures.set_eslint_config(config_value);
31
32 let config_value: bool = Confirm::with_theme(&theme)
33 .with_prompt("Add Vitest for Unit Testing?")
34 .interact_on(&term)
35 .unwrap();
36 configures.set_vitest_config(config_value);
37
38 let config_value: bool = Confirm::with_theme(&theme)
39 .with_prompt("Add Common Utils Library for project?")
40 .interact_on(&term)
41 .unwrap();
42 configures.set_common_library(config_value);
43
44 (project_name, configures)
45}