class Pod::VemarsProject
Attributes
basicInfo[R]
components_details[RW]
git_url[R]
language[R]
selected_components[R]
service_url[R]
sources[RW]
Public Class Methods
new(app_key, components, config_json, version=nil, bundle_id=nil, name='', language='objc', git_url, service_url,sources)
click to toggle source
# File lib/cocoapods-vemars/command/project.rb, line 26 def initialize(app_key, components, config_json, version=nil, bundle_id=nil, name='', language='objc', git_url, service_url,sources) @language = language @basicInfo = BasicInfo.new(app_key, bundle_id, name, version) @git_url = git_url @config_json = config_json @selected_components = components | (language == 'swift' ? %w[OneKit SwiftOneKit] : ['OneKit']) @components_details = [] @service_url = service_url @sources = sources end
Public Instance Methods
clone_template_project()
click to toggle source
# File lib/cocoapods-vemars/command/project.rb, line 66 def clone_template_project # puts 'cloning template' if File.directory?(basicInfo.name) || File.file?(basicInfo.name) system("rm -rf #{basicInfo.name}") end if git_url.end_with?(".git") cmd = "git clone #{git_url} #{basicInfo.name}" system(cmd) else destination = basicInfo.name FileUtils.mkdir_p(destination) content = URI.open(git_url) Zip::File.open_buffer(content) do |zip| zip.each do |f| fname = f.name if fname.start_with?("ve_Template_iOS") paths = fname.split("/") fname = fname.sub(paths[0],"") end fpath = File.join(destination, fname) zip.extract(f, fpath) unless File.exist?(fpath) end end end end
collect_components()
click to toggle source
# File lib/cocoapods-vemars/command/project.rb, line 108 def collect_components components_api = Components_api.new(@basicInfo.version,@service_url) all_components = components_api.getComponents @selected_components.each do |com| existed_com = all_components.find { |acom| acom.name == com } @components_details.append existed_com unless existed_com.nil? end end
construct_plist()
click to toggle source
# File lib/cocoapods-vemars/command/project.rb, line 127 def construct_plist content = File.read(@config_json) json = JSON.parse(content) json["project_info"]["app_id"] = json["project_info"]["app_id"].to_s services = Hash.new if @selected_components.include? "BDHotfix" services["bdhotfix"] = { "dist_area" => "cn", "domain_name" => "", "debug" => true} end if @selected_components.include? "VEH5Kit" services["jsbridge_services"] = { "auth_domain" => "", "auth_enable" => false} services["gecko_services"] = { "platform_domain" => "", "pattern" => "", "gecko_channels" => [], "gecko_access_key" => ""} end json["services"] = services File.open(Dir.pwd + "/onekit-config.plist", 'w') { |file| file.puts json.to_plist } end
construct_podfile()
click to toggle source
# File lib/cocoapods-vemars/command/project.rb, line 120 def construct_podfile template = PodfileTemplate.new(@basicInfo.version, @components_details, @sources) File.open('Podfile', "w") { |file| file.puts template.to_dsl } end
generate()
click to toggle source
# File lib/cocoapods-vemars/command/project.rb, line 37 def generate puts "generate project..." clone_template_project collect_components Dir.chdir(basicInfo.name) do language_switch tailor_demos Dir.chdir("Project") do construct_podfile Dir.chdir("Template_InHouse") do construct_plist end rename_project_files # replace_internal_project_settings end reinitialize_git_repo end end
language_switch()
click to toggle source
# File lib/cocoapods-vemars/command/project.rb, line 94 def language_switch if language == 'swift' puts "creating swift project..." system("rm -fr objc") system("mv swift/* ./") system("rm -fr ./swift") else puts "creating objc project..." system("rm -fr ./swift") system("mv objc/* ./") system("rm -fr objc") end end
patch(podfile_dir)
click to toggle source
# File lib/cocoapods-vemars/command/project.rb, line 56 def patch(podfile_dir) puts "patching project..." collect_components Dir.chdir(podfile_dir) do construct_plist patcher = Patcher.new(podfile_dir, @basicInfo.version, @components_details, @sources, @git_url) patcher.execute end end
project_folder()
click to toggle source
# File lib/cocoapods-vemars/command/project.rb, line 22 def project_folder File.join(Dir.pwd, "Project") end
reinitialize_git_repo()
click to toggle source
# File lib/cocoapods-vemars/command/project.rb, line 167 def reinitialize_git_repo `rm -rf .git/` `git init` end
rename_project_files()
click to toggle source
# File lib/cocoapods-vemars/command/project.rb, line 145 def rename_project_files renamer = ProjectRenamer.new("Template", basicInfo.name) renamer.execute end
replace_internal_project_settings()
click to toggle source
# File lib/cocoapods-vemars/command/project.rb, line 155 def replace_internal_project_settings Dir.glob(Dir.pwd + "/**/**/**/**").each do |name| next if Dir.exists? name text = File.read(name) basicInfo.string_replacements.each { |find, replace| text = text.gsub(find, replace) } File.open(name, "w") { |file| file.puts text } end end
tailor_demos()
click to toggle source
# File lib/cocoapods-vemars/command/project.rb, line 150 def tailor_demos tailor = DemoTailor.new(@components_details) tailor.execute end