Skip to content

Commit

Permalink
Reorganized the project into a workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
Hirevo committed Apr 12, 2020
1 parent 61ec975 commit 501e8b4
Show file tree
Hide file tree
Showing 65 changed files with 344 additions and 151 deletions.
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 7 additions & 87 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,87 +1,7 @@
[package]
name = "alexandrie"
version = "0.1.0"
edition = "2018"
authors = ["Nicolas Polomack <nicolas@polomack.eu>"]
description = "An alternative crate registry, implemented in Rust."
repository = "https://github.com/Hirevo/alexandrie"
documentation = "https://crates.polomack.eu/docs/alexandrie"
keywords = ["crates", "cargo", "web", "registry"]
categories = ["development-tools"]
license = "MIT OR Apache-2.0"

default-run = "alexandrie"

[dependencies]
# core
tide = { version = "0.5.0" }
http = { version = "0.1.21" }

# data types
url = { version = "2.1.1" }
semver = { version = "0.9.0", features = ["serde"] }
chrono = { version = "0.4.10", features = ["serde"] }

# file formats
serde = { version = "1.0.104", features = ["derive"] }
json = { package = "serde_json", version = "1.0.44" }
toml = { version = "0.5.5" }

# binary parsing
byteorder = { version = "1.3.2" }
bytes = { version = "0.5.3" }

# (en|de)coding / hashing
ring = { version = "0.16.9" }
hex = { version = "0.4.0" }
base64 = { version = "0.11.0" }
percent-encoding = { version = "2.1.0" }

# database
diesel = { version = "1.4.3", features = ["r2d2", "chrono", "numeric"] }
diesel_migrations = { version = "1.4.0" }

# async primitives
async-std = { version = "1.4.0", features = ["unstable", "attributes"] }
futures = { version = "0.3.1" }

# error handling
thiserror = { version = "1.0.9" }

# README rendering
syntect = { version = "3.3.0" }
cmark = { package = "pulldown-cmark", version = "0.6.1" }
flate2 = { version = "1.0.13" }
tar = { version = "0.4.26" }

# frontend
handlebars = { version = "2.0.4", optional = true }
cookie = { version = "0.12.0", features = ["percent-encode"], optional = true }
time = { version = "0.1.42", optional = true }
num-format = { version = "0.4.0", optional = true }
bigdecimal = { version = "0.1.0", features = ["serde"], optional = true }

# git2
git2 = { version = "0.11.0", optional = true }

# logs
log = { version = "0.4.8" }
slog = { version = "2.5.2" }
slog-stdlog = { version = "4.0.0" }
slog-scope = { version = "4.3.0" }
slog-term = { version = "2.4.2" }
slog-async = { version = "2.3.0" }
slog-json = { version = "2.3.0" }

# miscellaneous
path-absolutize = { version = "1.1.7" }
mime_guess = { version = "2.0.1" }

[features]
# default = ["frontend", "sqlite"]
# default = ["frontend", "mysql"]
default = ["frontend", "postgres"]
frontend = ["handlebars", "num-format", "bigdecimal", "cookie", "time"]
mysql = ["diesel/mysql", "diesel_migrations/mysql"]
sqlite = ["diesel/sqlite", "diesel_migrations/sqlite"]
postgres = ["diesel/postgres", "diesel_migrations/postgres"]
[workspace]
members = [
"alexandrie",
"alexandrie-index",
"alexandrie-storage",
"alexandrie-rendering"
]
25 changes: 25 additions & 0 deletions alexandrie-index/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "alexandrie-index"
version = "0.1.0"
edition = "2018"
authors = ["Nicolas Polomack <nicolas@polomack.eu>"]
description = "The index management library for Alexandrie, an alternative crate registry."
repository = "https://github.com/Hirevo/alexandrie"
documentation = "https://crates.polomack.eu/docs/alexandrie"
keywords = ["crates", "cargo", "web", "registry"]
categories = ["development-tools"]
license = "MIT OR Apache-2.0"

[dependencies]
# data types
semver = { version = "0.9.0", features = ["serde"] }

# file formats
serde = { version = "1.0.104", features = ["derive"] }
json = { package = "serde_json", version = "1.0.44" }

# error handling
thiserror = { version = "1.0.9" }

# git2
git2 = { version = "0.11.0", optional = true }
5 changes: 3 additions & 2 deletions src/index/cli.rs → alexandrie-index/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use std::process::{Command, Stdio};
use semver::{Version, VersionReq};

use crate::error::Error;
use crate::index::tree::Tree;
use crate::index::{CrateVersion, Indexer};
use crate::models::CrateVersion;
use crate::tree::Tree;
use crate::Indexer;

/// The 'command-line' crate index management strategy type.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;

use serde::{Deserialize, Serialize};

use crate::index::cli::CommandLineIndex;
use crate::cli::CommandLineIndex;

/// The configuration struct for the 'command-line' index management strategy.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;

use serde::{Deserialize, Serialize};

use crate::index::git2::Git2Index;
use crate::git2::Git2Index;

/// The configuration struct for the 'git2' index management strategy.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ pub mod cli;
#[cfg(feature = "git2")]
pub mod git2;

use crate::config::index::cli::CommandLineIndexConfig;
use crate::index::Index;
use crate::config::cli::CommandLineIndexConfig;
use crate::Index;

#[cfg(feature = "git2")]
use crate::config::index::git2::Git2IndexConfig;
use crate::config::git2::Git2IndexConfig;

/// The configuration enum for index management strategies.
///
Expand Down
43 changes: 43 additions & 0 deletions alexandrie-index/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use semver::Version;
use thiserror::Error;

/// The Error type for the registry.
///
/// It can represent any kind of error the registry might encounter.
#[derive(Error, Debug)]
pub enum Error {
/// An IO error (file not found, access forbidden, etc...).
#[error("IO error: {0}")]
IOError(#[from] std::io::Error),
/// JSON (de)serialization error (invalid JSON parsed, etc...).
#[error("JSON error: {0}")]
JSONError(#[from] json::Error),
/// Git2 error.
#[error("libgit2 error: {0}")]
#[cfg(feature = "git2")]
Git2Error(#[from] git2::Error),
/// Other index-specific error (crate not found, etc...).
#[error("index-specific error: {0}")]
IndexError(#[from] IndexError),
}

/// The Error type for Alexandrie's own errors.
#[derive(Error, Debug)]
pub enum IndexError {
/// The requested crate cannot be found.
#[error("no crate named '{name}' found")]
CrateNotFound {
/// The requested crate's name.
name: String,
},
/// The published crate version is lower than the current hosted version.
#[error("the published version is too low (hosted version is {hosted}, and thus {published} <= {hosted})")]
VersionTooLow {
/// The krate's name.
krate: String,
/// The available hosted version.
hosted: Version,
/// The proposed version to be published.
published: Version,
},
}
5 changes: 3 additions & 2 deletions src/index/git2.rs → alexandrie-index/src/git2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use std::sync::Mutex;
use semver::{Version, VersionReq};

use crate::error::Error;
use crate::index::tree::Tree;
use crate::index::{CrateVersion, Indexer};
use crate::models::CrateVersion;
use crate::tree::Tree;
use crate::Indexer;

/// The 'git2' crate index management strategy type.
///
Expand Down
15 changes: 10 additions & 5 deletions src/index/mod.rs → alexandrie-index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ use semver::{Version, VersionReq};

/// Index management through `git` shell command invocations.
pub mod cli;
mod models;
mod tree;
/// Configuration-related types.
pub mod config;
/// Error-handling types.
pub mod error;

/// Index management using [**`libgit2`**][libgit2].
/// [libgit2]: https://libgit2.org
#[cfg(feature = "git2")]
pub mod git2;

pub use models::{CrateDependency, CrateDependencyKind, CrateVersion};
mod models;
mod tree;

pub use models::*;

use crate::cli::CommandLineIndex;
use crate::error::Error;
use crate::index::cli::CommandLineIndex;

#[cfg(feature = "git2")]
use crate::index::git2::Git2Index;
use crate::git2::Git2Index;

/// The crate indexing management strategy type.
///
Expand Down
File renamed without changes.
19 changes: 10 additions & 9 deletions src/index/tree.rs → alexandrie-index/src/tree.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use super::models::CrateVersion;
use crate::error::AlexError;
use crate::Error;
use semver::{Version, VersionReq};
use std::fs;
use std::io;
use std::io::BufRead;
use std::io::Write;
use std::path::PathBuf;

use semver::{Version, VersionReq};

use crate::error::{Error, IndexError};
use crate::models::CrateVersion;

#[derive(Debug, Clone, PartialEq)]
pub struct Tree {
path: PathBuf,
Expand All @@ -30,7 +31,7 @@ impl Tree {
pub fn match_record(&self, name: &str, req: VersionReq) -> Result<CrateVersion, Error> {
let path = self.compute_record_path(name);
let file = fs::File::open(path).map_err(|err| match err.kind() {
io::ErrorKind::NotFound => Error::from(AlexError::CrateNotFound {
io::ErrorKind::NotFound => Error::from(IndexError::CrateNotFound {
name: String::from(name),
}),
_ => Error::from(err),
Expand All @@ -41,7 +42,7 @@ impl Tree {
.flat_map(|ret: Option<CrateVersion>| ret.into_iter())
.filter(|krate| req.matches(&krate.vers))
.max_by(|k1, k2| k1.vers.cmp(&k2.vers));
Ok(found.ok_or_else(|| AlexError::CrateNotFound {
Ok(found.ok_or_else(|| IndexError::CrateNotFound {
name: String::from(name),
})?)
}
Expand Down Expand Up @@ -77,7 +78,7 @@ impl Tree {
.max_by(|k1, k2| k1.vers.cmp(&k2.vers))
.expect("at least one record should exist");
if record.vers <= latest.vers {
return Err(Error::from(AlexError::VersionTooLow {
return Err(Error::from(IndexError::VersionTooLow {
krate: record.name,
hosted: latest.vers,
published: record.vers,
Expand Down Expand Up @@ -106,7 +107,7 @@ impl Tree {
{
let path = self.compute_record_path(name);
let file = fs::File::open(path.as_path()).map_err(|err| match err.kind() {
io::ErrorKind::NotFound => Error::from(AlexError::CrateNotFound {
io::ErrorKind::NotFound => Error::from(IndexError::CrateNotFound {
name: String::from(name),
}),
_ => Error::from(err),
Expand All @@ -123,7 +124,7 @@ impl Tree {
.iter_mut()
.find(|krate| krate.vers == version)
.ok_or_else(|| {
Error::from(AlexError::CrateNotFound {
Error::from(IndexError::CrateNotFound {
name: String::from(name),
})
})?;
Expand Down
25 changes: 25 additions & 0 deletions alexandrie-rendering/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "alexandrie-rendering"
version = "0.1.0"
edition = "2018"
authors = ["Nicolas Polomack <nicolas@polomack.eu>"]
description = "The markdown rendering library for Alexandrie, an alternative crate registry."
repository = "https://github.com/Hirevo/alexandrie"
documentation = "https://crates.polomack.eu/docs/alexandrie"
keywords = ["crates", "cargo", "web", "registry"]
categories = ["development-tools"]
license = "MIT OR Apache-2.0"

[dependencies]
# data types
semver = { version = "0.9.0", features = ["serde"] }

# file formats
serde = { version = "1.0.104", features = ["derive"] }

# error handling
thiserror = { version = "1.0.9" }

# README rendering
syntect = { version = "3.3.0" }
cmark = { package = "pulldown-cmark", version = "0.6.1" }
File renamed without changes.
Loading

0 comments on commit 501e8b4

Please sign in to comment.