2024-07-12 23:09:37 +01:00
|
|
|
// #![deny(missing_docs)] - TODO: bring this back before publishing 0.5
|
|
|
|
|
|
|
|
#[cfg(not(any(feature = "roblox", feature = "lune", feature = "luau")))]
|
|
|
|
compile_error!("at least one of the features `roblox`, `lune`, or `luau` must be enabled");
|
|
|
|
|
2024-07-14 14:19:15 +01:00
|
|
|
use crate::lockfile::Lockfile;
|
2024-07-12 23:09:37 +01:00
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
2024-07-17 18:38:01 +01:00
|
|
|
pub mod download;
|
2024-07-22 15:41:45 +01:00
|
|
|
mod git;
|
2024-07-17 18:38:01 +01:00
|
|
|
pub mod linking;
|
2024-07-12 23:09:37 +01:00
|
|
|
pub mod lockfile;
|
2024-03-04 20:18:49 +00:00
|
|
|
pub mod manifest;
|
2024-07-12 23:09:37 +01:00
|
|
|
pub mod names;
|
2024-07-14 14:19:15 +01:00
|
|
|
pub mod resolver;
|
|
|
|
pub mod scripts;
|
2024-07-12 23:09:37 +01:00
|
|
|
pub mod source;
|
|
|
|
|
2024-03-04 20:18:49 +00:00
|
|
|
pub const MANIFEST_FILE_NAME: &str = "pesde.yaml";
|
2024-07-12 23:09:37 +01:00
|
|
|
pub const LOCKFILE_FILE_NAME: &str = "pesde.lock";
|
2024-07-14 14:19:15 +01:00
|
|
|
pub const DEFAULT_INDEX_NAME: &str = "default";
|
2024-07-17 18:38:01 +01:00
|
|
|
pub const PACKAGES_CONTAINER_NAME: &str = ".pesde";
|
2024-07-22 15:41:45 +01:00
|
|
|
pub const MAX_ARCHIVE_SIZE: usize = 4 * 1024 * 1024;
|
2024-07-12 23:09:37 +01:00
|
|
|
|
|
|
|
pub(crate) static REQWEST_CLIENT: Lazy<reqwest::blocking::Client> = Lazy::new(|| {
|
|
|
|
reqwest::blocking::Client::builder()
|
|
|
|
.user_agent(concat!(
|
|
|
|
env!("CARGO_PKG_NAME"),
|
|
|
|
"/",
|
|
|
|
env!("CARGO_PKG_VERSION")
|
|
|
|
))
|
|
|
|
.build()
|
|
|
|
.expect("failed to create reqwest client")
|
|
|
|
});
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Clone)]
|
|
|
|
pub struct AuthConfig {
|
2024-07-22 15:41:45 +01:00
|
|
|
pesde_token: Option<String>,
|
|
|
|
git_credentials: Option<gix::sec::identity::Account>,
|
2024-07-12 23:09:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl AuthConfig {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
AuthConfig::default()
|
|
|
|
}
|
|
|
|
|
2024-07-22 15:41:45 +01:00
|
|
|
pub fn pesde_token(&self) -> Option<&str> {
|
|
|
|
self.pesde_token.as_deref()
|
2024-07-12 23:09:37 +01:00
|
|
|
}
|
|
|
|
|
2024-07-22 15:41:45 +01:00
|
|
|
pub fn git_credentials(&self) -> Option<&gix::sec::identity::Account> {
|
|
|
|
self.git_credentials.as_ref()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_pesde_token<S: AsRef<str>>(mut self, token: Option<S>) -> Self {
|
|
|
|
self.pesde_token = token.map(|s| s.as_ref().to_string());
|
2024-07-12 23:09:37 +01:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2024-07-22 15:41:45 +01:00
|
|
|
pub fn with_git_credentials(
|
|
|
|
mut self,
|
|
|
|
git_credentials: Option<gix::sec::identity::Account>,
|
|
|
|
) -> Self {
|
|
|
|
self.git_credentials = git_credentials;
|
|
|
|
self
|
2024-07-12 23:09:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Project {
|
|
|
|
path: PathBuf,
|
|
|
|
data_dir: PathBuf,
|
|
|
|
auth_config: AuthConfig,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Project {
|
|
|
|
pub fn new<P: AsRef<Path>, Q: AsRef<Path>>(
|
|
|
|
path: P,
|
|
|
|
data_dir: Q,
|
|
|
|
auth_config: AuthConfig,
|
|
|
|
) -> Self {
|
|
|
|
Project {
|
|
|
|
path: path.as_ref().to_path_buf(),
|
|
|
|
data_dir: data_dir.as_ref().to_path_buf(),
|
|
|
|
auth_config,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn path(&self) -> &Path {
|
|
|
|
&self.path
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn data_dir(&self) -> &Path {
|
|
|
|
&self.data_dir
|
|
|
|
}
|
|
|
|
|
2024-07-22 15:41:45 +01:00
|
|
|
pub fn auth_config(&self) -> &AuthConfig {
|
|
|
|
&self.auth_config
|
|
|
|
}
|
|
|
|
|
2024-07-12 23:09:37 +01:00
|
|
|
pub fn read_manifest(&self) -> Result<Vec<u8>, errors::ManifestReadError> {
|
|
|
|
let bytes = std::fs::read(self.path.join(MANIFEST_FILE_NAME))?;
|
|
|
|
Ok(bytes)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn deser_manifest(&self) -> Result<manifest::Manifest, errors::ManifestReadError> {
|
|
|
|
let bytes = std::fs::read(self.path.join(MANIFEST_FILE_NAME))?;
|
|
|
|
Ok(serde_yaml::from_slice(&bytes)?)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn write_manifest<S: AsRef<[u8]>>(&self, manifest: S) -> Result<(), std::io::Error> {
|
|
|
|
std::fs::write(self.path.join(MANIFEST_FILE_NAME), manifest.as_ref())
|
|
|
|
}
|
2024-07-14 14:19:15 +01:00
|
|
|
|
|
|
|
pub fn deser_lockfile(&self) -> Result<Lockfile, errors::LockfileReadError> {
|
|
|
|
let bytes = std::fs::read(self.path.join(LOCKFILE_FILE_NAME))?;
|
|
|
|
Ok(serde_yaml::from_slice(&bytes)?)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn write_lockfile(&self, lockfile: Lockfile) -> Result<(), errors::LockfileWriteError> {
|
|
|
|
let writer = std::fs::File::create(self.path.join(LOCKFILE_FILE_NAME))?;
|
|
|
|
serde_yaml::to_writer(writer, &lockfile)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
2024-07-12 23:09:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub mod errors {
|
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
#[derive(Debug, Error)]
|
|
|
|
#[non_exhaustive]
|
|
|
|
pub enum ManifestReadError {
|
|
|
|
#[error("io error reading manifest file")]
|
|
|
|
Io(#[from] std::io::Error),
|
|
|
|
|
|
|
|
#[error("error deserializing manifest file")]
|
|
|
|
Serde(#[from] serde_yaml::Error),
|
|
|
|
}
|
2024-07-14 14:19:15 +01:00
|
|
|
|
|
|
|
#[derive(Debug, Error)]
|
|
|
|
#[non_exhaustive]
|
|
|
|
pub enum LockfileReadError {
|
|
|
|
#[error("io error reading lockfile file")]
|
|
|
|
Io(#[from] std::io::Error),
|
|
|
|
|
|
|
|
#[error("error deserializing lockfile file")]
|
|
|
|
Serde(#[from] serde_yaml::Error),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Error)]
|
|
|
|
#[non_exhaustive]
|
|
|
|
pub enum LockfileWriteError {
|
|
|
|
#[error("io error writing lockfile file")]
|
|
|
|
Io(#[from] std::io::Error),
|
|
|
|
|
|
|
|
#[error("error serializing lockfile file")]
|
|
|
|
Serde(#[from] serde_yaml::Error),
|
|
|
|
}
|
2024-03-25 16:29:31 +00:00
|
|
|
}
|