定制用于快速创造Cocoapod子仓库的模版脚本

使用自定义脚本方法

$ pod lib create yourPodName --template-url=https://github.com/xx/PodTemplate.git

构建自己的脚本

参考官方的pod-template

$ git clone https://github.com/CocoaPods/pod-template.git

脚本主要流程

  1. 模版主入口:configure。
  2. 执行TemplateConfigurator.rb。

  3. 询问创建iOS/macOS,以及oc/swift,对应ConfigurationiOS.rb/ConfigureMacOSSwift.rb/ConfigureSwift.rb。

  4. replace_variables_in_files,为Pod模版注入参数(作者,事件,Pod名)。
  5. clean_template_files,清理模版不需要的文件 。
  6. rename_template_files,重命名模版文件。
  7. add_pods_to_podfile,将当前Pod添加Example的podfile中。
  8. customise_prefix,设置类名默认前缀。
  9. rename_classes_folder,Pod文件夹重命名。
  10. ensure_carthage_compatibility,适配carthage用法。
  11. reinitialize_git_repo,重制当前文件夹的git仓库信息。
  12. run_pod_install,为Example执行pod install。
  13. @message_bank.farewell_message,提示完成信息

###ConfigurationiOS.rb

  1. 询问是否创建Example工程。注释掉直接keep_demo = :yes,即可默认创建Example工程 。
  2. 询问是否使用单元测试框架,framework = :none,根据需求直接不使用即可。
  3. 询问类前缀,此处保留,依各业务模块需求命名类前缀。

ProjectManipulator.rb

  1. 执行指定格式文本替换。
@string_replacements = {
        "PROJECT_OWNER" => @configurator.user_name,
        "TODAYS_DATE" => @configurator.date,
        "TODAYS_YEAR" => @configurator.year,
        "PROJECT" => @configurator.pod_name,
        "CPD" => @prefix
      }
  1. 调用主要装配工程的脚本。
def add_podspec_metadata
      project_metadata_item = @project.root_object.main_group.children.select { |group| group.name == "Podspec Metadata" }.first
      project_metadata_item.new_file "../" + @configurator.pod_name  + ".podspec"
      project_metadata_item.new_file "../README.md"
      project_metadata_item.new_file "../LICENSE"
    end
  1. Example工程处理,如果选择不创建工程,则会移除工程文件。
  2. 文件/文件夹重命名。

参考

基于官方pod模板制作适合于自己的pod模板