foundry-rs / compilers

Utilities for working with native solc and compiling projects.
Apache License 2.0
59 stars 36 forks source link

Allow creating a `TempProject` in any arbitrary path #22

Open DaniPopes opened 8 months ago

DaniPopes commented 8 months ago

Needed this to initialize a project in an already-initialized template at a fixed path in Foundry tests, basically:

/// Initializes a new project in the given directory.
pub fn initialize(at: &Path) {
    let global_path = Path::new("/tmp/my_template/");
    let project = MyProject::new_with_root(global_path); // Wraps TempProject
    if project.is_empty() { // std::fs::read_dir or whatever
        project.initialize().unwrap();
    }
    project.copy_to(at).unwrap();
    // can also return a new project here
    // Project::new_with_root(at)
}