check_dependencies 0.1.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.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +77 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +2 -0
- data/bin/check_dependencies +228 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/check_dependencies.gemspec +20 -0
- data/lib/check_all_depencies/version.rb +3 -0
- data/lib/check_all_depencies.rb +228 -0
- metadata +85 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7b09ec9dbfff4ae05a366698f0c9a3cfa88ff6f6e22b00a8fb87a714fc779337
|
|
4
|
+
data.tar.gz: 9813997bb97acac6fee25a7167d28427ef7a20ee4d13acc2620a6cb13b7fcf57
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2c0482690d841b1ac71f8a75a7c73d4b582ed0875b35a6902ed1fce6cf98d4e192114017677785390bb49c25c0a9ac280b4ce986732a4d69ee20663227ed8cde
|
|
7
|
+
data.tar.gz: 95b16ef3c5a139b0f0a888a5eed4e51ef1c52ce5cf960b4b940e9a5d39b073524014cb44a8a867547e2fd3852bf886a2fd846b5392ae28aece9428d9d9e4d469
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
```markdown
|
|
2
|
+
# check_dependencies Gem
|
|
3
|
+
|
|
4
|
+
check_dependencies Gem is a Ruby gem that offers utilities to assist in managing CocoaPods dependencies within iOS projects. This gem provides functionality to dynamically switch between local path-based dependencies and remote git branch-based dependencies.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Install the gem by adding it to your Gemfile:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem 'check_dependencies', git: 'https://github.com/ITxiansheng/check_dependencies.git'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
$ bundle install
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or install it yourself as:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
$ gem install check_dependencies
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
The gem provides a command-line interface for interacting with its functionalities. You can use the `check_dependencies` command followed by appropriate options.
|
|
29
|
+
|
|
30
|
+
### Command Syntax
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
check_dependencies --lockPath LOCK_PATH --depWay DEP_WAY --configPath CONFIG_PATH
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Options
|
|
37
|
+
|
|
38
|
+
- `--lockPath LOCK_PATH`: Specifies the path to your Podfile.lock file.
|
|
39
|
+
- `--depWay DEP_WAY`: Specifies the dependency mode. This can be either `path` for local path dependencies or `branch` for remote git branch dependencies.
|
|
40
|
+
- `--configPath CONFIG_PATH`: Specifies the path to the configuration file containing dependency configurations.
|
|
41
|
+
|
|
42
|
+
### Example
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
check_dependencies --lockPath ./Podfile.lock --depWay path --configPath ./repo_configs.txt
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Functions Overview
|
|
49
|
+
|
|
50
|
+
The gem provides the following key functionalities:
|
|
51
|
+
|
|
52
|
+
- Parsing `Podfile.lock` content to extract pod dependencies.
|
|
53
|
+
- Generating Podfile entries for local path or remote git branch dependencies.
|
|
54
|
+
- Processing and formatting dependencies for correct integration into Podfiles.
|
|
55
|
+
|
|
56
|
+
## Workflow
|
|
57
|
+
|
|
58
|
+
1. **Configuration Preparation**: Prepare the `repo_configs` file with the necessary configuration for each library. This file should map library names to their configuration, including local path, branch name, and git URL.
|
|
59
|
+
|
|
60
|
+
2. **Running the Gem**: Execute the gem with the required options. Based on the specified `depWay`, the gem will process the `Podfile.lock` file and the `repo_configs` to output the necessary Podfile entries.
|
|
61
|
+
|
|
62
|
+
3. **Integration**: After generating the Podfile entries, integrate them into your Podfile as needed. This allows you to switch between using local versions of libraries (for development or debugging) and their remote versions (for production or shared development).
|
|
63
|
+
|
|
64
|
+
## Note
|
|
65
|
+
|
|
66
|
+
- Ensure that the `repo_configs` file is properly formatted and from a trusted source to avoid potential security risks.
|
|
67
|
+
|
|
68
|
+
## Contributing
|
|
69
|
+
|
|
70
|
+
Bug reports and pull requests are welcome on GitHub at [example/check_dependencies](https://github.com/ITxiansheng/check_dependencies). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ITxiansheng/check_dependencies/blob/main/CODE_OF_CONDUCT.md).
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
This README provides an overview of the gem's installation, usage, functions, workflow, notes, contributing guidelines, and license information. Adjust as needed for your specific project and preferences.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 ITxiansheng
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
```markdown
|
|
2
|
+
# check_dependencies Gem
|
|
3
|
+
|
|
4
|
+
check_dependencies Gem is a Ruby gem that offers utilities to assist in managing CocoaPods dependencies within iOS projects. This gem provides functionality to dynamically switch between local path-based dependencies and remote git branch-based dependencies.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Install the gem by adding it to your Gemfile:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem 'check_dependencies', git: 'https://github.com/ITxiansheng/check_dependencies.git'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
$ bundle install
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or install it yourself as:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
$ gem install check_dependencies
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
The gem provides a command-line interface for interacting with its functionalities. You can use the `check_dependencies` command followed by appropriate options.
|
|
29
|
+
|
|
30
|
+
### Command Syntax
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
check_dependencies --lockPath LOCK_PATH --depWay DEP_WAY --configPath CONFIG_PATH
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Options
|
|
37
|
+
|
|
38
|
+
- `--lockPath LOCK_PATH`: Specifies the path to your Podfile.lock file.
|
|
39
|
+
- `--depWay DEP_WAY`: Specifies the dependency mode. This can be either `path` for local path dependencies or `branch` for remote git branch dependencies.
|
|
40
|
+
- `--configPath CONFIG_PATH`: Specifies the path to the configuration file containing dependency configurations.
|
|
41
|
+
|
|
42
|
+
### Example
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
check_dependencies --lockPath ./Podfile.lock --depWay path --configPath ./repo_configs.txt
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Functions Overview
|
|
49
|
+
|
|
50
|
+
The gem provides the following key functionalities:
|
|
51
|
+
|
|
52
|
+
- Parsing `Podfile.lock` content to extract pod dependencies.
|
|
53
|
+
- Generating Podfile entries for local path or remote git branch dependencies.
|
|
54
|
+
- Processing and formatting dependencies for correct integration into Podfiles.
|
|
55
|
+
|
|
56
|
+
## Workflow
|
|
57
|
+
|
|
58
|
+
1. **Configuration Preparation**: Prepare the `repo_configs` file with the necessary configuration for each library. This file should map library names to their configuration, including local path, branch name, and git URL.
|
|
59
|
+
|
|
60
|
+
2. **Running the Gem**: Execute the gem with the required options. Based on the specified `depWay`, the gem will process the `Podfile.lock` file and the `repo_configs` to output the necessary Podfile entries.
|
|
61
|
+
|
|
62
|
+
3. **Integration**: After generating the Podfile entries, integrate them into your Podfile as needed. This allows you to switch between using local versions of libraries (for development or debugging) and their remote versions (for production or shared development).
|
|
63
|
+
|
|
64
|
+
## Note
|
|
65
|
+
|
|
66
|
+
- Ensure that the `repo_configs` file is properly formatted and from a trusted source to avoid potential security risks.
|
|
67
|
+
|
|
68
|
+
## Contributing
|
|
69
|
+
|
|
70
|
+
Bug reports and pull requests are welcome on GitHub at [example/check_dependencies](https://github.com/ITxiansheng/check_dependencies). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ITxiansheng/check_dependencies/blob/main/CODE_OF_CONDUCT.md).
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
This README provides an overview of the gem's installation, usage, functions, workflow, notes, contributing guidelines, and license information. Adjust as needed for your specific project and preferences.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
|
|
2
|
+
#!/usr/bin/env ruby
|
|
3
|
+
# Analyzes the Podfile.lock content to extract pod dependencies
|
|
4
|
+
def analyze_podfile_lock(podfile_lock_content)
|
|
5
|
+
unless podfile_lock_content.is_a?(String)
|
|
6
|
+
raise ArgumentError, 'podfile_lock_content must be a string.'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
pods_section_match = podfile_lock_content.match(/^PODS:\n(.*?)(?=\n\n|\z)/m)
|
|
10
|
+
if pods_section_match
|
|
11
|
+
pods_section_content = pods_section_match[1]
|
|
12
|
+
pods_lines = pods_section_content.split("\n")
|
|
13
|
+
pods_lines.map(&:strip)
|
|
14
|
+
else
|
|
15
|
+
raise 'PODS section not found in the provided Podfile.lock content.'
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Reads the local Podfile.lock content
|
|
20
|
+
def read_local_podfile_lock(file_path)
|
|
21
|
+
unless File.exist?(file_path)
|
|
22
|
+
raise "File not found: #{file_path}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
podfile_lock_content = File.read(file_path)
|
|
26
|
+
analyze_podfile_lock(podfile_lock_content)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Extracts unique specs from dependencies
|
|
30
|
+
def extract_unique_dependencies(pods)
|
|
31
|
+
unless pods.is_a?(Array)
|
|
32
|
+
raise ArgumentError, 'Input must be an array.'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
return [] if pods.empty?
|
|
36
|
+
|
|
37
|
+
unique_repositories = pods.each_with_object([]) do |dependency, unique|
|
|
38
|
+
repo_name = dependency.split('(').first.strip
|
|
39
|
+
cleaned_repo_name = repo_name.gsub(/- /, '')
|
|
40
|
+
unique << cleaned_repo_name unless unique.include?(cleaned_repo_name)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
unique_repositories
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Finds the shortest paths for dependencies
|
|
47
|
+
def find_shortest_paths(paths)
|
|
48
|
+
raise ArgumentError, 'Input must be an array' unless paths.is_a?(Array)
|
|
49
|
+
return [] if paths.empty?
|
|
50
|
+
raise ArgumentError, 'All elements in the array must be strings' unless paths.all? { |path| path.is_a?(String) }
|
|
51
|
+
|
|
52
|
+
shortest_paths = []
|
|
53
|
+
paths.each do |path|
|
|
54
|
+
is_shortest = true
|
|
55
|
+
paths.each do |other_path|
|
|
56
|
+
if path != other_path && other_path.start_with?(path)
|
|
57
|
+
is_shortest = false
|
|
58
|
+
break
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
shortest_paths << path if is_shortest
|
|
62
|
+
end
|
|
63
|
+
shortest_paths
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Builds all subspecs dependencies for a repo
|
|
67
|
+
def generate_repo_subspecs(repo,unique_repositories)
|
|
68
|
+
repo_subspecs = {}
|
|
69
|
+
unique_repositories.select { |dependency| dependency.start_with?(repo) }.each do |dependency|
|
|
70
|
+
if repo_subspecs.key?(repo)
|
|
71
|
+
repo_subspecs[repo] << dependency
|
|
72
|
+
else
|
|
73
|
+
repo_subspecs[repo] = [dependency]
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
return repo_subspecs
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Generates Podfile entry for path dependency
|
|
80
|
+
def generate_path_podfile_entry(lib,subspecs, base_path)
|
|
81
|
+
sub_specs = subspecs.map { |path| path.split('/', 2).last }.uniq
|
|
82
|
+
return "pod '#{lib}', :path => '#{base_path}'" if sub_specs.length <= 1
|
|
83
|
+
podfile_entry = "pod '#{lib}', :path => '#{base_path}', :subspecs => [\n"
|
|
84
|
+
sub_specs.each_with_index do |path, index|
|
|
85
|
+
subspec = path.gsub("#{lib}/", '')
|
|
86
|
+
podfile_entry << " '#{subspec}'"
|
|
87
|
+
podfile_entry << "," unless index == sub_specs.length - 1
|
|
88
|
+
podfile_entry << "\n"
|
|
89
|
+
end
|
|
90
|
+
podfile_entry << "]"
|
|
91
|
+
podfile_entry
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Generates Podfile entry for branch dependency
|
|
95
|
+
def generate_branch_podfile_entry(lib,subspecs, git_url, branch)
|
|
96
|
+
sub_specs = subspecs.map { |path| path.split('/', 2).last }.uniq
|
|
97
|
+
return "pod '#{lib}', :git => '#{git_url}', :branch => '#{branch}'" if sub_specs.length <= 1
|
|
98
|
+
podfile_entry = "pod '#{lib}', :git => '#{git_url}', :branch => '#{branch}', :subspecs => [\n"
|
|
99
|
+
sub_specs.each_with_index do |path, index|
|
|
100
|
+
subspec = path.gsub("#{lib}/", '')
|
|
101
|
+
podfile_entry << " '#{subspec}'"
|
|
102
|
+
podfile_entry << "," unless index == sub_specs.length - 1
|
|
103
|
+
podfile_entry << "\n"
|
|
104
|
+
end
|
|
105
|
+
podfile_entry << "]"
|
|
106
|
+
podfile_entry
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Generates all branch dependencies
|
|
110
|
+
def generate_map_branch_podfiles(lockPath, repo_configs)
|
|
111
|
+
raise ArgumentError, 'lockPath must be a string.' unless lockPath.is_a?(String)
|
|
112
|
+
raise ArgumentError, 'repo_configs must be a hash.' unless repo_configs.is_a?(Hash)
|
|
113
|
+
|
|
114
|
+
dependencies = read_local_podfile_lock(lockPath)
|
|
115
|
+
unique_dependencies = extract_unique_dependencies(dependencies)
|
|
116
|
+
# Throws an exception if unique_dependencies is empty
|
|
117
|
+
raise 'No unique dependencies found. Please check your Podfile.lock content and repo_configs.' if unique_dependencies.empty?
|
|
118
|
+
|
|
119
|
+
puts "====branch dependencies===="
|
|
120
|
+
podfile_entrys = []
|
|
121
|
+
repo_configs.each do |key, value|
|
|
122
|
+
next unless value.is_a?(Hash) && value.key?("git_url") && value.key?("branch")
|
|
123
|
+
|
|
124
|
+
git_url = value["git_url"]
|
|
125
|
+
branch = value["branch"]
|
|
126
|
+
repo_subspecs = generate_repo_subspecs(key, unique_dependencies)
|
|
127
|
+
repo_shortest_subspecs = find_shortest_paths(repo_subspecs[key])
|
|
128
|
+
# Generates Podfile entry
|
|
129
|
+
podfile_entry = generate_branch_podfile_entry(key, repo_shortest_subspecs, git_url, branch)
|
|
130
|
+
podfile_entrys << podfile_entry
|
|
131
|
+
end
|
|
132
|
+
puts podfile_entrys.join("\n")
|
|
133
|
+
podfile_entrys.join("\n")
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Generates all path dependencies
|
|
137
|
+
def generate_map_path_podfiles(lockPath, repo_configs)
|
|
138
|
+
raise ArgumentError, 'lockPath must be a string.' unless lockPath.is_a?(String)
|
|
139
|
+
raise ArgumentError, 'repo_configs must be a hash.' unless repo_configs.is_a?(Hash)
|
|
140
|
+
|
|
141
|
+
pods = read_local_podfile_lock(lockPath)
|
|
142
|
+
unique_dependencies = extract_unique_dependencies(pods)
|
|
143
|
+
|
|
144
|
+
# Throws an exception if unique_dependencies is empty
|
|
145
|
+
raise 'No unique dependencies found. Please check your Podfile.lock content and repo_configs.' if unique_dependencies.empty?
|
|
146
|
+
|
|
147
|
+
puts "====path dependencies===="
|
|
148
|
+
podfile_entrys = []
|
|
149
|
+
repo_configs.each do |key, value|
|
|
150
|
+
next unless value.is_a?(Hash) && value.key?("path")
|
|
151
|
+
|
|
152
|
+
path = value["path"]
|
|
153
|
+
repo_subspecs = generate_repo_subspecs(key, unique_dependencies)
|
|
154
|
+
repo_shortest_subspecs = find_shortest_paths(repo_subspecs[key])
|
|
155
|
+
# Generates Podfile entry
|
|
156
|
+
podfile_entry = generate_path_podfile_entry(key, repo_shortest_subspecs, path)
|
|
157
|
+
podfile_entrys << podfile_entry
|
|
158
|
+
end
|
|
159
|
+
puts podfile_entrys.join("\n")
|
|
160
|
+
podfile_entrys.join("\n")
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
require 'optparse'
|
|
164
|
+
require 'json'
|
|
165
|
+
|
|
166
|
+
options = {}
|
|
167
|
+
OptionParser.new do |opts|
|
|
168
|
+
opts.banner = "Usage: check_all_depencies --lockPath LOCK_PATH --depWay DEP_WAY --configPath CONFIG_PATH"
|
|
169
|
+
|
|
170
|
+
opts.on("--lockPath LOCK_PATH", "Specify the Podfile.lock path") do |lockPath|
|
|
171
|
+
options[:lockPath] = lockPath
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
opts.on("--depWay DEP_WAY", "Specify the depWay parameter (path or branch)") do |depWay|
|
|
175
|
+
options[:depWay] = depWay
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# repo_configs examples
|
|
179
|
+
config_string = <<~CONFIG
|
|
180
|
+
repo_configs = {
|
|
181
|
+
'Lib1' => {
|
|
182
|
+
"branch" => "dev1",
|
|
183
|
+
"path" => "/Users/xxxxxxxxx/xxxxlib",
|
|
184
|
+
"git_url" => "xxxxxxxxxxxxxxxxxx"
|
|
185
|
+
},
|
|
186
|
+
'Lib2' => {
|
|
187
|
+
"branch" => "dev2",
|
|
188
|
+
"path" => "/Users/xxxxxxxxx/xxxxlib",
|
|
189
|
+
"git_url" => "xxxxxxxxxxxxxxxxxx"
|
|
190
|
+
},
|
|
191
|
+
'Lib3' => {
|
|
192
|
+
"branch" => "dev3",
|
|
193
|
+
"path" => "/Users/xxxxxxxxx/xxxxlib",
|
|
194
|
+
"git_url" => "xxxxxxxxxxxxxxxxxx"
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
CONFIG
|
|
198
|
+
|
|
199
|
+
opts.on("--configPath CONFIG_PATH", "Specify the path to repo_configs\n\n\n repo_configs examples:\n #{config_string}") do |configPath|
|
|
200
|
+
options[:configPath] = configPath
|
|
201
|
+
end
|
|
202
|
+
end.parse!
|
|
203
|
+
|
|
204
|
+
# Check if all required arguments were provided
|
|
205
|
+
if options[:lockPath].nil? || options[:depWay].nil? || options[:configPath].nil?
|
|
206
|
+
puts "Please provide lockPath, depWay, and configPath parameters.\n you can run:\n ruby MapHelper.rb --help "
|
|
207
|
+
exit
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# Function to read and parse the repo_configs.txt file
|
|
211
|
+
def read_repo_configs(config_path)
|
|
212
|
+
content = File.read(config_path)
|
|
213
|
+
eval(content) # Using eval to parse the Ruby hash from the file, be cautious with its use!
|
|
214
|
+
rescue
|
|
215
|
+
puts "Failed to read or parse the repo_configs from #{config_path}"
|
|
216
|
+
exit
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
repo_configs = read_repo_configs(options[:configPath])
|
|
220
|
+
|
|
221
|
+
# Calls before pod install complete
|
|
222
|
+
if options[:depWay] == "path"
|
|
223
|
+
generate_map_path_podfiles(options[:lockPath], repo_configs)
|
|
224
|
+
elsif options[:depWay] == "branch"
|
|
225
|
+
generate_map_branch_podfiles(options[:lockPath], repo_configs)
|
|
226
|
+
else
|
|
227
|
+
puts "Invalid argument. Please provide 'path' or 'branch'."
|
|
228
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "check_all_depencies"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Gem::Specification.new do |spec|
|
|
2
|
+
spec.name = "check_dependencies"
|
|
3
|
+
spec.version = "0.1.0"
|
|
4
|
+
spec.authors = ["ITxiansheng"]
|
|
5
|
+
spec.email = ["itxiansheng@gmail.com"]
|
|
6
|
+
|
|
7
|
+
spec.summary = %q{check all dependencies}
|
|
8
|
+
spec.description = %q{Long description of your gem}
|
|
9
|
+
spec.homepage = "https://github.com/ITxiansheng/check_dependencies"
|
|
10
|
+
spec.license = "MIT"
|
|
11
|
+
|
|
12
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
13
|
+
spec.bindir = "bin"
|
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
15
|
+
spec.require_paths = ["lib"]
|
|
16
|
+
|
|
17
|
+
# 添加依赖
|
|
18
|
+
spec.add_dependency "bundler", "~> 2.0"
|
|
19
|
+
spec.add_dependency "rake", "~> 13.0"
|
|
20
|
+
end
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
|
|
2
|
+
#!/usr/bin/env ruby
|
|
3
|
+
# Analyzes the Podfile.lock content to extract pod dependencies
|
|
4
|
+
def analyze_podfile_lock(podfile_lock_content)
|
|
5
|
+
unless podfile_lock_content.is_a?(String)
|
|
6
|
+
raise ArgumentError, 'podfile_lock_content must be a string.'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
pods_section_match = podfile_lock_content.match(/^PODS:\n(.*?)(?=\n\n|\z)/m)
|
|
10
|
+
if pods_section_match
|
|
11
|
+
pods_section_content = pods_section_match[1]
|
|
12
|
+
pods_lines = pods_section_content.split("\n")
|
|
13
|
+
pods_lines.map(&:strip)
|
|
14
|
+
else
|
|
15
|
+
raise 'PODS section not found in the provided Podfile.lock content.'
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Reads the local Podfile.lock content
|
|
20
|
+
def read_local_podfile_lock(file_path)
|
|
21
|
+
unless File.exist?(file_path)
|
|
22
|
+
raise "File not found: #{file_path}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
podfile_lock_content = File.read(file_path)
|
|
26
|
+
analyze_podfile_lock(podfile_lock_content)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Extracts unique specs from dependencies
|
|
30
|
+
def extract_unique_dependencies(pods)
|
|
31
|
+
unless pods.is_a?(Array)
|
|
32
|
+
raise ArgumentError, 'Input must be an array.'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
return [] if pods.empty?
|
|
36
|
+
|
|
37
|
+
unique_repositories = pods.each_with_object([]) do |dependency, unique|
|
|
38
|
+
repo_name = dependency.split('(').first.strip
|
|
39
|
+
cleaned_repo_name = repo_name.gsub(/- /, '')
|
|
40
|
+
unique << cleaned_repo_name unless unique.include?(cleaned_repo_name)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
unique_repositories
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Finds the shortest paths for dependencies
|
|
47
|
+
def find_shortest_paths(paths)
|
|
48
|
+
raise ArgumentError, 'Input must be an array' unless paths.is_a?(Array)
|
|
49
|
+
return [] if paths.empty?
|
|
50
|
+
raise ArgumentError, 'All elements in the array must be strings' unless paths.all? { |path| path.is_a?(String) }
|
|
51
|
+
|
|
52
|
+
shortest_paths = []
|
|
53
|
+
paths.each do |path|
|
|
54
|
+
is_shortest = true
|
|
55
|
+
paths.each do |other_path|
|
|
56
|
+
if path != other_path && other_path.start_with?(path)
|
|
57
|
+
is_shortest = false
|
|
58
|
+
break
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
shortest_paths << path if is_shortest
|
|
62
|
+
end
|
|
63
|
+
shortest_paths
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Builds all subspecs dependencies for a repo
|
|
67
|
+
def generate_repo_subspecs(repo,unique_repositories)
|
|
68
|
+
repo_subspecs = {}
|
|
69
|
+
unique_repositories.select { |dependency| dependency.start_with?(repo) }.each do |dependency|
|
|
70
|
+
if repo_subspecs.key?(repo)
|
|
71
|
+
repo_subspecs[repo] << dependency
|
|
72
|
+
else
|
|
73
|
+
repo_subspecs[repo] = [dependency]
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
return repo_subspecs
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Generates Podfile entry for path dependency
|
|
80
|
+
def generate_path_podfile_entry(lib,subspecs, base_path)
|
|
81
|
+
sub_specs = subspecs.map { |path| path.split('/', 2).last }.uniq
|
|
82
|
+
return "pod '#{lib}', :path => '#{base_path}'" if sub_specs.length <= 1
|
|
83
|
+
podfile_entry = "pod '#{lib}', :path => '#{base_path}', :subspecs => [\n"
|
|
84
|
+
sub_specs.each_with_index do |path, index|
|
|
85
|
+
subspec = path.gsub("#{lib}/", '')
|
|
86
|
+
podfile_entry << " '#{subspec}'"
|
|
87
|
+
podfile_entry << "," unless index == sub_specs.length - 1
|
|
88
|
+
podfile_entry << "\n"
|
|
89
|
+
end
|
|
90
|
+
podfile_entry << "]"
|
|
91
|
+
podfile_entry
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Generates Podfile entry for branch dependency
|
|
95
|
+
def generate_branch_podfile_entry(lib,subspecs, git_url, branch)
|
|
96
|
+
sub_specs = subspecs.map { |path| path.split('/', 2).last }.uniq
|
|
97
|
+
return "pod '#{lib}', :git => '#{git_url}', :branch => '#{branch}'" if sub_specs.length <= 1
|
|
98
|
+
podfile_entry = "pod '#{lib}', :git => '#{git_url}', :branch => '#{branch}', :subspecs => [\n"
|
|
99
|
+
sub_specs.each_with_index do |path, index|
|
|
100
|
+
subspec = path.gsub("#{lib}/", '')
|
|
101
|
+
podfile_entry << " '#{subspec}'"
|
|
102
|
+
podfile_entry << "," unless index == sub_specs.length - 1
|
|
103
|
+
podfile_entry << "\n"
|
|
104
|
+
end
|
|
105
|
+
podfile_entry << "]"
|
|
106
|
+
podfile_entry
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Generates all branch dependencies
|
|
110
|
+
def generate_map_branch_podfiles(lockPath, repo_configs)
|
|
111
|
+
raise ArgumentError, 'lockPath must be a string.' unless lockPath.is_a?(String)
|
|
112
|
+
raise ArgumentError, 'repo_configs must be a hash.' unless repo_configs.is_a?(Hash)
|
|
113
|
+
|
|
114
|
+
dependencies = read_local_podfile_lock(lockPath)
|
|
115
|
+
unique_dependencies = extract_unique_dependencies(dependencies)
|
|
116
|
+
# Throws an exception if unique_dependencies is empty
|
|
117
|
+
raise 'No unique dependencies found. Please check your Podfile.lock content and repo_configs.' if unique_dependencies.empty?
|
|
118
|
+
|
|
119
|
+
puts "====branch dependencies===="
|
|
120
|
+
podfile_entrys = []
|
|
121
|
+
repo_configs.each do |key, value|
|
|
122
|
+
next unless value.is_a?(Hash) && value.key?("git_url") && value.key?("branch")
|
|
123
|
+
|
|
124
|
+
git_url = value["git_url"]
|
|
125
|
+
branch = value["branch"]
|
|
126
|
+
repo_subspecs = generate_repo_subspecs(key, unique_dependencies)
|
|
127
|
+
repo_shortest_subspecs = find_shortest_paths(repo_subspecs[key])
|
|
128
|
+
# Generates Podfile entry
|
|
129
|
+
podfile_entry = generate_branch_podfile_entry(key, repo_shortest_subspecs, git_url, branch)
|
|
130
|
+
podfile_entrys << podfile_entry
|
|
131
|
+
end
|
|
132
|
+
puts podfile_entrys.join("\n")
|
|
133
|
+
podfile_entrys.join("\n")
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Generates all path dependencies
|
|
137
|
+
def generate_map_path_podfiles(lockPath, repo_configs)
|
|
138
|
+
raise ArgumentError, 'lockPath must be a string.' unless lockPath.is_a?(String)
|
|
139
|
+
raise ArgumentError, 'repo_configs must be a hash.' unless repo_configs.is_a?(Hash)
|
|
140
|
+
|
|
141
|
+
pods = read_local_podfile_lock(lockPath)
|
|
142
|
+
unique_dependencies = extract_unique_dependencies(pods)
|
|
143
|
+
|
|
144
|
+
# Throws an exception if unique_dependencies is empty
|
|
145
|
+
raise 'No unique dependencies found. Please check your Podfile.lock content and repo_configs.' if unique_dependencies.empty?
|
|
146
|
+
|
|
147
|
+
puts "====path dependencies===="
|
|
148
|
+
podfile_entrys = []
|
|
149
|
+
repo_configs.each do |key, value|
|
|
150
|
+
next unless value.is_a?(Hash) && value.key?("path")
|
|
151
|
+
|
|
152
|
+
path = value["path"]
|
|
153
|
+
repo_subspecs = generate_repo_subspecs(key, unique_dependencies)
|
|
154
|
+
repo_shortest_subspecs = find_shortest_paths(repo_subspecs[key])
|
|
155
|
+
# Generates Podfile entry
|
|
156
|
+
podfile_entry = generate_path_podfile_entry(key, repo_shortest_subspecs, path)
|
|
157
|
+
podfile_entrys << podfile_entry
|
|
158
|
+
end
|
|
159
|
+
puts podfile_entrys.join("\n")
|
|
160
|
+
podfile_entrys.join("\n")
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
require 'optparse'
|
|
164
|
+
require 'json'
|
|
165
|
+
|
|
166
|
+
options = {}
|
|
167
|
+
OptionParser.new do |opts|
|
|
168
|
+
opts.banner = "Usage: check_all_depencies --lockPath LOCK_PATH --depWay DEP_WAY --configPath CONFIG_PATH"
|
|
169
|
+
|
|
170
|
+
opts.on("--lockPath LOCK_PATH", "Specify the Podfile.lock path") do |lockPath|
|
|
171
|
+
options[:lockPath] = lockPath
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
opts.on("--depWay DEP_WAY", "Specify the depWay parameter (path or branch)") do |depWay|
|
|
175
|
+
options[:depWay] = depWay
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# repo_configs examples
|
|
179
|
+
config_string = <<~CONFIG
|
|
180
|
+
repo_configs = {
|
|
181
|
+
'Lib1' => {
|
|
182
|
+
"branch" => "dev1",
|
|
183
|
+
"path" => "/Users/xxxxxxxxx/xxxxlib",
|
|
184
|
+
"git_url" => "xxxxxxxxxxxxxxxxxx"
|
|
185
|
+
},
|
|
186
|
+
'Lib2' => {
|
|
187
|
+
"branch" => "dev2",
|
|
188
|
+
"path" => "/Users/xxxxxxxxx/xxxxlib",
|
|
189
|
+
"git_url" => "xxxxxxxxxxxxxxxxxx"
|
|
190
|
+
},
|
|
191
|
+
'Lib3' => {
|
|
192
|
+
"branch" => "dev3",
|
|
193
|
+
"path" => "/Users/xxxxxxxxx/xxxxlib",
|
|
194
|
+
"git_url" => "xxxxxxxxxxxxxxxxxx"
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
CONFIG
|
|
198
|
+
|
|
199
|
+
opts.on("--configPath CONFIG_PATH", "Specify the path to repo_configs\n\n\n repo_configs examples:\n #{config_string}") do |configPath|
|
|
200
|
+
options[:configPath] = configPath
|
|
201
|
+
end
|
|
202
|
+
end.parse!
|
|
203
|
+
|
|
204
|
+
# Check if all required arguments were provided
|
|
205
|
+
if options[:lockPath].nil? || options[:depWay].nil? || options[:configPath].nil?
|
|
206
|
+
puts "Please provide lockPath, depWay, and configPath parameters.\n you can run:\n ruby MapHelper.rb --help "
|
|
207
|
+
exit
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# Function to read and parse the repo_configs.txt file
|
|
211
|
+
def read_repo_configs(config_path)
|
|
212
|
+
content = File.read(config_path)
|
|
213
|
+
eval(content) # Using eval to parse the Ruby hash from the file, be cautious with its use!
|
|
214
|
+
rescue
|
|
215
|
+
puts "Failed to read or parse the repo_configs from #{config_path}"
|
|
216
|
+
exit
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
repo_configs = read_repo_configs(options[:configPath])
|
|
220
|
+
|
|
221
|
+
# Calls before pod install complete
|
|
222
|
+
if options[:depWay] == "path"
|
|
223
|
+
generate_map_path_podfiles(options[:lockPath], repo_configs)
|
|
224
|
+
elsif options[:depWay] == "branch"
|
|
225
|
+
generate_map_branch_podfiles(options[:lockPath], repo_configs)
|
|
226
|
+
else
|
|
227
|
+
puts "Invalid argument. Please provide 'path' or 'branch'."
|
|
228
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: check_dependencies
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- ITxiansheng
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-03-13 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.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '13.0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '13.0'
|
|
41
|
+
description: Long description of your gem
|
|
42
|
+
email:
|
|
43
|
+
- itxiansheng@gmail.com
|
|
44
|
+
executables:
|
|
45
|
+
- check_dependencies
|
|
46
|
+
- console
|
|
47
|
+
- setup
|
|
48
|
+
extensions: []
|
|
49
|
+
extra_rdoc_files: []
|
|
50
|
+
files:
|
|
51
|
+
- CODE_OF_CONDUCT.md
|
|
52
|
+
- Gemfile
|
|
53
|
+
- LICENSE.txt
|
|
54
|
+
- README.md
|
|
55
|
+
- Rakefile
|
|
56
|
+
- bin/check_dependencies
|
|
57
|
+
- bin/console
|
|
58
|
+
- bin/setup
|
|
59
|
+
- check_dependencies.gemspec
|
|
60
|
+
- lib/check_all_depencies.rb
|
|
61
|
+
- lib/check_all_depencies/version.rb
|
|
62
|
+
homepage: https://github.com/ITxiansheng/check_dependencies
|
|
63
|
+
licenses:
|
|
64
|
+
- MIT
|
|
65
|
+
metadata: {}
|
|
66
|
+
post_install_message:
|
|
67
|
+
rdoc_options: []
|
|
68
|
+
require_paths:
|
|
69
|
+
- lib
|
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '0'
|
|
80
|
+
requirements: []
|
|
81
|
+
rubygems_version: 3.0.3.1
|
|
82
|
+
signing_key:
|
|
83
|
+
specification_version: 4
|
|
84
|
+
summary: check all dependencies
|
|
85
|
+
test_files: []
|