moban icon indicating copy to clipboard operation
moban copied to clipboard

Detect included yaml files which are also targets

Open jayvdb opened this issue 5 years ago • 3 comments

If a mobanfile has a target which is also part of the mobanfile yaml file system, moban should generate that file first if the file is missing, and re-run whenever the generated yaml file is modified.

e.g.

A.yaml includes:

overrides: B.yaml

targets:
  - B.yaml: genB.yaml.jj2

This will allow the yaml data to be built dynamically using templates, either to bootstrap a project with default values based on other input values, or for changes to values to be propagated into other yaml variables which can then be used.

Or, it allows yaml values to contain variables.

e.g. mobanfile:

overrides: derived_data.yaml

app_name: foobar
copyright_start: 2016

targets:
  - derived_data.yaml: gen_derived_data.jj2
  - copyright.js: const_copyright_variables.c.jj2
  - copyright.php: const_copyright_variables.php.jj2

gen_derived_data.jj2:

copyright_string: "(c) {{app_name}} {{copyright_start}}-{% get_current_year() %}"

(very simplified)

In a single case, that could be achieved by putting the logic for copyright_string into the template logic for each template which needs it. Or improved by using a re-usable macro included into each template.

However the use case I have is a large collections of data is needed as inputs, and throughout the string values are constants which will infrequently change.

Another fun experiment is making the mobanfile also a template. This allows a repo to be 100% controlled by an upstream repo.

e.g. mobanfile

requires:
  - https://github.com/foo/bar
targets:
  mobanfile: gen_moban_file.jj2
  other_file: other_file_gen.jj2

If the upstream gen_moban_file.jj2 adds a new file which needs to be deployed, the mobanfile would be updated. Currently the user then needs to run moban again for the new file to be generated. The user might forget to do that.

jayvdb avatar Nov 15 '18 11:11 jayvdb