create_rspc_app/
frontend_framework.rs1use std::{fs::create_dir_all, io, path::Path};
2
3use crate::utils::replace_in_file;
4use include_dir::{include_dir, Dir};
5use strum::{Display, EnumIter, EnumString};
6
7use crate::framework::Framework;
8
9static REACT_TEMPLATE_TAURI: Dir<'_> =
10 include_dir!("$CARGO_MANIFEST_DIR/templates/react_base_tauri");
11static REACT_TEMPLATE_AXUM: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/templates/react_base_axum");
12
13static SOLID_TEMPLATE_TAURI: Dir<'_> =
14 include_dir!("$CARGO_MANIFEST_DIR/templates/solid_base_tauri");
15static SOLID_TEMPLATE_AXUM: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/templates/solid_base_axum");
16
17#[derive(Debug, Clone, Display, EnumIter, EnumString)]
18pub enum FrontendFramework {
19 React,
20 SolidJS,
21 }
23
24impl FrontendFramework {
25 pub fn render(&self, path: &Path, project_name: &str, framework: Framework) -> io::Result<()> {
26 let path = path.join("web");
27 create_dir_all(&path).unwrap();
28
29 match framework {
30 Framework::Tauri => match self {
31 FrontendFramework::React => {
32 REACT_TEMPLATE_TAURI.extract(path.clone()).unwrap();
33
34 replace_in_file(
35 path.join("package.json").as_path(),
36 "{{name}}",
37 project_name,
38 )?;
39 }
40 FrontendFramework::SolidJS => {
41 SOLID_TEMPLATE_TAURI.extract(path.clone()).unwrap();
42
43 replace_in_file(
44 path.join("package.json").as_path(),
45 "{{name}}",
46 project_name,
47 )?;
48 } },
50 Framework::Axum => match self {
51 FrontendFramework::React => {
52 REACT_TEMPLATE_AXUM.extract(path.clone()).unwrap();
53
54 replace_in_file(
55 path.join("package.json").as_path(),
56 "{{name}}",
57 project_name,
58 )?;
59 }
60 FrontendFramework::SolidJS => {
61 SOLID_TEMPLATE_AXUM.extract(path.clone()).unwrap();
62
63 replace_in_file(
64 path.join("package.json").as_path(),
65 "{{name}}",
66 project_name,
67 )?;
68 } },
70 }
71
72 Ok(())
73 }
74}