-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to migrate tarmac-manifest.toml (#88)
- Loading branch information
1 parent
1114b0f
commit f84cdd3
Showing
7 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use std::{collections::BTreeMap, path::PathBuf, sync::Arc}; | ||
|
||
use anyhow::Context; | ||
use resvg::usvg::fontdb::Database; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::asset::Asset; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct TarmacManifest { | ||
inputs: BTreeMap<PathBuf, TarmacEntry>, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct TarmacEntry { | ||
id: u64, | ||
} | ||
|
||
pub async fn migrate_manifest(args: MigrateTarmacManifestArgs) -> anyhow::Result<()> { | ||
let tarmac_manifest_contents = std::fs::read_to_string(&args.manifest_path) | ||
.context("Failed to open tarmac-manifest.toml")?; | ||
let tarmac_manifest: TarmacManifest = toml::from_str(&tarmac_manifest_contents) | ||
.context("Failed to parse tarmac-manifest.toml")?; | ||
|
||
let mut lockfile = crate::LockFile::default(); | ||
|
||
for (path, entry) in tarmac_manifest.inputs { | ||
let content_path = args.manifest_path.with_file_name(&path); | ||
let content = match std::fs::read(&content_path) { | ||
Ok(content) => content, | ||
Err(error) => { | ||
if error.kind() == std::io::ErrorKind::NotFound { | ||
log::warn!( | ||
"Content file {} not found, skipping", | ||
content_path.display() | ||
); | ||
|
||
continue; | ||
} else { | ||
return Err(error).with_context(|| { | ||
format!("Failed to read content file {}", content_path.display()) | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
let font_db = Arc::new(Database::new()); | ||
|
||
let asset = Asset::new( | ||
path.to_string_lossy().to_string(), | ||
content, | ||
&path.extension().unwrap_or_default().to_string_lossy(), | ||
font_db, | ||
) | ||
.await | ||
.with_context(|| format!("Failed to create asset for {}", path.to_string_lossy()))?; | ||
|
||
lockfile.entries.insert( | ||
path.to_string_lossy().to_string(), | ||
crate::FileEntry { | ||
asset_id: entry.id, | ||
hash: asset.hash(), | ||
}, | ||
); | ||
} | ||
|
||
lockfile | ||
.write( | ||
&args | ||
.manifest_path | ||
.with_file_name(crate::lockfile::FILE_NAME), | ||
) | ||
.await | ||
.context("Failed to write Asphalt lockfile")?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(clap::Args)] | ||
pub struct MigrateTarmacManifestArgs { | ||
/// The path to the tarmac-manifest.toml file. | ||
#[clap(default_value = "tarmac-manifest.toml")] | ||
pub manifest_path: PathBuf, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod init; | ||
pub mod list; | ||
pub mod migrate_tarmac_manifest; | ||
pub mod sync; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters