check_dependencies 0.1.3 → 0.1.4
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 +4 -4
- data/README.md +59 -55
- data/check_dependencies-0.1.3.gem +0 -0
- data/check_dependencies.gemspec +1 -1
- data/lib/check_dependencies.rb +134 -55
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4f5ba3bacaefc1ba390830e283976ce506c933131f4d7ec1af61d56aa551b4e5
|
|
4
|
+
data.tar.gz: f7061fabae1d98b1ec5c449be1b86a28990e08eafee37690bd4d1ff381ab12f4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1888a329986a98689335b452abe4bff3a166bdebac48ad351d0818f5af202347fb11b1cb9c25f5ea54e4269f996a58dee2cdca29c363093a7796339706c1de69
|
|
7
|
+
data.tar.gz: b46d24918f7b1b8d94cff1ae14c3de266e98acb842f1b26aeec14c10d22143e5a580a322302eff095e4bc45f03a727e49bd5e549ea14ea2d2581d4d2a5a8b871
|
data/README.md
CHANGED
|
@@ -1,86 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
# check_dependencies Gem
|
|
1
|
+
Based on your script, which involves generating podfile entries and comparing Podfile.lock files, here's a README outline that explains how to use it. You can customize this template to better fit your script's specifics and requirements.
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
---
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
# Podfile Utilities Script
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
This script provides utilities for iOS development with CocoaPods, including generating podfile entries for new dependencies and comparing differences between `Podfile.lock` files. It's designed to facilitate the management of dependencies in large-scale iOS projects.
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
gem 'check_dependencies', git: 'https://github.com/ITxiansheng/check_dependencies.git'
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
And then execute:
|
|
9
|
+
## Features
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
```
|
|
11
|
+
- **Generate Podfile Entries**: Automatically generates podfile entries for dependencies specified in a configuration file.
|
|
12
|
+
- **Compare Podfile.lock Files**: Compares two `Podfile.lock` files and highlights the added or removed dependencies, similar to a git diff.
|
|
19
13
|
|
|
20
|
-
|
|
14
|
+
## Requirements
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Remember to add GEM_BIN_DIR to your PATH.
|
|
27
|
-
|
|
28
|
-
you can run :
|
|
29
|
-
```bash
|
|
30
|
-
curl -sSL https://raw.githubusercontent.com/ITxiansheng/check_dependencies/main/gem_env_install.sh | bash
|
|
31
|
-
```
|
|
16
|
+
- Ruby (version 2.5 or later)
|
|
17
|
+
- JSON files for specifying dependencies
|
|
32
18
|
|
|
33
19
|
## Usage
|
|
34
20
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
### Command Syntax
|
|
21
|
+
### Generating Podfile Entries
|
|
22
|
+
|
|
23
|
+
To generate new podfile entries based on a JSON configuration:
|
|
40
24
|
|
|
41
|
-
```
|
|
42
|
-
|
|
25
|
+
```shell
|
|
26
|
+
ruby script.rb gen_pod --lockPath <path_to_Podfile.lock> --depWay <path_or_branch> --configPath <path_to_config.json>
|
|
43
27
|
```
|
|
44
28
|
|
|
45
|
-
|
|
29
|
+
- `lockPath`: Path to your `Podfile.lock`.
|
|
30
|
+
- `depWay`: Specify "path" or "branch" to indicate how the dependencies are to be fetched.
|
|
31
|
+
- `configPath`: Path to your JSON configuration file listing the dependencies.
|
|
32
|
+
|
|
33
|
+
**Example JSON Configuration (`gen_pod_config.json`):**
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"A": {
|
|
38
|
+
"branch": "release",
|
|
39
|
+
"path": "/path/to/A",
|
|
40
|
+
"git_url": "git@github.com:Example/A.git"
|
|
41
|
+
},
|
|
42
|
+
"B": {
|
|
43
|
+
"branch": "release",
|
|
44
|
+
"path": "/path/to/B",
|
|
45
|
+
"git_url": "git@github.com:Example/B.git"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
- `--depWay DEP_WAY`: Specifies the dependency mode. This can be either `path` for local path dependencies or `branch` for remote git branch dependencies.
|
|
49
|
-
- `--configPath CONFIG_PATH`: Specifies the path to the configuration file containing dependency configurations.
|
|
50
|
+
### Comparing Podfile.lock Files
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
To compare two `Podfile.lock` files and list differences in dependencies:
|
|
52
53
|
|
|
53
|
-
```
|
|
54
|
-
|
|
54
|
+
```shell
|
|
55
|
+
ruby script.rb dif_pod --oldLockPath <path_to_old_Podfile.lock> --newLockPath <path_to_new_Podfile.lock> [--configPath <path_to_config.json>]
|
|
55
56
|
```
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
- Parsing `Podfile.lock` content to extract pod dependencies.
|
|
62
|
-
- Generating Podfile entries for local path or remote git branch dependencies.
|
|
63
|
-
- Processing and formatting dependencies for correct integration into Podfiles.
|
|
58
|
+
- `oldLockPath`: Path to the older `Podfile.lock`.
|
|
59
|
+
- `newLockPath`: Path to the newer `Podfile.lock`.
|
|
60
|
+
- `configPath` (optional): Path to a JSON configuration file specifying which libraries to include in the comparison.
|
|
64
61
|
|
|
65
|
-
|
|
62
|
+
**Example JSON Configuration (`dif_pod_config.json`):**
|
|
66
63
|
|
|
67
|
-
|
|
64
|
+
```json
|
|
65
|
+
[
|
|
66
|
+
"A",
|
|
67
|
+
"B"
|
|
68
|
+
]
|
|
69
|
+
```
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
## Configuration
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
The configuration file for generating podfile entries should list each dependency along with its fetch method (path or branch) and relevant details. For comparing `Podfile.lock` files, the configuration file (optional) should list the names of the libraries to be included in the comparison.
|
|
72
74
|
|
|
73
|
-
##
|
|
75
|
+
## Notes
|
|
74
76
|
|
|
75
|
-
- Ensure
|
|
77
|
+
- Ensure the JSON configuration files are correctly formatted and located at the specified path.
|
|
78
|
+
- The script provides output similar to git diff, with dependencies being added marked in green and those being removed marked in red.
|
|
76
79
|
|
|
77
80
|
## Contributing
|
|
78
81
|
|
|
79
|
-
|
|
82
|
+
Feel free to fork this repository and submit pull requests to contribute to its development.
|
|
80
83
|
|
|
81
84
|
## License
|
|
82
85
|
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
Specify your license or leave it blank if you haven't decided on one yet.
|
|
87
|
+
|
|
88
|
+
---
|
|
85
89
|
|
|
86
|
-
|
|
90
|
+
Remember to replace placeholder texts with actual information relevant to your script and project. This README provides a basic structure and explanation for users on how to utilize your script effectively.
|
|
Binary file
|
data/check_dependencies.gemspec
CHANGED
data/lib/check_dependencies.rb
CHANGED
|
@@ -1,5 +1,81 @@
|
|
|
1
1
|
|
|
2
2
|
#!/usr/bin/env ruby
|
|
3
|
+
# Usage Hint
|
|
4
|
+
require 'optparse'
|
|
5
|
+
require 'json'
|
|
6
|
+
require 'set'
|
|
7
|
+
|
|
8
|
+
# Method to check for required options and print usage if missing
|
|
9
|
+
def check_required_options(options, required_keys, parser)
|
|
10
|
+
missing_options = required_keys.select { |key| options[key].nil? }
|
|
11
|
+
unless missing_options.empty?
|
|
12
|
+
puts "Missing required options: #{missing_options.join(', ')}"
|
|
13
|
+
puts parser
|
|
14
|
+
exit
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Define and parse options based on the command
|
|
19
|
+
options = {}
|
|
20
|
+
global_options = OptionParser.new do |opts|
|
|
21
|
+
opts.banner = "Usage: script.rb [command] [options]"
|
|
22
|
+
opts.separator ""
|
|
23
|
+
opts.separator "Commands:"
|
|
24
|
+
opts.separator " gen_pod: Generate podfile entries for new dependencies"
|
|
25
|
+
opts.separator " dif_pod: Generate differences between Podfile.lock files"
|
|
26
|
+
opts.separator ""
|
|
27
|
+
opts.separator "For command-specific help, run: script.rb [command] --help"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
gen_pod_config_string = <<~CONFIG
|
|
31
|
+
{
|
|
32
|
+
"A": {
|
|
33
|
+
"branch": "release",
|
|
34
|
+
"path": "XXXXXXXXXXXXXXX",
|
|
35
|
+
"git_url": "XXXXXXXXXXXXXXX"
|
|
36
|
+
},
|
|
37
|
+
"B": {
|
|
38
|
+
"branch": "release",
|
|
39
|
+
"path": "XXXXXXXXXXXXXXX",
|
|
40
|
+
"git_url": "XXXXXXXXXXXXXXX"
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
CONFIG
|
|
44
|
+
|
|
45
|
+
dif_pod_config_string = <<~CONFIG
|
|
46
|
+
[
|
|
47
|
+
"A",
|
|
48
|
+
"B"
|
|
49
|
+
]
|
|
50
|
+
CONFIG
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
command = ARGV.shift
|
|
54
|
+
case command
|
|
55
|
+
when "gen_pod"
|
|
56
|
+
command_options = OptionParser.new do |opts|
|
|
57
|
+
opts.banner = "Usage: gen_pod --lockPath LOCK_PATH --depWay DEP_WAY [--configPath CONFIG_PATH]"
|
|
58
|
+
opts.on("--lockPath LOCK_PATH", String, "Specify the Podfile.lock path") { |v| options[:lockPath] = v }
|
|
59
|
+
opts.on("--depWay DEP_WAY", String, "Specify the depWay parameter (path or branch)") { |v| options[:depWay] = v }
|
|
60
|
+
opts.on("--configPath CONFIG_PATH", String, "Specify the path to repo_configs\n\n\n repo_configs examples:\n#{gen_pod_config_string}") { |v| options[:configPath] = v }
|
|
61
|
+
end.parse!(ARGV)
|
|
62
|
+
check_required_options(options, [:lockPath, :depWay, :configPath], command_options)
|
|
63
|
+
|
|
64
|
+
when "dif_pod"
|
|
65
|
+
command_options = OptionParser.new do |opts|
|
|
66
|
+
opts.banner = "Usage: dif_pod --oldLockPath OLD_LOCK_PATH --newLockPath NEW_LOCK_PATH [--configPath CONFIG_PATH]"
|
|
67
|
+
opts.on("--oldLockPath OLD_LOCK_PATH", String, "Specify old Podfile.lock path") { |v| options[:oldLockPath] = v }
|
|
68
|
+
opts.on("--newLockPath NEW_LOCK_PATH", String, "Specify new Podfile.lock path") { |v| options[:newLockPath] = v }
|
|
69
|
+
opts.on("--configPath CONFIG_PATH", String, "Specify the path of conf which contains dif libs (optional) \n\n\n repo_configs examples:\n#{dif_pod_config_string}") { |v| options[:configPath] = v }
|
|
70
|
+
end.parse!(ARGV)
|
|
71
|
+
check_required_options(options, [:oldLockPath, :newLockPath], command_options)
|
|
72
|
+
|
|
73
|
+
else
|
|
74
|
+
puts global_options
|
|
75
|
+
exit
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
|
|
3
79
|
# Analyzes the Podfile.lock content to extract pod dependencies
|
|
4
80
|
def analyze_podfile_lock(podfile_lock_content)
|
|
5
81
|
unless podfile_lock_content.is_a?(String)
|
|
@@ -160,69 +236,72 @@ def generate_map_path_podfiles(lockPath, repo_configs)
|
|
|
160
236
|
podfile_entrys.join("\n")
|
|
161
237
|
end
|
|
162
238
|
|
|
163
|
-
require 'optparse'
|
|
164
|
-
require 'json'
|
|
165
239
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
240
|
+
def colorize(text, color_code)
|
|
241
|
+
"\e[#{color_code}m#{text}\e[0m"
|
|
242
|
+
end
|
|
243
|
+
def red(text); colorize(text, 31); end
|
|
244
|
+
def green(text); colorize(text, 32); end
|
|
169
245
|
|
|
170
|
-
|
|
171
|
-
|
|
246
|
+
def read_json_array_from_file_as_set(file_path)
|
|
247
|
+
# 确保文件存在
|
|
248
|
+
if File.exist?(file_path)
|
|
249
|
+
# 读取文件内容
|
|
250
|
+
file_content = File.read(file_path)
|
|
251
|
+
# 解析 JSON 字符串为 Ruby 数组
|
|
252
|
+
json_array = JSON.parse(file_content)
|
|
253
|
+
# 将数组转换为 Set 并返回
|
|
254
|
+
return json_array.to_set
|
|
255
|
+
else
|
|
256
|
+
puts "File not found: #{file_path}"
|
|
257
|
+
exit
|
|
172
258
|
end
|
|
259
|
+
rescue JSON::ParserError => e
|
|
260
|
+
puts "Error parsing JSON from #{file_path}: #{e.message}"
|
|
261
|
+
exit
|
|
262
|
+
end
|
|
173
263
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
264
|
+
def compare_podfile_locks(old_lock_path, new_lock_path, config_path = nil)
|
|
265
|
+
config_set = read_json_array_from_file_as_set(config_path)
|
|
266
|
+
|
|
267
|
+
old_pods = read_local_podfile_lock(old_lock_path)
|
|
268
|
+
new_pods = read_local_podfile_lock(new_lock_path)
|
|
177
269
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
'
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
|
270
|
+
old_unique_deps = find_shortest_paths(extract_unique_dependencies(old_pods)).to_set
|
|
271
|
+
new_unique_deps = find_shortest_paths(extract_unique_dependencies(new_pods)).to_set
|
|
272
|
+
if !config_set.empty?
|
|
273
|
+
old_unique_deps = old_unique_deps.select { |dep| config_set.include?(dep.split('/').first) }
|
|
274
|
+
new_unique_deps = new_unique_deps.select { |dep| config_set.include?(dep.split('/').first) }
|
|
275
|
+
end
|
|
276
|
+
only_in_old = old_unique_deps - new_unique_deps
|
|
277
|
+
only_in_new = new_unique_deps - old_unique_deps
|
|
198
278
|
|
|
199
|
-
|
|
200
|
-
|
|
279
|
+
# 检查差异并决定退出状态
|
|
280
|
+
if only_in_old.empty? && only_in_new.empty?
|
|
281
|
+
puts "没有差异,成功退出"
|
|
282
|
+
exit 0
|
|
283
|
+
else
|
|
284
|
+
puts "存在差异:"
|
|
285
|
+
only_in_old.each { |dep| puts "#{red('-')} #{dep}" }
|
|
286
|
+
only_in_new.each { |dep| puts "#{green('+')} #{dep}" }
|
|
287
|
+
exit 1
|
|
201
288
|
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 check_dependencies --help "
|
|
207
|
-
exit
|
|
208
289
|
end
|
|
209
290
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
291
|
+
if command == "gen_pod"
|
|
292
|
+
file_content = File.read(options[:configPath])
|
|
293
|
+
puts file_content
|
|
294
|
+
repo_configs =JSON.parse(file_content)
|
|
295
|
+
puts repo_configs
|
|
296
|
+
# Calls before pod install complete
|
|
297
|
+
if options[:depWay] == "path"
|
|
298
|
+
generate_map_path_podfiles(options[:lockPath], repo_configs)
|
|
299
|
+
elsif options[:depWay] == "branch"
|
|
300
|
+
generate_map_branch_podfiles(options[:lockPath], repo_configs)
|
|
301
|
+
else
|
|
302
|
+
puts "Invalid argument. Please provide 'path' or 'branch'."
|
|
303
|
+
end
|
|
304
|
+
elsif command == "dif_pod"
|
|
305
|
+
compare_podfile_locks(options[:oldLockPath], options[:newLockPath], options[:configPath])
|
|
217
306
|
end
|
|
218
307
|
|
|
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: check_dependencies
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ITxiansheng
|
|
@@ -57,6 +57,7 @@ files:
|
|
|
57
57
|
- bin/check_dependencies
|
|
58
58
|
- bin/console
|
|
59
59
|
- bin/setup
|
|
60
|
+
- check_dependencies-0.1.3.gem
|
|
60
61
|
- check_dependencies.gemspec
|
|
61
62
|
- gem_env_install.sh
|
|
62
63
|
- lib/check_dependencies.rb
|