-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmod.rs
More file actions
104 lines (88 loc) · 2.16 KB
/
mod.rs
File metadata and controls
104 lines (88 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! Project templates
mod api;
mod full;
mod minimal;
mod web;
use anyhow::Result;
use clap::ValueEnum;
/// Available project templates
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum ProjectTemplate {
/// Minimal starter template
Minimal,
/// REST API template with CRUD
Api,
/// Web app template with Tera templates
Web,
/// Full-featured template with all batteries
Full,
}
/// Generate a project from a template
pub async fn generate_project(
name: &str,
template: ProjectTemplate,
features: &[String],
) -> Result<()> {
match template {
ProjectTemplate::Minimal => minimal::generate(name, features).await,
ProjectTemplate::Api => api::generate(name, features).await,
ProjectTemplate::Web => web::generate(name, features).await,
ProjectTemplate::Full => full::generate(name, features).await,
}
}
/// Common files for all templates
pub mod common {
use anyhow::Result;
use tokio::fs;
pub async fn generate_gitignore(path: &str) -> Result<()> {
let content = r#"# Generated by Cargo
/target/
# IDE
.idea/
.vscode/
*.swp
*.swo
# Environment
.env
.env.local
.env.*.local
# OS
.DS_Store
Thumbs.db
# Logs
*.log
"#;
fs::write(format!("{path}/.gitignore"), content).await?;
Ok(())
}
pub async fn generate_env_example(path: &str) -> Result<()> {
let content = r#"# Server configuration
HOST=127.0.0.1
PORT=8080
# Environment (development, production)
RUSTAPI_ENV=development
# Database (if using sqlx)
# DATABASE_URL=postgres://user:pass@localhost/db
# JWT Secret (if using extras-jwt feature)
# JWT_SECRET=your-secret-key-here
# Logging
RUST_LOG=info
"#;
fs::write(format!("{path}/.env.example"), content).await?;
Ok(())
}
pub fn features_to_cargo(features: &[String]) -> String {
if features.is_empty() {
String::new()
} else {
format!(
", features = [{}]",
features
.iter()
.map(|f| format!("\"{}\"", f))
.collect::<Vec<_>>()
.join(", ")
)
}
}
}