Module: WeexBuilder::IOSProject

Defined in:
lib/platform_ios.rb

Class Method Summary collapse

Class Method Details

.create(project_name) ⇒ Object



8
9
10
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
# File 'lib/platform_ios.rb', line 8

def create(project_name)
  # Clone the ios template project 
  template_url = "http://git.yanzijia.cn/huzhitui/__WEEX_TEMPLATE__iOS.git"
  project_dir = File.join(Dir.pwd, 'Platforms/iOS', "#{project_name}")
  return unless system "git clone #{template_url} #{project_dir}"

  # Change the dir name
  Dir.glob("#{project_dir}/__WEEX_TEMPLATE__*").each do |name|
    cmd = "mv #{name} #{project_dir}/#{project_name}"
    if /.xcodeproj$/ =~ name
      cmd << ".xcodeproj"
    end
    system cmd
  end

  podfile = File.join(project_dir, "Podfile")
  File.open(podfile, 'r') do |output|
    buffer = output.read.gsub(/__WEEX_TEMPLATE__/, "#{project_name}")
    File.open(podfile, 'w') { |input| input.write(buffer) }
  end

  # Update the project info.
  pbxproj = File.join(project_dir, "#{project_name}.xcodeproj", 'project.pbxproj')
  File.open(pbxproj, 'r') do |output|
    buffer = output.read.gsub(/__WEEX_TEMPLATE__/, "#{project_name}")
    File.open(pbxproj, 'w') { |input| input.write(buffer) }
  end

  # Open the project
  puts 'The Xcode Project has been Created Successfully.'

  # system 'pod install'

end