Is the heuristic CocoaPods uses for the “pod try” command documented anywhere?

a 夏天 提交于 2019-12-21 09:36:45

问题


In CocoaPods v.0.29, the 'pod try' command was added (see http://blog.cocoapods.org/CocoaPods-0.29/). From the documentation (bold emphasis mine):

In other words the command automates the following steps:

  1. Checkout the source of the Pod in a temporary directory.
  2. Search for any project looking like a demo project using some simple heuristics.
  3. Install any CocoaPods dependencies if needed by the located project.
  4. Open the workspace/project in Xcode.

I've searched both Google and StackOverflow and have not been able to find any documentation about the specific heuristics that CocoaPods uses to locate a demo project. Is the process by which CocoaPods locates a demo project, and/or best practices for including a demo project and scheme documented anywhere? I am putting together a library which I hope to turn into a CocoaPod soon, and would like to ensure that my sample project will actually work correctly with CocoaPods.

Thank you for your time.


回答1:


I was looking for this as well and the only thing I got was the source of the pod-try plugin:

# Picks a project or workspace suitable for the demo purposes in the
# given directory.
#
# To decide the project simple heuristics are used according to the name,
# if no project is found this method raises and `Informative` otherwise
# if more than one project is found the choice is presented to the user.
#
# @param  [#to_s] dir
#         The path where to look for projects.
#
# @return [String] The path of the project.
#
def pick_demo_project(dir)
  projs = projects_in_dir(dir)
  if projs.count == 0
    raise Informative, 'Unable to find any project in the source files' \
      " of the Pod: `#{dir}`"
  elsif projs.count == 1
    projs.first
  elsif (workspaces = projs.grep(/(demo|example).*\.xcworkspace$/i)).count == 1
    workspaces.first
  elsif (projects = projs.grep(/demo|example/i)).count == 1
    projects.first
  else
    message = 'Which project would you like to open'
    selection_array = projs.map do |p|
      Pathname.new(p).relative_path_from(dir).to_s
    end
    index = choose_from_array(selection_array, message)
    projs[index]
  end
end

I don't know Ruby, but seems that it gets the list of all XCode projects/workspaces (except the Pods project and the projects that have a sister workspace) and picks:

  1. The only item if there's only one item found.
  2. The only workspace that has "demo" or "example" in filename if there's only one such item found.
  3. The only project that has "demo" or "example" in filename if there's only one such item found.
  4. Nothing, but let's you choose from all the items found.

If somebody has corrections to this - they're welcomed, as I'm no Ruby guy.



来源:https://stackoverflow.com/questions/25396075/is-the-heuristic-cocoapods-uses-for-the-pod-try-command-documented-anywhere

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!