module WeexBuilder::IOSProject

Public Instance Methods

create(project_name) click to toggle source
# 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