crossbundle_tools/commands/apple/
gen_app_folder.rs

1use 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
6/// Generates an apple app folder.
7pub 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    // Create app folder
17    let app_path = target_dir.join(format!("{}.app", project_name));
18    remove_dir_all(&app_path).ok();
19    create_dir_all(&app_path)?;
20    // Copy options
21    let mut options = CopyOptions::new();
22    options.skip_exist = true;
23    options.content_only = true;
24    // Copy resources to app folder if provided
25    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    // Copy assets to app folder if provided
32    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}