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
67 68 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 |
# File 'lib/cocoapods-vemars/command/project.rb', line 67 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
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/cocoapods-vemars/command/project.rb', line 114 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 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
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/cocoapods-vemars/command/project.rb', line 141 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") && services.include?("hotfix") hotfix = services["hotfix"] hotfix["dist_area"] = "cn" hotfix["debug"] = true services["hotfix"] = hotfix end if @selected_components.include?("VEH5Kit") && services.include?("h5") h5 = services["h5"] 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
134 135 136 137 138 |
# File 'lib/cocoapods-vemars/command/project.rb', line 134 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 |
# 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 Dir.chdir("Template_InHouse") do construct_plist end rename_project_files # replace_internal_project_settings end reinitialize_git_repo end end |
#language_switch ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/cocoapods-vemars/command/project.rb', line 100 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
57 58 59 60 61 62 63 64 65 |
# File 'lib/cocoapods-vemars/command/project.rb', line 57 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
188 189 190 191 |
# File 'lib/cocoapods-vemars/command/project.rb', line 188 def reinitialize_git_repo `rm -rf .git/` `git init` end |
#rename_project_files ⇒ Object
166 167 168 169 |
# File 'lib/cocoapods-vemars/command/project.rb', line 166 def rename_project_files renamer = ProjectRenamer.new("Template", basicInfo.name) renamer.execute end |
#replace_internal_project_settings ⇒ Object
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/cocoapods-vemars/command/project.rb', line 176 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
171 172 173 174 |
# File 'lib/cocoapods-vemars/command/project.rb', line 171 def tailor_demos tailor = DemoTailor.new(@components_details) tailor.execute end |