Skip to content

Commit 76dce71

Browse files
committed
Igniter installer
(install igniter: mix archive.install hex igniter_new) you can try mix igniter.new my_project --install exatomvm@github:petermm/exatomvm && cd my_project adds dependency and atomvm project config and the start function. early days in igniter world, but should be good to go. Signed-off-by: Peter M <[email protected]>
1 parent 434f730 commit 76dce71

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed

lib/mix/tasks/ExAtomVM.install.ex

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
defmodule Mix.Tasks.Exatomvm.Install do
2+
use Igniter.Mix.Task
3+
4+
@example "mix igniter.new my_project --install exatomvm@github:atomvm/exatomvm && cd my_project"
5+
6+
@shortdoc "Add and config AtomVM"
7+
@moduledoc """
8+
#{@shortdoc}
9+
10+
## Example
11+
12+
```bash
13+
#{@example}
14+
```
15+
16+
"""
17+
18+
@impl Igniter.Mix.Task
19+
def info(_argv, _composing_task) do
20+
%Igniter.Mix.Task.Info{
21+
# Groups allow for overlapping arguments for tasks by the same author
22+
# See the generators guide for more.
23+
group: :exatomvm,
24+
# dependencies to add
25+
adds_deps: [],
26+
# dependencies to add and call their associated installers, if they exist
27+
installs: [],
28+
# An example invocation
29+
example: @example,
30+
# A list of environments that this should be installed in.
31+
only: nil,
32+
# a list of positional arguments, i.e `[:file]`
33+
positional: [],
34+
# Other tasks your task composes using `Igniter.compose_task`, passing in the CLI argv
35+
# This ensures your option schema includes options from nested tasks
36+
composes: [],
37+
# `OptionParser` schema
38+
schema: [],
39+
# Default values for the options in the `schema`
40+
defaults: [],
41+
# CLI aliases
42+
aliases: [],
43+
# A list of options in the schema that are required
44+
required: []
45+
}
46+
end
47+
48+
@impl Igniter.Mix.Task
49+
def igniter(igniter) do
50+
Igniter.update_elixir_file(igniter, "mix.exs", fn zipper ->
51+
with {:ok, zipper} <- Igniter.Code.Function.move_to_def(zipper, :project, 0),
52+
{:ok, zipper} <-
53+
Igniter.Code.Keyword.put_in_keyword(
54+
zipper,
55+
[:atomvm],
56+
start: Igniter.Project.Module.module_name_prefix(igniter),
57+
esp32_flash_offset: 0x250000,
58+
stm32_flash_offset: 0x8080000,
59+
chip: "auto",
60+
port: "auto"
61+
) do
62+
{:ok, zipper}
63+
end
64+
end)
65+
|> Igniter.Project.Module.find_and_update_module!(
66+
Igniter.Project.Module.module_name_prefix(igniter),
67+
fn zipper ->
68+
case Igniter.Code.Function.move_to_def(zipper, :start, 0) do
69+
:error ->
70+
# start not available
71+
zipper =
72+
Igniter.Code.Common.add_code(
73+
zipper,
74+
"""
75+
def start do
76+
IO.inspect("Hello AtomVM!")
77+
:ok
78+
end
79+
""",
80+
:before
81+
)
82+
83+
{:ok, zipper}
84+
85+
_ ->
86+
{:ok, zipper}
87+
end
88+
end
89+
)
90+
end
91+
end

mix.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ defmodule ExAtomVM.MixProject do
2121
# Run "mix help deps" to learn about dependencies.
2222
defp deps do
2323
[
24-
{:uf2tool, "1.1.0"}
24+
{:uf2tool, "1.1.0"},
25+
{:igniter, "~> 0.4"}
2526
# {:dep_from_hexpm, "~> 0.3.0"},
2627
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
2728
]

0 commit comments

Comments
 (0)