mix-add

A global CLI tool for adding dependencies to Elixir projects without manually editing mix.exs. Built with Igniter for safe and reliable code modifications.

Features

Installation

As a global escript (Recommended)

# Clone and build
git clone https://github.com/hoangbits/mix-add.git
cd mix-add
mix deps.get
mix escript.build

# Install globally
mix escript.install

# Or install directly from Hex (once published)
mix escript.install hex mix_add_cli

As a project dependency

Add to your mix.exs:

{:mix_add_cli, "~> 1.0", only: [:dev]}

Then run:

mix deps.get

Usage

Global CLI (after escript installation)

# Add latest version
mix-add phoenix

# Add specific version
mix-add phoenix "~> 1.7"

# Add to specific environments
mix-add excoveralls --only dev,test

# Add from GitHub
mix-add my_lib --github username/my_lib

# Add from Git with branch
mix-add my_lib --git https://github.com/user/lib.git --branch main

# Add local dependency
mix-add my_lib --path ../my_lib

# Override existing dependency
mix-add phoenix "~> 1.7.10" --override

As Mix task (when installed as dependency)

mix add phoenix "~> 1.7"

Options

Examples

Common use cases

# Add a standard Hex package
mix-add tesla

# Add with specific version
mix-add ecto "~> 3.11"

# Development-only dependency
mix-add dialyxir --only dev

# Test dependencies
mix-add mock "~> 0.3" --only test

# Multiple environments
mix-add phoenix_live_reload --only dev,test

# Exclude from runtime
mix-add inch_ex --only dev --runtime false

Git dependencies

# From GitHub
mix-add my_package --github elixir-lang/my_package

# From Git URL with branch
mix-add my_package --git https://gitlab.com/user/package.git --branch develop

# With specific tag
mix-add my_package --github user/package --tag v1.0.0

# With commit ref
mix-add my_package --git https://github.com/user/package.git --ref abc123

Local dependencies

# Relative path
mix-add my_local_lib --path ../my_local_lib

# Absolute path
mix-add my_local_lib --path /Users/me/projects/my_local_lib

Umbrella projects

The tool automatically detects umbrella projects and finds the nearest mix.exs:

# From any subdirectory
cd apps/my_app/lib/some/deep/path
mix-add phoenix  # Will find and update apps/my_app/mix.exs

How it works

  1. Finds mix.exs: Searches current directory and up to 5 parent levels
  2. Fetches version: If not specified, queries Hex.pm for latest stable version
  3. Modifies AST: Uses Igniter to safely modify the Elixir AST
  4. Preserves formatting: Maintains your existing code style
  5. Shows notice: Reminds you to run mix deps.get

Development

# Clone the repository
git clone https://github.com/hoangbits/mix-add.git
cd mix-add

# Install dependencies
mix deps.get

# Run tests
mix test

# Build escript
mix escript.build

# Test locally
./mix_add_cli phoenix

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT License - see LICENSE file for details

Credits

Built with Igniter by the Ash Project team.

Author

hoangbits