Skip to content

New Resource Generator

Chris Laskey edited this page Aug 17, 2020 · 1 revision

Short Summary

Interactive command-line tool to generate a new resource from the command line:

$ mix artemis.gen.resource

Contributors

Name GitHub
Chris Laskey @chrislaskey

Pattern Overview

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.

Value Proposition

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.

Implementation

Initial Configuration

After executing $ mix artemis.gen.resource, interactive prompts ask the user for information about the new resource:

Screen Shot 2020-08-17 at 5 03 43 PM

Executing Steps

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:

Screen Shot 2020-08-17 at 5 13 33 PM

Discussion

Thoughts? Feedback? View the discussion thread for this pattern.