sodapopcan

sodapopcan

Request for feedback on Vials (wrappers for mix tasks)

EDIT: I forgot to link the repo, ha: GitHub - sodapopcan/vials: Tweak your mix generators

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!

Most Liked

BartOtten

BartOtten

This seems very nice to me. Less burden to keep custom generators up-to-date with upstream and possibly working with different versions of Phoenix.

Pre-mature note: a place to share Vials would be nice :slight_smile:

Nefcairon

Nefcairon

So this is to personalize, individualize, adapt, tweak the result of a mix task? "If so, “aftercare” comes to my mind.

There are always certain steps of changes that everyone undertakes after creating a new phoenix app (e.g. change password in config/dev.exs for the db). I would be interested in other people’s vials, too.

sodapopcan

sodapopcan

Yeah, I’m really just writing it with generators in mind, though theoretically you could use it to wrap any mix task. I think once I cut a 0.1.0 release I’ll make an new “Introducing” thread and make that clearer as I don’t think “wrappers for mix tasks” is particularly appealing at a glance.

I like that name but I think I’m going to stick with Vials as I like being able to have a name for the files that is related to the name. That would be hard with aftercare.

I was talking about with with @BartOtten. I’m not sure exactly how to handle that yet. I’m a little wary of accepting PRs in the project as it could get out of hand, but if this project gets any real use then there should definitely be a solution for sharing vials. I’m open to suggestions, of course!

D4no0

D4no0

After reading the comments it surely is a tool with a lot of potential!

The thing that would make it real interesting would be to be able to access the task code before/after it is executed? The only sad thing about this is that the classic mix task is just a run function and it has side effects in it.

Maybe an interesting approach would be to build a data structure at the end of the task and have some kind of “server” execute everything afterwards? this would open possibilities to mix and pipe these kind of tasks.

sodapopcan

sodapopcan

That’s interesting. I’m currently just focused on a DSL, well, basically for creating and manipulating source files but I’m open to other use-cases

Can you give an example of what you’re describing? Like metaprogramming a mix task itself?

Otherwise currently Vial files work like you describe in that they just build up a list of messages which get processed by a “Runner”. Currently it uses an Agent to store up the messages but I’m likely going to refactor to use a module attribute—the Agent got me going quicker as I didn’t have to figure out how to store anonymous functions in a module attribute but I think I have a solution. I’m also in the midst of refactoring to clean some stuff up (namely the guys of add_dep shouldn’t be in the DSL module.

Where Next?

Popular in RFCs Top

bennydreamtech23
So recently I have been looking for ways to improve my workflow in elixir and I saw all the commands I need to run to setup a project and...
New
pzingg
I took a phx.gen.auth application and added support for storing a user’s cookie consent settings. Created a couple of modal dialogs to ha...
New
c4710n
This package is a simple wrapper of beam-telemetry packages. It provides a modular approach for using beam-telemetry packages. The basi...
New
sodapopcan
EDIT: I forgot to link the repo, ha: GitHub - sodapopcan/vials: Tweak your mix generators This project is not quite ready for prime-time...
New
wingyplus
Hi, I start working on the fork version of Elixir GRPC. What I’ve done is the past few days: Support Elixir 1.11+ Support OTP 23+ OTP...
New
BartOtten
This lib is now published and has a new topic. Once this topic was about PhxAltRoutes. A lib pioneering localized routes for Phoenix. I...
New
bortzmeyer
Not a replacement for serious authoritative DNS servers, of course, but useful for some uses (such as returning the IP address of the DNS...
New
bluzky
Hi everyone, I would like to introduce my new project OrangeCMS, it’s an application that help you to create/edit content post for your ...
New
tmbb
SciEx - Scientific programming Code here (very early stage): GitHub - tmbb/sci_ex: Scientific programming for Elixir I have decided to s...
New
laibulle
Hello, I am playing with quantitative finance with Elixir. This library is more a way for me to explore and learn in this area and especi...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement