<file_sep>"use strict";

var path = require('path');

var fs = require('fs-extra');

var cwd = process.cwd();

var toArr = function toArr(val) {
  return Array.isArray(val) ? val : val ? [val] : [];
};

module.exports = function (options) {
  var rendererPath = options.renderer ? options.renderer : path.resolve(cwd, './doc-scripts.renderer.js');
  var hasRenderer = false;

  try {
    fs.accessSync(rendererPath);
    hasRenderer = true;
  } catch (e) {}

  var code = "\n  var React = require('react')\n  var ReactDOM = require('react-dom')\n  var ReactDocRenderer = require('" + (hasRenderer ? rendererPath : 'react-doc-renderer') + "')\n  " + toArr(options.requires).map(function (path) {
    return "require(\"" + path + "\")";
  }) + "\n  ReactDocRenderer = ReactDocRenderer.__esModule ? ReactDocRenderer.default : ReactDocRenderer\n\n  var docs = [\n    " + options.docs.map(function (path) {
    return "(function(){\n          var component = require(\"" + path + "\");\n          return {\n            path:\"" + path + "\",\n            component:component,\n            meta:component.meta\n          }\n        })()";
  }).join(',') + "\n  ];\n  \n  ReactDOM.render(\n     React.createElement(ReactDocRenderer,{docs:docs}),\n     document.getElementById('root')\n  );\n  ";
  return {
    code: code
  };
};<file_sep>const path = require('path')
const fs = require('fs-extra')
const cwd = process.cwd()

const toArr = val => (Array.isArray(val) ? val : val ? [val] : [])

module.exports = function(options) {
  const rendererPath = options.renderer
    ? options.renderer
    : path.resolve(cwd, './doc-scripts.renderer.js')
  let hasRenderer = false
  try {
    fs.accessSync(rendererPath)
    hasRenderer = true
  } catch (e) {}

  const code = `
  var React = require('react')
  var ReactDOM = require('react-dom')
  var ReactDocRenderer = require('${
    hasRenderer ? rendererPath : 'react-doc-renderer'
  }')
  ${toArr(options.requires).map(path => {
    return `require("${path}")`
  })}
  ReactDocRenderer = ReactDocRenderer.__esModule ? ReactDocRenderer.default : ReactDocRenderer

  var docs = [
    ${options.docs
      .map(path => {
        return `(function(){
          var component = require("${path}");
          return {
            path:"${path}",
            component:component,
            meta:component.meta
          }
        })()`
      })
      .join(',')}
  ];
  
  ReactDOM.render(
     React.createElement(ReactDocRenderer,{docs:docs}),
     document.getElementById('root')
  );
  `

  return {
    code
  }
}
