Skip to content

Commit d62fa80

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 d62fa80

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

lib/mix/tasks/ExAtomVM.install.ex

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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: Sourceror.parse_string!("0x250000"),
58+
stm32_flash_offset: Sourceror.parse_string!("0x8080000"),
59+
chip: "auto",
60+
port: "auto"
61+
) do
62+
{:ok, zipper}
63+
end
64+
end)
65+
|> Igniter.mkdir("avm_deps")
66+
|> Igniter.Project.Module.find_and_update_module!(
67+
Igniter.Project.Module.module_name_prefix(igniter),
68+
fn zipper ->
69+
case Igniter.Code.Function.move_to_def(zipper, :start, 0) do
70+
:error ->
71+
# start not available
72+
zipper =
73+
Igniter.Code.Common.add_code(
74+
zipper,
75+
"""
76+
def start do
77+
IO.inspect("Hello AtomVM!")
78+
:ok
79+
end
80+
""",
81+
placement: :before
82+
)
83+
84+
{:ok, zipper}
85+
86+
_ ->
87+
{:ok, zipper}
88+
end
89+
end
90+
)
91+
end
92+
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)