"use strict";

var _fs = _interopRequireDefault(require("fs"));

var _getOptions = _interopRequireDefault(require("../utils/getOptions.js"));

var _path = _interopRequireDefault(require("path"));

var _reactLiveConvertor = require("./reactLiveConvertor");

var _markdownLoader = require("./markdownLoader.js");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

module.exports = function (source) {
  const comNameAry = this.resourcePath.split(_path.default.sep);
  const filePath = this.resourcePath;

  const appPath = _fs.default.realpathSync(process.cwd());

  const changePath = filePath.replace('/lib/', '/src/');
  const comName = comNameAry[comNameAry.length - 1];
  const name = comName.substring(0, comName.lastIndexOf('.'));
  const options = (0, _getOptions.default)();
  const originalFilePath = filePath.startsWith(appPath) ? filePath : changePath;

  const src = _fs.default.readFileSync(originalFilePath).toString();

  options.docs.enableMDParser && (source = (0, _markdownLoader.markdownParser)(source));
  options.docs.enableReactLive && (source = (0, _reactLiveConvertor.reactLiveConvertor)(source, originalFilePath)); //to Enable the ReactLive Converter

  return `${source};${name}.source=${JSON.stringify(src)};${name}.filePath=${JSON.stringify(filePath)}`;
};