Skip to content

Commit

Permalink
reimplement once again
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-makarov committed Feb 22, 2021
1 parent de060bc commit a90848a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
53 changes: 26 additions & 27 deletions lib/cocoapods-core/single_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,29 @@ def raw_versions
end.compact
end

def podspecs
Pathname.glob(repo.join('*.podspec'))
def process_podspec(path, output_path)
spec = Specification.from_file(path)
File.open(output_path, 'w') { |f| f.write(spec.to_pretty_json) }
output_path
end

def preload_podspecs_at_version(version)
version_dir = repo.join('.git', '.specs', version.to_s)
if version_dir.exist?
Pathname.glob(version_dir.join('*'))
else
repo_git(['checkout', version.to_s])
version_dir.mkpath
Pathname.glob(repo.join('*.podspec')).map do |podspec_path|
name = podspec_path.basename('.podspec')
process_podspec(podspec_path, version_dir.join("#{name}.podspec.json"))
end.compact
end
end

def spec_paths
raw_versions.map do |version|
podspecs.map do |podspec|
specification_path(podspec.basename('.podspec'), version)
end.compact
preload_podspecs_at_version(version)
end.flatten
end

Expand All @@ -52,10 +66,9 @@ def spec_paths
#
#
def pods
pods = spec_paths.map do |spec_path|
spec_paths.map do |spec_path|
spec_path.basename('.podspec.json').to_s
end
Set.new(pods).sort
end.flatten.uniq.sort
end

# @return [Array<Version>] all the available versions for the Pod, sorted
Expand All @@ -75,16 +88,6 @@ def versions(name)
end.compact.sort.reverse
end

# @return [Specification] the specification for a given version of Pod.
#
# @param @see specification_path
#
def specification(name, version)
repo_git(['checkout', version])

Specification.from_file(specification_path(name, version))
end

# Returns the path of the specification with the given name and version.
#
# @param [String] name
Expand All @@ -99,17 +102,13 @@ def specification_path(name, version)
raise ArgumentError, 'No name' unless name
raise ArgumentError, 'No version' unless version

path = repo.join('.git', '.specs', name, version.to_s)
preload_podspecs_at_version(version)

unless path.join("#{name}.podspec.json").exist?
repo_git(['checkout', version])
return unless repo.join("#{name}.podspec").exist?
path = repo.join('.git', '.specs', version.to_s, "#{name}.podspec.json")

spec = Specification.from_file(repo.join("#{name}.podspec"))
path.mkpath
File.open(path.join("#{name}.podspec.json"), 'w') { |f| f.write(spec.to_pretty_json) }
end
path.join("#{name}.podspec.json")
return nil unless path.exist?

path
end

# @return [Array<Specification>] all the specifications contained by the
Expand Down
3 changes: 2 additions & 1 deletion lib/cocoapods-core/source/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ def source_from_path(path)
TrunkSource.new(key)
when (key + '.url').exist?
CDNSource.new(key)
when Dir[key.join('*.podspec')].count > 0
when key.join('.git', '.specs').exist? || Dir[key.join('*.podspec')].count > 0
SingleSource.new(key)
else
require 'pry'; binding.pry
Source.new(key)
end
end
Expand Down

0 comments on commit a90848a

Please sign in to comment.