Packages
corex
0.1.0-rc.0
0.1.2
0.1.1
0.1.0
0.1.0-rc.1
0.1.0-rc.0
0.1.0-beta.5
0.1.0-beta.4
0.1.0-beta.3
0.1.0-beta.2
0.1.0-beta.1
0.1.0-alpha.33
0.1.0-alpha.32
0.1.0-alpha.31
0.1.0-alpha.30
0.1.0-alpha.29
0.1.0-alpha.28
0.1.0-alpha.27
0.1.0-alpha.26
0.1.0-alpha.25
0.1.0-alpha.24
0.1.0-alpha.23
0.1.0-alpha.22
0.1.0-alpha.21
0.1.0-alpha.20
0.1.0-alpha.19
0.1.0-alpha.18
0.1.0-alpha.17
0.1.0-alpha.16
0.1.0-alpha.15
0.1.0-alpha.14
0.1.0-alpha.13
0.1.0-alpha.12
0.1.0-alpha.11
0.1.0-alpha.10
0.1.0-alpha.9
0.1.0-alpha.8
0.1.0-alpha.7
0.1.0-alpha.6
0.1.0-alpha.5
0.1.0-alpha.4
0.1.0-alpha.3
0.1.0-alpha.2
0.1.0-alpha.1
Accessible and unstyled UI components library written in Elixir and TypeScript that integrates Zag.js state machines into the Phoenix Framework.
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/corex.design.ex
defmodule Mix.Tasks.Corex.Design do
use Mix.Task
@shortdoc "Copies the Corex design asset tree into assets/corex/"
@moduledoc """
Copies the Corex design asset tree from the `corex` package `priv/` directory
into your app's `assets/corex/`.
The copy is safe by default - it **skips any target that already exists**.
Pass `--force` to overwrite.
## Options
* `--designex` - also copy the design token source tree into `assets/corex/design/`
* `--force` - overwrite the target(s) if they already exist
## Examples
mix corex.design # first-time copy; no-op if already present
mix corex.design --force # overwrite existing assets/corex/
mix corex.design --designex # also copy the token source tree
mix corex.design --designex --force
"""
@impl true
def run(argv) do
{opts, _} =
OptionParser.parse!(argv,
strict: [designex: :boolean, force: :boolean],
aliases: [f: :force]
)
priv = priv_dir!()
force? = Keyword.get(opts, :force, false)
designex? = Keyword.get(opts, :designex, false)
dest = Path.expand(Path.join("assets", "corex"))
copy_tree!(priv, ["design", "corex"], dest, force?)
write_design_version!(dest)
if designex? do
copy_tree!(
priv,
["design", "design"],
Path.expand(Path.join(["assets", "corex", "design"])),
force?
)
end
:ok
end
defp priv_dir! do
case :code.priv_dir(:corex) do
{:error, _} ->
Mix.raise(
"Could not resolve :corex priv directory - is the corex dependency available?"
)
priv ->
List.to_string(priv)
end
end
defp copy_tree!(priv, rel_segments, dest, force?) do
src = Path.join([priv | rel_segments])
unless File.dir?(src) do
Mix.raise("Expected Corex packaged tree at #{src}")
end
if File.exists?(dest) and not force? do
Mix.shell().info([
:yellow,
"* ",
:reset,
"#{Path.relative_to_cwd(dest)} already exists, skipping (pass --force to overwrite)"
])
else
File.mkdir_p!(Path.dirname(dest))
File.cp_r!(src, dest)
Mix.shell().info([
:green,
"* copied ",
:reset,
"#{Path.relative_to_cwd(src)} → #{Path.relative_to_cwd(dest)}"
])
end
end
defp write_design_version!(dest) do
version =
case Application.spec(:corex, :vsn) do
nil -> "unknown"
vsn -> vsn |> to_string() |> String.trim_leading("v")
end
File.write!(Path.join(dest, "VERSION"), version <> "\n")
end
end