SwiftGen 6系がリリースされて、めでたく"paths"
keyが"inputs"
keyにrenameされていましたので本記事はお役御免となりました。
ちなみに、2019/07/06時点でのSwiftGenの最新版は6.1.0
です。
The swiftgen.yml config file now accepts multiple outputs for each command, allowing you to generate multiple outputs from the same files and content. This also means that the output parameter is now deprecated, in favour of the outputs parameter, and it may be removed in a future version of SwiftGen. Similarly, the paths parameter has been renamed to inputs for consistency. You can always use swiftgen config lint to validate your configuration file.
以下は元記事です。
ドキュメントで推奨している通りにswiftgen.yml
の設定をしたのに、エラーになってハマったのでメモしておきます。
環境
ツール | バージョン |
---|---|
SwiftGen | 5.3.0 |
ハマった現象
SwiftGenのmaster
にあるConfigFile.mdに書かれている推奨設定でswiftgen.ymlを作成すると、以下のエラーが発生します。
Missing entry for key xxxx.paths.
Command /bin/sh failed with exit code 1
原因
SwiftGenのmaster
にあるConfigFile.mdが、リリース前の最新バージョンの内容になっていることが原因。
最新バージョンでは現行バージョンの5.3.0
には存在しない"inputs"
keyが追加&推奨されていたため、5.3.0
では必須の"paths"
keyが見つからないエラーが発生していました。
Branch/Tag | URL |
---|---|
master | https://github.com/SwiftGen/SwiftGen/blob/master/Documentation/ConfigFile.md |
master-example-swiftgen.yml
input_dir: Sources/Resources
output_dir: Sources/Generated/
strings:
inputs: Base.lproj/Localizable.strings
outputs:
- templateName: structured-swift3
output: L10n-Constants.swift
xcassets:
- inputs: Logos.xcassets
outputs:
- templateName: swift3
output: Logos-Constants.swift
params:
enumName: Logos
- inputs:
- Colors.xcassets
- Images.xcassets
outputs:
- templatePath: customswift3
output: Assets-Constants.swift
回避方法
現行バージョンのTag 5.3.0
に紐づいたConfigFile.mdの内容は正しいので、こちらを参照してSwiftGen.ymlを作成することで問題なく実行できます。
Branch/Tag | URL |
---|---|
5.3.0 | https://github.com/SwiftGen/SwiftGen/blob/5.3.0/Documentation/ConfigFile.md |
5.3.0-example-swiftgen.yml
input_dir: Sources/Resources
output_dir: Sources/Generated/
strings:
paths: Base.lproj/Localizable.strings
templateName: structured-swift3
output: L10n-Constants.swift
xcassets:
- paths: Logos.xcassets
templateName: swift3
output: Logos-Constants.swift
params:
enumName: Logos
- paths:
- Colors.xcassets
- Images.xcassets
templatePath: customswift3
output: Assets-Constants.swift
備考
本件についてはすでに下記Issueで議論されていたので、近日中にmasterのドキュメントが修正される可能性はありそうです。