Class: Flatter::FileMover

Inherits:
Object
  • Object
show all
Defined in:
lib/xcflatter.rb

Instance Method Summary collapse

Instance Method Details

#move_all_files_with_ext_to_root_group(project_path, dest_file_ext, root_group_path) ⇒ Object

Move all files with specific extenstion from subfolders to root group



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/xcflatter.rb', line 11

def move_all_files_with_ext_to_root_group(project_path, dest_file_ext, root_group_path)
  project = Xcodeproj::Project.open(project_path)

  # Get root group
  if root_group_path.nil?
      root_group = project.main_group
  else
      root_group = project[root_group_path]
  end

  # Move files in FS
  base_dir_path = root_group.real_path.to_s

  # For each project file move to root group
  project.files.each do |file|
      file_ext = File.extname(file.path)
      if dest_file_ext == file_ext
          # Move files in FS hierarchy
          initial_path = file.real_path
          result_path = base_dir_path + '/' + File.basename(file.path)
          if result_path != initial_path
              FileUtils.mv(initial_path, result_path)
          end

          # Fix and move files in Xcode hierarchy
          file.set_source_tree("<group>")
          file.set_path(File.basename(file.path))
          file.move(root_group)
      end
  end

  project.save()
end