cocoapods-dependManager 0.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 73928a8843d69a8b6f6060db1d0153e67e165fa3374de81fc1dbc6840e92f977
4
+ data.tar.gz: 3e3c5b530603e546a73a8ad95091f4feb97c1c2a7744b56c326888e8344f358f
5
+ SHA512:
6
+ metadata.gz: 86939d4000c10c78b382a965f65ed7bb32a29f362b57cbf264bb9849565fe516f7b38de03a21219ad68e6a2b802b1a9b012ec920aef9a6645d73dc0b17399d6f
7
+ data.tar.gz: c2047c289157af949820e13837a409b0f8dea831a4bca4fa727edcc154bd67f5286c59b3c3d20dd2e3d45ae3b74a0320ac39a6edbb4897a4f41f5d51e7dd9ccc
@@ -0,0 +1,112 @@
1
+ module Pod
2
+ class Command
3
+ class Dependmanager
4
+ class Add < Dependmanager
5
+ self.summary = "Add podspec dependency"
6
+ self.description = <<-DESC
7
+ Add a podspec dependency to all targets or a target in working Podfile.
8
+
9
+ Examples:
10
+
11
+ $ pod depend add AFNetworking
12
+ $ pod depend add AFNetworking --target=AppleWatch
13
+ $ pod depend add AFNetworking "~> 1.0.0"
14
+ $ pod depend add AFNetworking https://github.com/gowalla/AFNetworking.git --tag=1.0.0
15
+ $ pod depend add AFNetworking ~/Documents/AFNetworking
16
+ $ pod depend add JSONKit https://example.com/JSONKit.podspec
17
+ DESC
18
+
19
+ self.arguments = [
20
+ CLAide::Argument.new('NAME', true),
21
+ CLAide::Argument.new(%w(REQUIREMENT GIT-URL SPEC-URL LOCALPATH), false),
22
+ ]
23
+
24
+ def self.options
25
+ [
26
+ ['--target=TARGET', 'The target where you want to add the dependency'],
27
+ ['--tag=TAG', 'The git tag you want to depend'],
28
+ ['--commit=COMMIT', 'The git commit you want to depend'],
29
+ ['--branch=BRANCH', 'The git branch you want to depend'],
30
+ ['--podfile=PODFILE', 'podfile name, defalut Podfile'],
31
+ ].concat(super)
32
+ end
33
+
34
+ def initialize(argv)
35
+ @git_tag = argv.option('tag')
36
+ @git_commit = argv.option('commit')
37
+ @git_branch = argv.option('branch')
38
+ @target = argv.option('target')
39
+ @podfile_name = argv.option('podfile')
40
+ @name = argv.shift_argument
41
+ @source = argv.shift_argument
42
+ super
43
+ end
44
+
45
+ def validate!
46
+ super
47
+ help! 'A Pod name is required.' unless @name
48
+ end
49
+
50
+ require 'cocoapods-dependManager/command/converter'
51
+ def run
52
+ # verify_podfile_exists!
53
+ podfile_path = ''
54
+ if @podfile_name
55
+ podfile_path = Pathname.pwd + @podfile_name
56
+ else
57
+ podfile_path = Pathname.pwd + 'Podfile'
58
+ end
59
+ podfile = Podfile.from_file(podfile_path)
60
+ contents ||= File.open(podfile_path, 'r:utf-8') { |f| f.read }
61
+
62
+ dependency = Dependency.new(@name, self.requirements)
63
+
64
+ podfile.target_definitions.each do |name, definition|
65
+ if name != "Pods" && (@target == nil || @target == name)
66
+ newTargetContents = CocoapodsDepend::Converter.target_dependencies_to_ruby(definition.name, definition.dependencies.push(dependency))
67
+ contents = contents.gsub(/^target\s[\"|']#{name}[\"|'].+?end\n[\n]?/m, (newTargetContents + "\n\n"))
68
+ end
69
+ end
70
+ podfile_path.open('w') { |f| f << contents}
71
+ end
72
+
73
+ def requirements
74
+ if not @source
75
+ requirements = nil
76
+ elsif git_url?(@source)
77
+ requirements = {:git => @source}
78
+ requirements[:tag] = @git_tag if @git_tag
79
+ requirements[:commit] = @git_commit if @git_commit
80
+ requirements[:branch] = @git_branch if @git_branch
81
+ elsif podspec_url?(@source)
82
+ requirements = {:podspec => @source}
83
+ elsif local_path?(@source)
84
+ requirements = {:path => @source}
85
+ else
86
+ requirements = @source
87
+ end
88
+ requirements
89
+ end
90
+
91
+ def http_url?(name)
92
+ prefixs = ['http://', 'https://']
93
+ prefixs.any? { |prefix| name.start_with?(prefix) }
94
+ end
95
+
96
+ def git_url?(name)
97
+ http_url?(name) && name.end_with?('.git')
98
+ end
99
+
100
+ def podspec_url?(name)
101
+ http_url?(name) && name.end_with?('.podspec')
102
+ end
103
+
104
+ def local_path?(name)
105
+ prefixs = ['/', '~/', './']
106
+ prefixs.any? { |prefix| name.start_with?(prefix) }
107
+ end
108
+
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,31 @@
1
+ require 'cocoapods-core'
2
+
3
+ module CocoapodsDepend
4
+ class Converter
5
+ def self.dependency_to_ruby(dependency)
6
+ base_code = "pod '#{dependency.name}'"
7
+ requirement_code = dependency.requirement.to_s
8
+ extrnal_code = dependency.external_source.to_s.gsub(/[{}]/, "").gsub(/["]/, "'")
9
+
10
+ base_code += ", '#{requirement_code}'" unless requirement_code == ">= 0"
11
+ # base_code += ", #{dependency.head.to_s}" if dependency.head
12
+ base_code += ", #{extrnal_code}" unless extrnal_code.empty?
13
+
14
+ base_code
15
+ end
16
+
17
+ def self.target_dependencies_to_ruby(target_name, dependencies)
18
+ target_code = "target '#{target_name}' do\n\n"
19
+
20
+ dependencies.each do |dependency|
21
+ target_code += "#{dependency_to_ruby(dependency)}\n"
22
+ end
23
+
24
+ target_code + "\nend"
25
+ end
26
+
27
+ def self.target_definition_to_ruby(target_definition)
28
+ target_dependencies_to_ruby(target_definition.name, target_definition.dependencies)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ module Pod
2
+ class Command
3
+ # This is an example of a cocoapods plugin adding a top-level subcommand
4
+ # to the 'pod' command.
5
+ #
6
+ # You can also create subcommands of existing or new commands. Say you
7
+ # wanted to add a subcommand to `list` to show newly deprecated pods,
8
+ # (e.g. `pod list deprecated`), there are a few things that would need
9
+ # to change.
10
+ #
11
+ # - move this file to `lib/pod/command/list/deprecated.rb` and update
12
+ # the class to exist in the the Pod::Command::List namespace
13
+ # - change this class to extend from `List` instead of `Command`. This
14
+ # tells the plugin system that it is a subcommand of `list`.
15
+ # - edit `lib/cocoapods_plugins.rb` to require this file
16
+ #
17
+ # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
18
+ # in the `plugins.json` file, once your plugin is released.
19
+ #
20
+ class Dependmanager < Command
21
+ self.summary = 'Short description of cocoapods-dependManager.'
22
+ self.abstract_command = true
23
+ require 'cocoapods-dependManager/command/add.rb'
24
+ require 'cocoapods-dependManager/command/list.rb'
25
+ require 'cocoapods-dependManager/command/remove.rb'
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,59 @@
1
+ module Pod
2
+ class Command
3
+ class Dependmanager
4
+ class List < Dependmanager
5
+ self.summary = "list dependencies"
6
+
7
+ self.description = <<-DESC
8
+ List all dependencies in working podfile
9
+ DESC
10
+
11
+ def self.options
12
+ [
13
+ ['--target=TARGET', 'list all dependencies in `TARGET`'],
14
+ ['--podfile=PODFILE', 'podfile name, defalut Podfile'],
15
+ ].concat(super)
16
+ end
17
+
18
+ def initialize(argv)
19
+ @target = argv.option('target')
20
+ @podfile_name = argv.option('podfile')
21
+ super
22
+ end
23
+
24
+ def run
25
+ podfile_path = ''
26
+ if @podfile_name
27
+ podfile_path = Pathname.pwd + @podfile_name
28
+ else
29
+ podfile_path = Pathname.pwd + 'Podfile'
30
+ end
31
+ target_definitions = Podfile.from_file(podfile_path).target_definitions
32
+ if @target
33
+ unless target_definitions.has_key?(@target)
34
+ help! 'The target is not exist'
35
+ else
36
+ print_target_dependencies(target_definitions[@target])
37
+ end
38
+ else
39
+ target_definitions.each do |name, definition|
40
+ unless name == 'Pods'
41
+ print_target_dependencies(definition)
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ def print_target_dependencies(target_definition)
48
+ UI.title "Target #{target_definition.name}" do
49
+ target_definition.dependencies.each do |dependency|
50
+ UI.puts "- #{dependency.to_s}"
51
+ end
52
+ end
53
+ UI.puts "\n"
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,61 @@
1
+ module Pod
2
+ class Command
3
+ class Dependmanager
4
+ class Remove < Dependmanager
5
+ self.summary = "Remove podspec dependency"
6
+ self.description = <<-DESC
7
+ Remove a podspec dependency at all targets or a target in working Podfile.
8
+
9
+ Examples:
10
+
11
+ $ pod depend remove AFNetworking
12
+ $ pod depend remove AFNetworking --target=AppleWatch
13
+ DESC
14
+
15
+ self.arguments = [
16
+ CLAide::Argument.new('NAME', true),
17
+ ]
18
+
19
+ def self.options
20
+ [
21
+ ['--target=TARGET', 'The target where you want to remove the dependency.'],
22
+ ['--podfile=PODFILE', 'podfile name, defalut Podfile'],
23
+ ].concat(super)
24
+ end
25
+
26
+ def initialize(argv)
27
+ @target = argv.option('target')
28
+ @name = argv.shift_argument
29
+ @podfile_name = argv.option('podfile')
30
+ super
31
+ end
32
+
33
+ def validate!
34
+ super
35
+ help! 'A Pod name is required.' unless @name
36
+ end
37
+
38
+ require 'cocoapods-dependManager/command/converter'
39
+ def run
40
+ podfile_path = ''
41
+ if @podfile_name
42
+ podfile_path = Pathname.pwd + @podfile_name
43
+ else
44
+ podfile_path = Pathname.pwd + 'Podfile'
45
+ end
46
+ podfile = Podfile.from_file(podfile_path)
47
+ contents ||= File.open(podfile_path, 'r:utf-8') { |f| f.read }
48
+
49
+ podfile.target_definitions.each do |name, definition|
50
+ if name != "Pods" && (@target == nil || @target == name)
51
+ newTargetDependencies = definition.dependencies.delete_if { |d| d.name == @name }
52
+ newTargetContents = CocoapodsDepend::Converter.target_dependencies_to_ruby(definition.name, newTargetDependencies)
53
+ contents = contents.gsub(/^target\s[\"|']#{name}[\"|'].+?end\n[\n]?/m, (newTargetContents + "\n\n"))
54
+ end
55
+ end
56
+ podfile_path.open('w') { |f| f << contents}
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-dependManager/command/dependManager'
@@ -0,0 +1,3 @@
1
+ module CocoapodsDependmanager
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-dependManager/gem_version'
@@ -0,0 +1 @@
1
+ require 'cocoapods-dependManager/command'
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-dependManager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - huainanzi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-25 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '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: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: edit Podfile(add,remove,list)
42
+ email:
43
+ - 1033459670@qq.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/cocoapods-dependManager.rb
49
+ - lib/cocoapods-dependManager/command.rb
50
+ - lib/cocoapods-dependManager/command/add.rb
51
+ - lib/cocoapods-dependManager/command/converter.rb
52
+ - lib/cocoapods-dependManager/command/dependManager.rb
53
+ - lib/cocoapods-dependManager/command/list.rb
54
+ - lib/cocoapods-dependManager/command/remove.rb
55
+ - lib/cocoapods-dependManager/gem_version.rb
56
+ - lib/cocoapods_plugin.rb
57
+ homepage: https://github.com/EXAMPLE/cocoapods-dependManager
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.1.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A longer description of cocoapods-dependManager.
80
+ test_files: []