Mix.Utils

Utilities used throughout Mix and tasks.

Conversions

This module handles two types of conversions:

Source

Summary

camelize(arg1)

Converts the given string to CamelCase format

command_to_module(command, at \\ Elixir)

Takes a command name and attempts to load a module with the command name converted to a module name in the given at scope

command_to_module_name(s)

Takes a command and converts it to the module name format

config_merge(old, new)

Merges two configs recursively, merging keyword lists and concatenating normal lists

extract_files(paths, exts_or_pattern)

Extract files from a list of paths

extract_stale(sources, targets)

Extract all stale sources compared to the given targets

mix_home()

Gets the mix home. It defaults to ~/.mix unless the MIX_HOME environment variable is set

mix_paths()

Gets all extra paths defined in the environment variable MIX_PATH. MIX_PATH may contain multiple paths. If on Windows, those paths should be separated by ;, if on unix systems, use :

module_name_to_command(module, nesting \\ 0)

Takes a module and converts it to a command. The nesting argument can be given in order to remove the nesting of a module

read_manifest(file)

Reads the given file as a manifest and returns each entry as a list

read_path!(path)

Opens and reads content from either a URL or a local filesystem path

stale?(sources, targets)

Returns true if any of the sources are stale compared to the given targets

symlink_or_copy(source, target)

Symlink directory source to target or copy it recursively in case symlink fails. Expect source and target to be absolute paths as it generates a relative symlink

underscore(atom)

Converts the given atom or binary to underscore format

write_manifest(file, entries)

Writes a manifest file with the given entries list

Functions

camelize(arg1)

Converts the given string to CamelCase format.

Examples

Mix.Utils.camelize "foo_bar" #=> "FooBar"
Source
command_to_module(command, at \\ Elixir)

Takes a command name and attempts to load a module with the command name converted to a module name in the given at scope.

Returns { :module, module } in case a module exists and is loaded, { :error, reason } otherwise.

Examples

Mix.Utils.command_to_module("compile", Mix.Tasks)
#=> { :module, Mix.Tasks.Compile }
Source
command_to_module_name(s)

Takes a command and converts it to the module name format.

Examples

command_to_module_name("compile.elixir")
#=> "Compile.Elixir"
Source
config_merge(old, new)

Merges two configs recursively, merging keyword lists and concatenating normal lists.

Source
extract_files(paths, exts_or_pattern)

Extract files from a list of paths.

If any of the paths is a directory, the directory is looped recursively searching for the given extensions or the given pattern. When looking up directories, files starting with "." are ignored.

Source
extract_stale(sources, targets)

Extract all stale sources compared to the given targets.

Source
mix_home()

Gets the mix home. It defaults to ~/.mix unless the MIX_HOME environment variable is set.

Source
mix_paths()

Gets all extra paths defined in the environment variable MIX_PATH. MIX_PATH may contain multiple paths. If on Windows, those paths should be separated by ;, if on unix systems, use :.

Source
module_name_to_command(module, nesting \\ 0)

Takes a module and converts it to a command. The nesting argument can be given in order to remove the nesting of a module.

Examples

module_name_to_command(Mix.Tasks.Compile, 2)
#=> "compile"

module_name_to_command("Mix.Tasks.Compile.Elixir", 2)
#=> "compile.elixir"
Source
read_manifest(file)

Reads the given file as a manifest and returns each entry as a list.

A manifest is a tabular file where each line is a row and each entry in a row is separated by "\t". The first entry must always be a path to a compiled artifact.

In case there is no manifest file, returns an empty list.

Source
read_path!(path)

Opens and reads content from either a URL or a local filesystem path.

Used by tasks like local.install and local.rebar that support installation either from a URL or a local file.

Raises if the given path is not a url, nor a file or if the file or url are invalid.

Source
stale?(sources, targets)

Returns true if any of the sources are stale compared to the given targets.

Source

Symlink directory source to target or copy it recursively in case symlink fails. Expect source and target to be absolute paths as it generates a relative symlink.

Source
underscore(atom)

Converts the given atom or binary to underscore format.

If an atom is given, it is assumed to be an Elixir module, so it is converted to a binary and then processed.

Examples

Mix.Utils.underscore "FooBar"  #=> "foo_bar"
Mix.Utils.underscore "Foo.Bar" #=> "foo/bar"
Mix.Utils.underscore Foo.Bar   #=> "foo/bar"

In general, underscore can be thought of as the reverse of camelize, however, in some cases formatting may be lost:

Mix.Utils.underscore "SAPExample"  #=> "sap_example"
Mix.Utils.camelize   "sap_example" #=> "SapExample"
Source
write_manifest(file, entries)

Writes a manifest file with the given entries list.

Source