Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 39 additions & 99 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ pacquet_registry = { version = "0.0.1", path = "crates/registry" }
pacquet_tarball = { version = "0.0.1", path = "crates/tarball" }
pacquet_package_json = { version = "0.0.1", path = "crates/package_json" }

clap = { version = "4" }
anyhow = { version = "1.0.71" }
clap = { version = "4", features = ["derive"] }
flate2 = { version = "1.0.26" }
futures-util = { version = "0.3.28" }
rayon = { version = "1.7.0" }
reqwest = { version = "0.11", features = ["json", "stream"] }
serde = { version = "1.0.164", features = ["derive"] }
serde_json = { version = "1.0.99" }
tar = { version = "0.4.38" }
thiserror = { version = "1.0.40" }
tokio = { version = "1" }
tokio = { version = "1", features = ["rt", "macros"] }

[workspace.metadata.workspaces]
allow_branch = "main"
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ path = "src/main.rs"
pacquet_registry = { workspace = true }
pacquet_package_json = { workspace = true }

anyhow = { workspace = true }
clap = { workspace = true }
rayon = { workspace = true }
tokio = { workspace = true }
29 changes: 17 additions & 12 deletions crates/cli/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
use clap::{Arg, Command};
use clap::{Parser, Subcommand};

fn init_package_command() -> Command {
Command::new("init").about("Initialize a package")
/// Experimental package manager for node.js written in rust.
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub subcommand: Subcommands,
}

fn add_package_command() -> Command {
Command::new("add").about("Add a package").arg(Arg::new("package"))
#[derive(Subcommand, Debug)]
pub enum Subcommands {
Init,
Add(AddArgs),
}

pub fn get_commands() -> Command {
Command::new("pacquet")
.bin_name("pacquet")
.version("alpha")
.author("Yagiz Nizipli")
.arg_required_else_help(true)
.subcommands([add_package_command(), init_package_command()])
#[derive(Parser, Debug)]
/// Add a package
pub struct AddArgs {
/// Name of the package
#[arg(short, long)]
pub package: String,
}
38 changes: 18 additions & 20 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
mod commands;

use anyhow::{Context, Result};
use clap::Parser;
use commands::{Cli, Subcommands};
use pacquet_package_json::PackageJson;
use pacquet_registry::RegistryManager;

use crate::commands::get_commands;

pub async fn run_commands() {
let matches = get_commands().get_matches();
let current_directory = std::env::current_dir().expect("current directory should exist");
pub async fn run_commands() -> Result<()> {
let current_directory =
std::env::current_dir().context("problem fetching current directory")?;
let cache_directory = current_directory.join(".pacquet").as_path().to_owned();
let node_modules = current_directory.join("node_modules").as_path().to_owned();

if !cache_directory.exists() {
std::fs::create_dir(&cache_directory).expect("cache folder creation failed");
std::fs::create_dir(&cache_directory).context("cache folder creation failed")?;
}

if !node_modules.exists() {
std::fs::create_dir(&node_modules).expect("node_modules folder creation failed");
std::fs::create_dir(&node_modules).context("node_modules folder creation failed")?;
}

let mut registry_manager = RegistryManager::new(cache_directory);

if let Some(subcommand) = matches.subcommand_matches("add") {
if let Some(package_name) = subcommand.get_one::<String>("package") {
registry_manager.get_package(package_name).await.expect("TODO: panic message");
let cli = Cli::parse();

match &cli.subcommand {
Subcommands::Init => {
let pkg = PackageJson::from_current_directory();
pkg.create_if_needed();
}
Subcommands::Add(args) => {
registry_manager.get_package(&args.package).await?;
Comment thread
steveklabnik marked this conversation as resolved.
}
} else if matches.subcommand_matches("init").is_some() {
let pkg = PackageJson::from_current_directory();
pkg.create_if_needed();
}
}

pub fn main() {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(run_commands())
Ok(())
}
11 changes: 5 additions & 6 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub fn main() {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(pacquet_cli::run_commands())
use anyhow::Result;

#[tokio::main(flavor = "current_thread")]
Comment thread
anonrig marked this conversation as resolved.
pub async fn main() -> Result<()> {
pacquet_cli::run_commands().await
}
1 change: 0 additions & 1 deletion crates/registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ repository.workspace = true
pacquet_tarball = { workspace = true }

futures-util = { workspace = true }
rayon = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/registry/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ pub enum RegistryError {
#[error("missing version `{0}` on package `${0}`")]
MissingVersionRelease(String, String),
#[error("network error while downloading `${0}`")]
Network(String),
#[error("filesystem error: `{0}`")]
FileSystem(String),
Network(#[from] reqwest::Error),
#[error("io error `${0}`")]
Io(#[from] std::io::Error),
#[error("serialization failed: `${0}")]
Serialization(String),
}
Loading