|
| 1 | +use std::io; |
| 2 | +use std::path::absolute; |
| 3 | +use std::{fs, path::Path}; |
| 4 | + |
| 5 | +use lcas::{build, create_repo, create_store, install_artifact}; |
| 6 | + |
| 7 | +fn main() -> Result<(), String> { |
| 8 | + // Helper variables |
| 9 | + // `input_dir` is the artifact, likely produced by a build system etc. This is what we want to "transmit". |
| 10 | + let input_dir = absolute(Path::new("./example_dir")).unwrap(); |
| 11 | + // `repo_dir` is the Repo's contained directory, and should be hosted on a web server, as a directory, etc. |
| 12 | + let repo_dir = absolute(Path::new("./example_repo")).unwrap(); |
| 13 | + // `store_dir` is the local path for the local store, and will be where the Store is placed, and each artifact inside. |
| 14 | + let store_dir = absolute(Path::new("./example_store")).unwrap(); |
| 15 | + |
| 16 | + // Create an example repo and a store, *locally* |
| 17 | + create_repo(repo_dir.as_path())?; |
| 18 | + create_store(&store_dir)?; |
| 19 | + |
| 20 | + // Create an example artifact |
| 21 | + fs::create_dir_all(Path::new("./example_dir/nested_dir/super_nested_dir")).unwrap(); |
| 22 | + fs::write("./example_dir/a", "Wow a file").unwrap(); |
| 23 | + fs::write("./example_dir/nested_dir/b", "Wow another file, shocking.").unwrap(); |
| 24 | + fs::write( |
| 25 | + "./example_dir/nested_dir/super_nested_dir/c", |
| 26 | + "Nested nested nested file", |
| 27 | + ) |
| 28 | + .unwrap(); |
| 29 | + |
| 30 | + // Compile the artifact into a manifest and chunks and store it |
| 31 | + build( |
| 32 | + input_dir.as_path(), |
| 33 | + repo_dir.as_path(), |
| 34 | + &"generic".to_string(), |
| 35 | + ) |
| 36 | + .expect("Build Failure"); |
| 37 | + |
| 38 | + // Install the resulting manifest into an artifact in the `store_dir` |
| 39 | + install_artifact(&"generic".to_string(), store_dir.as_path(), &repo_dir); |
| 40 | + |
| 41 | + Ok(()) |
| 42 | +} |
0 commit comments