How to create a hierarchy data structure from a template in javascript

I’m trying to build a simple tool that can create a large tree structure automatically. The idea is you define the structure and how many items you want in each nesting and then javascript builds the array for you. I want to end up with a flat list of items with parentIds.

I’ve a “template” structure but don’t know how to turn that into all the data. For example here’s a template I have.

[
    {
        "id": "6acc93d156dc11eea34331ffef2d706d",
        "parentId": null,
        "name": "ep101",
        "seq": [
            "ep101",
            "ep102"
        ]
    },
    {
        "id": "0d305b4056e011eea34331ffef2d706d",
        "parentId": "6acc93d156dc11eea34331ffef2d706d",
        "name": "ep101sh010",
        "seq": [
            "ep101sh010",
            "ep101sh020"
        ]
    },
    {
        "id": "28ea228056e011eea34331ffef2d706d",
        "parentId": "0d305b4056e011eea34331ffef2d706d",
        "name": "Generic",
        "seq": []
    }
]

In this example the resulting tree would look something like this.

ep101
– ep101sh010
–– Generic
– ep101sh020
–– Generic
ep102
– ep102sh010
–– Generic
– ep102sh020
–– Generic

Any help would be appreciated thanks!