mirror of
https://github.com/SkyfallWasTaken/dinopkg.git
synced 2025-05-22 06:43:05 +00:00
WIP install command
This commit is contained in:
parent
32845b9006
commit
f59bb4def4
9 changed files with 44 additions and 11 deletions
|
@ -1,17 +1,17 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use dinopkg_package_json::PackageJson;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const NPM_REGISTRY_ROOT_URL: &str = "https://registry.npmjs.org";
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct PackageInfo {
|
||||
/// The name of the package, for example `discord.js`.
|
||||
name: String,
|
||||
|
||||
/// A map of versions to their respective version info.
|
||||
///
|
||||
///
|
||||
/// The key is the version string (e.g. `0.1.0`), and the value is the version's `package.json` info.
|
||||
versions: HashMap<String, PackageJson>,
|
||||
}
|
||||
|
@ -23,10 +23,13 @@ pub enum Error {
|
|||
}
|
||||
|
||||
impl PackageInfo {
|
||||
pub async fn get_package_info(package_name: &str, client: &reqwest::Client) -> Result<PackageInfo, Error> {
|
||||
pub async fn from_name(
|
||||
package_name: &str,
|
||||
client: &reqwest::Client,
|
||||
) -> Result<PackageInfo, Error> {
|
||||
let url = format!("{NPM_REGISTRY_ROOT_URL}/{package_name}");
|
||||
let response = client.get(&url).send().await?;
|
||||
let package_info = response.json::<PackageInfo>().await?;
|
||||
Ok(package_info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue