Skip to content

Commit

Permalink
haxelib install WORKING
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjamuffin99 committed Jan 3, 2025
1 parent c5d5c0d commit 212ad59
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 119 deletions.
120 changes: 10 additions & 110 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ gix = { version = "0.67.0", default-features = false, features = [
"verbose-object-parsing-errors",
"tracing-detail",
] }
haxeformat = "0.2.3"
human_bytes = "0.4.3"
indicatif = "0.17.8"
reqwest = { version = "0.12.9", features = ["json", "stream"] }
reqwest = { version = "0.12.9", features = ["json", "stream", "blocking"] }
semver = { version = "1.0.23", features = ["serde"] }
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.118"
tempfile = "3.13.0"
thiserror = "2.0.3"
tokio = { version = "1.41.0", features = ["full"] }
url = "2.5.3"
urlencoding = "2.1.3"
yansi = "1.0.1"
zip = "2.1.3"

Expand Down
46 changes: 40 additions & 6 deletions src/commands/haxelib_command.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
use anyhow::Result;
use anyhow::{anyhow, Ok, Result};
use gix::actor::signature::decode;
use reqwest::blocking::Client;

use crate::{
commands,
hmm::haxelib::{Haxelib, HaxelibType},
hmm::haxelib::{self, Haxelib, HaxelibType},
};

pub fn install_haxelib(name: &str, version: &Option<String>) -> Result<()> {
println!("Installing haxelib: {} {:?}", name, version);
let haxelib_install = Haxelib {
let mut haxelib_install = Haxelib {
name: name.to_string(),
haxelib_type: HaxelibType::Haxelib,
vcs_ref: version.clone(),
vcs_ref: None,
dir: None,
url: None,
version: version.clone(),
version: None,
};
match version {
Some(version) => haxelib_install.version = Some(version.to_string()),

None => {
// we need to query the latest version from haxelib
// haxelib url: lib.haxe.org/api/3.0/index.n/
// needs X-Haxe-Remoting header
// and __x param with the query
// in __x param, we can query with something like
// ay3:apiy16:getLatestVersionhay4:limeh

let serialized = format!("ay3:apiy16:getLatestVersionhay{}:{}h", name.len(), name);
let client = Client::new();

let resp = client
.get("https://lib.haxe.org/api/3.0/index.n/")
.header("X-Haxe-Remoting", "1")
.query(&[("__x", serialized)])
.send()?;

let resp = resp.text()?;
let resp_splits = resp.split(":").collect::<Vec<&str>>();
let decoded_resp = urlencoding::decode(resp_splits[1])?;

println!("Latest version of {} is {}", name, decoded_resp);

if (decoded_resp.starts_with("No such Project")) {
return Err(anyhow!("{}", decoded_resp)); // this haxelib doesn't exist
}

haxelib_install.version = Some(decoded_resp.to_string());
}
};
commands::install_command::install_from_haxelib(&haxelib_install)?;
Ok(())
Expand Down

0 comments on commit 212ad59

Please sign in to comment.