class TYCiCore::TemplateProject

Attributes

platform[R]
prefix[R]
remove_demo_target[R]
string_replacements[R]
xcodeproj_path[R]

Public Class Methods

new(configurator) click to toggle source
# File lib/tuya/ci/core/template/template_project.rb, line 9
def initialize(configurator)
        @configurator = configurator
  @xcodeproj_path = configurator.xcodeproj_path
  @platform = configurator.platform
  @remove_demo_target = configurator.remove_demo_project
  @prefix = configurator.prefix
end

Public Instance Methods

project_folder() click to toggle source
# File lib/tuya/ci/core/template/template_project.rb, line 33
def project_folder
  File.dirname @xcodeproj_path
end
rename_files() click to toggle source
# File lib/tuya/ci/core/template/template_project.rb, line 37
def rename_files
  # shared schemes have project specific names
  scheme_path = project_folder + "/PROJECT.xcodeproj/xcshareddata/xcschemes/"
  File.rename(scheme_path + "PROJECT.xcscheme", scheme_path +  @configurator.pod_name + "-Example.xcscheme")

  # rename xcproject
  File.rename(project_folder + "/PROJECT.xcodeproj", project_folder + "/" +  @configurator.pod_name + ".xcodeproj")

  unless @remove_demo_target
    # change app file prefixes
    ["CPDAppDelegate.h", "CPDAppDelegate.m", "CPDViewController.h", "CPDViewController.m"].each do |file|
      before = project_folder + "/PROJECT/" + file
      next unless File.exists? before

      after = project_folder + "/PROJECT/" + file.gsub("CPD", prefix)
      File.rename before, after
    end

    # add module impl
    ["PROJECTImpl.h", "PROJECTImpl.m"].each do |file|
      before = "#{@configurator.pod_name}/PROJECT/Classes/" + file

      next unless File.exists? before

      after = "#{@configurator.pod_name}/PROJECT/Classes/" + file.gsub("PROJECT", @configurator.pod_name)
      File.rename before, after
    end

    # rename project related files
    ["PROJECT-Info.plist", "PROJECT-Prefix.pch", "PROJECT.entitlements"].each do |file|
      before = project_folder + "/PROJECT/" + file
      next unless File.exists? before

      after = project_folder + "/PROJECT/" + file.gsub("PROJECT", @configurator.pod_name)
      File.rename before, after
    end
  end

end
rename_project_folder() click to toggle source
# File lib/tuya/ci/core/template/template_project.rb, line 77
def rename_project_folder
  if Dir.exist? project_folder + "/PROJECT"
    File.rename(project_folder + "/PROJECT", project_folder + "/" + @configurator.pod_name)
  end
end
replace_internal_project_settings() click to toggle source
# File lib/tuya/ci/core/template/template_project.rb, line 83
def replace_internal_project_settings

  all_dir = Dir.glob(project_folder + "/**/**/**/**")# + Dir.glob("#{@configurator.pod_name}/**/**/**/**")

  all_dir.each do |name|
    next if Dir.exists? name
    text = File.read(name)
    for find, replace in @string_replacements
        text = text.gsub(find, replace)
    end

    File.open(name, "w") { |file| file.puts text }
  end
end
run() click to toggle source
# File lib/tuya/ci/core/template/template_project.rb, line 17
def run
  @string_replacements = {
          "PROJECT_OWNER" => @configurator.owner_email,
    "PROJECT" => @configurator.pod_name,
    "CPD" => @configurator.prefix
  }

  replace_internal_project_settings

  @project = Xcodeproj::Project.open(@xcodeproj_path)
  @project.save

  rename_files
  rename_project_folder
end