Save 37% off PRO during our Black Friday Sale! »

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

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

70d9714ea13fc1133803d61fb16e4160?s=128

Yusuke Hosonuma

March 08, 2018
Tweet

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. YDPEFPQFO ͱ͍͏πʔϧΛ࡞ͬͨ 3 Copyright (C) DeNA Co.,Ltd. All Rights Reserved.

    λʔϛφϧ͔Β9DPEFΛ։͘
  4. xcode-open 4 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. •

    ػೳ • ϫʔΫεϖʔε༏ઌ • 9DPEFόʔδϣϯͷࢦఆɾϩοΫ • ଞ • )PNFCSFXʢUBQʣͰ഑෍ • 5SBWJT$* • 9$5FTU IUUQTHJUIVCDPN:VTVLF)PTPOVNBYDPEFPQFO ཉ͔ͬͨ͠ͷͰ࡞ͬͨ
  5. 4XJGU1BDLBHF.BOBHFS ʹ͍ͭͯ ֶΜͩ͜ͱΛγΣΞ͢ΔΑʂ 5 Copyright (C) DeNA Co.,Ltd. All Rights

    Reserved.
  6. ΞδΣϯμ 6 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. •

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

  8. Swift Package Manager 8 Copyright (C) DeNA Co.,Ltd. All Rights

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

  10. ͳͥ SwiftPM Ͱ࡞ͬͨʁ 10 Copyright (C) DeNA Co.,Ltd. All Rights

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

  12. ॳظԽ 12 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. $

    swift package init --type executable . !"" Package.swift !"" README.md !"" Sources # $"" awesome_cli # $"" main.swift $"" Tests λʔήοτɾґଘఆٛ ΤϯτϦϙΠϯτ ࣮ߦܗࣜͰॳظԽ
  13. 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ͷίʔυͰॻ͘
  14. ґଘؔ܎ͷߋ৽ 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͞ΕΔ
  15. Ϗϧυɾ࣮ߦ 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ͳόΠφϦ͕ग़ྗ͞Ε͍ͯΔ ͷͰɺͦͷ··࣮ߦͰ͖Δ
  16. Xcode Project ੜ੒ 16 Copyright (C) DeNA Co.,Ltd. All Rights

    Reserved. $ swift package generate-xcodeproj generated: ./awesome_cli.xcodeproj εΩʔϜΛબΜͰ࣮ߦ ίϯιʔϧʹग़ྗ͞Εͨʂ
  17. XcodeͰ࣮ߦɾσόοά 17 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ೚ҙͷҾ਺Λ௥ՃͰ͖Δ

    ϒϨʔΫϙΠϯτ΋࢖͑Δ
  18. ίϚϯυͷ੔ཧ 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
  19. ίϚϯυͷ੔ཧ 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 ͳΜ͔ͩίϚϯυଟͯ͘໘౗ʜ
  20. .BLFpMF 20 Copyright (C) DeNA Co.,Ltd. All Rights Reserved.

  21. 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
  22. 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 γϯϓϧͳίϚϯυʹͳͬͨʂ
  23. ར༻ͨ͠ϥΠϒϥϦ 23 Copyright (C) DeNA Co.,Ltd. All Rights Reserved.

  24. ར༻ͨ͠ϥΠϒϥϦ 24 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Library

    આ໌ kylef/ Commander ίϚϯυϥΠϯҾ਺ύʔαʢλΠϓηʔϑʣ kareman/ SwiftShell ShellΛݺͼग़ͤΔ JohnSundell/ Files ϑΝΠϧૢ࡞Λߦ͑Δ (JU)VCͰ୳͢ͱ݁ߏ͍Ζ͍Ζ͋Δʂ
  25. ഑෍ 25 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ࠓճ͸ׂѪN

    @@ N
  26. ϋϚϦϙΠϯτʁ 26 Copyright (C) DeNA Co.,Ltd. All Rights Reserved.

  27. ᶃ Xcode Project ͕ແ͘ͳͬͨ 27 Copyright (C) DeNA Co.,Ltd. All

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

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

  30. ·ͱΊ 30 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. •

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

  32. 32 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. $ spm-boot

    your-app-name spm-boot ίϚϯυͰ.BLFpMF·Ͱੜ੒ IUUQTHJUIVCDPN:VTVLF)PTPOVNB41.#PPU
  33. .PSFUSZ4XJGU 33 Copyright (C) DeNA Co.,Ltd. All Rights Reserved.