futurice / jalapeno

CLI for creating, managing and sharing spiced up templates
https://futurice.github.io/jalapeno/
Apache License 2.0
7 stars 0 forks source link

Support multiple recipes in a single project #1

Closed majori closed 1 year ago

ilkka commented 1 year ago

Could this be the start of this? Does there need to be some central metadata file in addition to these?

Feature: Execute recipes
    Executing Jalapeno recipes to template out projects

  Scenario: Execute single recipe
    Given a project directory
    And a recipe "foo" that generates file "README.md"
    When I execute recipe "foo"
    Then the project directory should contain file "README.md"
    And the project directory should contain file ".jalapeno/1-foo.yml"

  Scenario: Execute multiple recipes
    Given a project directory
    And a recipe "foo" that generates file "README.md"
    And a recipe "bar" that generates file "Taskfile.yml"
    When I execute recipe "foo"
    And I execute recipe "bar"
    Then the project directory should contain file "README.md"
    And the project directory should contain file "Taskfile.yml"
    And the project directory should contain file ".jalapeno/1-foo.yml"
    And the project directory should contain file ".jalapeno/2-bar.yml"
majori commented 1 year ago

Yeah, this was the idea I had in mind also! Also for now we probably want to block execution of a recipe if it touches the same files as the previous ones:

Scenario: New recipe conflicts with the previous recipe
    Given a project directory
    And a recipe "foo" that generates file "README.md"
    And a recipe "bar" that generates file "README.md"
    When I execute recipe "foo"
    And I execute recipe "bar"
    Then the project directory should contain file "README.md"
    And the project directory should contain file ".jalapeno/1-foo.yml"
    And execution of recipe "bar" has failed with error ...
ilkka commented 1 year ago

Currently the way rendered recipe loading works is that for the Files list, all the files in the project directory are loaded. This means that the recipe doesn't really know if a file was rendered by itself or if it was added by the user manually, and in the case of multiple recipes, it could not know which recipe it is conflicting with, which might be nice to show to the user.

I'm thinking that while we're working on this, we could make the Files list be an array of structs, with e.g. filenames and hashes, and make it also be serializable, except for the file content. The content would be added by rendering, and could still be loaded from the project directory too, except it wouldn't be a file tree walk, it would instead look at the rendered files list in the metadata and load those.

That would then let us do things like

ilkka commented 1 year ago

Actually we should probably just put all the rendered recipes in one recipes.yaml separated by the YAML file separator mechanism.