diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.rs | 87 | ||||
-rw-r--r-- | src/content.rs | 10 | ||||
-rw-r--r-- | src/main.rs | 41 |
3 files changed, 76 insertions, 62 deletions
diff --git a/src/commands.rs b/src/commands.rs index 9b7a9aa..a863705 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -39,29 +39,61 @@ pub fn initialize(root : &str) { } } } +} - let gd_ignore = &format!("{}/.gdignore", &root); - if !Path::new(gd_ignore).exists() { - match write(gd_ignore, content::create_gdignore_file()) { - Ok(_v) => (), - Err(_e) => { - utils::log_error("There was a problem creating the .gdignore file!"); - exit(1); - } - } - } +pub fn initialize_glam_files(root : &str) { + // Create glam.d/ folder if it doesn't exist + if !Path::new(&format!("{}/.glam.d/", root)).exists() { + let res = utils::run_shell_command( + "mkdir -p .glam.d", + &root, + false + ); + + utils::assert_res(&res, "Couldn't create .glam.d/ folder!"); + + let gd_ignore = &format!("{}/.glam.d/.gdignore", &root); + if !Path::new(gd_ignore).exists() { + match write(gd_ignore, content::create_gdignore_file()) { + Ok(_v) => (), + Err(_e) => { + utils::log_error("There was a problem creating the .gdignore file!"); + exit(1); + } + } + } + + utils::log_info("Created .glam.d/ folder"); + } + + // Create .glam file if it doesn't exist + if !Path::new(&format!("{}/.glam", root)).exists() { + fs::write(&format!("{}/.glam",root), + content::create_glam_file()) + .expect("Couldn't create .glam file!"); + utils::log_info("Created .glam file"); + } } -pub fn check_ignores(root : &str) { +pub fn check_initialization(root : &str) -> bool { let git_ignore = &format!("{}/.gitignore", &root); if !Path::new(git_ignore).exists() { utils::log_warning(".gitignore file does not exist!"); } - let gd_ignore = &format!("{}/.gdignore", &root); - if !Path::new(gd_ignore).exists() { - utils::log_warning(".gdignore file does not exist!"); + let mut ret = true; + let glam_file = &format!("{}/.glam", &root); + if !Path::new(glam_file).exists() { + utils::log_error(".glam file does not exist!"); + ret = false; } + + let glam_folder = &format!("{}/.glam.d/", &root); + if !Path::new(glam_folder).exists() { + utils::log_error(".glam.d/ folder does not exist!"); + ret = false; + } + return ret; } pub fn install_all_packages(root : &str, verbose : bool, copy_files : bool) { @@ -84,7 +116,6 @@ pub fn install_all_packages(root : &str, verbose : bool, copy_files : bool) { } pub fn install_package(root : &str, git_repo : &str, commit : &str, copy_files : bool, verbose : bool) { - let glam_file_path = format!("{}/.glam", root); // Find glam object or create one with default configuration @@ -193,6 +224,7 @@ pub fn remove_package(root : &str, package_name : &str, verbose : bool) { write_glam_file(&glam_file_path, &glam_object); } +// TODO: just "apply" don't apply changes to all repositories pub fn apply_changes(root : &str, package_name : &str, create_from_addon : &str, verbose : bool) { let glam_file_path = format!("{}/.glam", root); @@ -305,6 +337,8 @@ fn install_glam_package(root : &str, commit : &str, package : &mut GlamPackage, ); utils::assert_res(&res, "Couldn't create addons folder!"); + // TODO: Why this is throwing Err("cp: -t: No such file or directory\n") on mac? + println!("cp -rf .glam.d/{}/{}/* -t {}", package.name, package.source_folder, package.target_folder); // Copy addon repository content to target folder let res = utils::run_shell_command( @@ -411,29 +445,6 @@ fn remove_glam_package_files(root : &str, package : &GlamPackage, verbose : bool utils::assert_res(&res, "Couldn't copy files to addons!"); } -pub fn initialize_glam_files(root : &str) { - // Create glam.d/ folder if it doesn't exist - if !Path::new(&format!("{}/.glam.d/", root)).exists() { - let res = utils::run_shell_command( - "mkdir -p .glam.d", - &root, - false - ); - - utils::assert_res(&res, "Couldn't create .glam.d/ folder!"); - - utils::log_info("Created .glam.d/ folder"); - } - - // Create .glam file if it doesn't exist - if !Path::new(&format!("{}/.glam", root)).exists() { - fs::write(&format!("{}/.glam",root), - content::create_glam_file()) - .expect("Couldn't create .glam file!"); - utils::log_info("Created .glam file"); - } -} - fn clone_or_fetch_package(root : &str, package : &mut GlamPackage, verbose : bool) { // If glam package folder doesn't exist, clone project if !Path::new(&format!("{}/.glam.d/{}", root, package.name)).exists() { diff --git a/src/content.rs b/src/content.rs index d1ffa2d..94ea18d 100644 --- a/src/content.rs +++ b/src/content.rs @@ -1,9 +1,10 @@ pub fn create_gitignore_file() -> String { return -r#"# Godot-specific ignores +r#"# Godot 4+ ignores +.godot/ + +# Godot 3 ignores .import/ -export.cfg -export_presets.cfg # Imported translations (automatically generated from CSV files) *.translation @@ -18,8 +19,7 @@ data_*/ pub fn create_gdignore_file() -> String { return -r#"# Glam-specific ignores -.glam.d/"#.to_string(); +r#"# Hide this folder from Godot editor"#.to_string(); } pub fn create_glam_file() -> String { diff --git a/src/main.rs b/src/main.rs index 0412f52..7e317cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,9 @@ struct Cli { verbose: bool } +// TODO: Rename commands +// replace package to repository? + #[derive(Subcommand)] enum Commands { /// Initialize Godot project for GLAM @@ -80,47 +83,47 @@ fn main() { Commands::InstallPackage {git_repo, commit, no_copy} => { let root = commands::search_project_root(); - commands::check_ignores(&root); - commands::initialize_glam_files(&root); - commands::install_package(&root, git_repo, commit, !*no_copy, cli.verbose); + if commands::check_initialization(&root) { + commands::install_package(&root, git_repo, commit, !*no_copy, cli.verbose); + } }, Commands::Install { no_copy } => { let root = commands::search_project_root(); - commands::check_ignores(&root); - commands::initialize_glam_files(&root); - commands::install_all_packages(&root, cli.verbose, !*no_copy); + if commands::check_initialization(&root) { + commands::install_all_packages(&root, cli.verbose, !*no_copy); + } }, Commands::UpdatePackage { package_name, no_copy } => { let root = commands::search_project_root(); - commands::check_ignores(&root); - commands::initialize_glam_files(&root); - commands::update_package(&root, &package_name, cli.verbose, !*no_copy); + if commands::check_initialization(&root) { + commands::update_package(&root, &package_name, cli.verbose, !*no_copy); + } + }, Commands::Update { no_copy } => { let root = commands::search_project_root(); - commands::check_ignores(&root); - commands::initialize_glam_files(&root); - commands::update_all_packages(&root, cli.verbose, !*no_copy); + if commands::check_initialization(&root) { + commands::update_all_packages(&root, cli.verbose, !*no_copy); + } }, Commands::RemovePackage {package_name} => { let root = commands::search_project_root(); - commands::check_ignores(&root); - commands::initialize_glam_files(&root); - commands::remove_package(&root, &package_name, cli.verbose); + if commands::check_initialization(&root) { + commands::remove_package(&root, &package_name, cli.verbose); + } }, Commands::Apply {package_names, create_from_addon} => { let root = commands::search_project_root(); - commands::check_ignores(&root); - commands::initialize_glam_files(&root); - for package_name in package_names { + if commands::check_initialization(&root) { + for package_name in package_names { commands::apply_changes(&root, &package_name, &create_from_addon, cli.verbose); + } } - }, } } |