LoginSignup
20
21

More than 5 years have passed since last update.

Elixir | Mix | プロジェクト管理 CLI ツール Mix によるプロジェクト新規作成

Last updated at Posted at 2014-11-15

Elixir | Mix | プロジェクト管理 CLI ツール Mix によるプロジェクト新規作成

概要

Elixir ではプロジェクトの作成・コンパイル・テストなどを管理する
ツールとして、 Mix が提供されています。

Mix で新規プロジェクトを作成してみます。

$ mix new fizzbuzz
* creating README.md
* creating .gitignore
* creating mix.exs
* creating config
* creating config/config.exs
* creating lib
* creating lib/fizzbuzz.ex
* creating test
* creating test/test_helper.exs
* creating test/fizzbuzz_test.exs

$ tree
.
`-- fizzbuzz
    |-- config
    |   `-- config.exs
    |-- lib
    |   `-- fizzbuzz.ex
    |-- mix.exs
    |-- README.md
    `-- test
        |-- fizzbuzz_test.exs
        `-- test_helper.exs

各ファイル / ディレクトリについて

README.md

プロジェクトの説明を書くファイル。 Markdown で記述する。
GitHubを利用している方はご存知の用に、GitHubのプロジェクトに
このファイルを配置すると自動的に HTML に変換されてプロジェクトのホームページとなる。
※GitHub 以外の最近リポジトリ管理のWebツールは大抵 README.md の HTML 表示機能を持っている

config/

アプリケーション独自の設定ファイルを配置するディレクトリ。
自動生成時に下記のような config.exs が配置される。

config/config.exs
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for third-
# party users, it should be done in your mix.exs file.

# Sample configuration:
#
#     config :logger, :console,
#       level: :info,
#       format: "$date $time [$level] $metadata$message\n",
#       metadata: [:user_id]

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
#     import_config "#{Mix.env}.exs"

lib/

プロジェクトのソースコードを配置するディレクトリ。
Mix は自動生成時に lib/プロジェクト名.exs を生成します。

lib/fizzbuzz.exs
defmodule Fizzbuzz do
end

mix.exs

プロジェクトの設定を行うためのファイル。

  • プロジェクト名
  • バージョン
  • 依存ライブラリ

などを設定します。

mix.exs
defmodule Fizzbuzz.Mixfile do
  use Mix.Project

  def project do
    [app: :fizzbuzz,
     version: "0.0.1",
     elixir: "~> 1.0.0",
     deps: deps]
  end

  # Configuration for the OTP application
  #
  # Type `mix help compile.app` for more information
  def application do
    [applications: [:logger]]
  end

  # Dependencies can be Hex packages:
  #
  #   {:mydep, "~> 0.3.0"}
  #
  # Or git/path repositories:
  #
  #   {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
  #
  # Type `mix help deps` for more examples and options
  defp deps do
    []
  end
end

test/

テストを置く場所。
Mix はデフォルトでテストのヘルパー( test/test_helper.exs )と
test/プロジェクト名_test.exs を生成します。

test_helper.exs
ExUnit.start()
test/fizzbuzz_test.exs
defmodule FizzbuzzTest do
  use ExUnit.Case

  test "the truth" do
    assert 1 + 1 == 2
  end
end

参照

20
21
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
20
21