LoginSignup
8
7

More than 5 years have passed since last update.

[Elixir]ezファイルを作成して、"mix archive.install"する

Last updated at Posted at 2015-09-20

Goal

.ezファイルを作成して、"mix archive.install"する。

Dev-Environment

OS: Windows8.1
Erlang: Eshell V6.4, OTP-Version 17.5
Elixir: v1.0.5

Wait a minute

カスタムタスクを作成した後、そのプロジェクト内もしくはダウンロードしたプロジェクトでしか使えないのは不便ですね。
mixが使えれば、どこからでも呼べるコマンドにしたいですね。

具体的には、"archive.install"でezファイルをインストールして、
mixコマンドからどのディレクトリにいても呼べるようにしたいです。

というわけで、やっていきましょう!!

Index

mix archive.build
|> Preparation
|> mix archive.build
|> Extra

Preparation

プロジェクトの準備をします。

Example:

>cd path/to/create/directory
>mix new ez_sample
* creating README.md
* creating .gitignore
* creating mix.exs
* creating config
* creating config/config.exs
* creating lib
* creating lib/ez_sample.ex
* creating test
* creating test/test_helper.exs
* creating test/ez_sample_test.exs

Your mix project was created successfully.
You can use mix to compile it, test it, and more:

    cd ez_sample
    mix test

Run `mix help` for more commands.


>cd ez_sample

>mix test

Directory: lib/mix

ディレクトリを作成。

Directory: lib/mix/tasks

ディレクトリを作成。

適当なカスタムタスクを作成します。
ただ、引数を表示するだけのカスタムタスク。

File: mix/tasks/ez_sample.ex

defmodule Mix.Tasks.EzSample do
  use Mix.Task

  @shortdoc "ez sample"

  def run(args) do
    IO.puts (inspect args)
  end
end

mix archive.build

それでは、.ezファイルに固めてmixにインストールできるようにします。

Example:

>mix archive.build
Generated archive ez_sample-0.0.1.ez with MIX_ENV=dev

.exファイルを作成するのは、これだけ(笑)

次は、mixにインストールします。

>mix archive.install ez_sample-0.0.1.ez
Are you sure you want to install archive ez_sample-0.0.1.ez? [Yn] y
* creating c:/Users/user_name/.mix/archives/ez_sample-0.0.1.ez

今回使っているプロジェクト以外の適当なディレクトリに移動してからカスタムタスクを試す。

>cd appropriate/path

>mix ez_sample hoge
["hoge"]

>mix ez_sample hoge huge foo:bar
["hoge", "huge", "foo:bar"]

Extra

手を動かすことはない。

依存関係のライブラリがある場合注意が必要。

ex_mark2pdfと言うライブラリを作成していたのだが、
そのライブラリは、earmarkライブラリに依存している。

ex_mark2pdfを.ezファイルに固めて使ってみたところ、
earmarkの関数がないと言われる。

方法があるのか分からないが、依存関係先の機能(関数)は使えない模様。

Speaking to oneself

今回は、.ezファイルへの固め方でした。
探す必要がないくらい簡単でしたorz

Bibliography

特になし。

8
7
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
8
7