6 releases

0.1.6 Aug 5, 2023
0.1.5 Apr 6, 2023

#2086 in Command line utilities

23 downloads per month

MIT license

29KB
692 lines

fmerge

fmerge is a tool that allows merging files recursively and with custom placeholder patterns. The include file statements are always relative to the file that includes them.

Example

Test data

root.json

{
    "data": [
        {{ ./item1.json }},
        {{ ./item2.json }}
    ]
}

item1.json

{
    "name": "Item 1",
    "data": {{ ./item_data.json }}
}

item2.json

{
    "name": "Item 2",
    "data": {{ ./item_data.json }}
}

item_data.json

{
    "foo": "bar"
}

Execution

Merging these files together can be done by executing the following code:

fmerge merge -f=./root.json -p="{{ %f }}"

The resulting file will be printed to STDOUT and will look like this:

{
    "data": [
        {
    "name": "Item 1",
    "data": {
    "foo": "bar"
}
},
        {
    "name": "Item 2",
    "data": {
    "foo": "bar"
}
}
    ]
}

The text replacement is done without respect to the formatting. The structure above is valid JSON, just formatted incorrectly. fmerge does not modify the content it merges in any way, shape or form.
The correctly formatting JSON looks as follows:

{
  "data": [
    {
      "name": "Item 1",
      "data": {
        "foo": "bar"
      }
    },
    {
      "name": "Item 2",
      "data": {
        "foo": "bar"
      }
    }
  ]
}

Dependencies

~7–14MB
~161K SLoC