'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports['default'] = generateEntryFile;

var _fs = require('fs');

var _fs2 = _interopRequireDefault(_fs);

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _nunjucks = require('nunjucks');

var _nunjucks2 = _interopRequireDefault(_nunjucks);

var _context = require('./context');

var _context2 = _interopRequireDefault(_context);

var _getRoutesPath = require('./getRoutesPath');

var _getRoutesPath2 = _interopRequireDefault(_getRoutesPath);

var _escapeWinPath = require('./escapeWinPath');

var _escapeWinPath2 = _interopRequireDefault(_escapeWinPath);

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

var entryTemplate = _fs2['default'].readFileSync(_path2['default'].join(__dirname, '../../nunjucks/entry.nunjucks.js')).toString();
var entryWithoutSiderTemplate = _fs2['default'].readFileSync(_path2['default'].join(__dirname, '../../nunjucks/entrywithoutsider.nunjucks.js')).toString();

function generateEntryFile(mainPackage, configEntryName) {
  var tmpDirPath = _context2['default'].tmpDirPath,
      isDev = _context2['default'].isDev;

  var entryPath = _path2['default'].join(tmpDirPath, 'entry.' + configEntryName + '.js');
  var entryWithoutSiderPath = _path2['default'].join(tmpDirPath, 'entry.withoutsider.js');
  var routesPath = (0, _getRoutesPath2['default'])(mainPackage, configEntryName);
  _fs2['default'].writeFileSync(entryPath, _nunjucks2['default'].renderString(entryTemplate, {
    routesPath: (0, _escapeWinPath2['default'])(routesPath),
    source: isDev ? 'src' : 'lib'
  }));
  _fs2['default'].writeFileSync(entryWithoutSiderPath, _nunjucks2['default'].renderString(entryWithoutSiderTemplate, {
    routesPath: (0, _escapeWinPath2['default'])(routesPath),
    source: isDev ? 'src' : 'lib'
  }));
}