mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-04 02:08:12 +08:00
Move branding and package install into cargo-run (#4266)
* Move branding asset fetch into cargo-run * Move frontend npm install into cargo-run * Rename branding::ensure to branding::setup * Wording nits --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
use crate::cmd::prelude::*;
|
||||
use crate::{Error, workspace_dir};
|
||||
|
||||
const INFO_FILE: &str = ".branding";
|
||||
const DIR: &str = "branding";
|
||||
|
||||
pub fn setup() -> Result<(), Error> {
|
||||
let workspace = workspace_dir();
|
||||
let info_path = workspace.join(INFO_FILE);
|
||||
let dir_path = workspace.join(DIR);
|
||||
let marker_path = dir_path.join(INFO_FILE);
|
||||
|
||||
let info = std::fs::read_to_string(&info_path).map_err(|e| Error::Io(e, format!("reading '{}'", info_path.display())))?;
|
||||
|
||||
if let Ok(marker) = std::fs::read_to_string(&marker_path)
|
||||
&& marker == info
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut lines = info.lines().map(str::trim).filter(|l| !l.is_empty());
|
||||
let url = lines
|
||||
.next()
|
||||
.ok_or_else(|| Error::Io(std::io::Error::other("missing URL"), format!("parsing '{}'", info_path.display())))?;
|
||||
let sha256 = lines
|
||||
.next()
|
||||
.ok_or_else(|| Error::Io(std::io::Error::other("missing SHA-256"), format!("parsing '{}'", info_path.display())))?;
|
||||
|
||||
eprintln!("Downloading branding assets from <{url}>...");
|
||||
|
||||
if dir_path.exists() {
|
||||
std::fs::remove_dir_all(&dir_path).map_err(|e| Error::Io(e, format!("removing '{}'", dir_path.display())))?;
|
||||
}
|
||||
|
||||
utils::internal("download").args([url, sha256, DIR, "--extract", "--strip", "1"]).dir(&workspace).run()?;
|
||||
|
||||
std::fs::copy(&info_path, &marker_path).map_err(|e| Error::Io(e, format!("writing '{}'", marker_path.display())))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user