RW Setup Proposal: Complementing Generators with Setup

I recently added a tailwind Generator to Redwood. (You can try it out now by upgrading to the latest canary, yarn rw upgrade -t canary.) It got me thinking about the nature of Generators.

One thing’s no surprise: Redwood loves Generators. There’s one for nearly everything, and that’s probably why I added one for tailwind: why wrangle with a webpack config if you could just punch in a CLI command? It should be that easy (and now it is!). At least, Redwood got me thinking that way.

image

Looking at all the Generators in Redwood, there’s the routine lot, like Layout, Page, Cell, Component, etc., that crunch boilerplate by handing you a directory stuffed with files. We run them many times as we’re building out our app; they make developing a joy. Then there’s the group like Auth. (And it’s Auth that kicked this all off.) This group is super: they don’t just get rid of boilerplate, but install packages, modify files–whatever it takes to wire up your app, from front to back, Side to Side, Web to API.

Both of these are wins for DX. But are both of these really Generators? It seems like there’s a better way to think about the super group:

Setup

You can think of the Auth Generator as setting something up for you. It’s a one-time thing: you run it, specifying your provider, and you’re good to go. So we’re proposing a new entry-point CLI command to match this thinking: setup. It’d look something like this:

yarn rw setup auth0
yarn rw setup tailwindcss
yarn rw setup vercel-deploy

You’d run it just like any other Redwood command. But instead of there being any types (e.g. page in yarn rw g page home), there’d be a single namespace: whatever’s after setup is what’s being setup.

We thought about a dual namespace, where running Setup resembles running a Generator:

yarn rw setup auth auth0 

But we decided against it after thinking about the kind of extensibility we’re after. In the future, we’re thinking about providing a Deno-like convenience. That is, just give setup a URL and it’ll run:

yarn rw setup https://github.com/jtoar/my-custom-redwood-setup/releases/tag/v0.3.0 

The steps from here would be:

  1. Introduce a new CLI command, setup, as an alternate entry point to Auth, Deploy, and Utils commands.
  2. Provide a deprecation warning for running Auth, Deploy, and Utils commands via generate.

Let us know what you think!

4 Likes

Thanks for this writeup! It’s important to note also that some of the existing auth generators would need to be renamed, for instance yarn rw g auth netlify would probably become yarn rw setup netlify-identity or the like, as this would be a single namespace and just netlify wouldn’t make much sense anymore. We would also want to create good documentation for the various packages and categorize them to make them easy to find since we’d be removing the categorization namespaces (auth and util).

:100:

TBH rw g util tailwind never did sit quite right with me. We’re not generating a utility here. We’re setting up tailwind, that’s what we’re doing! So yes! I’m all for this change :slight_smile:

4 Likes

Yes, exactly! The distinction here would be that generators are for things you might plausibly do more than once (and then probably edit the generated output). Setuppers (that’s the name, right?) would be for one-time setup, configuration, and installation tasks.

Oooh, that’s awesome!

When someone is trying to create a new “setup” command, maybe they could use yarn rw setup file:// in order to test it out?

For testing, and IDE integration, it would also be nice if the command was able to output as JSON, like @aldonline suggested over here: https://github.com/redwoodjs/redwood/issues/843

2 Likes

Will we have a generator for that? :stuck_out_tongue:

1 Like