Method: Fastlane::SwiftLaneManager.link_user_configs_to_project

Defined in:
fastlane/lib/fastlane/swift_lane_manager.rb


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 'fastlane/lib/fastlane/swift_lane_manager.rb', line 176

def self.link_user_configs_to_project(updated_message: nil)
  tool_files_folder = FastlaneCore::FastlaneFolder.path

  # All the tools that could have <tool name>file.swift their paths, and where we expect to find the user's tool files.
  all_user_tool_file_paths = TOOL_CONFIG_FILES.map do |tool_name|
    [
      File.join(tool_files_folder, "#{tool_name}.swift"),
      "../#{tool_name}.swift",
      "../../#{tool_name}.swift"
    ]
  end

  # Tool files the user now provides
  new_user_tool_file_paths = collect_tool_paths_for_replacement(all_user_tool_file_paths: all_user_tool_file_paths, look_for_new_configs: true)

  # Tool files we provide AND the user doesn't provide
  user_tool_files_possibly_removed = collect_tool_paths_for_replacement(all_user_tool_file_paths: all_user_tool_file_paths, look_for_new_configs: false)

  fastlane_runner_project = self.runner_project
  runner_target = target_for_fastlane_runner_project(runner_project: fastlane_runner_project)
  target_file_refs = target_source_file_refs(target: runner_target)

  # Swap in all new user supplied configs into the project
  project_modified = swap_paths_in_target(
    file_refs_to_swap: target_file_refs,
    expected_path_to_replacement_path_tuples: new_user_tool_file_paths
  )

  # Swap out any configs the user has removed, inserting fastlane defaults
  project_modified = swap_paths_in_target(
    file_refs_to_swap: target_file_refs,
    expected_path_to_replacement_path_tuples: user_tool_files_possibly_removed
  ) || project_modified

  if project_modified
    fastlane_runner_project.save
    updated_message ||= "Updated #{FastlaneCore::FastlaneFolder.swift_runner_project_path}"
    UI.success(updated_message)
  else
    UI.success("FastlaneSwiftRunner project is up-to-date")
  end

  return project_modified
end