Swift製CLIツールをMintを使わずSwiftPackageManagerで管理する

 Swift製CLIツールをMintを使わずSwiftPackageManagerで管理する

83d400bf204ff2a10a1ee934287f0a9d?s=128

Yasuharu Yanamura

February 12, 2020
Tweet

Transcript

  1. Swift੡CLIπʔϧΛMintΛ࢖Θͣ SwiftPackageManagerͰ؅ཧ͢Δ Potatotips #68 2020/2/12 Yasuharu Yanamura

  2. ࣗݾ঺հ • Yasuharu Yanamura/༄ଜ ߁੖ • ɹ@yanamura_ɹɹ@yanamura • ίωώτגࣜձࣾ •

    ϚϚϦiOSΞϓϦ։ൃ
  3. iOSͷ։ൃͰ࢖͏πʔϧྨ • SwiftFormat • SwiftLint • XcodeGen etc...

  4. ؅ཧํ๏͸͍Ζ͍Ζ • Homebrew • Cocoapods • Mint

  5. Swift Package ManagerΛ࢖ͬͨํ๏

  6. ࢖͍ํ // swift-tools-version:5.1 import PackageDescription let package = Package( name:

    "Tools", dependencies: [ .package(url: "https://github.com/apple/swift-format", .branch("master")), .package(url: "https://github.com/yonaskolb/XcodeGen", from: "2.13.0"), .package(url: "https://github.com/mac-cain13/R.swift", .exact("5.1.0")), ] ) Package.swift
  7. ࢖͍ํ // swift-tools-version:5.1 import PackageDescription let package = Package( name:

    "Tools", dependencies: [ .package(url: "https://github.com/apple/swift-format", .branch("master")), .package(url: "https://github.com/yonaskolb/XcodeGen", from: "2.13.0"), .package(url: "https://github.com/mac-cain13/R.swift", .exact("5.1.0")), ] ) Package.swift OBNF͸ద౰
  8. ࢖͍ํ // swift-tools-version:5.1 import PackageDescription let package = Package( name:

    "Tools", dependencies: [ .package(url: "https://github.com/apple/swift-format", .branch("master")), .package(url: "https://github.com/yonaskolb/XcodeGen", from: "2.13.0"), .package(url: "https://github.com/mac-cain13/R.swift", .exact("5.1.0")), ] ) Package.swift EFQFOEFODJFTʹ࢖͏ πʔϧΛྻڍ
  9. ࢖͍ํ $ swift run -c release xcodegen ࣮ߦ

  10. ࢖͍ํ $ swift run -c release xcodegen ࣮ߦ ॳճ࣮ߦ͸Ϗϧυ͕૸ΔͷͰ஗͍͕ɺ ̎ճ໨Ҏ߱͸Ωϟογϡ͞ΕΔͷͰ଎͍

  11. MintͷΑ͏ͳύοέʔδ؅ཧπʔϧͷΠϯ ετʔϧͳ͠Ͱ࢖͑Δ

  12. طʹSwiftPM࢖ͬͯΔ৔߹ - Package.swiftͷdependenciesʹπʔϧྨ͸͍Εͨ͘ͳ͍ dependencies: [ .package(url: "https://github.com/kylef/PathKit.git", from: "1.0.0"), .package(url:

    "https://github.com/jakeheis/SwiftCLI.git", from: "5.0.0"), .package(url: "https://github.com/apple/swift-format", .branch("master")), ], πʔϧ͸ผʹ͍ͨ͠
  13. طʹSwiftPM࢖ͬͯΔ৔߹ - πʔϧ༻ͷσΟϨΫτϦΛ࡞ͬͯͦ͜ʹπʔϧ༻ͷ Package.swiftΛஔ͘

  14. طʹSwiftPM࢖ͬͯΔ৔߹ - πʔϧ༻ͷσΟϨΫτϦΛ࡞ͬͯͦ͜ʹπʔϧ༻ͷ Package.swiftΛஔ͘ - swift runͷpackage-pathͰͦͷσΟϨΫτϦΛࢦఆ $ swift run

    -c release --package-path Tools xcodegen 1BDLBHFTXJGUͷ͋Δ σΟϨΫτϦΛࢦఆ
  15. Mintͱͷൺֱ

  16. Ωϟογϡͷอଘઌ SwiftPackageManager: ./.buildҎԼʹอଘ Mint: /user/local/mintҎԼʹอଘ

  17. ઃఆϑΝΠϧ SwiftPackageManager: Package.swift͕ඞਢ Mint: Mintfileͳ͠Ͱ΋࣮ߦͰ͖Δ $ mint run yonoskolb/XcodeGen@2.13.1 xcodegen

  18. ৄ͘͠͸ͪ͜Β • Swift੡CLIπʔϧΛMintΛ࢖ΘͣSwiftPMͰ؅ཧ͢Δ - ίωώτ ։ൃऀϒϩά-

  19. ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ