(&self, install_config: InstallConfig)
| 20 | } |
| 21 | |
| 22 | fn install(&self, install_config: InstallConfig) -> Result<()> { |
| 23 | for filename in Asset::iter() { |
| 24 | if filename.starts_with("README.md") |
| 25 | || filename.contains(".cargo/admin") && !filename.contains(".cargo/admin/dist") |
| 26 | { |
| 27 | continue; |
| 28 | } |
| 29 | |
| 30 | let file_contents = Asset::get(filename.as_ref()).unwrap(); |
| 31 | let mut file_path = std::path::PathBuf::from(&install_config.project_dir); |
| 32 | file_path.push(filename.as_ref()); |
| 33 | let mut directory_path = std::path::PathBuf::from(&file_path); |
| 34 | directory_path.pop(); |
| 35 | |
| 36 | add_file_msg(filename.as_ref()); |
| 37 | std::fs::create_dir_all(directory_path)?; |
| 38 | std::fs::write(file_path, file_contents.data)?; |
| 39 | } |
| 40 | |
| 41 | // TODO: Fix these appends/prepends by prepending the filepath with project_dir |
| 42 | // currently, this works because we assume the current working directory is the project's root |
| 43 | |
| 44 | // TODO: don't use concurrently as the anchor for new frontend dependencies |
| 45 | fs::replace( |
| 46 | "frontend/package.json", |
| 47 | r#""concurrently": "^7.1.0""#, |
| 48 | r#""concurrently": "^7.1.0", |
| 49 | "react-query": "^3.21.0""#, |
| 50 | )?; |
| 51 | |
| 52 | fs::append( |
| 53 | "frontend/src/dev.tsx", |
| 54 | indoc! {r#"// Sets up the development environment. |
| 55 | // |
| 56 | // Note: When running `cargo frontend` and `cargo backend` individually, "DEV_SERVER_PORT" is not set. |
| 57 | // Use `cargo fullstack` for the full development experience. |
| 58 | if (import.meta.env.DEV_SERVER_PORT) { |
| 59 | import('./setupDevelopment') |
| 60 | } |
| 61 | "#}, |
| 62 | )?; |
| 63 | |
| 64 | match install_config.backend_framework { |
| 65 | BackendFramework::ActixWeb => { |
| 66 | register_service_msg("(dev-only) /development"); |
| 67 | register_service_msg("(dev-only) /admin"); |
| 68 | fs::replace( |
| 69 | "backend/main.rs", |
| 70 | r"/* Development-only routes */", |
| 71 | r#"/* Development-only routes */ |
| 72 | // Mount development-only API routes |
| 73 | api_scope = api_scope.service(create_rust_app::dev::endpoints(web::scope("/development"))); |
| 74 | // Mount the admin dashboard on /admin |
| 75 | app = app.service(web::scope("/admin").service(Files::new("/", ".cargo/admin/dist/").index_file("admin.html")));"#, |
| 76 | )?; |
| 77 | } |
| 78 | BackendFramework::Poem => { |
| 79 | register_service_msg("(dev-only) /development"); |
no test coverage detected