Class: Pod::Command::MPAAS::Info

Inherits:
Pod::Command::MPAAS show all
Defined in:
lib/cocoapods-mPaaS/command/mpaas/info.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Info

Returns a new instance of Info.



13
14
15
16
17
18
# File 'lib/cocoapods-mPaaS/command/mpaas/info.rb', line 13

def initialize(argv)
  @module_input, @version_input = argv.shift_argument, argv.shift_argument
  @show_pod = argv.flag?("show-pod")
  @only_mPaaS = argv.flag?("only-mPaaS")
  super
end

Instance Method Details

#runObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/cocoapods-mPaaS/command/mpaas/info.rb', line 95

def run
  if @show_pod
    project_dir = Dir::pwd
    podfile_path = File.join(project_dir, "Podfile")
    podfile = Pod::Podfile.from_file(podfile_path)
    podfile.dependencies.each do |dependency|
      LogTools.p_green dependency.to_s
    end
  elsif !@version_input
    podfile_path = File.join(Dir::pwd, "Podfile")
    if File.exist?(podfile_path)
      mpaas_podfile = MPaaSPodfile.new
      mpaas_podfile.run(podfile_path)

      if mpaas_podfile.localContentJsonPath
        abs_path = File.expand_path(mpaas_podfile.localContentJsonPath, Dir::pwd)
        if File.exist?(abs_path)
          content_hash = JSON.parse(File.read(abs_path))
          version = content_hash["baseline"] || "unknown"
          modules_hash = content_hash["modules"] || content_hash
          module_info_hash = content_hash["module_info"]
          removable_options_hash = content_hash["removable_options"]
          optional_frameworks_hash = content_hash["optional_frameworks"]
          options_hash = content_hash["options"]
          show_baseline_info(version, modules_hash, module_info_hash, removable_options_hash, optional_frameworks_hash, options_hash)
          return
        else
          LogTools.p_yellow "Local content.json not found at: #{abs_path}, falling back..."
        end
      end
    end

    baseline_file_path = File.join(CocoapodsmPaaS::MPAAS_LOCAL_PATH, "baseline")
    if File::exist?(baseline_file_path)
      Dir::foreach(baseline_file_path) do |version|
        baseline_filepath = File.join(baseline_file_path, version, "content.json")
        unless File::exist?(baseline_filepath)
          next
        end
        content_hash = BaselineTools.getContentFileByVersion(version)
        baseline_hash = BaselineTools.getBaselineByVersion(version)
        removable_options_hash = content_hash["removable_options"]
        optional_frameworks_hash = content_hash["optional_frameworks"]
        options_hash = content_hash["options"]
        show_baseline_info(version, baseline_hash, nil, removable_options_hash, optional_frameworks_hash, options_hash)
      end
    else
      LogTools.p_red "No baseline file found !!! Check the path : #{baseline_file_path} "
    end
  else
    baseline_file_path = File.join(CocoapodsmPaaS::MPAAS_LOCAL_PATH, "baseline")
    if File::exist?(baseline_file_path)
      Dir::foreach(baseline_file_path) do |version|
        if version != @version_input
          next
        end
        baseline_filepath = File.join(baseline_file_path, version, "content.json")
        unless File::exist?(baseline_filepath)
          next
        end
        content_hash = BaselineTools.getContentFileByVersion(version)
        baseline_hash = BaselineTools.getBaselineByVersion(version)
        removable_options_hash = content_hash["removable_options"]
        optional_frameworks_hash = content_hash["optional_frameworks"]
        options_hash = content_hash["options"]
        show_baseline_info(version, baseline_hash, nil, removable_options_hash, optional_frameworks_hash, options_hash)
      end
    else
      LogTools.p_red "No baseline file found !!! Check the path : #{baseline_file_path} "
    end
  end
end

#show_baseline_info(version, baseline_hash, module_info_hash, removable_options_hash = nil, optional_frameworks_hash = nil, options_hash = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/cocoapods-mPaaS/command/mpaas/info.rb', line 20

def show_baseline_info(version, baseline_hash, module_info_hash, removable_options_hash = nil, optional_frameworks_hash = nil, options_hash = nil)
  LogTools.p ""
  LogTools.p_red version

  # 反查:哪些模块是别人的可选依赖(模块名 → 父模块名列表)
  optional_of = {}
  if options_hash
    options_hash.each do |parent_name, opt_names|
      opt_names.each do |opt_name|
        optional_of[opt_name] ||= []
        optional_of[opt_name] << parent_name
      end
    end
  end

  baseline_hash.each do |name, dependencies_hash|
    if @module_input && !name.downcase.include?(@module_input.downcase)
      next
    end

    LogTools.p_green "mPaaS_pod \"#{name}\", \"#{version}\""

    if module_info_hash && module_info_hash[name]
      info = module_info_hash[name]
      LogTools.p_yellow "# #{info["title"]};#{info["description"]};#{info["releaseNote"]}"
    else
      LogTools.p_yellow "# " + BaselineTools.getModuleInfoByName(name, version)
    end

    # 标注当前模块可移除的可选子模块
    if removable_options_hash && removable_options_hash[name]
      removable = removable_options_hash[name]
      LogTools.p_yellow "# removable modules: #{removable.join(', ')}"
    end

    # 标注当前模块本身是哪些父模块的可选依赖
    if optional_of[name]
      LogTools.p_yellow "# removable by: #{optional_of[name].join(', ')}"
    end

    if @only_mPaaS
      LogTools.p ""
      next
    end

    # 构建"可被移除" frameworks 集合(当前模块本身是别人的可选依赖时,它的直接 frameworks)
    removable_by_pods = Set.new
    if optional_of[name] && optional_frameworks_hash && optional_frameworks_hash[name]
      optional_frameworks_hash[name].each { |fw| removable_by_pods.add(fw) }
    end

    # 构建"可移除" frameworks 集合(当前模块的可选子模块的直接 frameworks)
    removable_pods = Set.new
    if removable_options_hash && removable_options_hash[name] && optional_frameworks_hash
      removable_options_hash[name].each do |opt_name|
        if optional_frameworks_hash[opt_name]
          optional_frameworks_hash[opt_name].each { |fw| removable_pods.add(fw) }
        end
      end
    end

    dependencies_hash.each do |pod_name, pod_version|
      if removable_by_pods.include?(pod_name)
        LogTools.p "pod \"#{pod_name}\", \"#{pod_version}\"  # [removable by parent]"
      elsif removable_pods.include?(pod_name)
        LogTools.p "pod \"#{pod_name}\", \"#{pod_version}\"  # [removable]"
      else
        LogTools.p "pod \"#{pod_name}\", \"#{pod_version}\""
      end
    end

    LogTools.p ""
  end
end