check_dependencies 0.1.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b59a47c5d8d3061675a6e65e54208c165f191889dff8e155fafe30bee1427b4a
4
- data.tar.gz: 9a53f687b2dd4502ddb42a38be5d2b48e41f839d6eb2923bac1258aee057bf61
3
+ metadata.gz: 4f5ba3bacaefc1ba390830e283976ce506c933131f4d7ec1af61d56aa551b4e5
4
+ data.tar.gz: f7061fabae1d98b1ec5c449be1b86a28990e08eafee37690bd4d1ff381ab12f4
5
5
  SHA512:
6
- metadata.gz: a585576604889412b7b2e9b628841e1ac641c49e33b0716ef1fa57962a3830a362c5e42bad867e23110c662c87d0bf2eb81fab1d336bd165f43884438a20bf4b
7
- data.tar.gz: 8e360c2429323cd223abefb702918867917f4276bc3a278b06635a2b00b123c3f3c5c6861cceca5bf9302e33bd4eb7a267dc8a4c3319f62cd622e28547c129c8
6
+ metadata.gz: 1888a329986a98689335b452abe4bff3a166bdebac48ad351d0818f5af202347fb11b1cb9c25f5ea54e4269f996a58dee2cdca29c363093a7796339706c1de69
7
+ data.tar.gz: b46d24918f7b1b8d94cff1ae14c3de266e98acb842f1b26aeec14c10d22143e5a580a322302eff095e4bc45f03a727e49bd5e549ea14ea2d2581d4d2a5a8b871
data/README.md CHANGED
@@ -1,79 +1,90 @@
1
- ```markdown
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
- 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.
3
+ ---
5
4
 
6
- ## Installation
5
+ # Podfile Utilities Script
7
6
 
8
- Install the gem by adding it to your Gemfile:
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
- ```ruby
11
- gem 'check_dependencies', git: 'https://github.com/ITxiansheng/check_dependencies.git'
12
- ```
13
-
14
- And then execute:
9
+ ## Features
15
10
 
16
- ```bash
17
- $ bundle install
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
- Or install it yourself as:
14
+ ## Requirements
21
15
 
22
- ```bash
23
- $ gem install check_dependencies
24
- ```
16
+ - Ruby (version 2.5 or later)
17
+ - JSON files for specifying dependencies
25
18
 
26
19
  ## Usage
27
20
 
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
- ```bash
30
- check_dependencies --help
31
- ```
32
- ### Command Syntax
21
+ ### Generating Podfile Entries
22
+
23
+ To generate new podfile entries based on a JSON configuration:
33
24
 
34
- ```bash
35
- check_dependencies --lockPath LOCK_PATH --depWay DEP_WAY --configPath CONFIG_PATH
25
+ ```shell
26
+ ruby script.rb gen_pod --lockPath <path_to_Podfile.lock> --depWay <path_or_branch> --configPath <path_to_config.json>
36
27
  ```
37
28
 
38
- ### Options
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
+ ```
39
49
 
40
- - `--lockPath LOCK_PATH`: Specifies the path to your Podfile.lock file.
41
- - `--depWay DEP_WAY`: Specifies the dependency mode. This can be either `path` for local path dependencies or `branch` for remote git branch dependencies.
42
- - `--configPath CONFIG_PATH`: Specifies the path to the configuration file containing dependency configurations.
50
+ ### Comparing Podfile.lock Files
43
51
 
44
- ### Example
52
+ To compare two `Podfile.lock` files and list differences in dependencies:
45
53
 
46
- ```bash
47
- check_dependencies --lockPath ./Podfile.lock --depWay path --configPath ./repo_configs.txt
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>]
48
56
  ```
49
57
 
50
- ## Functions Overview
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.
51
61
 
52
- The gem provides the following key functionalities:
62
+ **Example JSON Configuration (`dif_pod_config.json`):**
53
63
 
54
- - Parsing `Podfile.lock` content to extract pod dependencies.
55
- - Generating Podfile entries for local path or remote git branch dependencies.
56
- - Processing and formatting dependencies for correct integration into Podfiles.
57
-
58
- ## Workflow
59
-
60
- 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.
64
+ ```json
65
+ [
66
+ "A",
67
+ "B"
68
+ ]
69
+ ```
61
70
 
62
- 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.
71
+ ## Configuration
63
72
 
64
- 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).
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.
65
74
 
66
- ## Note
75
+ ## Notes
67
76
 
68
- - Ensure that the `repo_configs` file is properly formatted and from a trusted source to avoid potential security risks.
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.
69
79
 
70
80
  ## Contributing
71
81
 
72
- 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).
82
+ Feel free to fork this repository and submit pull requests to contribute to its development.
73
83
 
74
84
  ## License
75
85
 
76
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
77
- ```
86
+ Specify your license or leave it blank if you haven't decided on one yet.
87
+
88
+ ---
78
89
 
79
- 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.
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "check_dependencies"
3
- spec.version = "0.1.2"
3
+ spec.version = "0.1.4"
4
4
  spec.authors = ["ITxiansheng"]
5
5
  spec.email = ["itxiansheng@gmail.com"]
6
6
 
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.description = %q{Long description of your gem}
9
9
  spec.homepage = "https://github.com/ITxiansheng/check_dependencies"
10
10
  spec.license = "MIT"
11
-
11
+ spec.post_install_message = "Remember to add GEM_BIN_DIR to your PATH.\n you can run :\n curl -sSL https://raw.githubusercontent.com/ITxiansheng/check_dependencies/main/gem_env_install.sh | bash"
12
12
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
13
13
  spec.bindir = "bin"
14
14
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -0,0 +1,28 @@
1
+ #!/bin/bash
2
+ # 查找gem可执行文件目录
3
+ GEM_BIN_DIR=$(gem env | grep -Eo 'EXECUTABLE DIRECTORY: [^ ]+' | cut -d ' ' -f3)
4
+
5
+ # 检测你使用的shell并选择相应的配置文件
6
+ if [[ $SHELL == */zsh ]]; then
7
+ # 对于zsh
8
+ CONFIG_FILE="${HOME}/.zshrc"
9
+ elif [[ $SHELL == */bash ]]; then
10
+ # 对于bash
11
+ CONFIG_FILE="${HOME}/.bash_profile"
12
+ if [ ! -f "$CONFIG_FILE" ]; then
13
+ CONFIG_FILE="${HOME}/.bashrc"
14
+ fi
15
+ else
16
+ echo "Unsupported shell."
17
+ exit 1
18
+ fi
19
+
20
+ # 检查GEM_BIN_DIR是否已经在PATH中
21
+ if [[ ":$PATH:" != *":$GEM_BIN_DIR:"* ]]; then
22
+ # 如果不在PATH中,添加它
23
+ echo "Exporting GEM bin directory to PATH in $CONFIG_FILE"
24
+ echo "export PATH=\"\$PATH:$GEM_BIN_DIR\"" >> "$CONFIG_FILE"
25
+ echo "Done. Please restart your terminal or source your $CONFIG_FILE"
26
+ else
27
+ echo "GEM bin directory ($GEM_BIN_DIR) already in PATH."
28
+ fi
@@ -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
- options = {}
167
- OptionParser.new do |opts|
168
- opts.banner = "Usage: check_dependencies --lockPath LOCK_PATH --depWay DEP_WAY --configPath CONFIG_PATH"
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
- opts.on("--lockPath LOCK_PATH", "Specify the Podfile.lock path") do |lockPath|
171
- options[:lockPath] = lockPath
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
- opts.on("--depWay DEP_WAY", "Specify the depWay parameter (path or branch)") do |depWay|
175
- options[:depWay] = depWay
176
- end
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
- # 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
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
- 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
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
- # 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
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: check_dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ITxiansheng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-13 00:00:00.000000000 Z
11
+ date: 2024-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -57,7 +57,9 @@ 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
62
+ - gem_env_install.sh
61
63
  - lib/check_dependencies.rb
62
64
  - lib/check_dependencies/version.rb
63
65
  - sig/check_dependencies.rbs
@@ -65,7 +67,10 @@ homepage: https://github.com/ITxiansheng/check_dependencies
65
67
  licenses:
66
68
  - MIT
67
69
  metadata: {}
68
- post_install_message:
70
+ post_install_message: |-
71
+ Remember to add GEM_BIN_DIR to your PATH.
72
+ you can run :
73
+ curl -sSL https://raw.githubusercontent.com/ITxiansheng/check_dependencies/main/gem_env_install.sh | bash
69
74
  rdoc_options: []
70
75
  require_paths:
71
76
  - lib