mirror of
https://github.com/yewprint/yewprint
synced 2024-11-22 11:33:04 +00:00
Fix CSS version to v3 (#135)
This commit is contained in:
parent
fd67f09ba5
commit
b8358f3ceb
3 changed files with 16 additions and 5 deletions
|
@ -51,6 +51,7 @@ fn download_css(package: &Package, force: bool) -> Result<()> {
|
|||
|
||||
let version = yewprint_css::download_from_npm_package(
|
||||
"@blueprintjs/docs-theme",
|
||||
"3.11.1",
|
||||
Path::new("package/lib/css/docs-theme.css"),
|
||||
&static_path.join("docs-theme.css"),
|
||||
)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "yewprint-css"
|
||||
version = "0.1.1"
|
||||
version = "0.2.0"
|
||||
authors = ["Cecile Tonglet <cecile.tonglet@cecton.com>"]
|
||||
edition = "2018"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
|
|
@ -2,10 +2,13 @@ use anyhow::{bail, Context, Result};
|
|||
use serde::Deserialize;
|
||||
use std::path::Path;
|
||||
|
||||
const LATEST_BLUEPRINT_WORKING_VERSION: &str = "3.54.0";
|
||||
|
||||
/// Download the CSS of Blueprint to a provided destination path.
|
||||
pub fn download_css(dest: impl AsRef<Path>) -> Result<()> {
|
||||
let version = download_from_npm_package(
|
||||
"@blueprintjs/core",
|
||||
LATEST_BLUEPRINT_WORKING_VERSION,
|
||||
Path::new("package/lib/css/blueprint.css"),
|
||||
dest,
|
||||
)
|
||||
|
@ -17,6 +20,7 @@ pub fn download_css(dest: impl AsRef<Path>) -> Result<()> {
|
|||
/// Download any file from NPM package's latest version.
|
||||
pub fn download_from_npm_package(
|
||||
package_name: &str,
|
||||
version: &str,
|
||||
src: impl AsRef<Path>,
|
||||
dest: impl AsRef<Path>,
|
||||
) -> Result<String> {
|
||||
|
@ -25,8 +29,14 @@ pub fn download_from_npm_package(
|
|||
let src = src.as_ref();
|
||||
let dest = dest.as_ref();
|
||||
|
||||
let info = reqwest::blocking::get(format!("https://registry.npmjs.org/{}", package_name))?
|
||||
.json::<PackageInfo>()?;
|
||||
let version = if version.is_empty() || version == "latest" {
|
||||
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!(
|
||||
"https://registry.npmjs.org/{}/-/{}-{}.tgz",
|
||||
|
@ -35,7 +45,7 @@ pub fn download_from_npm_package(
|
|||
.split_once('/')
|
||||
.map(|(_, name)| name)
|
||||
.unwrap_or(package_name),
|
||||
info.dist_tags.latest,
|
||||
version,
|
||||
))?
|
||||
.bytes()?;
|
||||
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 {
|
||||
let mut entry = entry.unwrap();
|
||||
entry.unpack(dest)?;
|
||||
Ok(info.dist_tags.latest)
|
||||
Ok(version)
|
||||
} else {
|
||||
bail!("could not find `{}` in archive!", src.display());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue