EDIT: I forgot to link the repo, ha: GitHub - sodapopcan/vials: Wrappers for mix tasks
This project is not quite ready for prime-time but I wanted to solicit some early feedback to see if it’s something people would want to use.
This started out with the idea of being able to manipulate the output of phx_new
but I ended up making it a more general wrapper around mix tasks.
A “vial” is a file that is named after a mix task and saved in ~/vials
(this is configurable).
Here is one for mix phx.new
:
# ~/vials/phx.new.ex
defmodule SomeModuleName.ItDoesNot.Matter.WhatItsCalled do
use Vials
base_path @target
remove "priv/static/favicon.ico"
remove_comments() # remove comments from all .ex and .exs file.
# remove_comments/1 with accept a filename or list of filenames.
add_dep {:some_dep, "~> 0.0.1"}
if @opts[:binary_id] do
create "lib/#{@target}/schema.ex", """
defmodule #{Macro.camelize(@target)}.Schema do
defmacro __using__(_) do
quote do
use Ecto.Schema, warn: false
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
end
end
end
"""
end
edit "lib/#{@target}/router.ex", fn contents ->
# Crudely manipulate the contents of `router.ex` with Elixir's standard library.
end
end
The next step is to add a few more DSL functions (like move
) and then some helper functions for editing files. I’m very new to AST manipulation and have been getting comfortable with Sourceror. This actually works right now:
def SomeMod do
use Vials
create "some_file.ex" do
defmodule Foo do
def bar do
"baz"
end
end
end
end
…though there is no way to use the injected module attributes. I’m getting there!
Anyway, I just wanted some early feedback. I’m also open to another name. I don’t mind Vials but there is already a project on hexpm called Vial (singular), I’m not sure how active it is.
I’m currently in the midst of refactoring so I’m not too open to PRs atm but I would really appreciate feedback and generally what the appetite for something like this is.
There’s more info in the README.
Thanks!