mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 10:58:04 +08:00
* 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>
41 lines
1.3 KiB
Rust
41 lines
1.3 KiB
Rust
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(())
|
|
}
|