LoginSignup
3
3

More than 5 years have passed since last update.

Swift Package Manager (Swift 3.0-dev)を使って "README Generator" を作りました

Last updated at Posted at 2016-05-08

GitHub に tryswift の Team があるのですが、そこに tryswiftdev という名前の コマンドラインツール を作りました。
いくつか作っている機能のうち、README Generator を紹介します。

なにこれ?

新しいプロジェクトの README.md を簡単に作成します。

  1. 既存の README.md を複製します。
  2. README.md の文字列(たとえばタイトル)を一括変換します。

ReadmeGenerator.gif

使い方

0. 事前準備

新しいプロジェクトのディレクトリを作成してください。(例: DragonBall

$ mkdir DragonBall
HomeDirectory
├── Pokemon
│   └── README.md (Pokemon)
└── DragonBall ✨

1. README.md を複製

まず、既存の Pokemon プロジェクトから README.md を複製します。

$ tryswiftdev -d ./Pokemon ./DragonBall
HomeDirectory
├── Pokemon
│   └── README.md (Pokemon)
└── DragonBall
    └── README.md (Pokemon) ✨

2. README.md 内の文字列を一括変換

次に、複製した README.md 内の文字列を一括変換します。
(例: PokemonDragonBall

$ cd DragonBall
$ tryswiftdev -r Pokemon DragonBall
HomeDirectory
├── Pokemon
│   └── README.md (Pokemon)
└── DragonBall
    └── README.md (DragonBall) ✨

結果

1c1
- # Pokemon
+ # DragonBall
3c3
- __Pokemon__ is a library written in Swift.
+ __DragonBall__ is a library written in Swift.
9c9
- 1. Create a [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile), and add `github "JPMartha/Pokemon" ~> 1.0.0`.
+ 1. Create a [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile), and add `github "JPMartha/DragonBall" ~> 1.0.0`.
11c11
- 3. On your application targets’ “Build Phases” settings tab, in the “Link Binary With Libraries” section, click the “+” icon and add `Pokemon.framework` from the Carthage/Build folder on disk.
+ 3. On your application targets’ “Build Phases” settings tab, in the “Link Binary With Libraries” section, click the “+” icon and add `DragonBall.framework` from the Carthage/Build folder on disk.
16c16
-   and add the "Input Files" to Pokemon.framework:
+   and add the "Input Files" to DragonBall.framework:
18c18
-   $(SRCROOT)/Carthage/Build/iOS/Pokemon.framework
+   $(SRCROOT)/Carthage/Build/iOS/DragonBall.framework
29c29
-   pod 'Pokemon', '~> 1.0.0'
+   pod 'DragonBall', '~> 1.0.0'
42c42
- __Pokemon__ is released under the [MIT License](LICENSE).
+ __DragonBall__ is released under the [MIT License](LICENSE).

動作環境

なんで今こんなん作ったん?

Swift 3.0 で導入予定の Swift Package Manager に質問や Pull request を送っているうちに自分でもコマンドラインツールを作ってみたくなりました。

既存のコマンドラインツールは Commandant というライブラリを使っているものが多いですがこのツールはそれを使っていません。
また Xcode プロジェクト(.xcodeproj)もありません。

今のところシェルスクリプトのほうが簡単にできそうな内容ですが、Swift でやることによってなにかおもしろいことにつながらないかと考えながら楽しんでやっています。

そうやって作ったツールがどなたかのお役に立てればうれしいので公開しました。

おまけ

ご存知の方が多いと思いますが、Swift.org のブログに Swift 3.0 Release Process が公開されたので載せておきます。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3