apps-create 0.0.5

apps开发脚手架,用于快速初始化项目
use std::error::Error;

#[derive(Debug, Clone)]
pub struct VueProject {
    /// 是否需要monorepo
    pub use_monorepo: bool,
    /// 子仓库名称
    pub working_name: Option<String>,
    /// 是否是子仓库
    pub is_sub_project: bool,
    
    /// 是否需要测试框架
    pub use_test: bool,

    /// 是否需要一个基础模板
    pub use_sub_project: bool,
    
    /// 是否需要一个基础模板
    pub sub_project_name: Option<String>,
}


#[derive(Debug, Clone, PartialEq)]
pub enum CopyType {
    File,
    Dir,
}

/// 复制项目配置
pub struct CopyProject {
    /// 源路径
    pub source_path: String,
    /// 目标路径
    pub target_path: String,
    /// 复制类型
    pub copy_type: CopyType,

    /// 是否需要处理内容
    pub need_process_content: bool,
    /// 内容处理器
    pub content_processor: Option<Box<dyn Fn(&str) -> Result<String, Box<dyn Error>>>>,
}

impl CopyProject {

    pub fn with_dir (
        source_path: String, 
        target_path: String, 
    ) -> CopyProject {
        CopyProject  {
            source_path,
            target_path,
            copy_type: CopyType::Dir,
            need_process_content: false,
            content_processor: None,
        }
    }

    pub fn with_file (
        source_path: String, 
        target_path: String, 
    ) -> CopyProject {

        CopyProject  {
            source_path,
            target_path,
            copy_type: CopyType::File,
            need_process_content: false,
            content_processor: None,
        }
    }

    pub fn with_content_processor(
        mut self,
        processor: impl Fn(&str) -> Result<String, Box<dyn Error>> + 'static,
    ) -> Self {
        self.content_processor = Some(Box::new(processor));
        self.need_process_content = true;
        self
    }
}