Class: Pod::Command::IceGenerate

Inherits:
Pod::Command show all
Defined in:
lib/pod/command/icegenerate.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ IceGenerate

Returns a new instance of IceGenerate.



15
16
17
18
19
20
# File 'lib/pod/command/icegenerate.rb', line 15

def initialize(argv)
  @name = argv.shift_argument
  @prefix = argv.shift_argument
  ENV['CP_PROJECT_NAME'] = @name
  super
end

Instance Method Details

#copy_resourcesObject



98
99
100
101
102
103
104
105
# File 'lib/pod/command/icegenerate.rb', line 98

def copy_resources
  Dir.chdir(@name) do
      UI.puts "Copying Resources from WhiteLabel".green
      system("cp -r #{BRIGHT_COMMON_RESOURCES} #{@name}/Resources/Common/")
      system("cp -r #{BRIGHT_DEFAULT_ASSETCATALOG} #{@name}/Resources/")
      system("cp #{BRIGHT_REVISION_SCRIPT} #{@name}/Scripts")
  end
end

#create_project_filesObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/pod/command/icegenerate.rb', line 62

def create_project_files
  #Create Directories
  FileUtils.mkdir_p("#{@name}/#{@name}")
  dirs = ["Supporting Files", "Skinners", "Resources", "Scripts"]
  dirs.each { |dir| FileUtils.mkdir_p("#{@name}/#{@name}//#{dir}/") }
  FileUtils.mkdir_p("#{@name}/#{@name}/Resources/Common/")

  #Create Root Files
  Dir.chdir "#{@name}" do
    File.delete(".gitignore") if File.exist?(".gitignore")
    Pod::Helper::Gitignore.new(@name,@prefix).file
    Pod::Helper::Podfile.new(@name,@prefix).file
    Pod::Helper::Readme.new(@name,@prefix).file
  end

  #Create Bootstrap Delegates
  Dir.chdir "#{@name}/#{@name}" do
    Pod::Helper::BootstrapDelegateH.new(@name,@prefix).file
    Pod::Helper::BootstrapDelegateM.new(@name,@prefix).file
  end

  #Create Supporting Files
  Dir.chdir "#{@name}/#{@name}/Supporting Files" do
    Pod::Helper::InfoPlist.new(@name,@prefix).file
    Pod::Helper::MainM.new(@name,@prefix).file
    Pod::Helper::PrefixHeader.new(@name,@prefix).file
  end

  #Create SidebarContainerViewControllerSkinner
  Dir.chdir "#{@name}/#{@name}/Skinners" do
    Pod::Helper::SidebarContainerViewControllerSkinnerH.new(@name,@prefix).file
    Pod::Helper::SidebarContainerViewControllerSkinnerM.new(@name,@prefix).file
  end

end

#create_xcode_projectObject



107
108
109
110
111
# File 'lib/pod/command/icegenerate.rb', line 107

def create_xcode_project
  UI.puts "Creating #{@name}.xcodeproj"
  builder = Helper::ProjectBuilder.new(@name,@prefix)
  project = builder.build_project
end

#new_project(name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pod/command/icegenerate.rb', line 33

def new_project(name)
  if File.directory?("#{name}")
    UI.puts"Fatal: Directory #{name} already exists. Please delete it and run again.".red
    return
  end

  FileUtils.mkdir_p("#{@name}")
  run_git_command("clone -b #{BRIGHT_BRANCH} #{BRIGHT_PROJECT_URL} ../#{@name}")

  create_project_files
  create_xcode_project
  copy_resources
  remove_unnecessary_folders

  run_pod_command('install')

  run_git_command("add -A")
  run_git_command(%q(commit -m "Autogenerated project with cocoapods-icemobile-plugin"))
  run_git_command("remote rm origin")
end

#remove_unnecessary_foldersObject



54
55
56
57
58
59
60
# File 'lib/pod/command/icegenerate.rb', line 54

def remove_unnecessary_folders
  Dir.foreach("./#{@name}") do |item|
    next if item == '.' or item == '..' or item.start_with?".git" or item.start_with?"Pod" or item.start_with?"README.md" or BRIGHT_REQUIRED.include?(item) or item.start_with?"#{@name}" 
      UI.puts "Removing #{item}".green
      FileUtils.rm_rf("./#{@name}/#{item}")
  end
end

#runObject



27
28
29
# File 'lib/pod/command/icegenerate.rb', line 27

def run
    new_project(@name)
end

#run_bundle_command(command) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/pod/command/icegenerate.rb', line 127

def run_bundle_command(command)
  Dir.chdir(@name) do
    _bundle_command = Gem.bin_path('bundler', 'bundle')

    require 'bundler'
    Bundler.with_clean_env do
      UI.puts "run bundle #{command}".green
      `"#{Gem.ruby}" "#{_bundle_command}" #{command}`
    end
  end
end

#run_git_command(command) ⇒ Object



113
114
115
116
117
118
# File 'lib/pod/command/icegenerate.rb', line 113

def run_git_command(command)
  Dir.chdir(@name) do
      UI.puts "run git #{command}".green
      system("git #{command}")
  end
end

#run_pod_command(command) ⇒ Object



120
121
122
123
124
125
# File 'lib/pod/command/icegenerate.rb', line 120

def run_pod_command(command)
  Dir.chdir(@name) do
      UI.puts "run pod #{command}".green
      system("pod #{command}")
  end
end

#validate!Object



22
23
24
25
# File 'lib/pod/command/icegenerate.rb', line 22

def validate!
  super
  help! "Usage: ice-generate <PROJECT_NAME> <PROJECT_PREFIX>" unless @name && @prefix
end