Module: Pod::Meta::MetaReference

Defined in:
lib/cocoapods-modularization/meta/meta_reference.rb

Constant Summary collapse

PODFILE_NAMES =
[
  'CocoaPods.podfile.yaml',
  'CocoaPods.podfile',
  'Podfile',
  'Podfile.rb',
].freeze

Class Method Summary collapse

Class Method Details

.decode_podfile(config) ⇒ Object

podfile => meta & data



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cocoapods-modularization/meta/meta_reference.rb', line 11

def decode_podfile(config)
  # check podfile
  podfile = Podfile.from_file(podfile_path_in_dir(installation_root))

  unless File.directory?(MetaConstants.pods_scripts_path)
    FileUtils.mkdir_p(MetaConstants.pods_scripts_path)
  end

  unless File.directory?(MetaConstants.pods_generator_path)
    FileUtils.mkdir_p(MetaConstants.pods_generator_path)
  end

  UI.puts "podfile to meta"
  podfile_to_meta(podfile)

  UI.puts "podfile to data"
  podfile_to_data(podfile, config)
end

.encode_podfile(enable_branch = false) ⇒ Object

podfile <= meta & data



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cocoapods-modularization/meta/meta_reference.rb', line 31

def encode_podfile(enable_branch = false)
  raise 'meta.yml not found, run \'pod mod sync\' at first' unless File.exists?(Meta::MetaConstants.meta_path)
  meta = MetaConstants.generate_yml_to_hash(MetaConstants.meta_path)

  raise 'data.yml not found, run \'pod mod sync\' at first' unless File.exists?(Meta::MetaConstants.data_path)
  data = MetaConstants.read_data(enable_branch)

  target_definitions = meta['target_definitions']
  cached_branch_hash = enable_branch ? Private::PrivateCache.cached_branch_hash : nil
  target_definitions.each do |target_definition|
    next unless target_definition.kind_of?(Hash)
    meta_dependency_from_data(target_definition, data, enable_branch)
  end

  File::open('CocoaPods.podfile.yaml', "w") { |io| io.puts meta.to_yaml }
end

.installation_rootObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cocoapods-modularization/meta/meta_reference.rb', line 48

def installation_root
  @installation_root ||= begin
    current_dir = Pathname.new(Dir.pwd.unicode_normalize(:nfkc))
    current_path = current_dir
    until current_path.root?
      if podfile_path_in_dir(current_path)
        installation_root = current_path
        unless current_path == current_dir
          UI.puts("[in #{current_path}]")
        end
        break
      else
        current_path = current_path.parent
      end
    end
    installation_root || current_dir
  end
end

.podfile_path_in_dir(dir) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/cocoapods-modularization/meta/meta_reference.rb', line 67

def podfile_path_in_dir(dir)
  PODFILE_NAMES.each do |filename|
    candidate = dir + filename
    if candidate.file?
      return candidate
    end
  end
  nil
end