This repository has been archived by the owner on Dec 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(toolchain): add project-specific meta.json files (#405)
- Loading branch information
1 parent
c259044
commit c00eb72
Showing
4 changed files
with
139 additions
and
124 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,49 @@ | ||
use anyhow::*; | ||
use sha1::{Digest, Sha1}; | ||
use std::{env, path::PathBuf}; | ||
|
||
/// Root of the current project. | ||
pub fn project_root() -> Result<PathBuf> { | ||
Ok(env::current_dir()?) | ||
} | ||
|
||
/// Returns a unique hash to the current project's path. | ||
pub fn project_path_hash() -> Result<String> { | ||
let project_root = project_root()?; | ||
let mut hasher = Sha1::new(); | ||
hasher.update(project_root.to_string_lossy().as_bytes()); | ||
Ok(format!("{:x}", hasher.finalize())) | ||
} | ||
|
||
/// Where all data gets stored globally. | ||
pub fn data_dir() -> Result<PathBuf> { | ||
Ok(dirs::data_dir().context("dirs::data_dir()")?.join("rivet")) | ||
} | ||
|
||
/// Global config data. | ||
pub fn user_config_dir(base_data_dir: &PathBuf) -> Result<PathBuf> { | ||
Ok(base_data_dir.join("config")) | ||
} | ||
|
||
pub fn meta_config_file(base_data_dir: &PathBuf) -> Result<PathBuf> { | ||
Ok(user_config_dir(base_data_dir)?.join("meta.json")) | ||
} | ||
|
||
/// Global user config file. | ||
pub fn user_settings_config_file(base_data_dir: &PathBuf) -> Result<PathBuf> { | ||
Ok(user_config_dir(base_data_dir)?.join("settings.json")) | ||
} | ||
|
||
/// Project user config file. | ||
pub fn project_settings_config_file() -> Result<PathBuf> { | ||
Ok(project_root()?.join(".rivet").join("settings.json")) | ||
} | ||
|
||
/// Directory specific to this project. | ||
/// | ||
/// This is not stored within the project itself since it causes problems with version control & | ||
/// bugs in WSL. | ||
pub fn project_data_dir(base_data_dir: &PathBuf) -> Result<PathBuf> { | ||
Ok(base_data_dir.join("projects").join(project_path_hash()?)) | ||
} | ||
|
||
/// Stores all meta. | ||
pub fn meta_config_file(base_data_dir: &PathBuf) -> Result<PathBuf> { | ||
Ok(project_data_dir(base_data_dir)?.join("meta.json")) | ||
} |