Skip to content

Commit

Permalink
source to target, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 23, 2023
1 parent a653d56 commit 19246df
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn copy_binaries(

/// Copies resources to a path.
fn copy_resources(resources: ResourcePaths<'_>, path: &Path) -> Result<()> {
for resource in resources.into_iter() {
for resource in resources.iter() {
let resource = resource?;
println!("cargo:rerun-if-changed={}", resource.path().display());
copy_file(resource.path(), path.join(resource.target()))?;
Expand Down
4 changes: 2 additions & 2 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@
]
},
"BundleResources": {
"description": "Definition for bundle resources. Can be either a list of paths to include or a map of target to source paths.",
"description": "Definition for bundle resources. Can be either a list of paths to include or a map of source to target paths.",
"anyOf": [
{
"description": "A list of paths to include.",
Expand All @@ -1249,7 +1249,7 @@
}
},
{
"description": "A map of target to source paths.",
"description": "A map of source to target paths.",
"type": "object",
"additionalProperties": {
"type": "string"
Expand Down
4 changes: 2 additions & 2 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,14 +621,14 @@ impl Default for WindowsConfig {
}

/// Definition for bundle resources.
/// Can be either a list of paths to include or a map of target to source paths.
/// Can be either a list of paths to include or a map of source to target paths.
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields, untagged)]
pub enum BundleResources {
/// A list of paths to include.
List(Vec<String>),
/// A map of target to source paths.
/// A map of source to target paths.
Map(HashMap<String, String>),
}

Expand Down
18 changes: 11 additions & 7 deletions core/tauri-utils/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<'a> ResourcePaths<'a> {

/// Returns the resource iterator that yields the source and target paths.
/// Needed when using [`Self::from_map`].
pub fn into_iter(self) -> ResourcePathsIter<'a> {
pub fn iter(self) -> ResourcePathsIter<'a> {
self.iter
}
}
Expand Down Expand Up @@ -165,8 +165,10 @@ impl<'a> Iterator for ResourcePathsIter<'a> {
}
self.current_pattern_is_valid = true;
return Some(Ok(Resource {
target: if let (Some(current_dest), Some(current_pattern)) = (&self.current_dest, &self.current_pattern) {
if current_pattern.0.contains("*") {
target: if let (Some(current_dest), Some(current_pattern)) =
(&self.current_dest, &self.current_pattern)
{
if current_pattern.0.contains('*') {
current_dest.join(path.file_name().unwrap())
} else {
current_dest.join(path.strip_prefix(&current_pattern.1).unwrap())
Expand Down Expand Up @@ -215,7 +217,7 @@ impl<'a> Iterator for ResourcePathsIter<'a> {
match &mut self.pattern_iter {
PatternIter::Slice(iter) => {
if let Some(pattern) = iter.next() {
self.current_pattern = Some((pattern.to_string(), normalize(&Path::new(pattern))));
self.current_pattern = Some((pattern.to_string(), normalize(Path::new(pattern))));
self.current_pattern_is_valid = false;
let glob = match glob::glob(pattern) {
Ok(glob) => glob,
Expand All @@ -226,14 +228,16 @@ impl<'a> Iterator for ResourcePathsIter<'a> {
}
}
PatternIter::Map(iter) => {
if let Some((dest, pattern)) = iter.next() {
self.current_pattern = Some((pattern.to_string(), normalize(&Path::new(pattern))));
if let Some((pattern, dest)) = iter.next() {
self.current_pattern = Some((pattern.to_string(), normalize(Path::new(pattern))));
self.current_pattern_is_valid = false;
let glob = match glob::glob(pattern) {
Ok(glob) => glob,
Err(error) => return Some(Err(error.into())),
};
self.current_dest.replace(resource_relpath(&PathBuf::from(dest)));
self
.current_dest
.replace(resource_relpath(&PathBuf::from(dest)));
self.glob_iter = Some(glob);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion tooling/bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ impl Settings {

/// Copies resources to a path.
pub fn copy_resources(&self, path: &Path) -> crate::Result<()> {
for resource in self.resource_files().into_iter() {
for resource in self.resource_files().iter() {
let resource = resource?;
let dest = path.join(resource.target());
common::copy_file(resource.path(), dest)?;
Expand Down
2 changes: 1 addition & 1 deletion tooling/bundler/src/bundle/windows/msi/wix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ fn generate_resource_data(settings: &Settings) -> crate::Result<ResourceMap> {

let mut added_resources = Vec::new();

for resource in settings.resource_files().into_iter() {
for resource in settings.resource_files().iter() {
let resource = resource?;

let resource_path = cwd
Expand Down
4 changes: 2 additions & 2 deletions tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@
]
},
"BundleResources": {
"description": "Definition for bundle resources. Can be either a list of paths to include or a map of target to source paths.",
"description": "Definition for bundle resources. Can be either a list of paths to include or a map of source to target paths.",
"anyOf": [
{
"description": "A list of paths to include.",
Expand All @@ -1249,7 +1249,7 @@
}
},
{
"description": "A map of target to source paths.",
"description": "A map of source to target paths.",
"type": "object",
"additionalProperties": {
"type": "string"
Expand Down

0 comments on commit 19246df

Please sign in to comment.