lib/render.js
function render(q) {
  if (!q.length) {
    complete();
    return;
  }

  const item = q.shift();

  // render HTML file
  fs.writeFile(`${item.file}.html`, item.html, err => {
    if (err) throw err;

    // if prerendering is enabled
    if (typeof options.prerender === "object" && options.prerender !== null) {
      // wait for response from browser
      puppet.once("message", height => {
        // store height
        item.json.height = height;

        // render JSON file
        fs.writeFile(`${item.file}.json`, JSON.stringify(item.json), err => {
          if (err) throw err;
          process.send(`success::Generated ${item.name}`);

          // render next
          render(q);
        });
      });

      // open html file in browser
      puppet.send({
        url: `http://localhost:${options.prerender.port}/${
          options.prerender.path
        }/${item.slug}.html`
      });

      // if no prerendering is to be done
    } else {
      // render JSON file
      fs.writeFile(`${item.file}.json`, JSON.stringify(item.json), err => {
        if (err) throw err;
        process.send(`success::Generated ${item.name}`);

        // render next
        render(q);
      });
    }
  });
}
function render(q) {
  if (!q.length) {
    complete();
    return;
  }

  const item = q.shift();

  // render HTML file
  fs.writeFile(`${item.file}.html`, item.html, err => {
    if (err) throw err;

    // if prerendering is enabled
    if (typeof options.prerender === "object" && options.prerender !== null) {
      // wait for response from browser
      puppet.once("message", height => {
        // store height
        item.json.height = height;

        // render JSON file
        fs.writeFile(`${item.file}.json`, JSON.stringify(item.json), err => {
          if (err) throw err;
          process.send(`success::Generated ${item.name}`);

          // render next
          render(q);
        });
      });

      // open html file in browser
      puppet.send({
        url: `http://localhost:${options.prerender.port}/${
          options.prerender.path
        }/${item.slug}.html`
      });

      // if no prerendering is to be done
    } else {
      // render JSON file
      fs.writeFile(`${item.file}.json`, JSON.stringify(item.json), err => {
        if (err) throw err;
        process.send(`success::Generated ${item.name}`);

        // render next
        render(q);
      });
    }
  });
}
function render ( q ) { if ( ! q . length ) { complete ( ) ; return ; } const item = q . shift ( ) ; // render HTML file fs . writeFile ( ` ${ item . file } ` , item . html , err => { if ( err ) throw err ; // if prerendering is enabled if ( typeof options . prerender === "object" && options . prerender !== null ) { // wait for response from browser puppet . once ( "message" , height => { // store height item . json . height = height ; // render JSON file fs . writeFile ( ` ${ item . file } ` , JSON . stringify ( item . json ) , err => { if ( err ) throw err ; process . send ( ` ${ item . name } ` ) ; // render next render ( q ) ; } ) ; } ) ; // open html file in browser puppet . send ( { url : ` ${ options . prerender . port } ${ options . prerender . path } ${ item . slug } ` } ) ; // if no prerendering is to be done } else { // render JSON file fs . writeFile ( ` ${ item . file } ` , JSON . stringify ( item . json ) , err => { if ( err ) throw err ; process . send ( ` ${ item . name } ` ) ; // render next render ( q ) ; } ) ; } } ) ; }
Recursive render
generates component html file
and json file after that
Recursive render generates component html file and json file after that