6 releases

0.1.6 Aug 5, 2023
0.1.5 Apr 6, 2023

#788 in Command line utilities

Download history 24/week @ 2024-02-19 4/week @ 2024-02-26 5/week @ 2024-03-11 116/week @ 2024-04-01

121 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

~6.5–9.5MB
~160K SLoC