title: How to automate the creation of a directory structure with node given an json file representing the dir structure?
body: <p>Given a JSON file representing the pages I want to create a file structure for:</p>
  
  <pre><code>[{"id": 1, "name":"page1"}, 
   {"id": 2, "name":"page2"}, 
   {"id": 3, "name":"page3"}, ...]
  </code></pre>
  
  <p>I'd like to create a script to run with node that's going to create the directories and files for me and end up with a structure like this:</p>
  
  <pre><code>- Folder "pages"
     - Folder "page1"
        - Folder "page"
           - index file
        - index file
     - Folder "page2"
        - Folder "page"
           - index file
        - index file
  </code></pre>
  
  <p>etc...</p>
  
  <p>Any help appreciated thanks!</p>
  
  <p>UPDATE:</p>
  
  <pre><code>structure.js:
  const structure = [
    {
      id: 1,
      name: 'home'
    },
    {
      id: 2,
      name: 'about'
    },
    {
      id: 3,
      name: 'work'
    }
  ];
  module.exports = structure;
  
  build.js:
  const fse = require('fs-extra');
  const structure = require('./structure');
  
  try {
    if (!fse.existsSync('pages')) {
      fse.mkdir('pages', () =&gt; {
        structure.forEach(page =&gt; {
          fse.mkdir(`./pages/${page.name}`, () =&gt; {
            fse.mkdir(`./pages/${page.name}/page`, () =&gt; {
              fse.writeFile(`./pages/${page.name}/page/index.tsx`, `template`);
            });
            fse.writeFile(`./pages/${page.name}/index.tsx`, `api`);
          });
        });
      });
      fse.writeFile(`./pages/index.tsx`, `index`);
    }
  } catch (err) {
    console.error(err);
  }
  </code></pre>
  
  <p>This will work but I don't like the callback chain, haven't tried fs.extra yet but looks like it would solve that callback pyramid perhaps</p>