Xcode file templateを管理するためのCLIツールを作ってみた
みなさん、Xcode file template使ってますか?
Xcodeから新規ファイルを作るときに出てくるアレです。
自作の方法について、詳しくはXcodeのファイルテンプレートを自作する を見ていただければわかるのですが、
.xctemplate
というフォルダに、
- TemplateInfo.plist
- TemplateIcon.png
- ___FILEBASENAME___.swift
などの必要なファイルを配置して、
~/Library/Developer/Xcode/Templates/File Templates/
ディレクトリ以下に.xctemplate
を配置することで、自作テンプレートを使うことができるようになります。
今回、この.xctemplate
をGitHubなどのGitホスティングサービスからダウンロードして利用できるようなDonut というCLIツールを作成しました。
tl;dr
作ったもの
Donut (https://github.com/natmark/Donut)
Donutのインストールについて
MintというSwift command line tool用のpackage manager経由でインストールすることができます。
$ mint install natmark/Donut
Donutの使い方
-
.xctemplate
が含まれていて、Tagがつけられているリポジトリに対して、Donut経由でインストールすることが可能です。
donut list
ローカルにインストールされているテンプレートの一覧が取得できます。
$ donut list
🍩 3 templates are installed
* Donut.xctemplate (0.1.0)
* ProcessingKit.xctemplate (undefined)
* Realm Model Object.xctemplate (undefined)
donut install
リモートリポジトリから、.xctemplate
をインストールできます。
$ donut install https://github.com/natmark/Donut
🍩 Found https://github.com/natmark/Donut (latest)
🍩 Searching .xctemplate from remote repository
🍩 Found Donut.xctemplate
🍩 Checkout from https://github.com/natmark/Donut
🍩 Successfully installed https://github.com/natmark/Donut (latest)
donut remove
ローカルにインストールされている.xctemplate
を削除できます。
$ donut remove Donut
🍩 Found templates:
* github.com/natmark/Donut/Donut.xctemplate (0.1.0)
Continue with Uninstall? [yN]y
🍩 Successfully uninstalled github.com/natmark/Donut/Donut.xctemplate (0.1.0)
まとめ
Donut
を使うことで、簡単に.xctemplate
を管理することができます!
自作ライブラリ用のファイルテンプレートをDonut
で共有する文化ができればいいなと思います!