Fix CSS version to v3 (#135)

This commit is contained in:
Cecile Tonglet 2022-04-04 17:23:59 +01:00 committed by GitHub
parent fd67f09ba5
commit b8358f3ceb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 5 deletions

View file

@ -51,6 +51,7 @@ fn download_css(package: &Package, force: bool) -> Result<()> {
let version = yewprint_css::download_from_npm_package( let version = yewprint_css::download_from_npm_package(
"@blueprintjs/docs-theme", "@blueprintjs/docs-theme",
"3.11.1",
Path::new("package/lib/css/docs-theme.css"), Path::new("package/lib/css/docs-theme.css"),
&static_path.join("docs-theme.css"), &static_path.join("docs-theme.css"),
) )

View file

@ -1,6 +1,6 @@
[package] [package]
name = "yewprint-css" name = "yewprint-css"
version = "0.1.1" version = "0.2.0"
authors = ["Cecile Tonglet <cecile.tonglet@cecton.com>"] authors = ["Cecile Tonglet <cecile.tonglet@cecton.com>"]
edition = "2018" edition = "2018"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"

View file

@ -2,10 +2,13 @@ use anyhow::{bail, Context, Result};
use serde::Deserialize; use serde::Deserialize;
use std::path::Path; use std::path::Path;
const LATEST_BLUEPRINT_WORKING_VERSION: &str = "3.54.0";
/// Download the CSS of Blueprint to a provided destination path. /// Download the CSS of Blueprint to a provided destination path.
pub fn download_css(dest: impl AsRef<Path>) -> Result<()> { pub fn download_css(dest: impl AsRef<Path>) -> Result<()> {
let version = download_from_npm_package( let version = download_from_npm_package(
"@blueprintjs/core", "@blueprintjs/core",
LATEST_BLUEPRINT_WORKING_VERSION,
Path::new("package/lib/css/blueprint.css"), Path::new("package/lib/css/blueprint.css"),
dest, dest,
) )
@ -17,6 +20,7 @@ pub fn download_css(dest: impl AsRef<Path>) -> Result<()> {
/// Download any file from NPM package's latest version. /// Download any file from NPM package's latest version.
pub fn download_from_npm_package( pub fn download_from_npm_package(
package_name: &str, package_name: &str,
version: &str,
src: impl AsRef<Path>, src: impl AsRef<Path>,
dest: impl AsRef<Path>, dest: impl AsRef<Path>,
) -> Result<String> { ) -> Result<String> {
@ -25,8 +29,14 @@ pub fn download_from_npm_package(
let src = src.as_ref(); let src = src.as_ref();
let dest = dest.as_ref(); let dest = dest.as_ref();
let info = reqwest::blocking::get(format!("https://registry.npmjs.org/{}", package_name))? let version = if version.is_empty() || version == "latest" {
.json::<PackageInfo>()?; let info = reqwest::blocking::get(format!("https://registry.npmjs.org/{}", package_name))?
.json::<PackageInfo>()?;
info.dist_tags.latest
} else {
version.to_string()
};
let archive = reqwest::blocking::get(format!( let archive = reqwest::blocking::get(format!(
"https://registry.npmjs.org/{}/-/{}-{}.tgz", "https://registry.npmjs.org/{}/-/{}-{}.tgz",
@ -35,7 +45,7 @@ pub fn download_from_npm_package(
.split_once('/') .split_once('/')
.map(|(_, name)| name) .map(|(_, name)| name)
.unwrap_or(package_name), .unwrap_or(package_name),
info.dist_tags.latest, version,
))? ))?
.bytes()?; .bytes()?;
let mut archive = tar::Archive::new(flate2::read::GzDecoder::new(archive.deref())); let mut archive = tar::Archive::new(flate2::read::GzDecoder::new(archive.deref()));
@ -51,7 +61,7 @@ pub fn download_from_npm_package(
if let Some(entry) = blueprint_css { if let Some(entry) = blueprint_css {
let mut entry = entry.unwrap(); let mut entry = entry.unwrap();
entry.unpack(dest)?; entry.unpack(dest)?;
Ok(info.dist_tags.latest) Ok(version)
} else { } else {
bail!("could not find `{}` in archive!", src.display()); bail!("could not find `{}` in archive!", src.display());
} }