amber icon indicating copy to clipboard operation
amber copied to clipboard

[RFC] Recipes as patches on base templates or other recipe

Open damianham opened this issue 6 years ago • 2 comments

Abstract

The current recipes implementation means that each recipe needs to provide app, controller, model and scaffold templates. There are 2 main disadvantages to this

  • lots of duplication of code among recipes
  • the need to update many recipes to stay aligned with Amber releases

Proposal

Recipes should be a patch on either the base templates or another recipe (which would be a patch on the base templates or another recipe and so on). Therefore every recipe should indicate the recipe that it extends e.g.

# recipe shard.yml
name: amber_material
version: 1.0.1
authors:
   - Damian Hamill <[email protected]>
description: |
   Application recipe for a React SPA with Material UI
license: MIT
generator_version: 2
extends: damianham/amber_modular

If extending the base templates the value for the extends key should be base. If the extends value is missing or blank it is assumed the recipe extends the base templates.

When creating a new application from a recipe, the recipes feature should

  • create the application folder according to the application name - appname
  • create a temporary folder to store shards - appname/.recipes
  • create a folder to store the final templates - appname/.recipes/templates
  • install the recipe shard and all dependencies into appname/.recipes/lib
  • install the base templates into appname/.recipes/templates
  • apply each recipe patch in order of descendency into the appname/.recipes/templates folder
  • create the application using appname/.recipes/templates as the source
  • define /appname/.recipes/templates as the recipe in appname/.amber.yml

Recipes could be either a set of patches to template folders or folders to merge with folders in the parent and specified in the recipe shard.yml as;

# merge the app and model folders from this recipe with the relevant parent templates
# files in the recipe replace files in the parent
merge:
  - app
  - model

# apply the controller and scaffold patches to the relevant parent templates
patch:
  controller: base.controller.recipe.controller.diff
  scaffold: base.scaffold.recipe.scaffold.diff

damianham avatar Mar 12 '19 06:03 damianham

@damianham I like this idea. It would be great to leverage the existing generators and only replace the templates for the areas you want changed without duplicating the work in the recipes. :100:

drujensen avatar May 20 '19 02:05 drujensen

@drujensen OK great, when I get some free time I will make a start on this.

damianham avatar May 20 '19 10:05 damianham