'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

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

var _fsExtra2 = _interopRequireDefault(_fsExtra);

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _cli = require('../../cli');

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

var route = function route(req, res) {
  var resHtml = '';

  var page = _path2.default.join(__dirname + '/../views/list-structure.html');
  if (_cli.coreUtils.file.exist(page)) {
    resHtml = _fsExtra2.default.readFileSync(page, 'utf8');
  }

  var structure = _cli.Manager.instance.getStructureAndTemplates().structure;
  structure = JSON.stringify(structure).replace(new RegExp(_cli.config.root, 'g'), '');
  var template = _cli.Handlebars.compile(resHtml, { noEscape: true });
  var tmp = template({
    config: JSON.stringify(_cli.config),
    structure: structure
  });
  return res.send(tmp);
};

exports.default = route;