Upgrade to Pro — share decks privately, control downloads, hide ads and more …

今日から始めるSwiftPackageManagerで作るCLIツール/swiftpm-cli

 今日から始めるSwiftPackageManagerで作るCLIツール/swiftpm-cli

Yusuke Hosonuma

March 08, 2018
Tweet

More Decks by Yusuke Hosonuma

Other Decks in Programming

Transcript

  1. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. try! Swift Tokyo

    2018 After Talks Day 1 2018/03/08 (Thu) 
 ࡉপ ༞հ@DeNA ࠓ೔͔Β࢝ΊΔ 4XJGU1BDLBHF.BOBHFS Ͱ࡞Δ$-*πʔϧ 1
  2. ˙:VTVLF)PTPOVNBʢ!UPCJʣ • ॴଐ ⁃ %F/"ɹ48&5άϧʔϓɹςετج൫νʔϜ • 'BWPSJUF ⁃  •

    ۙگ ⁃ USZ4XJGUָ͔ͬͨ͠ʂ ⁃ ελοϑɾεϐʔΧʔɾϘϥϯςΟΞͷํʹײँʂ ⁃ 'MVUUFSʹظ଴ 8IP Copyright (C) DeNA Co.,Ltd. All Rights Reserved. 2
  3. xcode-open 4 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. •

    ػೳ • ϫʔΫεϖʔε༏ઌ • 9DPEFόʔδϣϯͷࢦఆɾϩοΫ • ଞ • )PNFCSFXʢUBQʣͰ഑෍ • 5SBWJT$* • 9$5FTU IUUQTHJUIVCDPN:VTVLF)PTPOVNBYDPEFPQFO ཉ͔ͬͨ͠ͷͰ࡞ͬͨ
  4. ΞδΣϯμ 6 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. •

    4XJGU1BDLBHF.BOBHFSͷ͓͞Β͍ • ಋೖɾ։ൃ • ϥΠϒϥϦ • ഑෍ • ϋϚϦϙΠϯτ • ·ͱΊ
  5. Swift Package Manager 8 Copyright (C) DeNA Co.,Ltd. All Rights

    Reserved. • 4XJGUඪ४ͷύοέʔδϚωʔδϟ • 4XJGUͰॻ͔Ε͍ͯΔ • )PNFCSFXͷ։ൃऀ͕ܞΘͬͯΔʢΒ͍͠ʣ • ϥΠϒϥϦ΍࣮ߦόΠφϦΛ࡞ΕΔ • 9DPEFϓϩδΣΫτΛੜ੒Ͱ͖Δ
  6. ͳͥ SwiftPM Ͱ࡞ͬͨʁ 10 Copyright (C) DeNA Co.,Ltd. All Rights

    Reserved. • ͳΜͱͳ͘ • ݱঢ়ͷ4XJGU1.ͷ࣮ྗΛݟ͔ͨͬͨ • 6*,JUʹࢧ഑͞Εͳ͍ੈքΛݟ͔ͨͬͨ • 4XJGUͷϦϋϏϦ • ଞͷબ୒ࢶ • 3VCZ1ZUIPO,PUMJO(Pଞ • ΠϯλϓϦλܥ͸ىಈ͕एׯ஗͍ʢؾ͕͢Δʣ • (P͸ྑͦ͞͏ͳؾ͕͢Δ͚Ͳະܦݧ
  7. ॳظԽ 12 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. $

    swift package init --type executable . !"" Package.swift !"" README.md !"" Sources # $"" awesome_cli # $"" main.swift $"" Tests λʔήοτɾґଘఆٛ ΤϯτϦϙΠϯτ ࣮ߦܗࣜͰॳظԽ
  8. Package.swift 13 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. import

    PackageDescription let package = Package( name: “awesome_cli", dependencies: [ .package( url: "https://github.com/kareman/SwiftShell.git", from: "3.0.1"), ], targets: [ .target( name: “awesome_cli", dependencies: ["SwiftShell"]), ] ) ґଘϥΠϒϥϦΛ഑ྻͰఆٛ λʔήοτΛ഑ྻͰఆٛ λʔήοτ͕ར༻͢ΔґଘΛ഑ྻͰఆٛ 4XJGUͷίʔυͰॻ͘
  9. ґଘؔ܎ͷߋ৽ 14 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. $

    swift package update Fetching https://github.com/kareman/SwiftShell.git Cloning https://github.com/kareman/SwiftShell.git Resolving https://github.com/kareman/ SwiftShell.git at 3.0.1 $ tree -a . ├── .build │ ├── checkouts │ │ └── SwiftShell.git—7315839884107259463 … │ ├── dependencies-state.json │ └── repositories │ ├── SwiftShell.git--7315839884107259463 ґଘؔ܎͕%-ɾ$IFDLPVU͞ΕΔ
  10. Ϗϧυɾ࣮ߦ 15 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. $

    swift build … Linking ./.build/x86_64-apple-macosx10.10/debug/ awesome_cli $ .build/debug/awesome_cli Hello, world! &YFDVUBCMFͳόΠφϦ͕ग़ྗ͞Ε͍ͯΔ ͷͰɺͦͷ··࣮ߦͰ͖Δ
  11. Xcode Project ੜ੒ 16 Copyright (C) DeNA Co.,Ltd. All Rights

    Reserved. $ swift package generate-xcodeproj generated: ./awesome_cli.xcodeproj εΩʔϜΛબΜͰ࣮ߦ ίϯιʔϧʹग़ྗ͞Εͨʂ
  12. ίϚϯυͷ੔ཧ 18 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. આ໌

    ίϚϯυ ॳظԽ swift package init —type executable ґଘؔ܎ͷߋ৽ swift package update Ϗϧυ swift build ࣮ߦ .build/debug/awesome_cli ςετ swift test Xcodeੜ੒ swift package generate-xcodeproj
  13. ίϚϯυͷ੔ཧ 19 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. આ໌

    ίϚϯυ ॳظԽ swift package init —type executable ґଘؔ܎ͷߋ৽ swift package update Ϗϧυ swift build ࣮ߦ .build/debug/awesome_cli ςετ swift test Xcodeੜ੒ swift package generate-xcodeproj ͳΜ͔ͩίϚϯυଟͯ͘໘౗ʜ
  14. Makefile 21 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. EXE=awesome_cli

    init: swift package init --type executable update: swift package update build: swift build test: swift test debug: .build/debug/$(EXE) run: build debug xcode: swift package generate-xcodeproj
  15. Makefile 22 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Make

    Default make init swift package init —type executable make update swift package update make build swift build make test swift test make debug .build/debug/awesome_cli make xcode swift package generate-xcodeproj make run swift build && .build/debug/awesome_cli γϯϓϧͳίϚϯυʹͳͬͨʂ
  16. ར༻ͨ͠ϥΠϒϥϦ 24 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Library

    આ໌ kylef/ Commander ίϚϯυϥΠϯҾ਺ύʔαʢλΠϓηʔϑʣ kareman/ SwiftShell ShellΛݺͼग़ͤΔ JohnSundell/ Files ϑΝΠϧૢ࡞Λߦ͑Δ (JU)VCͰ୳͢ͱ݁ߏ͍Ζ͍Ζ͋Δʂ
  17. ᶃ Xcode Project ͕ແ͘ͳͬͨ 27 Copyright (C) DeNA Co.,Ltd. All

    Rights Reserved. • HJUJHOPSFʹॻ͔ΕͯΔͷͰίϛοτ͞Εͳ͍ • ϑΝΠϧπϦʔ͔Β9DPEFΛੜ੒͢Δ࢓༷ 9DPEF1SPKFDUΛ࠶ੜ੒͢Δʂ
  18. ᶄ Xcode ͷ༷ࢠ͕͓͔͍͠ 28 Copyright (C) DeNA Co.,Ltd. All Rights

    Reserved. • 9DPEF1SPKFDUΛ࠶ੜ੒ͯ͠ΈΔ • CVJMEΛ࡟আͯ͠ΈΔ • ͦΕͰ΋มͳΤϥʔ͕ग़Δ͜ͱ΋͋Δ • Τϥʔͩͱݴ͍ͭͭϏϧυ੒ޭ͢Δ࣌΋͋Δ ίϚϯυϥΠϯΛ৴༻͢Δʂ
  19. ·ͱΊ 30 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. •

    4XJGU1.͸ͦΕͳΓʹྑ͘ग़དྷͯΔ w w w w w • 9DPEFͰ։ൃɾσόοάʢগ͠ෆ҆ఆʁʣ • .BLFpMFΛ࡞Δͱศར • ഑෍ํ๏΋͍Ζ͍Ζ • J04Ҏ֎Ͱͷ4XJGU • ษڧʹͳΔʢͱࢥ͏ʣ • 1VSF4XJGUͳָ͠͞
  20. 32 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. $ spm-boot

    your-app-name spm-boot ίϚϯυͰ.BLFpMF·Ͱੜ੒ IUUQTHJUIVCDPN:VTVLF)PTPOVNB41.#PPU