ios 保留文件夹结构可可Pods

p8ekf7hl  于 2023-06-25  发布在  iOS
关注(0)|答案(3)|浏览(137)

我用这个教程创建了一个简单的私有pod:http://pablin.org/2013/05/18/cocoapods-for-internal-libraries/
实际上我的repo只有一组类
一切都好,我可以完美地安装我的吊舱。唯一的问题是所有的文件都安装在主文件夹中,所以它不会保留文件夹结构。
我有这个文件夹结构,存储库名为:myRepository

Classes 
 |
 ------ foo.h and foo.m
 ------ Controller Layer
        |
        ----------- foo2.h and foo2.m
 ------ ViewLayer
        |
        ----------- foo3.h and foo3.m

所有文件都被复制到一个名为myRepository的文件夹中。
这是我的podspec:

Pod::Spec.new do |s|

  s.name         = "fooClasses"
  s.version      = "0.0.1"
  s.summary      = "Common clases of foo"

  s.homepage     = "http://foo.com"

  s.license      = 'BSD'
  s.license      = { :type => 'Foo License', :file => 'LICENSE.txt' }

  s.author       = { "me" => "me@me.com" }

  s.platform     = :ios, '7.0'

  s.source       = { :git => "https://github.com/myRepository.git", :tag => "0.0.1" }

  s.source_files  = "**/*.{h,m}"

  s.requires_arc = true
end

我已经尝试使用s.preserve_path =“*”和s.preserve_path =“Classes”
你知道吗?
谢谢!!!

ippsafx7

ippsafx71#

好吧,我已经实现了创建我自己的文件夹与subspec。
可以使用以下行创建子等级库:

s.subspec 'folder name' do |ss|
    ss.source_files = 'files'
    ss.frameworks = 'frameworks'
end

ss.frameworks不是强制性的。
您可以从CocoaPods邮件列表中看到完整的答案:
https://groups.google.com/forum/#!topic/cocoapods/0kV8r2xnqA8
谢谢mcitrrus
我更喜欢遵循AFNetworking pod规范:
https://github.com/AFNetworking/AFNetworking/blob/master/AFNetworking.podspec

8iwquhpp

8iwquhpp2#

如果你经常使用开发pod,那么cocoapods创建的默认项目结构有很多问题:

  • 如果在source_files/resources等的根目录下没有至少一个文件,那么根目录在项目中不会获得等效的组。
  • groups的 location 指向pod目录的根目录(不一定是源文件所在的位置)。这意味着你不能只是右键单击组和“添加文件”,因为它把文件放在错误的位置。
  • 模块之间的组和文件的顺序不同,因为东西是按名称排序的,你的pod显然有不同的名称,可能会出现在Frameworks/Pods/Dependencies/Support Files之前。

我一直在寻找一个解决上述所有问题的解决方案,最终得出了以下结论:

前提条件

我使用如下目录结构设置我的pod(示例显示名为SomeLib的pod)

Example/
   SomeLib-Example/...
   SomeLib-Example.xcodeproject

fix_project_structure (this is an empty text file)

SomeLib.podspec

Sources/
   FolderA/
      ClassA.swift
   FolderB/
      ClassA.swift

Tests/
   fix_project_structure (another empty text file)
   FolderA/
      ClassATests.swift
   FolderB/
      ClassBTests.swift

第一步-组镜像目录层次

在你的podspec文件中,我们利用根目录中的空fix_project_structure来修复组结构……

s.source_files = 'Sources/**/*.{swift}', 'fix_project_structure'
  s.resource_bundles = {
    s.name => ['Sources/**/*.{xcassets,json,storyboard,xib,xcdatamodeld}', 'fix_project_structure']
  }

  s.test_spec 'Tests' do |test_spec|
    test_spec.source_files = 'Tests/**/*', 'Tests/fix_project_structure'
  end

步骤2 -重新排序和修复组位置

  • 这实际上是一个可选步骤(见注解)*

将以下post_integrate步骤添加到您的Podfile中...

post_integrate do |installer|

  # Fix up the Development Pods so they are easier to work with.
  # The following changes are made to any pod that contains a `fix_project_structure` file
  #  - Removes the (now redundant) `fix_project_structure` file
  #  - Moves the root {project_name} group to the top
  #  - Moves the {project_name}/Sources group to the top
  #  - Moves the {project_name}/Tests group below {project_name}/Sources
  #  - Repoints the {project_name}/Tests group so it reflects its location on disc
  # Note this script makes no functional changes to the pod so you should be able to comment out 
  #   all of this script and have things continue to work just fine
  installer.generated_projects.each do |project|

    fix_files = project.files.select { |file| File.basename(file.path) == "fix_project_structure" }
    project_name = "#{File.basename(project.path, '.xcodeproj')}"
    next if fix_files.nil? || fix_files.empty? || project_name.nil?

    puts "#{project_name} -> #{project.path}"
    puts "  `fix_project_structure` file(s) FOUND"
    puts "    Removing `fix_project_structure` file(s) from project entirely"
    fix_files.each { |fix_file| fix_file.remove_from_project }

    project_group = project.groups.find.find { |group| group.to_s == project_name }
    next if project_group.nil?

    puts "  `#{project_name}` group FOUND"
    puts "    Moving `#{project_name}` group to top"
    project.main_group.children.delete(project_group)
    project.main_group.children.insert(0, project_group)

    sources_group = project_group.groups.find.find { |subgroup| subgroup.to_s == 'Sources' }
    if sources_group.nil? != true
      puts "    `#{project_name}/Sources` group FOUND"
      puts "      Moving `#{project_name}/Sources` group to top"
      project_group.children.delete(sources_group)
      project_group.children.insert(0, sources_group)

      tests_group = project_group.groups.find.find { |subgroup| subgroup.to_s == 'Tests' }
      if tests_group.nil? != true
        puts "    `#{project_name}/Test` group FOUND"

        puts "      Moving `#{project_name}/Test` group below `#{project_name}/Sources`"
        project_group.children.delete(tests_group)
        project_group.children.insert(1, tests_group)

        puts "      Adjusting `#{project_name}/Test` group and immediate children location"
        tests_group.set_path("#{tests_group.real_path}/Tests")
        tests_group.children.each do |tests_child|
          tests_child_path_before = tests_child.path
          tests_child.set_path("#{tests_child.real_path.to_s.gsub('/Tests/Tests/', '/Tests/')}")
          #puts "      '#{tests_child.path.to_s}' (previously '#{tests_child_path_before}')"
        end
      end
    end

    project.save

  end

end
oxcyiej7

oxcyiej73#

由于cocoapods的0.36版本中所做的更改,此答案/问题已过时。
PR 2647添加了默认的分组行为,只要你使用的是":path" pod。从1.3.1开始,它的行为是遍历/Classes/...结构,直到它看到一个文件或第二个子文件夹,并在. xcodeproj文件中从那里开始分组。

相关问题