-
Notifications
You must be signed in to change notification settings - Fork 4
New Resource Generator
Interactive command-line tool to generate a new resource from the command line:
$ mix artemis.gen.resource
Name | GitHub |
---|---|
Chris Laskey | @chrislaskey |
The Phoenix Framework provides command line generators like mix phx.gen.html
and mix phx.gen.schema
. These can be used to quickly and uniformly create new resources.
Inspired by these, the new resource generator in Artemis uses a custom, interactive mix task to guide users in creating a new resource. It captures the complete life-cycle, from database migrations through browser based tests.
The value of this pattern is:
- Interactive. Guides a user through all the layers of creating a resource from foundation to finish.
- Educational. Each step is clearly defined and executed in logical order, with additional prompts explaining actions.
- Development Speed. It greatly reduces the amount of code a developer needs to write.
- Uniformity. By using an existing resource as a template, it works without having to keep separate generator templates up to date.
The downsides of this pattern are:
- Templating. By using an existing resource is as a code template, the new resource's code may contain artifacts that aren't applicable to the new resource.
After executing $ mix artemis.gen.resource
, interactive prompts ask the user for information about the new resource:
The user is always prompted at the end of each step before continuing. Allowing the user to review and verify the generated code before continuing to the next step. Although the mix task does much of the heavy lifting, it should never feel like a black box. The goal is to be educational and informative.
Although most steps are fully automated, some require manual action. In those cases, example code is generated with prompts on where it needs be added:
Thoughts? Feedback? View the discussion thread for this pattern.