Skip to content

oyvindh/Mustache.MSBuild

Repository files navigation

Mustache.MSBuild

License Build Version Downloads

This repository contains the code for MSBuild tasks that allow the expansion of Mustache templates during the build. Typically useful if you do any infrastructure as code with MSBuild or simply need to generate some files.

There are two main ways to run this. The most simple, is to use the MustacheExpand task. This takes a template and a data file as input and produce the expanded result in a file. The other way, MustacheDirectoryExpand, is to expand a directory structure where data can be overridden at every level. This mode becomes very useful is you are expanding configuration that does not support parameterization.

MustacheExpand task

<MustacheExpand
    TemplateFile="mustache-templates/simple.mustache"
    DataFile="simple.json"
    InputData="data1=value1"
    DestinationFile="expanded.txt"/>

InputData will append to the data set or override values defined in the DataFile

MustacheDirectoryExpand task

To use the directory expansion, you need to declare the directory input and output structure that you want.

{
  "Children": [
    {
      "Name": "First"
    },
    {
      "Name": "Second",
      "Children": [
        {
            "Name": "FirstChild"
        }
      ]
    }
  ]
}

Then you can define parameters/data to the template expansion that override values downward in the tree structure

data
├── First
│   └── data.json
├── Second
│   └── FirstChild
│       └── data.json
└── data.json

Now, you can declare the task and do a directory wise template expansion.

<MustacheDirectoryExpand
    TemplateFile="app-resources.task.mustache"
    DataRootDirectory="data"
    DestinationRootDirectory="$(OutputPath)"
    DefaultDestinationFileName="expanded.txt"
    DefaultDataFileName="data.json"
    DirectoryStructureFile="directory-structure.json" />

Contribute

Refer to the contribution docs.

About

Run Mustache template expansion during the build

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •