View Source Workspace.Project (Workspace v0.1.0)

A struct holding a workspace project info.

Workspace project config

Each workspace project may optionally have some workspace related settings defined in it's Mix.Project config. There isn't a comprehensive list of all supported options since various plugins or mix tasks may define their own options that can be read from this configuration.

The following are the global workspace supported settings:

  • :tags - Tags associated with the current project. A single tags can be either an atom or a tuple of the form {atom, atom}. In the latter case this is considered a scoped tag. For example:

    tags: [:utils, {:scope, :shared}]

    The default value is [].

Summary

Types

t()

Struct holding info about a mix project

A project's tag.

Functions

Marks the given project as :affected.

Returns true if the project is affected, false otherwise.

Returns the Mix.Project config of the given mix.exs file.

Ensures that the given path is an existing mix.exs file.

Formats a tag as a binary.

Returns true if the project has any of the given tags.

Returns true if the project has at least one scoped tag with the given scope, false otherwise.

Returns true if the project has the given tag, false otherwise.

Runs the given function inside the given project.

Marks the given project as :modified.

Returns true if the project is modified, false otherwise

Creates a new project for the given project path.

Returns the project type of a project given the mix config.

Relative path of the project to the workspace

Returns all tags with the given scope.

Flags the given project as root project or not.

Sets the status of the given project.

Returns a map including the key properties of the given project.

Types

@type t() :: %Workspace.Project{
  app: atom(),
  changes: nil | [{Path.t(), Workspace.Git.change_type()}],
  config: keyword(),
  mix_path: binary(),
  module: module(),
  path: String.t(),
  root?: nil | boolean(),
  skip: term(),
  status: :undefined | :unaffected | :modified | :affected,
  tags: [tag()],
  workspace_path: binary()
}

Struct holding info about a mix project

@type tag() :: atom() | {atom(), atom()}

A project's tag.

It can either be a single atom or a tuple of atoms. In the latter case this is considered a scoped tag.

Functions

@spec affected(project :: t()) :: t()

Marks the given project as :affected.

A project is considered affected if any of it's dependencies (either direct or indirect) is modified.

Notice that if the project is already marked as :modified it's status does not change to :affected since by default modified projects are considered affected.

@spec affected?(project :: t()) :: boolean()

Returns true if the project is affected, false otherwise.

A project is considered :affected if it is either modified or indirectly affected from a modified dependency.

@spec config(mix_path :: binary()) :: keyword()

Returns the Mix.Project config of the given mix.exs file.

The project will be loaded using Mix.Project.in_project/4.

@spec ensure_mix_file!(path :: String.t()) :: :ok

Ensures that the given path is an existing mix.exs file.

If the file does not exist or the filename is not mix.exs it will raise.

@spec format_tag(tag :: tag()) :: String.t()

Formats a tag as a binary.

Link to this function

has_any_tag?(project, tags)

View Source
@spec has_any_tag?(project :: t(), tags :: [tag()]) :: boolean()

Returns true if the project has any of the given tags.

Link to this function

has_scoped_tag?(project, scope)

View Source
@spec has_scoped_tag?(project :: t(), scope :: atom()) :: boolean()

Returns true if the project has at least one scoped tag with the given scope, false otherwise.

@spec has_tag?(project :: t(), tag :: tag()) :: boolean()

Returns true if the project has the given tag, false otherwise.

Special tags

  • :* - matches all tags, it always returns true
@spec in_project(path :: binary(), fun :: (module() -> result)) :: result
when result: term()

Runs the given function inside the given project.

path can be one of the following:

  • a path to a mix.exs file
  • a path to a folder containing a mix.exs file

Both absolute and relative paths are supported.

This function will delegate to Mix.Project.in_project/4. The app name is extracted from the project folder name, so it is expected to match the internal defined :app name in mix.exs.

The return value of this function is the return value of fun

Examples

Mix.Project.in_project("/path/to/my_app/mix.exs", fn module -> module end)
#=> MyApp.MixProject
Link to this function

modified(project, changes)

View Source
@spec modified(project :: t(), changes :: []) :: t()

Marks the given project as :modified.

The changes is the list of changed files belonging to the current project that have changed.

An exception will be raised if the changes list is empty.

@spec modified?(project :: t()) :: boolean()

Returns true if the project is modified, false otherwise

Link to this function

new(path, workspace_path)

View Source
@spec new(mix_path :: String.t(), workspace_path :: String.t()) :: t()

Creates a new project for the given project path.

The path can be one of the following:

  • A path to a mix.exs file
  • A path to a project containing a mix.exs file

You can pass both absolute and relative paths. All paths will be expanded by default.

This will raise if the path does not correspond to a valid mix project.

@spec project_type(config :: keyword()) :: nil | atom()

Returns the project type of a project given the mix config.

The project type is defined under a :type attribute in the :workspace config. It can take an arbitrary value. If set to :workspace it indicates that the project is a root workspace project.

Link to this function

relative_to_workspace(project)

View Source
@spec relative_to_workspace(project :: t()) :: binary()

Relative path of the project to the workspace

Link to this function

scoped_tags(project, scope)

View Source
@spec scoped_tags(project :: t(), scope :: atom()) :: [tag()]

Returns all tags with the given scope.

Link to this function

set_root(project, root?)

View Source
@spec set_root(project :: t(), root? :: boolean()) :: t()

Flags the given project as root project or not.

Link to this function

set_status(project, status)

View Source
@spec set_status(project :: t(), status :: atom()) :: t()

Sets the status of the given project.

@spec to_map(project :: t()) :: map()

Returns a map including the key properties of the given project.

Only :app, :module, :mix_path, :path, :workspace_path, :status, :root and :changes are included.