cocoapods-query 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5cf435960d7f5044287ffe40bc613093c945705422f45fce97d7cb6446ce383b
4
+ data.tar.gz: 3cc5a61cfddc810a37b3012f7d6819593e470e748cf065969e064ea632302c02
5
+ SHA512:
6
+ metadata.gz: fc8ea8af042c3d10a528f6b131a9a2e3b97d0ecc9c5451ca97a2201367fed67cec9d81aaea8553b3111c8620d8606ea0089761b88dd95b9c29172cc6e66879cb
7
+ data.tar.gz: 8e2c7399ef648826034856cdeb660228d2a9fb0231147d0e55f3aac17d472683a4b81d97b1d5dbfdc149cc2bda5751eb9b7a3060c22107dec03c4fafc40e55ce
@@ -0,0 +1,16 @@
1
+ Contributing
2
+ ============
3
+
4
+ If you would like to contribute code to cocoapods-query you can do so through GitHub by
5
+ forking the repository and sending a pull request.
6
+
7
+ When submitting code, please make every effort to follow existing conventions
8
+ and style in order to keep the code as readable as possible. Please also make
9
+ sure your code has tests.
10
+
11
+ Before your code can be accepted into the project you must also sign the
12
+ [Individual Contributor License Agreement (CLA)][1].
13
+
14
+
15
+ [1]: https://spreadsheets.google.com/spreadsheet/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ&ndplr=1
16
+
@@ -0,0 +1,73 @@
1
+ # Introduction
2
+
3
+ This plugin for CocoaPods helps locate pods in a project. It can show all pods or filter them based on some search term, such as author name, source file, dependency, and more. It is intended for projects with a large number of dependencies.
4
+
5
+ The plugin's output can be saved to YAML format for easy parsing by other tools (e.g. a CocoaPods GUI).
6
+
7
+ # Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'cocoapods-query'
12
+
13
+ And then run:
14
+
15
+ $ bundle
16
+
17
+ Or, install it system-wide with:
18
+
19
+ $ gem build cocoapods-query.gemspec
20
+ $ gem install cocoapods-query-1.0.0.gem
21
+
22
+ Or, in a single command:
23
+
24
+ $ bundle exec rake install
25
+
26
+ # Usage
27
+
28
+ The plugin adds a `query` command to CocoaPods. You can get help on its parameters with:
29
+
30
+ $ pod query --help
31
+
32
+ By default, the command lists all pods in the sandbox. This list can be filtered by one of several search terms. Here are some examples:
33
+
34
+ What pods contain the string "testing" in their name?
35
+
36
+ $ pod query --name testing --substring --case-insensitive
37
+
38
+ What pods have a direct dependency on Foo?
39
+
40
+ $ pod query --dependency Foo
41
+
42
+ What pods were created by hacker@example.com?
43
+
44
+ $ pod query --author-email hacker@example.com
45
+
46
+ What pods contain a source file named `HelloWorld.swift`?
47
+
48
+ $ pod query --source-file HelloWorld.swift --substring
49
+
50
+ # Caching
51
+
52
+ Finding pods in the CocoaPods project can take a long time when there are many dependencies. To speed things up, the `query` command accepts a `--cache` parameter, which is used to specify a YAML file containing previous output from the `--to-yaml` parameter. When the plugin sees the `--cache` parameter, it will use the data in this file instead of rebuiding the data from the current CocoaPods instance.
53
+
54
+ # Related Work
55
+
56
+ This plugin provides features that are similar to, and in some cases overlapping with, existing CocoaPods plugins.
57
+
58
+ * [list](https://guides.cocoapods.org/terminal/commands.html#pod_list), [search](https://github.com/CocoaPods/cocoapods-search), and [spec cat/which](https://guides.cocoapods.org/terminal/commands.html#pod_spec_cat): These commands look at all available pods, not just those in the sandbox, and they ignore local pods. The `search` command applies to all fields and cannot match a particular field.
59
+ * [cache list](https://guides.cocoapods.org/terminal/commands.html#pod_cache_list): Similar to `query --to-yaml` but does not provide filtering and outputs a limited set of data.
60
+ * [info](https://github.com/cocoapods/cocoapods-podfile_info): Similar to `query --to-yaml` but is old, unmaintained, and limited in options.
61
+ * [search sort](https://github.com/DenTelezhkin/cocoapods-sorted-search): Similar to `list` or `search` but allows sorting by stars, forks, or activity.
62
+
63
+ # Development
64
+
65
+ For local development of this plugin, the simplest approach is to install it into an existing app via absolute path. For example, if the code is in a directory called `projects/cocoapods-query` off the home directory, add the following line to the app's Gemfile:
66
+
67
+ gem 'cocoapods-query', path: "#{ENV['HOME']}/projects/cocoapods-query"
68
+
69
+ You can then make changes to the code and they will be executed when using the `query` command from the app's directory.
70
+
71
+ # Copyright
72
+
73
+ Copyright 2020 Square, Inc.
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pod/command/query'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CocoaPodsQuery
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cocoapods'
4
+ require 'json'
5
+ require 'yaml'
6
+
7
+ module Pod
8
+ class Command
9
+ class Query < Command
10
+ self.summary = 'Shows pods in the project filtered by name or other attribute'
11
+ self.description = <<-DESC
12
+ This command starts by finding all pods in the project, then filters out those that do not match
13
+ the specified criteria, and finally returns the results. In other words, the output is all pods
14
+ that satisfy the intersection of all search terms. (It returns all pods in the project if no
15
+ parameters are given.)
16
+
17
+ The starting list of pods comes either from the current instance or from a previously created cache
18
+ in YAML format (if --from-yaml is given). The output is either a list of pod names or a file containing
19
+ pod data in YAML format (if --to-yaml is given).
20
+
21
+ You can modify how the search terms are handled by specifying the optional --case-insensitive or
22
+ --substring flags. They apply to all search terms.
23
+ DESC
24
+
25
+ def self.options
26
+ [
27
+ ['--name=NAME', 'Include pods whose name matches the given string'],
28
+ ['--version=VERSION', 'Include pods whose version matches the given string'],
29
+ ['--author-email=EMAIL', 'Include pods having at least one author with the given email'],
30
+ ['--author-name=NAME', 'Include pods having at least one author of the given name'],
31
+ ['--summary=SUMMARY', 'Include pods whose summary matches the given string'],
32
+ ['--description=DESCRIPTION', 'Include pods whose description matches the given string'],
33
+ ['--source-file=FILE', 'Include pods whose source list includes the given file name'],
34
+ ['--swift', 'Only include pods that use Swift (--no-swift for only pods that do not)'],
35
+ ['--local', 'Only include locally sourced pods (--no-local for only remote pods)'],
36
+ ['--case-insensitive', 'Don\'t consider case when matching strings'],
37
+ ['--substring', 'Allow substring matching for string parameters'],
38
+ ['--to-yaml=FILE', 'Output the results in YAML format with additional Podspec data (authors, source files, dependencies, etc.) to the given file'],
39
+ ['--to-json=FILE', 'Output the results in JSON format with additional Podspec data (authors, source files, dependencies, etc.) to the given file'],
40
+ ['--cache=FILE', 'Load the sandbox data from the given YAML file (created previously with the --to-yaml parameter) instead of from the current sandbox instance']
41
+ ].concat(super)
42
+ end
43
+
44
+ def initialize(argv)
45
+ super
46
+ @name = argv.option('name')
47
+ @version = argv.option('version')
48
+ @author_email = argv.option('author-email')
49
+ @author_name = argv.option('author-name')
50
+ @summary = argv.option('summary')
51
+ @description = argv.option('description')
52
+ @source_file = argv.option('source-file')
53
+ @swift = argv.flag?('swift')
54
+ @local = argv.flag?('local')
55
+ @case_insensitive = argv.flag?('case-insensitive', false)
56
+ @substring = argv.flag?('substring', false)
57
+ @to_yaml = argv.option('to-yaml')
58
+ @to_json = argv.option('to-json')
59
+ @cache = argv.option('cache')
60
+ end
61
+
62
+ def run
63
+ UI.puts 'Loading targets...'
64
+
65
+ matching_targets = all_targets(@cache).select do |target|
66
+ (@name.nil? || str_match(@name, target[:name])) &&
67
+ (@version.nil? || str_match(@version, target[:version])) &&
68
+ (@author_name.nil? || target[:authors].any? { |author| !author[:name].nil? && str_match(@author_name, author[:name]) }) &&
69
+ (@author_email.nil? || target[:authors].any? { |author| !author[:email].nil? && str_match(@author_email, author[:email]) }) &&
70
+ (@summary.nil? || str_match(@summary, target[:summary])) &&
71
+ (@description.nil? || str_match(@description, target[:description])) &&
72
+ (@source_file.nil? || target[:source_files].nil? || target[:source_files].any? { |s| str_match(@source_file, s) }) &&
73
+ (@swift.nil? || @swift == target[:uses_swift]) &&
74
+ (@local.nil? || @local == target[:local])
75
+ end
76
+
77
+ File.open(@to_yaml, 'w') { |file| file.write(matching_targets.to_yaml) } if @to_yaml
78
+ File.open(@to_json, 'w') { |file| file.write(matching_targets.to_json) } if @to_json
79
+
80
+ matching_targets.each { |target| UI.puts target[:name] }
81
+ end
82
+
83
+ private
84
+
85
+ # Returns an array of all pods in the sandbox. Each element in the array is a hash with
86
+ # metadata about the pod such as version, authors, source files, dependencies, and more.
87
+ #
88
+ # @note For projects with a large dependency graph, this function can take a long time to
89
+ # run if a cache is not given.
90
+ #
91
+ # @param [String] target_cache
92
+ # If non-nil, the targets are loaded from this file instead of from the current
93
+ # sandbox instance. The file should contain the YAML-encoded results of a previous
94
+ # call to this function.
95
+ #
96
+ # @return [Array<Hash>] an array of hashes containing pod metadata
97
+ def all_targets(target_cache)
98
+ return YAML.safe_load(File.read(target_cache), permitted_classes: [Symbol]) unless target_cache.nil?
99
+
100
+ targets = Pod::Config.instance.with_changes(silent: true) do
101
+ Pod::Installer.targets_from_sandbox(
102
+ Pod::Config.instance.sandbox,
103
+ Pod::Config.instance.podfile,
104
+ Pod::Config.instance.lockfile
105
+ ).flat_map(&:pod_targets).uniq
106
+ end
107
+
108
+ targets.map do |target|
109
+ file = target.sandbox.local_podspec(target.pod_name)
110
+ swift_versions = target.root_spec.swift_versions
111
+ file_accessor = target.file_accessors.find { |accessor| accessor.spec.root == target.root_spec }
112
+ dependencies = target.root_spec.dependencies.map(&:name)
113
+
114
+ {
115
+ name: target.name,
116
+ version: target.version,
117
+ authors: target.root_spec.authors.map { |name, email| { name: name, email: email }.compact },
118
+ is_local: target.sandbox.local?(target.name),
119
+ root_directory: file_accessor.root.to_s,
120
+ podspec_file: file ? file.relative_path_from(file_accessor.root).to_s : nil,
121
+ license: target.root_spec.license,
122
+ summary: target.root_spec.summary,
123
+ description: target.root_spec.description,
124
+ homepage: target.root_spec.homepage,
125
+ uses_swift: target.uses_swift?,
126
+ swift_versions: swift_versions.empty? ? nil : swift_versions.map(&:to_s),
127
+ readme_file: file_accessor.readme.to_s.empty? ? nil : file_accessor.readme.relative_path_from(file_accessor.root).to_s,
128
+ platforms: target.root_spec.available_platforms.map { |platform| { name: platform.symbolic_name, version: platform.deployment_target.to_s } },
129
+ dependencies: dependencies.empty? ? nil : dependencies,
130
+ source_files: file_accessor.source_files.map { |pathname| pathname.relative_path_from(file_accessor.root).to_s }
131
+ }.compact
132
+ end
133
+ end
134
+
135
+ def str_match(str1, str2)
136
+ if @case_insensitive
137
+ str1 = str1.downcase
138
+ str2 = str2.downcase
139
+ end
140
+
141
+ @substring ? str2.include?(str1) : str1 == str2
142
+ end
143
+ end
144
+ end
145
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-query
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Trevor Harmon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-24 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: :development
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: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cocoapods
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: This plugin for CocoaPods helps locate pods in a project. It can show
56
+ all pods or filter them based on some search term, such as author name, source file,
57
+ dependency, and more. It is intended for projects with a large number of dependencies.
58
+ email:
59
+ - trevorh@squareup.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - CONTRIBUTING.md
65
+ - README.md
66
+ - lib/cocoapods_plugin.rb
67
+ - lib/cocoapods_query.rb
68
+ - lib/pod/command/query.rb
69
+ homepage: https://github.com/square/cocoapods-query
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.0.4
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: CocoaPods plugin to search for pods
92
+ test_files: []