Sha256: fb13634fafb1f94de9619527fa01b809a983d48b95c03e10f6aa26b46e2af02d

Contents?: true

Size: 1.82 KB

Versions: 4

Compression:

Stored size: 1.82 KB

Contents

class IB::Project
  attr_accessor :platform, :app_path, :resources_path, :pods_headers_path

  def initialize options={}
    @platform          = options[:platform] || detect_platform || :ios
    @app_path          = options[:app_path] || "app"
    @resources_path    = options[:resources_path] || "resources"
    @pods_headers_path = options[:pods_headers_path] || "vendor/Pods/Headers"
  end

  def detect_platform
    # TODO: find a better way to detect platform
    if defined?(Motion::Project::Config)
      if Motion::Project::App.config.respond_to?(:platforms)
        Motion::Project::App.config.platforms[0] == 'MacOSX' ? :osx : :ios
      end
    end
  end

  def app_files
    Motion::Project::App.config.files.select do |file|
      file =~ /^(\.\/)?app\//
    end
  end

  def write
    ib_project = "ib.xcodeproj"
    project = Xcodeproj::Project.new(ib_project)
    target = project.new_target(:static_library, 'ib', platform)

    resources = project.new_group("Resources")
    resources.path = resources_path

    support   = project.new_group("Supporting Files")
    support.path = ib_project

    pods      = project.new_group("Pods")
    pods.path = pods_headers_path

    generator = IB::Generator.new(detect_platform)
    generator.write(app_files, ib_project)

    support.new_file "ib.xcodeproj/Stubs.h"
    file = support.new_file "ib.xcodeproj/Stubs.m"
    target.add_file_references([ file ])

    resource_exts = %W{xcdatamodeld png jpg jpeg storyboard xib lproj}
    Dir.glob("#{resources_path}/**/*.{#{resource_exts.join(",")}}") do |file|
      resources.new_reference(file)
    end

    Dir.glob("#{pods_headers_path}/**/*.h") do |file|
      pods.new_reference(file)
    end

    %W{QuartzCore CoreGraphics CoreData}.each do |framework|
      target.add_system_framework framework
    end

    project.save(ib_project)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ib-0.4.3 lib/ib/project.rb
ib-0.4.2 lib/ib/project.rb
ib-0.4.1 lib/ib/project.rb
ib-0.4.0 lib/ib/project.rb