cocoapods-dongjia 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fe1262bed9c25b306334ca2209ed82ab194d6ae2acffa2ce1fbb5909cb9fffc
4
- data.tar.gz: e6a19a4bfa5c3ba0ce4e96d6589e059b125d661ce03780b3503b62c1de8bbf93
3
+ metadata.gz: efc0ab6aa826c7a42d8327bc53a3a9f64aefc1356ea2b7f8537c9acda1f58ddd
4
+ data.tar.gz: 7f5be68a76076ee849c8e93354f2172d9d00cbbc3a98c77105b7b1bbdbc8b79a
5
5
  SHA512:
6
- metadata.gz: da01ddfcb389cf6540e7d33ccc37d4fbd8ebbc3b56d3620a7aa79736fa681d6938f5a306a1e8371616e48ffde8faaabba455cc9ad2fc9f7cd32aea8e12bdb234
7
- data.tar.gz: be71f22d99add9e089c327dd3db70cfd437432af40628b36d9de22b6e404ab0886e93613c0ea8a1424b0522f131099c1f113609f15e6ec21f8f63bdf3889f1fb
6
+ metadata.gz: 4bb4f8b1e01471ae6699f761d8dc3b50e320a34c4e943f10ea60b31facffcd2598b3c52d7c9daaedc12869cdee66e059c97796c841a6f90d48bc9ab858756de5
7
+ data.tar.gz: af313e23c27a894121796b5e30f67847ea9fe53bc77d5c51b0b66900f28a9461594b1dae752d28a9aa520398171cdb2f0c51ac2b6229040bcdacc327d752feab
@@ -1,3 +1,5 @@
1
1
  require 'cocoapods-dongjia/command/reinstall'
2
2
  require 'cocoapods-dongjia/command/install'
3
- require 'cocoapods-dongjia/command/demo'
3
+ require 'cocoapods-dongjia/command/demo'
4
+ require 'cocoapods-dongjia/command/strip'
5
+ require 'cocoapods-dongjia/command/open'
@@ -0,0 +1,32 @@
1
+ require 'cocoapods'
2
+
3
+ module Pod
4
+
5
+ class Command
6
+
7
+ class Open < Command
8
+
9
+ self.summary = '快速打开项目的 .xcworkspace'
10
+
11
+ self.description = <<-DESC
12
+ 快速打开项目的 .xcworkspace
13
+ DESC
14
+
15
+ def validate!
16
+ super
17
+
18
+ workspace_list = Pathname.glob('*.xcworkspace')
19
+ @workspace_path = workspace_list.first if workspace_list.size == 1
20
+
21
+ help! '没有找到 xcworkspace' unless @workspace_path.exist?
22
+ end
23
+
24
+ def run
25
+ `open #{@workspace_path}`
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,169 @@
1
+ require 'cocoapods'
2
+ require 'set'
3
+ require 'pry'
4
+
5
+ module Pod
6
+
7
+ class Image
8
+ attr_accessor :dir
9
+ attr_accessor :name
10
+ attr_accessor :fuzzy_name
11
+ def initialize(dir, name)
12
+ @dir = dir
13
+ if name.end_with?('@2x') || name.end_with?('@3x')
14
+ name = name[0, name.length-3]
15
+ end
16
+ @name = name
17
+
18
+ # 只处理最后一段为数字,或分了三段及以上的命名形式
19
+ comps = name.split('_')
20
+ last = comps.last
21
+ if last.to_i > 0 || last.start_with?('0') || comps.count >= 3
22
+ @fuzzy_name = name[0, name.length - last.length]
23
+ else
24
+ @fuzzy_name = ''
25
+ end
26
+ end
27
+
28
+ def eql?(other)
29
+ @dir == other.dir && @name == other.name
30
+ end
31
+
32
+ def hash
33
+ [@dir, @name].hash
34
+ end
35
+
36
+ def fullpath
37
+ File.join(@dir, @name)
38
+ end
39
+ end
40
+
41
+ class Command
42
+
43
+ class Strip < Command
44
+
45
+ self.summary = '查找工程内所有无效资源'
46
+
47
+ self.description = <<-DESC
48
+ 查找工程内所有无效资源
49
+ DESC
50
+
51
+ def validate!
52
+ super
53
+
54
+ @img_exts = ['.png', '.jpg', '.jpeg', '.webp', '.gif']
55
+
56
+ @proj_paths = []
57
+ @proj_paths |= Pathname.glob('*.xcodeproj')
58
+ @proj_paths |= Pathname.glob('Pods/*.xcodeproj')
59
+
60
+ help! '未发现任何工程' unless @proj_paths.count > 0
61
+ end
62
+
63
+ # 遍历目录找出所有图片
64
+ def traverse(path, except_dirs, bk = nil)
65
+ dir = File.dirname(path)
66
+ ext = File.extname(path)
67
+ name = File.basename(path, ext)
68
+ basename = File.basename(path)
69
+ if except_dirs.include?(basename)
70
+ return
71
+ end
72
+ if File.directory?(path)
73
+ if ext == '.imageset'
74
+ # imageset 直接返回
75
+ bk.call(dir, name, ext)
76
+ else
77
+ Dir.foreach(path) do |name|
78
+ unless name.start_with?('.') || name.end_with?('.launchimage')
79
+ traverse(File.join(path, name), except_dirs, bk)
80
+ end
81
+ end
82
+ end
83
+ else
84
+ bk.call(dir, name, ext) if @img_exts.include?(ext)
85
+ end
86
+ end
87
+
88
+ # 获取源文件
89
+ def get_source_files
90
+ source_files = []
91
+ @proj_paths.each do |path|
92
+ proj = Xcodeproj::Project.open(path)
93
+ proj.targets.each do |target|
94
+ target.build_phases.each do |phase|
95
+ if phase.is_a?(Xcodeproj::Project::PBXSourcesBuildPhase)
96
+ source_files |= phase.files
97
+ end
98
+ end
99
+ end
100
+ end
101
+ source_files
102
+ end
103
+
104
+ # 获取所有图片资源
105
+ def get_images
106
+ images = Set[]
107
+ except_dirs = [
108
+ 'QYResource.bundle',
109
+ 'DJMate',
110
+ 'IQKeyboardManager',
111
+ 'EnterpriseEditionImages.xcassets',
112
+ 'MJRefresh.bundle',
113
+ 'AlipaySDK.bundle',
114
+ 'AppIcon.appiconset',
115
+ 'KPCameraImages.xcassets'
116
+ ]
117
+ except_files = [
118
+ 'image_placeholder',
119
+ 'register_add_avatar'
120
+ ]
121
+ bk = Proc.new do |dir, name, ext|
122
+ next if except_files.include?(name)
123
+ images << Image.new(dir, name)
124
+ end
125
+ traverse(Dir.pwd, except_dirs, bk)
126
+ images
127
+ end
128
+
129
+ # 分析
130
+ def analyze(source_files, images)
131
+ source_files.map { |x| x.file_ref.real_path }.each do | path |
132
+ File.open(path, 'r') do |f|
133
+ image_using = []
134
+ f.each_line do |line|
135
+ next unless line.include?('"')
136
+ images.each do |img|
137
+ if line.include?('"' + img.name)
138
+ image_using << img
139
+ else
140
+ # 根据下划线分割剔除最后一项,再尝试匹配
141
+ if !img.fuzzy_name.empty?
142
+ if line.include?('"' + img.fuzzy_name + '%') ||
143
+ line.include?('"' + img.fuzzy_name + '"')
144
+ image_using << img
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+ images = images - image_using
151
+ end
152
+ end
153
+ images
154
+ end
155
+
156
+ def run
157
+ images = analyze(get_source_files, get_images)
158
+ puts "无效资源文件:"
159
+ images.each do |img|
160
+ path = Pathname.new(img.fullpath).relative_path_from(Dir.pwd).to_s
161
+ puts " #{path}"
162
+ end
163
+ end
164
+
165
+ end
166
+
167
+ end
168
+
169
+ end
@@ -1,7 +1,9 @@
1
1
  module CocoapodsDongjia
2
- VERSION = "1.0.9"
2
+ VERSION = "1.1.0"
3
3
  UPDATE_DESC = <<-EOS
4
- - 修复 lpod 指令可能的出错
5
- - 自动处理 appspecs 的签名
4
+ - 增加 pod open 指令,用于快速打开工程
5
+ - 增加 pod strip 指令,用于查找无用资源
6
+ - 增加 LTO 开关
7
+ - 兼容新版 DJRouter 定义
6
8
  EOS
7
9
  end
@@ -2,7 +2,7 @@ require 'cocoapods-dongjia/command'
2
2
  require_relative 'dongjia_source'
3
3
  require_relative 'dongjia_branch_inspector'
4
4
  require_relative 'dongjia_enterprise_inspector'
5
- require_relative 'dongjia_warning_manager'
5
+ require_relative 'dongjia_pods_iterator'
6
6
  require_relative 'dongjia_router'
7
7
  require_relative 'dongjia_scheme_manager'
8
8
 
@@ -29,11 +29,8 @@ module Dongjia
29
29
 
30
30
  Pod::HooksManager.register('cocoapods-dongjia', :post_install) do |ctx, params|
31
31
 
32
- # 关闭工程内的一些警告
33
- WarningManager.turn_off_warnings(
34
- params[:turn_off_warnings],
35
- ctx.sandbox_root
36
- )
32
+ # 关闭警告 / 检查 LTO
33
+ PodsIterator.iterate(params, ctx.sandbox_root)
37
34
 
38
35
  # 处理 appspec 配置
39
36
  SchemeManager.setup(ctx, params)
@@ -0,0 +1,77 @@
1
+ require 'xcodeproj'
2
+
3
+ module Dongjia
4
+
5
+ class PodsIterator
6
+
7
+ # 关闭警告
8
+ def self.disable_warnings(config, target_name)
9
+ # 禁用非 DJ 开头 Pod 的警告
10
+ config.build_settings['GCC_WARN_INHIBIT_ALL_WARNINGS'] = "YES" unless target_name.start_with?('DJ')
11
+
12
+ # 不检测 block 中的隐式 self 调用
13
+ config.build_settings['CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF'] = "NO"
14
+
15
+ # 不检测已废弃的方法
16
+ config.build_settings['GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS'] = "NO"
17
+
18
+ # 允许 objc_msgSend
19
+ config.build_settings['ENABLE_STRICT_OBJC_MSGSEND'] = "NO"
20
+
21
+ # 不检测注释
22
+ config.build_settings['CLANG_WARN_DOCUMENTATION_COMMENTS'] = "NO"
23
+
24
+ # 不严格的原型校验
25
+ config.build_settings['CLANG_WARN_STRICT_PROTOTYPES'] = "NO"
26
+
27
+ # 强制设置 deployment 版本为 8.0
28
+ if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 8.0
29
+ config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "8.0"
30
+ end
31
+
32
+ # 关闭 bitcode
33
+ config.build_settings['ENABLE_BITCODE'] = "NO"
34
+ end
35
+
36
+ # 打开 LTO
37
+ def self.enable_lto(config)
38
+ config.build_settings['LLVM_LTO'] = 'YES_THIN' if config.name == 'Release'
39
+ end
40
+
41
+ # 遍历所有 Pod 工程配置
42
+ def self.iterate(params, sandbox_root)
43
+ turn_off_warnings = params[:turn_off_warnings]
44
+ lto_enabled = params[:lto_enabled]
45
+ return if (turn_off_warnings != true) && (lto_enabled != true)
46
+
47
+ Dir.foreach(sandbox_root).select{|f| f.end_with?('xcodeproj')}.each do |name|
48
+
49
+ proj = Xcodeproj::Project.open(File.join(sandbox_root, name))
50
+
51
+ if name != 'Pods.xcodeproj'
52
+ proj.build_configurations.each do | config |
53
+ # 强制设置 deployment 版本为 8.0
54
+ if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 8.0
55
+ config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "8.0"
56
+ end
57
+ end
58
+ end
59
+
60
+ # project 的每个 target 配置
61
+ proj.targets.select {|t| !t.name.start_with?('Pods')}.each do | target |
62
+ next if target.name.start_with?('Pods')
63
+ target.build_configurations.each do | config |
64
+ disable_warnings(config, target.name) if turn_off_warnings
65
+ enable_lto(config) if lto_enabled
66
+ end
67
+ end
68
+
69
+ proj.save
70
+
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -30,11 +30,11 @@ EOS
30
30
  @body = ''
31
31
  @prefix = nil
32
32
  prefix_len = 0
33
- if @defining_line.start_with?('@redirectObj(')
34
- @prefix = 'redirectObj'
33
+ if @defining_line.start_with?('@RedirectObj(') || @defining_line.start_with?('@redirectObj(')
34
+ @prefix = 'RedirectObj'
35
35
  prefix_len = @prefix.length + 2
36
- elsif @defining_line.start_with?('@redirect(')
37
- @prefix = 'redirect'
36
+ elsif @defining_line.start_with?('@Redirect(') || @defining_line.start_with?('@redirect(')
37
+ @prefix = 'Redirect'
38
38
  prefix_len = @prefix.length + 2
39
39
  end
40
40
 
@@ -69,7 +69,7 @@ EOS
69
69
  pre_line = nil
70
70
  file.each_line do |line|
71
71
  is_start = false
72
- if line.start_with?('@redirect')
72
+ if line.start_with?('@Redirect') || line.start_with?('@redirect')
73
73
  # 路由定义开始
74
74
  item = RouterItem.new(line)
75
75
  item.pre_line = pre_line
@@ -18,7 +18,7 @@ module Dongjia
18
18
  latest_version = info['version']
19
19
  v = CocoapodsDongjia::VERSION
20
20
 
21
- if v < latest_version
21
+ if Gem::Version.new(v) < Gem::Version.new(latest_version)
22
22
  update_desc = info['metadata']['update_desc']
23
23
  warnings = "cocoapods-dongjia #{latest_version} is available.\n\n"
24
24
  warnings << update_desc.rstrip << "\n\n"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-dongjia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiangzhuoyi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-29 00:00:00.000000000 Z
11
+ date: 2020-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -63,16 +63,18 @@ files:
63
63
  - lib/cocoapods-dongjia/command.rb
64
64
  - lib/cocoapods-dongjia/command/demo.rb
65
65
  - lib/cocoapods-dongjia/command/install.rb
66
+ - lib/cocoapods-dongjia/command/open.rb
66
67
  - lib/cocoapods-dongjia/command/reinstall.rb
68
+ - lib/cocoapods-dongjia/command/strip.rb
67
69
  - lib/cocoapods-dongjia/gem_version.rb
68
70
  - lib/cocoapods_plugin.rb
69
71
  - lib/dongjia_branch_inspector.rb
70
72
  - lib/dongjia_config.rb
71
73
  - lib/dongjia_enterprise_inspector.rb
74
+ - lib/dongjia_pods_iterator.rb
72
75
  - lib/dongjia_router.rb
73
76
  - lib/dongjia_scheme_manager.rb
74
77
  - lib/dongjia_source.rb
75
- - lib/dongjia_warning_manager.rb
76
78
  - lib/helper/dongjia_version_checker.rb
77
79
  - lib/helper/pod.rb
78
80
  - lib/helper/podfile_local_importer.rb
@@ -84,8 +86,10 @@ licenses:
84
86
  - MIT
85
87
  metadata:
86
88
  update_desc: |2
87
- - 修复 lpod 指令可能的出错
88
- - 自动处理 appspecs 的签名
89
+ - 增加 pod open 指令,用于快速打开工程
90
+ - 增加 pod strip 指令,用于查找无用资源
91
+ - 增加 LTO 开关
92
+ - 兼容新版 DJRouter 定义
89
93
  post_install_message:
90
94
  rdoc_options: []
91
95
  require_paths:
@@ -101,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
105
  - !ruby/object:Gem::Version
102
106
  version: '0'
103
107
  requirements: []
104
- rubygems_version: 3.0.4
108
+ rubygems_version: 3.1.2
105
109
  signing_key:
106
110
  specification_version: 4
107
111
  summary: A longer description of cocoapods-dongjia.
@@ -1,68 +0,0 @@
1
- require 'xcodeproj'
2
-
3
- module Dongjia
4
-
5
- class WarningManager
6
-
7
- def self.turn_off_warnings(turn_off, sandbox_root)
8
-
9
- return if (turn_off != true)
10
-
11
- Dir.foreach(sandbox_root).select{|f| f.end_with?('xcodeproj')}.each do |name|
12
-
13
- proj = Xcodeproj::Project.open(File.join(sandbox_root, name))
14
-
15
- if name != 'Pods.xcodeproj'
16
- proj.build_configurations.each do | config |
17
- # 强制设置 deployment 版本为 8.0
18
- if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 8.0
19
- config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "8.0"
20
- end
21
- end
22
- end
23
-
24
- # project 的每个 target 配置
25
- proj.targets.each do | target |
26
-
27
- next if target.name.start_with?('Pods')
28
-
29
- target.build_configurations.each do | config |
30
-
31
- # 禁用非 DJ 开头 Pod 的警告
32
- config.build_settings['GCC_WARN_INHIBIT_ALL_WARNINGS'] = "YES" unless target.name.start_with?('DJ')
33
-
34
- # 不检测 block 中的隐式 self 调用
35
- config.build_settings['CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF'] = "NO"
36
-
37
- # 不检测已废弃的方法
38
- config.build_settings['GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS'] = "NO"
39
-
40
- # 允许 objc_msgSend
41
- config.build_settings['ENABLE_STRICT_OBJC_MSGSEND'] = "NO"
42
-
43
- # 不检测注释
44
- config.build_settings['CLANG_WARN_DOCUMENTATION_COMMENTS'] = "NO"
45
-
46
- # 不严格的原型校验
47
- config.build_settings['CLANG_WARN_STRICT_PROTOTYPES'] = "NO"
48
-
49
- # 强制设置 deployment 版本为 8.0
50
- if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 8.0
51
- config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "8.0"
52
- end
53
-
54
- # 关闭 bitcode
55
- config.build_settings['ENABLE_BITCODE'] = "NO"
56
- end
57
-
58
- end
59
-
60
- proj.save
61
-
62
- end
63
-
64
- end
65
-
66
- end
67
-
68
- end