Awesome
Easy to use tool to config transformations for JSON, XML and YAML.
Everyone remember XML Document Transform syntax to transform configuration files during the build process. But world is changing and now you can have different config types in your .NET projects.
Magic Chunks allows you to transform you JSON, XML and YAML files. You can run it at MSBuild, Cake, PSake or Powershell script as well as use Visual Studio Team Services build extension. Also, it's possible to reference Magic Chunks from your .NET projects in more complicated cases.
How it works
The main idea is quite simple. Magic Chunks represents transformation as a key-value collection.
The key contains path in the source file which should be modified, and the value contains data for this path in modified file.
If you are using Magic Chunks from .NET or Cake, you can also pass in any keys to be removed into the constructor.
XML
Imagine you have following XML based configuration file.
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.1" />
<authentication mode="None" />
</system.web>
</configuration>
So following transformations could be applied to this config:
{
"configuration/system.web/compilation/@debug": "false",
"configuration/system.web/authentication/@mode": "Forms"
}
As a result you will have config like this:
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.5.1" />
<authentication mode="Forms" />
</system.web>
</configuration>
JSON
The same approach works if you have JSON based configuration:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=webapp"
}
}
Transformation for the config could be:
{
"ConnectionStrings/DefaultConnection": "Data Source=10.0.0.5;Initial Catalog=Db1;Persist Security Info=True"
}
After transformation you will have:
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=10.0.0.5;Initial Catalog=Db1;Persist Security Info=True"
}
}
Supported formats
Magic Chunks supports following file formats:
Getting started
Let's say you have appsettings.json
file at C:\sources\project1
folder:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=webapp"
}
}
To use Magic Chunks download latest release manually or get it directly from Nuget.
For example we will use Powershell to transform configuration file. To do this you have to write something like this:
Import-Module .\MagicChunks.psm1
Format-MagicChunks -path C:\sources\project1\appsettings.json -transformations @{
"ConnectionStrings/DefaultConnection" = "Data Source=10.0.0.5;Initial Catalog=Db1;Persist Security Info=True"
}
To transform config files you can use any approach you like:
To learn more check wiki page.
Maintainers
- Sergey Zwezdin (@sergeyzwezdin)
- Gary Ewan Park (@gep13)
- Pascal Berger (@pascalberger)
Contributions
Any contributions are welcome. Most probably someone will want to extend it with additional formats. So feel free to make pull requests for your changes. Read contribution guidelines to start.
License
Magic Chunks is released under the MIT License.