LoginSignup
14
5

More than 5 years have passed since last update.

Xcode file templateを管理するためのCLIツールを作ってみた

Posted at

Xcode file templateを管理するためのCLIツールを作ってみた

みなさん、Xcode file template使ってますか?
Xcodeから新規ファイルを作るときに出てくるアレです。
スクリーンショット 2018-06-14 19.59.17.png

実はこのファイルテンプレート、自作することができます。
スクリーンショット 2018-06-14 20.01.54.png

自作の方法について、詳しくは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経由でインストールすることが可能です。

スクリーンショット 2018-06-14 20.23.23.png

Demo

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で共有する文化ができればいいなと思います!

14
5
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
14
5