-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
164 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,14 +1,18 @@ | ||
[package] | ||
name = "salvo-cli" | ||
version = "0.1.20" | ||
version = "0.1.23" | ||
edition = "2021" | ||
authors = ["Fankai Liu [email protected]"] | ||
authors = ["Fankai Liu [email protected]","mrxiaozhuox [email protected]"] | ||
keywords = ["salvo", "cli","template"] | ||
description = "This CLI tool is designed to streamline the creation of new Salvo web projects through the generation of template structures. It offers the flexibility to select from web API templates or web site templates, and the convenience of choosing a database connector. It auto-generates foundational code to give users a head start in their development process." | ||
license = "MIT/Apache-2.0" | ||
repository = "https://github.com/fankaiLiu/salvo-cli" | ||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[[bin]] | ||
name = "salvo" | ||
path = "src/main.rs" | ||
|
||
[dependencies] | ||
ansi_term = "0.12.1" | ||
anyhow = "1.0.75" | ||
|
@@ -19,4 +23,5 @@ handlebars = "4.4.0" | |
serde = { version = "1.0.188", features = ["derive"] } | ||
serde_json = "1.0.107" | ||
unicode-xid = "0.2.4" | ||
rust-i18n = "2" | ||
rust-i18n = "2" | ||
itertools = "0.12.0" |
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,12 +1,12 @@ | ||
use anyhow::Result; | ||
use clap::Parser; | ||
|
||
mod test; | ||
mod utils; | ||
use i18n::set_locale; | ||
mod i18n; | ||
rust_i18n::i18n!("locales", fallback = "en"); | ||
#[derive(Parser, Debug)] | ||
#[clap(version = "0.1.20", author = "Fankai liu <[email protected]>")] | ||
#[clap(version = "0.1.23", author = "Fankai liu <[email protected]>")] | ||
struct Opts { | ||
#[clap(subcommand)] | ||
subcmd: SubCommand, | ||
|
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
mod test_write_project; |
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,81 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use crate::{ | ||
utils::{ | ||
create_project::write_project_file, | ||
get_selection::{DbConnectionType, DbType, TemplateType, UserSelected}, | ||
}, | ||
Project, | ||
}; | ||
use itertools::Itertools; | ||
use std::path::Path; | ||
|
||
#[test] | ||
fn test_write_project_all_combinations() { | ||
let template_types = [TemplateType::SalvoWebSite, TemplateType::SalvoWebApi]; | ||
//let db_types = [DbType::Sqlite, DbType::Mysql, DbType::Postgres, DbType::Mssql]; | ||
let db_types = [DbType::Sqlite]; | ||
let db_conn_types = [ | ||
DbConnectionType::Sqlx, | ||
DbConnectionType::SeaOrm, | ||
DbConnectionType::Diesel, | ||
DbConnectionType::Rbatis, | ||
DbConnectionType::Mongodb, | ||
DbConnectionType::Nothing, | ||
]; | ||
|
||
// Generate all combinations | ||
let combinations = template_types | ||
.iter() | ||
.cartesian_product(db_types.iter()) | ||
.cartesian_product(db_conn_types.iter()) | ||
.map(|((template_type, db_type), db_conn_type)| (template_type, db_type, db_conn_type)) | ||
.collect::<Vec<_>>(); | ||
|
||
// Test each combination | ||
for (template_type, db_type, db_conn_type) in combinations { | ||
// Generate a unique project name for each combination | ||
let project_name = format!("test_{:?}_{:?}_{:?}", template_type, db_type, db_conn_type); | ||
|
||
let path_str = format!("target/{}", project_name); | ||
std::fs::remove_dir_all(&path_str).unwrap_or(()); | ||
let path = Path::new(&path_str); | ||
|
||
let user_selected = UserSelected { | ||
template_type: *template_type, | ||
db_type: *db_type, | ||
db_conn_type: *db_conn_type, | ||
}; | ||
let project = Project { | ||
project_name: project_name.clone(), | ||
lang: Some("zh".to_string()), | ||
}; | ||
match write_project_file(path, user_selected, project) { | ||
Ok(()) => { | ||
let output = std::process::Command::new("cargo") | ||
.arg("check") | ||
.current_dir(&path_str) | ||
.output() | ||
.expect("failed to execute process"); | ||
if !output.status.success() { | ||
eprintln!( | ||
"Failed on combination: template_type={:?}, db_type={:?}, db_conn_type={:?}", | ||
template_type, db_type, db_conn_type | ||
); | ||
eprintln!("Output: {:?}", output); | ||
panic!(); | ||
} | ||
} | ||
Err(e) => { | ||
eprintln!( | ||
"Failed to write project file on combination: template_type={:?}, db_type={:?}, db_conn_type={:?}", | ||
template_type, db_type, db_conn_type | ||
); | ||
eprintln!("Error: {:?}", e); | ||
panic!(); | ||
} | ||
} | ||
std::fs::remove_dir_all(&path_str).unwrap_or(()); | ||
} | ||
} | ||
} |
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