使用 Jazzy swift 文档生成从 podspec 中排除子规范

Exclude subspecs from podspec with Jazzy swift documentation generation

我目前正在开发 iOS SDK,使用 Cocoapods 管理部署并使用 Jazzy 生成文档。我最近在子规范中添加了对 Google ads v8 的依赖,在另一个子规范中添加了对 Google ads v7 的依赖,如下所示:

  s.subspec 'Admob' do |admob|
    admob.source_files = 'MyLib/Classes/admob/**/*.{swift,h,m}'
    admob.dependency 'MyLib/Core'
    admob.dependency 'Google-Mobile-Ads-SDK', '~> 8.0'
    admob.xcconfig = { 'OTHER_SWIFT_FLAGS' => '$(inherited) -D SDK_ADMOB' }
  end

  s.subspec 'Admob7' do |admob|
    admob.source_files = 'MyLib/Classes/admob7/**/*.{swift,h,m}'
    admob.dependency 'MyLib/Core'
    admob.dependency 'Google-Mobile-Ads-SDK', '~> 7.0'
    admob.xcconfig = { 'OTHER_SWIFT_FLAGS' => '$(inherited) -D SDK_ADMOB' }
    admob.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
    admob.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
  end

一切正常,除了我想用 Jazzy 生成文档时。这是我的会议:[​​=15=]

documentation: "*.md"
xcodebuild_arguments: -scheme,Tests
module: MyLib
sdk: iphone
source_directory: MyLib
podspec: MyLib.podspec
theme: fullwidth
readme: USERGUIDE.md

当我 运行 bundle exec jazzy 我有冲突因为它要你同时使用我所有的子规格:

Using config file /Users/***/***/.jazzy.yaml
Analyzing dependencies
bundler: failed to load command: jazzy (/usr/local/lib/ruby/gems/2.7.0/bin/jazzy)
Pod::Informative: [!] CocoaPods could not find compatible versions for pod "Google-Mobile-Ads-SDK":
  In Podfile:
    MyLib/Admob (from `/Users/***/***`) was resolved to 2.8.0, which depends on
      Google-Mobile-Ads-SDK (~> 8.0)

    MyLib/Admob7 (from `/Users/***/***`) was resolved to 2.8.0, which depends on
      Google-Mobile-Ads-SDK (~> 7.0)

有人能告诉我是否可以从我的文档生成中排除一个或多个子规范吗?

好的,Jazzy 中似乎没有解决此问题的选项。我最终写了这个脚本:

### Removing admob7 subspec before generating doc is necessary.
# add a new line to the podspec file to remove it after awk treatment
echo "" >> MyLib.podspec

# create the jazzy podspec
awk '!/Admob7/' RS=s.subspec ORS=s.subspec MyLib.podspec > MyLib.jazzy.podspec

# clean the last line which contains an awk artifact
sed -i '' -e '$ d' MyLib.jazzy.podspec

# remove the last line we added before
sed -i '' -e '$ d' MyLib.podspec

bundle exec jazzy

并更改了 jazzy yml 配置文件中的 podspec

documentation: "*.md"
xcodebuild_arguments: -scheme,Tests
module: MyLib
sdk: iphone
source_directory: MyLib
podspec: MyLib.jazzy.podspec
theme: fullwidth
readme: USERGUIDE.md