Class: Pod::VemarsProject
- Inherits:
-
Object
- Object
- Pod::VemarsProject
- Defined in:
- lib/cocoapods-vemars/command/project.rb
Instance Attribute Summary collapse
-
#basicInfo ⇒ Object
readonly
Returns the value of attribute basicInfo.
-
#components_details ⇒ Object
Returns the value of attribute components_details.
-
#demo_tag ⇒ Object
Returns the value of attribute demo_tag.
-
#git_url ⇒ Object
readonly
Returns the value of attribute git_url.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#selected_components ⇒ Object
readonly
Returns the value of attribute selected_components.
-
#service_url ⇒ Object
readonly
Returns the value of attribute service_url.
-
#sources ⇒ Object
Returns the value of attribute sources.
Instance Method Summary collapse
- #clone_template_project ⇒ Object
- #collect_components ⇒ Object
- #construct_plist ⇒ Object
- #construct_podfile ⇒ Object
- #generate ⇒ Object
-
#initialize(app_key, components, config_json, version = nil, bundle_id = nil, name = '', language = 'objc', git_url, service_url, sources) ⇒ VemarsProject
constructor
A new instance of VemarsProject.
- #language_switch ⇒ Object
- #patch(podfile_dir) ⇒ Object
- #project_folder ⇒ Object
- #reinitialize_git_repo ⇒ Object
- #rename_project_files ⇒ Object
- #replace_internal_project_settings ⇒ Object
- #tailor_demos ⇒ Object
Constructor Details
#initialize(app_key, components, config_json, version = nil, bundle_id = nil, name = '', language = 'objc', git_url, service_url, sources) ⇒ VemarsProject
Returns a new instance of VemarsProject.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cocoapods-vemars/command/project.rb', line 27 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 |
Instance Attribute Details
#basicInfo ⇒ Object (readonly)
Returns the value of attribute basicInfo.
14 15 16 |
# File 'lib/cocoapods-vemars/command/project.rb', line 14 def basicInfo @basicInfo end |
#components_details ⇒ Object
Returns the value of attribute components_details.
19 20 21 |
# File 'lib/cocoapods-vemars/command/project.rb', line 19 def components_details @components_details end |
#demo_tag ⇒ Object
Returns the value of attribute demo_tag.
21 22 23 |
# File 'lib/cocoapods-vemars/command/project.rb', line 21 def demo_tag @demo_tag end |
#git_url ⇒ Object (readonly)
Returns the value of attribute git_url.
16 17 18 |
# File 'lib/cocoapods-vemars/command/project.rb', line 16 def git_url @git_url end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
13 14 15 |
# File 'lib/cocoapods-vemars/command/project.rb', line 13 def language @language end |
#selected_components ⇒ Object (readonly)
Returns the value of attribute selected_components.
15 16 17 |
# File 'lib/cocoapods-vemars/command/project.rb', line 15 def selected_components @selected_components end |
#service_url ⇒ Object (readonly)
Returns the value of attribute service_url.
17 18 19 |
# File 'lib/cocoapods-vemars/command/project.rb', line 17 def service_url @service_url end |
#sources ⇒ Object
Returns the value of attribute sources.
20 21 22 |
# File 'lib/cocoapods-vemars/command/project.rb', line 20 def sources @sources end |
Instance Method Details
#clone_template_project ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cocoapods-vemars/command/project.rb', line 69 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 = "" if @demo_tag.nil? cmd = "git clone #{git_url} #{basicInfo.name}" else cmd = "git clone #{git_url} #{basicInfo.name} -b #{@demo_tag} --config advice.detachedHead=false" end 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 ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/cocoapods-vemars/command/project.rb', line 116 def collect_components components_api = Components_api.new(@basicInfo.version,@service_url) components_api.validate! 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 demo_com = all_components.find { |acom| acom.name == "ve_Template_iOS" } if !demo_com.nil? @demo_tag = demo_com.version end end |
#construct_plist ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/cocoapods-vemars/command/project.rb', line 144 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 = json["services"] if @selected_components.include?("BDHotfix") hotfix = {"host" => "https://plugin-patch-api.bytedance.com"} if services.include?("hotfix") hotfix = services["hotfix"] end hotfix["dist_area"] = "cn" hotfix["debug"] = true services["hotfix"] = hotfix end if @selected_components.include?("VEH5Kit") h5 = {"gecko_host" => "https://plugin-patch-api.bytedance.com","js_host" => "https://plugin-patch-api.bytedance.com"} if services.include?("h5") h5 = services["h5"] end h5["auth_enable"] = false h5["pattern"] = "" h5["gecko_channels"] = [] h5["gecko_access_key"] = "" services["h5"] = h5 end json["services"] = services File.open(Dir.pwd + "/onekit-config.plist", 'w') { |file| file.puts json.to_plist } end |
#construct_podfile ⇒ Object
137 138 139 140 141 |
# File 'lib/cocoapods-vemars/command/project.rb', line 137 def construct_podfile template = PodfileTemplate.new(@basicInfo.version, @components_details, @sources) File.open('Podfile', "w") { |file| file.puts template.to_dsl } end |
#generate ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cocoapods-vemars/command/project.rb', line 38 def generate puts "generate project..." collect_components clone_template_project Dir.chdir(basicInfo.name) do language_switch tailor_demos Dir.chdir("Project") do construct_podfile if !@config_json.nil? Dir.chdir("Template_InHouse") do construct_plist end end rename_project_files # replace_internal_project_settings end reinitialize_git_repo end end |
#language_switch ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cocoapods-vemars/command/project.rb', line 102 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) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/cocoapods-vemars/command/project.rb', line 59 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, @demo_tag) patcher.execute end end |
#project_folder ⇒ Object
23 24 25 |
# File 'lib/cocoapods-vemars/command/project.rb', line 23 def project_folder File.join(Dir.pwd, "Project") end |
#reinitialize_git_repo ⇒ Object
200 201 202 203 |
# File 'lib/cocoapods-vemars/command/project.rb', line 200 def reinitialize_git_repo `rm -rf .git/` `git init` end |
#rename_project_files ⇒ Object
178 179 180 181 |
# File 'lib/cocoapods-vemars/command/project.rb', line 178 def rename_project_files renamer = ProjectRenamer.new("Template", basicInfo.name) renamer.execute end |
#replace_internal_project_settings ⇒ Object
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/cocoapods-vemars/command/project.rb', line 188 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 ⇒ Object
183 184 185 186 |
# File 'lib/cocoapods-vemars/command/project.rb', line 183 def tailor_demos tailor = DemoTailor.new(@components_details) tailor.execute end |