crossbundle_tools/commands/apple/
gen_app_folder.rs1use crate::error::*;
2use fs_extra::dir::{copy as copy_dir, CopyOptions};
3use std::fs::{create_dir_all, remove_dir_all};
4use std::path::{Path, PathBuf};
5
6pub fn gen_apple_app_folder(
8 target_dir: &Path,
9 project_name: &str,
10 assets_dir: Option<PathBuf>,
11 resources_dir: Option<PathBuf>,
12) -> Result<PathBuf> {
13 if !target_dir.exists() {
14 create_dir_all(target_dir)?;
15 }
16 let app_path = target_dir.join(format!("{}.app", project_name));
18 remove_dir_all(&app_path).ok();
19 create_dir_all(&app_path)?;
20 let mut options = CopyOptions::new();
22 options.skip_exist = true;
23 options.content_only = true;
24 if let Some(resources_dir) = &resources_dir {
26 if !resources_dir.exists() {
27 return Err(AppleError::ResourcesNotFound.into());
28 }
29 copy_dir(resources_dir, &app_path, &options)?;
30 }
31 if let Some(assets_dir) = &assets_dir {
33 if !assets_dir.exists() {
34 return Err(AppleError::AssetsNotFound.into());
35 }
36 let assets_path = app_path.join("assets");
37 create_dir_all(&assets_path)?;
38 copy_dir(assets_dir, &assets_path, &options)?;
39 }
40 Ok(app_path)
41}