diff --git a/Cargo.toml b/Cargo.toml index d6a348a..9350b1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["packages/*", "packages/*/example", "packages/*/tests/*"] +members = ["packages/*", "packages/*/example", "packages/*/tests/*", "scripts"] resolver = "2" [workspace.package] diff --git a/scripts/Cargo.toml b/scripts/Cargo.toml new file mode 100644 index 0000000..1f93e17 --- /dev/null +++ b/scripts/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "scripts" +description = "Scripts for Rust Floating UI." +publish = false + +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +version.workspace = true + +[dependencies] +octocrab = "0.38.0" +serde.workspace = true +tokio = { version = "1.37.0", features = ["full"] } +toml = "0.8.12" diff --git a/scripts/src/bin/check.rs b/scripts/src/bin/check.rs new file mode 100644 index 0000000..a45e295 --- /dev/null +++ b/scripts/src/bin/check.rs @@ -0,0 +1,104 @@ +use std::{collections::HashMap, error::Error, fs}; + +use octocrab::models::repos::Release; +use serde::{Deserialize, Serialize}; + +// #[derive(Clone, Copy, Debug, PartialEq, Eq)] +// enum Package { +// Core, +// Dom, +// Leptos, +// Utils, +// } + +// impl Package { +// fn upstream(&self) -> UpstreamPackage { +// match self { +// Package::Core => UpstreamPackage::Core, +// Package::Dom => UpstreamPackage::Dom, +// Package::Leptos => UpstreamPackage::Vue, +// Package::Utils => UpstreamPackage::Utils, +// } +// } +// } + +#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +enum UpstreamPackage { + Core, + Dom, + Utils, + Vue, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +struct UpstreamConfig { + releases: HashMap, +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + let current_releases = read_current_releases()?; + + println!("{:#?}", current_releases); + + let new_releases = fetch_new_releases(current_releases).await?; + + println!("{:#?}", new_releases); + + Ok(()) +} + +fn read_current_releases() -> Result, Box> { + let upstream_config: UpstreamConfig = toml::from_str(&fs::read_to_string("upstream.toml")?)?; + + Ok(upstream_config.releases) +} + +async fn fetch_new_releases( + current_releases: HashMap, +) -> Result>, octocrab::Error> { + let octocrab = octocrab::instance(); + + let repo = octocrab.repos("floating-ui", "floating-ui"); + + let releases_by_package: HashMap> = HashMap::new(); + let mut releases_to_find_count = current_releases.len(); + + while releases_to_find_count > 0 { + let releases = repo + .releases() + .list() + .per_page(10) + .page(1u32) + .send() + .await?; + + for release in releases { + if !release.tag_name.starts_with("@floating-ui/") { + continue; + } + + let tag_name = &release.tag_name["@floating-ui/".len()..]; + let (package_name, package_version) = + tag_name.split_at(tag_name.rfind('@').unwrap_or(tag_name.len())); + + let upstream_package: Option = toml::from_str(package_name).ok(); + if let Some(upstream_package) = upstream_package { + if current_releases + .get(&upstream_package) + .expect("Upstream package version should exist.") + == package_version + { + releases_to_find_count -= 1; + continue; + } + + // TODO + // let package_releases = releases_by_package.get_mut(&upstream_package); + } + } + } + + Ok(releases_by_package) +} diff --git a/scripts/src/lib.rs b/scripts/src/lib.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/scripts/src/lib.rs @@ -0,0 +1 @@ + diff --git a/upstream.toml b/upstream.toml new file mode 100644 index 0000000..781c599 --- /dev/null +++ b/upstream.toml @@ -0,0 +1,5 @@ +[releases] +core = "1.5.2" +dom = "1.6.2" +utils = "0.2.0" +vue = "1.0.5"