(
path: T,
template_path: &Path,
template_config: &TemplateConfig,
globals: &Object,
render_files: &[PathBuf],
ignore_files: &[PathBuf],
replace: bool,
)
| 216 | |
| 217 | #[tracing::instrument(target = "cargo_lambda")] |
| 218 | async fn create_project<T: AsRef<Path> + Debug>( |
| 219 | path: T, |
| 220 | template_path: &Path, |
| 221 | template_config: &TemplateConfig, |
| 222 | globals: &Object, |
| 223 | render_files: &[PathBuf], |
| 224 | ignore_files: &[PathBuf], |
| 225 | replace: bool, |
| 226 | ) -> Result<()> { |
| 227 | tracing::trace!("rendering new project's template"); |
| 228 | |
| 229 | let parser = ParserBuilder::with_stdlib().build().into_diagnostic()?; |
| 230 | |
| 231 | let render_dir = tempfile::tempdir().into_diagnostic()?; |
| 232 | let render_path = render_dir.path(); |
| 233 | |
| 234 | let walk_dir = WalkDir::new(template_path).follow_links(false); |
| 235 | for entry in walk_dir { |
| 236 | let entry = entry.into_diagnostic()?; |
| 237 | let entry_path = entry.path(); |
| 238 | |
| 239 | let entry_name = entry_path |
| 240 | .file_name() |
| 241 | .ok_or_else(|| CreateError::InvalidTemplateEntry(entry_path.to_path_buf()))?; |
| 242 | |
| 243 | if entry_path.is_dir() { |
| 244 | if entry_name != ".git" { |
| 245 | create_dir_all(entry_path) |
| 246 | .into_diagnostic() |
| 247 | .wrap_err_with(|| format!("unable to create directory: {entry_path:?}"))?; |
| 248 | } |
| 249 | } else if entry_name == "cargo-lambda-template.zip" { |
| 250 | continue; |
| 251 | } else { |
| 252 | let relative = entry_path.strip_prefix(template_path).into_diagnostic()?; |
| 253 | |
| 254 | if should_ignore_file(relative, ignore_files, template_config, globals) { |
| 255 | continue; |
| 256 | } |
| 257 | |
| 258 | let mut new_path = render_path.join(relative); |
| 259 | if let Some(path) = render_path_with_variables(&new_path, &parser, globals) { |
| 260 | new_path = path; |
| 261 | } |
| 262 | |
| 263 | let parent_name = if let Some(parent) = new_path.parent() { |
| 264 | create_dir_all(parent).into_diagnostic()?; |
| 265 | parent.file_name().and_then(|p| p.to_str()) |
| 266 | } else { |
| 267 | None |
| 268 | }; |
| 269 | |
| 270 | if entry_name == "Cargo.toml" |
| 271 | || entry_name == "README.md" |
| 272 | || (entry_name == "main.rs" && parent_name == Some("src")) |
| 273 | || (entry_name == "lib.rs" && parent_name == Some("src")) |
| 274 | || parent_name == Some("bin") |
| 275 | || should_render_file(relative, render_files, template_config, globals) |
no test coverage detected