class GitignoreManager def initialize(gitignore_path = '.gitignore') @gitignore_path = gitignore_path.end_with?('.gitignore') ? gitignore_path : File.join(gitignore_path, '.gitignore') create_gitignore_if_not_exists end def self.ignore_redundant_files GitignoreManager.new(FilePath.project_root) .add_items([ "# Generated by Solara. Ignore redundant brand specific changes.", "**/artifacts/", "**/Artifacts/", "solara/brands/current_app.json", "solara/.solara/aliases/", "solara/.solara/solara_settings.json", ]) end def add_items(items) items.each do |item| add_item(item) end end def add_item(item) existing_items = read_gitignore if existing_items.include?(item) Solara.logger.debug("'#{item}' already exists in .gitignore") else File.open(@gitignore_path, 'a') do |file| file.puts(item) end Solara.logger.debug("Added '#{item}' to .gitignore") end end private def create_gitignore_if_not_exists unless File.exist?(@gitignore_path) File.open(@gitignore_path, 'w') do |file| file.puts("# Generated by Solara") file.puts("# Git ignore file") file.puts("# Add items to ignore below") end Solara.logger.debug("Created new .gitignore file at #{@gitignore_path}") end end def read_gitignore File.readlines(@gitignore_path).map(&:chomp) end end