cocoapods-vemars 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +109 -0
- data/LICENSE.txt +22 -0
- data/README.md +11 -0
- data/Rakefile +13 -0
- data/cocoapods-vemars.gemspec +23 -0
- data/lib/cocoapods-vemars.rb +13 -0
- data/lib/cocoapods-vemars/command.rb +1 -0
- data/lib/cocoapods-vemars/command/basicInfo.rb +52 -0
- data/lib/cocoapods-vemars/command/component.rb +25 -0
- data/lib/cocoapods-vemars/command/project.rb +140 -0
- data/lib/cocoapods-vemars/command/vemars.rb +34 -0
- data/lib/cocoapods-vemars/command/vemars/baselines.rb +22 -0
- data/lib/cocoapods-vemars/command/vemars/components.rb +40 -0
- data/lib/cocoapods-vemars/command/vemars/create.rb +92 -0
- data/lib/cocoapods-vemars/command/vemars/patch.rb +80 -0
- data/lib/cocoapods-vemars/gem_version.rb +3 -0
- data/lib/cocoapods-vemars/hook/podfile.rb +14 -0
- data/lib/cocoapods-vemars/hook/podfile_template.rb +110 -0
- data/lib/cocoapods-vemars/services/baselines_api.rb +31 -0
- data/lib/cocoapods-vemars/services/components_api.rb +60 -0
- data/lib/cocoapods-vemars/services/patcher.rb +198 -0
- data/lib/cocoapods-vemars/services/renamer.rb +88 -0
- data/lib/cocoapods-vemars/services/tailor.rb +38 -0
- data/lib/cocoapods_plugin.rb +1 -0
- data/plugins.rb +1 -0
- data/spec/command/vemars_spec.rb +12 -0
- data/spec/spec_helper.rb +50 -0
- metadata +102 -0
@@ -0,0 +1,198 @@
|
|
1
|
+
require_relative '../hook/podfile_template'
|
2
|
+
require_relative 'tailor'
|
3
|
+
require 'rexml/document'
|
4
|
+
include REXML
|
5
|
+
require "fileutils"
|
6
|
+
require 'tempfile'
|
7
|
+
require 'xcodeproj'
|
8
|
+
|
9
|
+
module Pod
|
10
|
+
class Patcher
|
11
|
+
include Pod
|
12
|
+
|
13
|
+
attr_reader :podfile_dir
|
14
|
+
attr_reader :template
|
15
|
+
|
16
|
+
def initialize(podfile_dir, baseline, components_details, source, git_url)
|
17
|
+
@podfile_dir = podfile_dir
|
18
|
+
@template = PodfileTemplate.new(baseline, components_details, source)
|
19
|
+
@components_details = components_details
|
20
|
+
@git_url = git_url
|
21
|
+
puts git_url
|
22
|
+
@hasInjectedSource = false
|
23
|
+
@hasInjectedVemarsPods = false
|
24
|
+
end
|
25
|
+
|
26
|
+
def execute
|
27
|
+
insert_plist
|
28
|
+
plugin_demos
|
29
|
+
patch_podfile
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
attr_accessor :hasInjectedSource
|
34
|
+
attr_accessor :hasInjectedVemarsPods
|
35
|
+
attr_reader :components_details
|
36
|
+
|
37
|
+
def patch_podfile
|
38
|
+
podfile_path = find_podfile
|
39
|
+
if podfile_path.nil? || podfile_path.empty?
|
40
|
+
UI.puts "can not file project Podfile "
|
41
|
+
return
|
42
|
+
end
|
43
|
+
UI.puts "patching project with podfile path #{podfile_path}"
|
44
|
+
|
45
|
+
tempfile = Tempfile.new('podfile_temp')
|
46
|
+
sourceAnchors = source_anchors(podfile_path)
|
47
|
+
targetAnchors = target_anchor(podfile_path)
|
48
|
+
|
49
|
+
File.open(podfile_path, 'r') do |f|
|
50
|
+
f.each_line{ |line|
|
51
|
+
pre_inject, post_inject = inject_source(sourceAnchors, line)
|
52
|
+
if pre_inject.empty?
|
53
|
+
pre_inject = inject_vemarsPodsDef(targetAnchors, line)
|
54
|
+
end
|
55
|
+
|
56
|
+
if post_inject.empty?
|
57
|
+
post_inject = inject_releasePodInTarget(line)
|
58
|
+
end
|
59
|
+
|
60
|
+
if !pre_inject.empty?
|
61
|
+
tempfile.puts pre_inject
|
62
|
+
end
|
63
|
+
tempfile.puts line
|
64
|
+
if !post_inject.empty?
|
65
|
+
tempfile.puts post_inject
|
66
|
+
end
|
67
|
+
}
|
68
|
+
end
|
69
|
+
tempfile.close
|
70
|
+
FileUtils.mv(tempfile.path, podfile_path)
|
71
|
+
end
|
72
|
+
|
73
|
+
def plugin_demos
|
74
|
+
clone_project
|
75
|
+
tailor_demos
|
76
|
+
cleanup
|
77
|
+
end
|
78
|
+
|
79
|
+
def clone_project
|
80
|
+
system("git clone #{@git_url} ./.vemars")
|
81
|
+
system("mv ./.vemars/DevPods ./DevPods")
|
82
|
+
end
|
83
|
+
|
84
|
+
def tailor_demos
|
85
|
+
tailor = DemoTailor.new(@components_details)
|
86
|
+
tailor.execute
|
87
|
+
end
|
88
|
+
|
89
|
+
def cleanup
|
90
|
+
system("rm -rf ./.vemars")
|
91
|
+
end
|
92
|
+
|
93
|
+
def find_podfile
|
94
|
+
locations = []
|
95
|
+
|
96
|
+
Dir.entries(Dir.pwd).select { |e| e.end_with?(".xcworkspace") }.each do |xcworkspace|
|
97
|
+
full_path = File.join(@podfile_dir, xcworkspace, "contents.xcworkspacedata")
|
98
|
+
if File.file?(full_path)
|
99
|
+
Document.new(File.new(full_path)).elements.each { |e|
|
100
|
+
e.elements.each ("FileRef"){ |ref|
|
101
|
+
locations << ref.attributes["location"]
|
102
|
+
}
|
103
|
+
}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
project = locations.reject { |e| e.include?("Pods/Pods.xcodeproj") }.map { |location|
|
108
|
+
File.expand_path("Podfile",File.dirname(File.join(@podfile_dir,location[6..-1])))
|
109
|
+
}.select { |full_path| File.file?(full_path) }
|
110
|
+
|
111
|
+
if project.empty?
|
112
|
+
|
113
|
+
full_path = File.join(@podfile_dir, "Podfile")
|
114
|
+
return full_path if File.file?(full_path)
|
115
|
+
|
116
|
+
full_path = File.join(@podfile_dir, "Project", "Podfile")
|
117
|
+
return full_path if File.file?(full_path)
|
118
|
+
end
|
119
|
+
|
120
|
+
if project.empty?
|
121
|
+
UI.puts "can not find Podfile in #{@podfile_dir}"
|
122
|
+
end
|
123
|
+
|
124
|
+
return project.first
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
def insert_plist
|
130
|
+
puts "insert plist"
|
131
|
+
plist_dir = Dir.pwd + "/onekit-config.plist"
|
132
|
+
Dir.entries(Dir.pwd).select { |e| e.end_with?(".xcodeproj") }.each do |xcodeproj|
|
133
|
+
full_path = File.join(@podfile_dir, xcodeproj)
|
134
|
+
puts "insert plist in :#{full_path}"
|
135
|
+
project = Xcodeproj::Project.open(full_path)
|
136
|
+
file = project.new_file(plist_dir)
|
137
|
+
main_target = project.targets.first
|
138
|
+
main_target.add_resources([file])
|
139
|
+
project.save
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
def source_anchors(podfile)
|
145
|
+
result = []
|
146
|
+
File.open podfile do |file|
|
147
|
+
result = file.find_all { |line| line.include?('source') }
|
148
|
+
end
|
149
|
+
return result
|
150
|
+
end
|
151
|
+
|
152
|
+
def target_anchor(podfile)
|
153
|
+
result = []
|
154
|
+
File.open podfile do |file|
|
155
|
+
result = file.find_all { |line| line.include?('target "') | line.include?("target '") }
|
156
|
+
end
|
157
|
+
return result
|
158
|
+
end
|
159
|
+
|
160
|
+
## return (pre-inject, post-inject)
|
161
|
+
def inject_source(anchor, line)
|
162
|
+
return '','' if @hasInjectedSource
|
163
|
+
|
164
|
+
pre_inject = ''
|
165
|
+
post_inject = ''
|
166
|
+
if anchor.empty?
|
167
|
+
pre_inject = @template.source_template
|
168
|
+
@hasInjectedSource = true
|
169
|
+
|
170
|
+
elsif line.include? anchor[anchor.length - 1]
|
171
|
+
post_inject = @template.source_template
|
172
|
+
@hasInjectedSource = true
|
173
|
+
end
|
174
|
+
return pre_inject,post_inject
|
175
|
+
end
|
176
|
+
|
177
|
+
## return pre_inject
|
178
|
+
def inject_vemarsPodsDef(anchor, line)
|
179
|
+
return '' if @hasInjectedVemarsPods
|
180
|
+
|
181
|
+
if !anchor.empty? && line.include?(anchor[0])
|
182
|
+
@hasInjectedVemarsPods = true
|
183
|
+
return @template.releasePod, ''
|
184
|
+
end
|
185
|
+
return ''
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
## return post_inject
|
190
|
+
def inject_releasePodInTarget(line)
|
191
|
+
if line.include?('target "') | line.include?("target '")
|
192
|
+
return "\trelease_pod \n\tpod 'App/Debug', :path => './DevPods/', :inhibitat_warnings => false"
|
193
|
+
end
|
194
|
+
return ''
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Pod
|
2
|
+
class ProjectRenamer
|
3
|
+
attr_reader :oldname
|
4
|
+
attr_reader :newname
|
5
|
+
|
6
|
+
attr_writer :processedPaths
|
7
|
+
|
8
|
+
def initialize(oldname, newname)
|
9
|
+
@oldname = oldname
|
10
|
+
@newname = newname
|
11
|
+
@processedPaths = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute
|
15
|
+
path = Dir.pwd
|
16
|
+
puts "#{path}"
|
17
|
+
if validatePath(path)
|
18
|
+
enumeratePath(path)
|
19
|
+
else
|
20
|
+
help! "Xcode project or workspace with name: #{@oldname} is not found in current path."
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private def validatePath(path)
|
25
|
+
projectPath = path + "/#{oldname}.xcodeproj"
|
26
|
+
workspace = path + "/#{oldname}.xcworkspace"
|
27
|
+
isValid = File.exist?(projectPath) || File.exist?(workspace)
|
28
|
+
return isValid
|
29
|
+
end
|
30
|
+
|
31
|
+
private def enumeratePath(path)
|
32
|
+
Dir.each_child(path) do |child|
|
33
|
+
childPath = path + "/#{child}"
|
34
|
+
if !@processedPaths.include?(childPath) && !shouldSkip(childPath)
|
35
|
+
processPath(childPath)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private def processPath(path)
|
41
|
+
# puts "Processing: #{path}"
|
42
|
+
if File.directory?(path)
|
43
|
+
enumeratePath(path)
|
44
|
+
elsif File.exist?(path)
|
45
|
+
updateContentsOfFile(path)
|
46
|
+
end
|
47
|
+
|
48
|
+
renameItem(path)
|
49
|
+
@processedPaths.push(path)
|
50
|
+
end
|
51
|
+
|
52
|
+
private def shouldSkip(element)
|
53
|
+
if element.include?(".DS_Store") ||
|
54
|
+
element.include?("Carthage") ||
|
55
|
+
element.include?("Pods") ||
|
56
|
+
element.include?("fastlane") ||
|
57
|
+
element.include?("build")
|
58
|
+
return true
|
59
|
+
end
|
60
|
+
|
61
|
+
extension = File.extname(element)
|
62
|
+
if extension.include?("appiconset") ||
|
63
|
+
extension.include?("json") ||
|
64
|
+
extension.include?("png") ||
|
65
|
+
extension.include?("xcuserstate")
|
66
|
+
return true
|
67
|
+
end
|
68
|
+
return false
|
69
|
+
end
|
70
|
+
|
71
|
+
private def updateContentsOfFile(path)
|
72
|
+
text = File.read(path)
|
73
|
+
text = text.gsub(oldname, newname)
|
74
|
+
File.open(path, "w") { |file| file.puts text }
|
75
|
+
end
|
76
|
+
|
77
|
+
private def renameItem(path)
|
78
|
+
oldItemName = File.basename(path)
|
79
|
+
if oldItemName.include?(oldname)
|
80
|
+
newItemName = oldItemName.gsub(oldname, newname)
|
81
|
+
directoryPath = File.dirname(path)
|
82
|
+
newPath = directoryPath + "/#{newItemName}"
|
83
|
+
File.rename(path, newPath)
|
84
|
+
# puts "--- Renamed: #{oldItemName} -> #{newItemName}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Pod
|
2
|
+
class DemoTailor
|
3
|
+
attr_reader :components_details
|
4
|
+
|
5
|
+
attr_writer :processedPaths
|
6
|
+
|
7
|
+
def initialize(components_details)
|
8
|
+
@components_details = components_details
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute
|
12
|
+
system("mkdir .vemars") unless Dir.exists? ".vemars"
|
13
|
+
system("mkdir .vemars/RedDemos")
|
14
|
+
system("mkdir .vemars/RedDemos/Base")
|
15
|
+
system("mkdir .vemars/RedDemos/Debug")
|
16
|
+
Dir.glob(Dir.pwd + "/DevPods/App/Base/Tasks/**").each do |name|
|
17
|
+
next unless Dir.exists? name
|
18
|
+
pod_name = name.split('/').last
|
19
|
+
next if pod_name == "OneKit"
|
20
|
+
next if @components_details.find {|com|
|
21
|
+
com.name == pod_name
|
22
|
+
}
|
23
|
+
system("mv #{name} #{Dir.pwd + "/.vemars/RedDemos/Base/#{pod_name}"}")
|
24
|
+
end
|
25
|
+
Dir.glob(Dir.pwd + "/DevPods/App/Debug/**").each do |name|
|
26
|
+
next unless Dir.exists? name
|
27
|
+
pod_name = name.split('/').last
|
28
|
+
next if pod_name == 'Cell' || pod_name == 'Public'
|
29
|
+
|
30
|
+
next if @components_details.find {|com|
|
31
|
+
com.name == pod_name
|
32
|
+
}
|
33
|
+
system("mv #{name} #{Dir.pwd + "/.vemars/RedDemos/Debug/#{pod_name}"}")
|
34
|
+
end
|
35
|
+
system("rm -rf .vemars/RedDemos")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'cocoapods-vemars/command'
|
data/plugins.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'cocoapods-vemars'
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
ROOT = Pathname.new(File.expand_path('../../', __FILE__))
|
3
|
+
$:.unshift((ROOT + 'lib').to_s)
|
4
|
+
$:.unshift((ROOT + 'spec').to_s)
|
5
|
+
|
6
|
+
require 'bundler/setup'
|
7
|
+
require 'bacon'
|
8
|
+
require 'mocha-on-bacon'
|
9
|
+
require 'pretty_bacon'
|
10
|
+
require 'pathname'
|
11
|
+
require 'cocoapods'
|
12
|
+
|
13
|
+
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
14
|
+
|
15
|
+
require 'cocoapods_plugin'
|
16
|
+
|
17
|
+
#-----------------------------------------------------------------------------#
|
18
|
+
|
19
|
+
module Pod
|
20
|
+
|
21
|
+
# Disable the wrapping so the output is deterministic in the tests.
|
22
|
+
#
|
23
|
+
UI.disable_wrap = true
|
24
|
+
|
25
|
+
# Redirects the messages to an internal store.
|
26
|
+
#
|
27
|
+
module UI
|
28
|
+
@output = ''
|
29
|
+
@warnings = ''
|
30
|
+
|
31
|
+
class << self
|
32
|
+
attr_accessor :output
|
33
|
+
attr_accessor :warnings
|
34
|
+
|
35
|
+
def puts(message = '')
|
36
|
+
@output << "#{message}\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
def warn(message = '', actions = [])
|
40
|
+
@warnings << "#{message}\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
def print(message)
|
44
|
+
@output << message
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
#-----------------------------------------------------------------------------#
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cocoapods-vemars
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- huangbomao@bytedance.com
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-07-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.2.15
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.2.15
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A short description of cocoapods-vemars.
|
42
|
+
email:
|
43
|
+
- huangbomao@bytedance.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- cocoapods-vemars.gemspec
|
55
|
+
- lib/cocoapods-vemars.rb
|
56
|
+
- lib/cocoapods-vemars/command.rb
|
57
|
+
- lib/cocoapods-vemars/command/basicInfo.rb
|
58
|
+
- lib/cocoapods-vemars/command/component.rb
|
59
|
+
- lib/cocoapods-vemars/command/project.rb
|
60
|
+
- lib/cocoapods-vemars/command/vemars.rb
|
61
|
+
- lib/cocoapods-vemars/command/vemars/baselines.rb
|
62
|
+
- lib/cocoapods-vemars/command/vemars/components.rb
|
63
|
+
- lib/cocoapods-vemars/command/vemars/create.rb
|
64
|
+
- lib/cocoapods-vemars/command/vemars/patch.rb
|
65
|
+
- lib/cocoapods-vemars/gem_version.rb
|
66
|
+
- lib/cocoapods-vemars/hook/podfile.rb
|
67
|
+
- lib/cocoapods-vemars/hook/podfile_template.rb
|
68
|
+
- lib/cocoapods-vemars/services/baselines_api.rb
|
69
|
+
- lib/cocoapods-vemars/services/components_api.rb
|
70
|
+
- lib/cocoapods-vemars/services/patcher.rb
|
71
|
+
- lib/cocoapods-vemars/services/renamer.rb
|
72
|
+
- lib/cocoapods-vemars/services/tailor.rb
|
73
|
+
- lib/cocoapods_plugin.rb
|
74
|
+
- plugins.rb
|
75
|
+
- spec/command/vemars_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
homepage: https://github.com/volcengine/ve_Template_iOS
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubygems_version: 3.0.9
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: A longer description of cocoapods-vemars.
|
100
|
+
test_files:
|
101
|
+
- spec/command/vemars_spec.rb
|
102
|
+
- spec/spec_helper.rb
|