Skip to content

Commit

Permalink
feat(copy): copy only content from temp to working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
perryrh0dan2 committed Feb 16, 2023
1 parent 5f95e8e commit 4b4baa4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 35 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tmpo"
description = "Command line utility to create new workspaces based on predefined templates"
version = "2.8.0"
version = "2.8.1"
authors = ["Thomas Pöhlmann <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -27,7 +27,7 @@ semver = "1.0.3"
convert_case = "0.5.0"
linked_hash_set = "0.1.4"
chrono = "0.4.13"
fs_extra = "1.2.0"
fs_extra = "1.3.0"

[dependencies.log4rs]
version = "1.0.0"
Expand Down
32 changes: 15 additions & 17 deletions src/action/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ impl Action {
// TODO find better solution
// try to avoid . in path
let target_dir = if workspace_directory != "." && workspace_directory != "./" {
current_dir.join(workspace_directory)
current_dir.join(&workspace_directory)
} else {
current_dir
};

// Check if directory already exits
if target_dir.exists() {
log::error!("Failed to create workspace!: Error: Already exists");
eprintln!("Failed to create workspace!: Error: Already exists");
log::error!("Failed to create workspace! {}: Error: Already exists", target_dir.to_string_lossy());
eprintln!("Failed to create workspace! {}: Error: Already exists", target_dir.to_string_lossy());
exit(1);
}

Expand Down Expand Up @@ -181,9 +181,6 @@ impl Action {

// Update inputs map
render_context.values.insert(value.key, input);

// // Update render context to use new input
// render_context.values = inputs.clone()
}
}

Expand All @@ -192,15 +189,15 @@ impl Action {
.unwrap();

// Create the temporary workspace
let tmp_workspace_path = tmp_dir.path().join(&workspace_name);
match fs::create_dir(&tmp_workspace_path) {
Ok(()) => (),
Err(error) => {
log::error!("{}", error);
eprintln!("{}", error);
exit(1);
}
};
let tmp_workspace_path = tmp_dir.path();
// match fs::create_dir(&tmp_workspace_path) {
// Ok(()) => (),
// Err(error) => {
// log::error!("{}", error);
// eprintln!("{}", error);
// exit(1);
// }
// };

// Initialize git if repository is given
// Done here so that the repository can be used in the scripts
Expand Down Expand Up @@ -233,7 +230,7 @@ impl Action {
}
};

// Create parent directories if they dont´t exist
// Create parent directories if they don´t exist
let mut parent_dir = target_dir.to_owned();
parent_dir.pop();
match fs::create_dir_all(&parent_dir) {
Expand Down Expand Up @@ -262,7 +259,8 @@ impl Action {
}
}

match dir::copy(tmp_workspace_path, target_dir, &dir::CopyOptions::new()) {
let copy_options = dir::CopyOptions::new().content_only(true);
match dir::copy(tmp_workspace_path, target_dir, &copy_options) {
Ok(_result) => (),
Err(error) => {
log::error!("{}", error);
Expand Down
18 changes: 9 additions & 9 deletions src/git/gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ extern crate base64;

#[derive(Deserialize, Debug)]
struct FileResponse {
file_name: String,
file_path: String,
size: usize,
encoding: String,
content_sha256: String,
r#ref: String,
blob_id: String,
commit_id: String,
last_commit_id: String,
// file_name: String,
// file_path: String,
// size: usize,
// encoding: String,
// content_sha256: String,
// r#ref: String,
// blob_id: String,
// commit_id: String,
// last_commit_id: String,
content: String,
}

Expand Down
8 changes: 4 additions & 4 deletions src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ pub fn render(text: &str, content: &Context) -> String {
}
};

// let escaped_text = text.replace(r"\", r"\\");
let escaped_text = text.replace(r"\", r"\\");
handlebars.register_escape_fn(no_escape);

// render the template
let result = match handlebars.render_template_with_context(&text, &context) {
let result = match handlebars.render_template_with_context(&escaped_text, &context) {
Ok(result) => result,
Err(error) => {
log::error!("Error rendering template: Error: {}", error);
text.to_owned()
}
};

return result;
return result.replace(r"\\", r"\");
}

#[cfg(test)]
Expand Down Expand Up @@ -177,7 +177,7 @@ mod tests {

#[test]
fn test_render_path() -> Result<(), Box<dyn std::error::Error>> {
let text = r"C:\test\test1234\\{{name}}.graphql.ts";
let text = r"C:\test\test1234\{{name}}.graphql.ts";
let mut values = HashMap::new();
values.insert(String::from("name"), String::from("ProductView"));
let content: Context = Context {
Expand Down

0 comments on commit 4b4baa4

Please sign in to comment.