podtool 1.0.0

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/podtool +91 -0
  3. data/lib/pod_tool.rb +133 -0
  4. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 81a12861d032b7313276cdc9824d6ad2386edb9688f2fac76d080a2a5b053897
4
+ data.tar.gz: 92789df3e8c2e62955226868d97b0bd48125391967411fd76944d4e5172c97d8
5
+ SHA512:
6
+ metadata.gz: b60a380c137d8ed782278ddea418ffa72bb1392a0a490ae8a405c4e20dc2af29cb86056a10e5fdc47ca0feedb54d3bc73662b5eb2faef9975e36bc8e67abcb87
7
+ data.tar.gz: 11cc5ad63505d3523e8d0b69596a3a45acbc077f7af0ea7a0343e78abd503e743d812b7a57f01ad01ac450629a50b4655bd97f3c20e2f235afffce8445061fab
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander/import'
5
+ require 'pod_tool'
6
+
7
+ program :name, 'podtool'
8
+ program :version, '1.0.0'
9
+ program :description, 'pod tools set'
10
+
11
+ command :parse do |c|
12
+ c.syntax = 'podtool parse [options]'
13
+ c.summary = 'parse Podfile to json'
14
+ c.description = 'parse Podfile to json use pod'
15
+ c.example 'description', 'podtool parse --podfile Example/Podfile'
16
+ c.option '--podfile FILE', 'Podfile path'
17
+ c.action do |args, _options|
18
+ PodTool.output_json(_options.podfile)
19
+ end
20
+ end
21
+
22
+ command :share do |c|
23
+ c.syntax = 'podtool share [options]'
24
+ c.summary = 'share one scheme of project'
25
+ c.description = 'share one scheme of project use xcodeproj gem'
26
+ c.example 'description', 'podtool share --project-path Pods/Pods.xcodeproj --pod-name KitPod'
27
+ c.option '--project-path FILE', 'project path'
28
+ c.option '--pod-name FILE', 'pod name'
29
+ c.action do |args, _options|
30
+ PodTool.share_pod_scheme(_options.project_path, _options.pod_name)
31
+ end
32
+ end
33
+
34
+ command :shareall do |c|
35
+ c.syntax = 'podtool shareall [options]'
36
+ c.summary = 'podtool shareall scheme'
37
+ c.description = 'podtool shareall scheme of project'
38
+ c.example 'description', 'podtool shareall --project-path Pods/Pods2.xcodeproj'
39
+ c.option '--project-path FILE', 'Some switch that does something'
40
+ c.action do |_args, _options|
41
+ PodTool.share_all_pod_scheme(_options.project_path)
42
+ end
43
+ end
44
+
45
+ command :removetarget do |c|
46
+ c.syntax = 'podtool removetarget [options]'
47
+ c.summary = 'remove one target'
48
+ c.description = 'remove one target use xcodeproj'
49
+ c.example 'description', 'podtool removetarget --project-path Pods/Pods.xcodeproj --pod-name KitPod'
50
+ c.option '--project-path FILE', 'Some switch that does something'
51
+ c.option '--pod-name FILE', 'Some switch that does something'
52
+ c.action do |args, _options|
53
+ PodTool.remove_target(_options.project_path, _options.pod_name)
54
+ end
55
+ end
56
+
57
+ command :removeTargetFrameSearchPath do |c|
58
+ c.syntax = 'podtool removeTargetFrameSearchPath [options]'
59
+ c.summary = 'remove one project target FRAMEWORK_SEARCH_PATHS special value'
60
+ c.description = 'remove one project target FRAMEWORK_SEARCH_PATHS special value use xcodeproj'
61
+ c.example 'description', 'command example'
62
+ c.option '--project-path FILE', 'Some switch that does something'
63
+ c.option '--target-name FILE', 'Some switch that does something'
64
+ c.option '--rm-name FILE', 'Some switch that does something'
65
+ c.action do |args, _options|
66
+ PodTool.remove_target_frame_search_path(_options.project_path, _options.target_name, _options.rm_name)
67
+ end
68
+ end
69
+
70
+ command :removePhase do |c|
71
+ c.syntax = 'podtool removePhase [options]'
72
+ c.summary = 'remove one project target one build_phases'
73
+ c.description = 'remove one project target one build_phases use Xcodeproj'
74
+ c.example 'description', 'command example'
75
+ c.option '--project-path FILE', 'Some switch that does something'
76
+ c.option '--target-name FILE', 'Some switch that does something'
77
+ c.option '--rm-name FILE', 'Some switch that does something'
78
+ c.action do |args, _options|
79
+ PodTool.remove_phase(_options.project_path, _options.target_name, _options.rm_name)
80
+ end
81
+ end
82
+
83
+ command :ud do |c|
84
+ c.syntax = 'url decode <org_url>'
85
+ c.summary = 'url decode'
86
+ c.description = 'url decode use ruby'
87
+ c.example 'description', 'command example'
88
+ c.action do |args, _options|
89
+ PodTool.unescape(args[0])
90
+ end
91
+ end
@@ -0,0 +1,133 @@
1
+ require 'cocoapods'
2
+ require 'json'
3
+ require 'xcodeproj'
4
+ require 'cocoapods-core'
5
+ require 'uri'
6
+ # tool of pod
7
+ class PodTool
8
+ # parse Cocoapods Podfile to json
9
+ #
10
+ # Example:
11
+ # >> PodfileTool.outputJson("/path_of_Podfile")
12
+ # => {json}
13
+ #
14
+ # Arguments:
15
+ # path: (path_of_Podfile)
16
+ # output to file name Podfile.json
17
+ # Example2:
18
+ # >> PodfileTool.outputJsonFile("/path_of_Podfile")
19
+ # => {json}
20
+ #
21
+ # Arguments:
22
+ # path: (path_of_Podfile)
23
+ def self.output_json(path)
24
+ if File.file?(path)
25
+ podfile_hash = Pod::Podfile.from_file(path).to_hash
26
+ podfile_json = JSON.pretty_generate(podfile_hash)
27
+ puts podfile_json
28
+ else
29
+ puts 'need Podfile Path!!!'
30
+ end
31
+ end
32
+
33
+ #
34
+ # share pod project scheme,Share a User Scheme. Basically this method move the xcscheme file from the xcuserdata folder to xcshareddata folder.
35
+ # Arguments:
36
+ # pods_project_path:(pods_project_path)
37
+ # Example3:
38
+ # >> PodfileTool.sharePodScheme("/path_of_Pod_project")
39
+ # => "Success share #{pod_name}"
40
+ #
41
+ #
42
+ def self.share_pod_scheme(pods_project_path, pod_name)
43
+ project = Xcodeproj::Project.open(pods_project_path)
44
+ schemes = Xcodeproj::Project.schemes(pods_project_path)
45
+ unless schemes.include? pod_name
46
+ Xcodeproj::XCScheme.share_scheme(project.path, pod_name)
47
+ end
48
+ puts "Success share #{pod_name}"
49
+ end
50
+
51
+ def self.share_all_pod_scheme(pods_project_path)
52
+ project = Xcodeproj::Project.open(pods_project_path)
53
+ project.targets.each do |e|
54
+ begin
55
+ Xcodeproj::XCScheme.share_scheme(project.path, e.name)
56
+ puts "Success share #{e.name}"
57
+ rescue => err
58
+ puts "Fail share #{e.name}"
59
+ puts err
60
+ end
61
+ end
62
+ project.save
63
+ end
64
+
65
+ #
66
+ # remove a target of project
67
+ # Arguments:
68
+ # project_path:(project_path)
69
+ # target_to_remove:(target_to_remove)
70
+ # Example4:
71
+ # >> PodfileTool.removeTarget(args[0], args[1])
72
+ # => puts "#{target.name} did remove from project!!"
73
+ #
74
+ #
75
+ def self.remove_target(project_path, target_to_remove)
76
+ project = Xcodeproj::Project.open(project_path)
77
+ project.targets.each do |target|
78
+ if target.name == target_to_remove
79
+ target.remove_from_project
80
+ puts "#{target.name} did remove from project!!"
81
+ end
82
+ end
83
+ project.save
84
+ end
85
+
86
+ #
87
+ # remove a target frame_search_path of project
88
+ # Arguments:
89
+ # project_path:(project_path)
90
+ # target_to_remove:(target_to_remove)
91
+ # frame_search_path:(frame_search_path)
92
+ # Example4:
93
+ # >> PodfileTool.removeTargetFrameSearchPath(args[0], args[1], args[1])
94
+ # => puts search_paths
95
+ #
96
+ #
97
+ def self.remove_target_frame_search_path(project_path, target_to_remove, frame_search_path)
98
+ project = Xcodeproj::Project.open(project_path)
99
+ project.targets.each do |target|
100
+ next unless target.name == target_to_remove
101
+ puts target.name
102
+ target.build_configurations.each do |configuration|
103
+ search_paths = configuration.build_settings['FRAMEWORK_SEARCH_PATHS'] ||= '$(inherited)'
104
+ if search_paths.is_a? Array
105
+ search_paths.delete_if { |e| e == frame_search_path }
106
+ end
107
+ puts "FRAMEWORK_SEARCH_PATHS:#{search_paths}"
108
+ end
109
+ end
110
+ project.save
111
+ end
112
+
113
+ def self.remove_phase(project_path, target_to_remove, p_toremove)
114
+ project = Xcodeproj::Project.open(project_path)
115
+ project.targets.each do |target|
116
+ # puts target.name
117
+ next unless target.name == target_to_remove
118
+ # puts target.methods
119
+ target.build_phases.each do |atarget|
120
+ puts atarget.display_name
121
+ if atarget.display_name == p_toremove
122
+ atarget.remove_from_project
123
+ project.save
124
+ puts "#{target.name} #{p_toremove} did remove"
125
+ end
126
+ end
127
+ end
128
+ end
129
+
130
+ def self.unescape(to)
131
+ puts URI.unescape(to)
132
+ end
133
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: podtool
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - dacaiguoguo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: pod tools set
14
+ email: dacaiguoguo@gmail.com
15
+ executables:
16
+ - podtool
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/podtool
21
+ - lib/pod_tool.rb
22
+ homepage: http://rubygems.org/gems/podtool
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.0.6
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: podtool fix Podfile, xcode project etc.
45
+ test_files: []