Git Product home page Git Product logo

magic-chunks's Introduction

AppVeyor Github Releases NuGet Visual Studio Marketplace

Magic Chunks

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:

  1. XML
  2. JSON
  3. YAML

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.

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.

magic-chunks's People

Contributors

sergeyzwezdin avatar droyad avatar ikaew avatar pascalberger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.