SpencerCDixon / redux-cli

An opinionated CLI for building redux/react apps quicker
881 stars 63 forks source link

blueprint partials #103

Open anithri opened 7 years ago

anithri commented 7 years ago

Imagine 3 standard concerns.

  1. propTypes
  2. styles
  3. redux-connect

And being able to include a partial for that concern in a blueprint as simply as <%= propTypePartial %>

This would ensure consistency of these across multiple blueprints. And enable concerns to be customized (think styled components vs imported css or an empty partial for the propTypes.

I don't have any solid ideas on how to pull it off. Any ideas about the standards of naming, discovery, how it's called from an ejs file, concerns for looping through an object or array...

anithri commented 7 years ago

It would be nice if we could also find a way to collect various import statements and emit them to the top of the file as part of the final write.

This allows partials to cleanly inject additional statements, and they all end up grouped at the top of the file

anithri commented 7 years ago

Lets add a partials directory at the top level of blueprints. Under that will be ejs files named for the specific partial it is.

/smart
  /files
    __root__
      ...
  /partials
    /propTypes,js
    /styles.css

Add two predicates to the blueprint obj. hasPartials and hasFiles. that are false if the respective directories are missing or empty.

partials names can optionally include the name of the blueprint from which you want to take it like smart.proptypes || proptypes@smart || smart/propTypes with the idea being if the blueprint name is missing it looks for the first partial that matches the name regardless of which blueprint it comes from.

Add a ejs helper to simplify including a partial that checks to see if it is supposed to render it and which file to render.

Add partial lookup that does a blueprint lookup and additional checks for the partial file. These can be cached during the intial blueprint lookup.

anithri commented 7 years ago

ejs doesn't seem to have the equivalent of ruby's content_for. Which makes inserting into blocks more problematic.

  1. the most obvious way to accomplish this is to register partials such that they be processed during the life cycle of the blueprint.
  2. Two stage render, first one accumulates data and outputs ejs tags to be used in a second pass. Hacky but doable.
  3. Load an existing file. use text parsing and string matching to determine where new text is to be inserted, then insert a ejs tag there, and render the file again. works great if you have a very good idea of how a particular file is structure or if you can leave # auto-generated do not edit or # End of Imports or # all imports above here
  4. The biggest places that this is going to help is with adding files to your routes or combineReducers file. Could we leave an ejs version of the generated file so that when we add too it we already have the template?
  5. Opposite of number 4 is to save the data used to render the file, and re render it using a combination of the historical and current data.