Class: Pod::Command::MPAAS::Update

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Update

Returns a new instance of Update.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cocoapods-mPaaS/command/mpaas/update.rb', line 22

def initialize(argv)
  @local_path = argv.option('local')
  @local_flag = argv.flag?('local') if @local_path.nil?
  @baseline_input = argv.shift_argument
  @all = argv.flag?('all')
  @install = argv.flag?('install')
  @pre = argv.flag?('pre')
  @dev = argv.flag?('dev')
  @httpRepo = argv.flag?('http')
  super
end

Class Method Details

.optionsObject



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

def self.options
  [
    ['--all', 'Update all (baseline list, mPaaS repo, and plugin itself).'],
    ['--pre', 'Include pre-release versions when updating.'],
    ['--dev', 'Include dev-test versions when updating.'],
    ['--local=PATH', 'Use local Component.json instead of network. PATH is optional if configured in Podfile.']
  ].concat(super)
end

Instance Method Details

#local_mode?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/cocoapods-mPaaS/command/mpaas/update.rb', line 34

def local_mode?
  @local_path || @local_flag
end

#manage_private_cocoapods_repo(repo_name, repo_url) ⇒ Object



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
# File 'lib/cocoapods-mPaaS/command/mpaas/update.rb', line 106

def manage_private_cocoapods_repo(repo_name, repo_url)
  LogTools.p_green Pod::MPAAS::Localization.t('mpaas.repo_manager.checking_repo', repo_name: repo_name)

  stdout, stderr, status = Open3.capture3("pod repo list")

  unless status.success?
    LogTools.p_red Pod::MPAAS::Localization.t('mpaas.repo_manager.error_details', message: stderr) unless stderr.empty?
    return false
  end

  if !stderr.empty?
    LogTools.p_yellow Pod::MPAAS::Localization.t('mpaas.repo_manager.pod_repo_list_warning', message: stderr)
  end

  repo_exists = false
  stdout.each_line do |line|
    if line.strip == repo_name
      repo_exists = true
      break
    end
  end

  if repo_exists
    update_success = system("pod repo update #{repo_name}")

    if update_success
      LogTools.p_green "update_success #{repo_name}"
    else
      LogTools.p_red Pod::MPAAS::Localization.t('mpaas.repo_manager.repo_update_failed', repo_name: repo_name)
      return false
    end
  else
    LogTools.p_green Pod::MPAAS::Localization.t('mpaas.repo_manager.repo_not_exists_adding', repo_name: repo_name)
    add_success = system("pod repo add #{repo_name} #{repo_url}")

    if add_success
      LogTools.p_green Pod::MPAAS::Localization.t('mpaas.repo_manager.validating_new_repo', repo_name: repo_name)
    else
      LogTools.p_red Pod::MPAAS::Localization.t('mpaas.repo_manager.add_failure_reasons', repo_url: repo_url)
      return false
    end
  end

  return true
rescue Errno::ENOENT => e
  LogTools.p_red Pod::MPAAS::Localization.t('mpaas.repo_manager.error_details', message: e.message)
  return false
rescue => e
  LogTools.p_red Pod::MPAAS::Localization.t('mpaas.repo_manager.unknown_error', message: e.message)
  return false
end

#resolve_content_output_path(version) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cocoapods-mPaaS/command/mpaas/update.rb', line 38

def resolve_content_output_path(version)
  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
      return File.expand_path(mpaas_podfile.localContentJsonPath, Dir::pwd)
    end
  end
  File.join(CocoapodsmPaaS::MPAAS_LOCAL_PATH, "baseline", version, "content.json")
end

#runObject



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/cocoapods-mPaaS/command/mpaas/update.rb', line 168

def run
  if local_mode?
    run_local
    return
  end

  if @all
    LogTools.p_red Pod::MPAAS::Localization.t('mpaas.update_command.execute_plugin_install_script')
    LogTools.p "sh <(curl -s #{CocoapodsmPaaS::MPAAS_IOS_PATH_PREFIX}/cocoapods/installmPaaSCocoaPodsPlugin.sh)"

    system "curl -o shell_installer_text #{CocoapodsmPaaS::MPAAS_IOS_PATH_PREFIX}/cocoapods/installmPaaSCocoaPodsPlugin.sh"
    system "sh shell_installer_text"
    system "rm shell_installer_text"

    LogTools.p_red Pod::MPAAS::Localization.t('mpaas.update_command.update_mpaas_repo')
    LogTools.p_green "update mPaaS repo ..."
    updatemPaaSRepo
    LogTools.p_green "update mPaaS repo Done"

    LogTools.p_red Pod::MPAAS::Localization.t('mpaas.update_command.update_local_baseline')
    LogTools.p_green "update mPaaS baseline ..."
    updateLocalBaseline
    LogTools.p_green "update mPaaS baseline Done"

  elsif @baseline_input
    content_path = resolve_content_output_path(@baseline_input)
    LogTools.p_green "1. update #{@baseline_input} baseline file ..."
    BaselineTools.updateContentFileByComponent(@baseline_input, false, @pre, @dev, content_path)
    LogTools.p_green "   update #{@baseline_input} baseline file Done"

    LogTools.p ""
    LogTools.p_green "2. update mPaaS repo ..."
    updatemPaaSRepo
    LogTools.p_green "   update mPaaS repo Done"

  else
    LogTools.p_red Pod::MPAAS::Localization.t('mpaas.update_command.update_mpaas_repo_second')
    LogTools.p_green "update mPaaS repo ..."
    updatemPaaSRepo
    LogTools.p_green "update mPaaS repo Done"

    LogTools.p_red Pod::MPAAS::Localization.t('mpaas.update_command.update_local_baseline_second')
    LogTools.p_green "update mPaaS baseline ..."
    updateLocalBaseline
    LogTools.p_green "update mPaaS baseline Done"

    if @install
      LogTools.p_green "pod install ..."
      system "pod install"
    end
  end
end

#run_localObject



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/update.rb', line 50

def run_local
  podfile_path = File.join(Dir::pwd, "Podfile")

  unless File.exist?(podfile_path)
    LogTools.p_red "Error: Podfile not found in current directory (#{Dir::pwd})"
    return
  end

  mpaas_podfile = MPaaSPodfile.new
  mpaas_podfile.run(podfile_path)

  component_path = @local_path
  if component_path.nil? || component_path.empty?
    component_path = mpaas_podfile.localComponentJsonPath
  end

  unless component_path && !component_path.empty?
    LogTools.p_red "Error: No Component.json path specified."
    LogTools.p_red "Use: pod mpaas update --local=path/to/Component.json"
    LogTools.p_red "Or configure in Podfile: mPaaS_local_component_json 'path/to/Component.json'"
    return
  end

  component_abs = File.expand_path(component_path, Dir::pwd)
  unless File.exist?(component_abs)
    LogTools.p_red "Error: Component JSON not found at: #{component_abs}"
    return
  end

  baseline = mpaas_podfile.mPaaSBaseline
  unless baseline
    LogTools.p_red "Error: mPaaS_baseline not found in Podfile"
    return
  end

  content_abs = resolve_content_output_path(baseline)

  LogTools.p_green "Reading Component.json from: #{component_abs}"
  LogTools.p_green "Baseline: #{baseline}"

  BaselineTools.updateContentFileFromLocal(component_abs, content_abs, baseline)

  LogTools.p_green "content.json updated at: #{content_abs}"
end

#updateLocalBaselineObject



158
159
160
161
162
163
164
165
166
# File 'lib/cocoapods-mPaaS/command/mpaas/update.rb', line 158

def updateLocalBaseline
  baseline_array = BaselineTools.getCurrentBaselineOnline
  baseline_array && baseline_array.each do |baseline|
    LogTools.p_green "1. update #{baseline} baseline file ..."
    content_path = resolve_content_output_path(baseline)
    BaselineTools.updateContentFileByComponent(baseline, false, @pre, false, content_path)
    LogTools.p_green "   update #{baseline} baseline file Done"
  end
end

#updatemPaaSRepoObject



95
96
97
98
99
100
101
102
# File 'lib/cocoapods-mPaaS/command/mpaas/update.rb', line 95

def updatemPaaSRepo
  if @dev then
    system "pod repo update #{CocoapodsmPaaS::MPAAS_REPO_NAME}"
    self.manage_private_cocoapods_repo(CocoapodsmPaaS::MPAAS_REPO_NAME_DEV, @httpRepo ? CocoapodsmPaaS::MPAAS_REPO_URL_DEV_HTTP : CocoapodsmPaaS::MPAAS_REPO_URL_DEV)
  else
    system "pod repo update #{CocoapodsmPaaS::MPAAS_REPO_NAME}"
  end
end