Skip to content

Commit

Permalink
Merge pull request #5 from X140Yu/cocoapods-plugin
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
X140Yu committed Sep 14, 2018
2 parents d1ae203 + 42e5cdb commit 93633c4
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 24 deletions.
4 changes: 2 additions & 2 deletions cocoapods-dependency.gemspec
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'cocoapods/dependency/version'
require 'cocoapods-dependency/version'

Gem::Specification.new do |spec|
spec.name = 'cocoapods-dependency'
spec.version = Cocoapods::Dependency::VERSION
spec.version = CocoapodsDependency::VERSION
spec.authors = ['Xinyu Zhao']
spec.email = ['zhaoxinyu1994@gmail.com']

Expand Down
1 change: 1 addition & 0 deletions lib/cocoapods-dependency.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'cocoapods-dependency/version'
10 changes: 7 additions & 3 deletions lib/cocoapods/analyze.rb → lib/cocoapods-dependency/analyze.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
require 'cocoapods'
require 'pathname'

module Cocoapods
module CocoapodsDependency
#
# Analyze the project using cocoapods
#
class DependencyAnalyzer
class Analyzer
def self.analyze(podfile_dir_path)
path = Pathname.new(podfile_dir_path)
raise 'absolute path is needed' unless path.absolute?

Dir.chdir(podfile_dir_path) do
analyze_with_podfile(
path,
Expand All @@ -24,9 +25,11 @@ def self.podfile_dependencies(podfile)
children_definitions = td.recursive_children
children_definitions.each do |cd|
dependencies_hash_array = cd.send(:get_hash_value, 'dependencies')
next if dependencies_hash_array.count == 0
next if dependencies_hash_array.count.zero?

dependencies_hash_array.each do |item|
next if item.class.name != 'Hash'

item.each do |name, _|
res.push name
end
Expand Down Expand Up @@ -78,6 +81,7 @@ def self.analyze_with_podfile(_podfile_dir_path, podfile, lockfile = nil)

def self.find_dependencies(name, map, res, dependencies_map, root_name)
return unless map[name]

map[name].each do |k|
find_dependencies(k.name, map, res, dependencies_map, root_name)
dependency = dependencies_map[k.name.split('/')[0]]
Expand Down
1 change: 1 addition & 0 deletions lib/cocoapods-dependency/command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'cocoapods-dependency/command/dependency'
30 changes: 30 additions & 0 deletions lib/cocoapods-dependency/command/dependency.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'cocoapods-dependency/analyze'
require 'pp'
module Pod
class Command

class Dependency < Command
self.summary = 'Analyzes the dependencies of any cocoapods projects.'

self.description = <<-DESC
Analyzes the dependencies of any cocoapods projects. Subspecs are properly handled.
DESC

# self.arguments = 'NAME'

def initialize(argv)
@name = argv.shift_argument
super
end

def validate!
super
verify_podfile_exists!
end

def run
pp CocoapodsDependency::Analyzer.analyze_with_podfile(nil, config.podfile)
end
end
end
end
4 changes: 4 additions & 0 deletions lib/cocoapods-dependency/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# :nocov:
module CocoapodsDependency
VERSION = "0.1.0"
end
6 changes: 0 additions & 6 deletions lib/cocoapods/dependency/version.rb

This file was deleted.

1 change: 1 addition & 0 deletions lib/cocoapods_plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'cocoapods-dependency/command'
24 changes: 12 additions & 12 deletions spec/cocoapods/dependency_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
RSpec.describe Cocoapods::Dependency do
RSpec.describe 'CocoapodsDependency' do
it 'has a version number' do
expect(Cocoapods::Dependency::VERSION).not_to be nil
expect(CocoapodsDependency::VERSION).not_to be nil
end

it 'no podfile exists in path will raise error' do
expect { Cocoapods::DependencyAnalyzer.analyze(Pathname.new('/')) }.to raise_error(/No Podfile exists/)
expect { CocoapodsDependency::Analyzer.analyze(Pathname.new('/')) }.to raise_error(/No Podfile exists/)
end

it 'generate custom podfile' do
Expand All @@ -27,7 +27,7 @@
end

expect(
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
).to eq('Masonry' => [])
end

Expand All @@ -46,7 +46,7 @@
}

expect(
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
).to eq(res_map)
end

Expand All @@ -64,7 +64,7 @@
}

expect(
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
).to eq(res_map)
end

Expand All @@ -82,7 +82,7 @@
}

expect(
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
).to eq(res_map)
end

Expand All @@ -101,7 +101,7 @@
}

expect(
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
).to eq(res_map)
end

Expand All @@ -122,7 +122,7 @@
}

expect(
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
).to eq(res_map)
end

Expand All @@ -146,7 +146,7 @@
}

expect(
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
).to eq(res_map)
end

Expand All @@ -167,7 +167,7 @@
}

expect(
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
).to eq(res_map)
end

Expand All @@ -190,7 +190,7 @@
}

expect(
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
).to eq(res_map)
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Coveralls.wear!

require 'bundler/setup'
require 'cocoapods/analyze'
require 'cocoapods-dependency/analyze'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down

0 comments on commit 93633c4

Please sign in to comment.